mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added unit tests on multi-dimensional arrays to isolate the bug
This commit is contained in:
		| @@ -96,6 +96,7 @@ | ||||
|     <ClCompile Include="..\JsonObjectBase.cpp" /> | ||||
|     <ClCompile Include="..\utility\jsmn.cpp" /> | ||||
|     <ClCompile Include="TestArrayExample.cpp" /> | ||||
|     <ClCompile Include="TestArrays.cpp" /> | ||||
|     <ClCompile Include="TestHashTableExample.cpp" /> | ||||
|     <ClCompile Include="TestGbathreeStrings.cpp" /> | ||||
|   </ItemGroup> | ||||
|   | ||||
| @@ -53,5 +53,8 @@ | ||||
|     <ClCompile Include="TestGbathreeStrings.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="TestArrays.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
							
								
								
									
										77
									
								
								tests/TestArrays.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								tests/TestArrays.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | ||||
| #include "CppUnitTest.h" | ||||
| #include "JsonParser.h" | ||||
|  | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
|  | ||||
| namespace ArduinoJsonParserTests | ||||
| { | ||||
| 	TEST_CLASS(TestArrays) | ||||
| 	{ | ||||
| 		JsonParser<32> parser; | ||||
|  | ||||
| 	public: | ||||
| 		 | ||||
| 		TEST_METHOD(OneDimensionArray) | ||||
| 		{ | ||||
| 			char json [] = "[0,0]"; | ||||
|  | ||||
| 			JsonArray array = parser.parseArray(json); | ||||
| 			Assert::IsTrue(array.success()); | ||||
| 			Assert::AreEqual(2, array.getLength()); | ||||
|  | ||||
| 			for (int i = 0; i < 2; i++) | ||||
| 			{ | ||||
| 				Assert::AreEqual(0L, array.getLong(i)); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		TEST_METHOD(TwoDimensionArray) | ||||
| 		{ | ||||
| 			char json[] = "[[0,0],[0,0]]"; | ||||
|  | ||||
| 			JsonArray array1 = parser.parseArray(json); | ||||
| 			Assert::IsTrue(array1.success()); | ||||
| 			Assert::AreEqual(2, array1.getLength()); | ||||
|  | ||||
| 			for (int i = 0; i < 2; i++) | ||||
| 			{ | ||||
| 				JsonArray array2 = array1.getArray(i); | ||||
|  | ||||
| 				Assert::AreEqual(2, array2.getLength()); | ||||
|  | ||||
| 				for (int j = 0; j < 2; j++) | ||||
| 				{ | ||||
| 					Assert::AreEqual(0L, array2.getLong(j)); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		TEST_METHOD(TreeDimensionArray) | ||||
| 		{ | ||||
| 			char json[] = "[[[0,0],[0,0]],[[0,0],[0,0]]]]"; | ||||
|  | ||||
| 			JsonArray array1 = parser.parseArray(json); | ||||
| 			Assert::IsTrue(array1.success()); | ||||
| 			Assert::AreEqual(2, array1.getLength()); | ||||
|  | ||||
| 			for (int i = 0; i < 2; i++) | ||||
| 			{ | ||||
| 				JsonArray array2 = array1.getArray(i); | ||||
|  | ||||
| 				Assert::AreEqual(2, array2.getLength()); | ||||
|  | ||||
| 				for (int j = 0; j < 2; j++) | ||||
| 				{ | ||||
| 					JsonArray array3 = array2.getArray(j); | ||||
|  | ||||
| 					Assert::AreEqual(2, array3.getLength()); | ||||
|  | ||||
| 					for (int k = 0; k < 2; k++) | ||||
| 					{ | ||||
| 						Assert::AreEqual(0L, array3.getLong(k)); | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	}; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user