Bläddra i källkod

Added a failng test

Benoit Blanchon 11 år sedan
förälder
incheckning
c1f4128ccd

+ 5 - 0
JsonGenerator/JsonValue.h

@@ -59,6 +59,11 @@ namespace ArduinoJson
                 content.asDouble = value;
             }
 
+            operator const char*()
+            {
+                return "";
+            }
+
             size_t printTo(Print& p) const
             {
                 // handmade polymorphism

+ 1 - 0
JsonGeneratorTests/JsonGeneratorTests.vcxproj

@@ -86,6 +86,7 @@
   <ItemGroup>
     <ClCompile Include="EscapedStringTests.cpp" />
     <ClCompile Include="JsonArrayTests.cpp" />
+    <ClCompile Include="JsonObject_Indexer_Tests.cpp" />
     <ClCompile Include="JsonObject_PrintTo_Tests.cpp" />
     <ClCompile Include="JsonValueTests.cpp" />
     <ClCompile Include="StringBuilderTests.cpp" />

+ 3 - 0
JsonGeneratorTests/JsonGeneratorTests.vcxproj.filters

@@ -30,5 +30,8 @@
     <ClCompile Include="JsonObject_PrintTo_Tests.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="JsonObject_Indexer_Tests.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 42 - 0
JsonGeneratorTests/JsonObject_Indexer_Tests.cpp

@@ -0,0 +1,42 @@
+/*
+* Arduino JSON library
+* Benoit Blanchon 2014 - MIT License
+*/
+
+#include "CppUnitTest.h"
+#include "JsonArray.h"
+#include "JsonObject.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+using namespace ArduinoJson::Generator;
+
+namespace JsonGeneratorTests
+{
+    TEST_CLASS(JsonObject_Indexer_Tests)
+    {
+        JsonObject<2> object;
+
+    public:
+
+    /*    TEST_METHOD(Empty)
+        {
+            mustNotContain("key");
+        }*/
+
+        TEST_METHOD(OneString)
+        {
+            object["key"] = "value";
+
+            mustContain("key", "value");
+        }
+
+
+    private:
+
+        void mustContain(const char* key, const char* expected)
+        {
+            auto actual = (const char*) object[key];
+            Assert::AreEqual(expected, actual);
+        }
+    };
+}