mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	Added unit tests of sample string given by gbatree
This commit is contained in:
		| @@ -97,6 +97,7 @@ | ||||
|     <ClCompile Include="..\utility\jsmn.cpp" /> | ||||
|     <ClCompile Include="TestArrayExample.cpp" /> | ||||
|     <ClCompile Include="TestHashTableExample.cpp" /> | ||||
|     <ClCompile Include="TestGbathreeStrings.cpp" /> | ||||
|   </ItemGroup> | ||||
|   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||||
|   <ImportGroup Label="ExtensionTargets"> | ||||
|   | ||||
| @@ -50,5 +50,8 @@ | ||||
|     <ClCompile Include="TestArrayExample.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="TestGbathreeStrings.cpp"> | ||||
|       <Filter>Source Files</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
							
								
								
									
										68
									
								
								tests/TestGbathreeStrings.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								tests/TestGbathreeStrings.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| #include "CppUnitTest.h" | ||||
| #include "JsonParser.h" | ||||
| #include <string> | ||||
|  | ||||
| using namespace std; | ||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | ||||
|  | ||||
| namespace ArduinoJsonParserTests | ||||
| { | ||||
| 	TEST_CLASS(TestGbathreeSample1) | ||||
| 	{ | ||||
| 		char json[1024]; | ||||
| 		JsonParser<200> parser; | ||||
| 		JsonHashTable root; | ||||
| 		 | ||||
|  | ||||
| 	public: | ||||
|  | ||||
| 		TEST_METHOD_INITIALIZE(Initialize) | ||||
| 		{ | ||||
| 			strcpy(json, "{ \"protocol_name\":\"fluorescence\",\"repeats\":1,\"wait\":0,\"averages\":1,\"measurements\":3,\"meas2_light\":15,\"meas1_baseline\":0,\"act_light\":20,\"pulsesize\":25,\"pulsedistance\":10000,\"actintensity1\":50,\"actintensity2\":255,\"measintensity\":255,\"calintensity\":255,\"pulses\":[50,50,50],\"act\":[2,1,2,2],\"red\":[2,2,2,2],\"detectors\":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]],\"alta\":[2,2,2,2],\"altb\":[2,2,2,2],\"measlights\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"measlights2\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]],\"altc\":[2,2,2,2],\"altd\":[2,2,2,2]}"); | ||||
| 			root = parser.parseHashTable(json); | ||||
| 		} | ||||
|  | ||||
| 		TEST_METHOD(Root) | ||||
| 		{ | ||||
| 			Assert::IsTrue(root.success()); | ||||
| 		} | ||||
|  | ||||
| 		TEST_METHOD(ProtocolName) | ||||
| 		{ | ||||
| 			string protocol_name = root.getString("protocol_name"); | ||||
| 			Assert::AreEqual(string("fluorescence"), protocol_name); | ||||
| 		} | ||||
|  | ||||
| 		TEST_METHOD(Measlights) | ||||
| 		{ | ||||
| 			// measlights:[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]] | ||||
|  | ||||
| 			JsonArray measlights = root.getArray("altd"); | ||||
| 			Assert::IsTrue(measlights.success()); | ||||
| 			Assert::AreEqual(4, measlights.getLength()); | ||||
|  | ||||
| 			for (int i = 0; i < 4; i++) | ||||
| 			{ | ||||
| 				Assert::AreEqual(4, measlights.getArray(i).getLength()); | ||||
|  | ||||
| 				for (int j = 0; j < 4; j++) | ||||
| 					Assert::AreEqual(15L, measlights.getArray(i).getLong(j)); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		TEST_METHOD(Altd) | ||||
| 		{ | ||||
| 			// altd:[2,2,2,2] | ||||
|  | ||||
| 			JsonArray altd = root.getArray("altd"); | ||||
| 			Assert::IsTrue(altd.success()); | ||||
|  | ||||
| 			Assert::AreEqual(4, altd.getLength()); | ||||
|  | ||||
| 			for (int i = 0; i < 4; i++) | ||||
| 			{ | ||||
| 				Assert::AreEqual(2L, altd.getLong(i)); | ||||
| 			} | ||||
| 		} | ||||
| 	}; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user