mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added a test of an empty hashtable
This commit is contained in:
		| @@ -11,23 +11,23 @@ namespace JsonGeneratorTests | ||||
|          | ||||
|     public: | ||||
|          | ||||
|         TEST_METHOD(EmptyArray) | ||||
|         TEST_METHOD(Empty) | ||||
|         { | ||||
|             AssertJsonIs("[]"); | ||||
|             assertJsonIs("[]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddNull) | ||||
|         { | ||||
|             arr.add((char*)0); | ||||
|  | ||||
|             AssertJsonIs("[null]"); | ||||
|             assertJsonIs("[null]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddOneString) | ||||
|         { | ||||
|             arr.add("hello"); | ||||
|  | ||||
|             AssertJsonIs("[\"hello\"]"); | ||||
|             assertJsonIs("[\"hello\"]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddTwoStrings) | ||||
| @@ -35,7 +35,7 @@ namespace JsonGeneratorTests | ||||
|             arr.add("hello"); | ||||
|             arr.add("world"); | ||||
|  | ||||
|             AssertJsonIs("[\"hello\",\"world\"]"); | ||||
|             assertJsonIs("[\"hello\",\"world\"]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddOneStringOverCapacity) | ||||
| @@ -44,14 +44,14 @@ namespace JsonGeneratorTests | ||||
|             arr.add("world"); | ||||
|             arr.add("lost"); | ||||
|  | ||||
|             AssertJsonIs("[\"hello\",\"world\"]"); | ||||
|             assertJsonIs("[\"hello\",\"world\"]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddOneNumber) | ||||
|         { | ||||
|             arr.add(3.14); | ||||
|  | ||||
|             AssertJsonIs("[3.14]"); | ||||
|             assertJsonIs("[3.14]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddTwoNumbers) | ||||
| @@ -59,7 +59,7 @@ namespace JsonGeneratorTests | ||||
|             arr.add(3.14); | ||||
|             arr.add(2.72); | ||||
|  | ||||
|             AssertJsonIs("[3.14,2.72]"); | ||||
|             assertJsonIs("[3.14,2.72]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddOneNumberOverCapacity) | ||||
| @@ -68,21 +68,21 @@ namespace JsonGeneratorTests | ||||
|             arr.add(2.72); | ||||
|             arr.add(1.41); | ||||
|  | ||||
|             AssertJsonIs("[3.14,2.72]"); | ||||
|             assertJsonIs("[3.14,2.72]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddTrue) | ||||
|         { | ||||
|             arr.add(true); | ||||
|  | ||||
|             AssertJsonIs("[true]"); | ||||
|             assertJsonIs("[true]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddFalse) | ||||
|         { | ||||
|             arr.add(false); | ||||
|  | ||||
|             AssertJsonIs("[false]"); | ||||
|             assertJsonIs("[false]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddTwoBooleans) | ||||
| @@ -90,7 +90,7 @@ namespace JsonGeneratorTests | ||||
|             arr.add(false); | ||||
|             arr.add(true); | ||||
|  | ||||
|             AssertJsonIs("[false,true]"); | ||||
|             assertJsonIs("[false,true]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddOneBooleanOverCapacity) | ||||
| @@ -99,7 +99,7 @@ namespace JsonGeneratorTests | ||||
|             arr.add(true); | ||||
|             arr.add(false); | ||||
|  | ||||
|             AssertJsonIs("[false,true]"); | ||||
|             assertJsonIs("[false,true]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddOneEmptyNestedArray) | ||||
| @@ -108,7 +108,7 @@ namespace JsonGeneratorTests | ||||
|              | ||||
|             arr.add(nestedArray); | ||||
|  | ||||
|             AssertJsonIs("[[]]"); | ||||
|             assertJsonIs("[[]]"); | ||||
|         } | ||||
|  | ||||
|         TEST_METHOD(AddOneNestedArrayWithOneItem) | ||||
| @@ -118,10 +118,12 @@ namespace JsonGeneratorTests | ||||
|  | ||||
|             arr.add(nestedArray); | ||||
|  | ||||
|             AssertJsonIs("[[3.14]]"); | ||||
|             assertJsonIs("[[3.14]]"); | ||||
|         } | ||||
|  | ||||
|         void AssertJsonIs(const char* expected) | ||||
|     private: | ||||
|  | ||||
|         void assertJsonIs(const char* expected) | ||||
|         {       | ||||
|             char buffer[256]; | ||||
|  | ||||
|   | ||||
| @@ -83,6 +83,7 @@ | ||||
|   </ItemDefinitionGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="JsonArrayTests.cpp" /> | ||||
|     <ClCompile Include="JsonHashTableTests.cpp" /> | ||||
|     <ClCompile Include="JsonObjectBase.cpp" /> | ||||
|     <ClCompile Include="StringBuilder.cpp" /> | ||||
|     <ClCompile Include="StringBuilderAppendEscapedTests.cpp" /> | ||||
| @@ -90,6 +91,7 @@ | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="JsonArray.h" /> | ||||
|     <ClInclude Include="JsonHashTable.h" /> | ||||
|     <ClInclude Include="JsonObjectBase.h" /> | ||||
|     <ClInclude Include="StringBuilder.h" /> | ||||
|   </ItemGroup> | ||||
|   | ||||
| @@ -30,6 +30,9 @@ | ||||
|     <ClCompile Include="StringBuilderAppendTests.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="JsonHashTableTests.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="JsonArray.h"> | ||||
| @@ -41,5 +44,8 @@ | ||||
|     <ClInclude Include="JsonObjectBase.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="JsonHashTable.h"> | ||||
|       <Filter>Header Files</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
							
								
								
									
										38
									
								
								JsonGeneratorTests/JsonHashTable.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								JsonGeneratorTests/JsonHashTable.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| /* | ||||
|  * Arduino JSON library | ||||
|  * Benoit Blanchon 2014 - MIT License | ||||
|  */ | ||||
|  | ||||
| #pragma once | ||||
|  | ||||
| #include "JsonObjectBase.h" | ||||
|  | ||||
| template<int N> | ||||
| class JsonHashTable : public JsonObjectBase | ||||
| { | ||||
| public: | ||||
|  | ||||
|     using JsonObjectBase::writeTo; | ||||
|  | ||||
| private: | ||||
|  | ||||
|    /* struct KeyValuePair | ||||
|     { | ||||
|         const char* key; | ||||
|         ObjectContainer value; | ||||
|     };*/ | ||||
|  | ||||
|     virtual void writeTo(StringBuilder& sb) | ||||
|     { | ||||
|         sb.append("{"); | ||||
|  | ||||
|         /*for (int i = 0; i < itemCount; i++) | ||||
|         { | ||||
|             if (i>0) sb.append(","); | ||||
|             writeObjectTo(items[i], sb); | ||||
|         }*/ | ||||
|  | ||||
|         sb.append("}"); | ||||
|     } | ||||
| }; | ||||
|  | ||||
							
								
								
									
										30
									
								
								JsonGeneratorTests/JsonHashTableTests.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								JsonGeneratorTests/JsonHashTableTests.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| #include "CppUnitTest.h" | ||||
| #include "JsonHashTable.h" | ||||
|  | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
|  | ||||
| namespace JsonGeneratorTests | ||||
| { | ||||
|     TEST_CLASS(JsonHashTableTests) | ||||
|     { | ||||
|         JsonHashTable<2> hash; | ||||
|  | ||||
|     public: | ||||
|          | ||||
|         TEST_METHOD(Empty) | ||||
|         { | ||||
|             assertJsonIs("{}"); | ||||
|         } | ||||
|  | ||||
|     private: | ||||
|  | ||||
|         void assertJsonIs(const char* expected) | ||||
|         { | ||||
|             char buffer[256]; | ||||
|  | ||||
|             hash.writeTo(buffer, sizeof(buffer)); | ||||
|  | ||||
|             Assert::AreEqual(expected, buffer); | ||||
|         } | ||||
|     }; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user