| 
									
										
										
										
											2014-07-22 20:33:17 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  | * Arduino JSON library | 
					
						
							|  |  |  | * Benoit Blanchon 2014 - MIT License | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-17 13:58:30 +02:00
										 |  |  | #include "CppUnitTest.h"
 | 
					
						
							|  |  |  | #include "JsonParser.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace Microsoft::VisualStudio::CppUnitTestFramework; | 
					
						
							|  |  |  | using namespace ArduinoJson::Parser; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace JsonParserTests | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-22 20:33:17 +02:00
										 |  |  |     TEST_CLASS(JsonArrayIteratorTests) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     public: | 
					
						
							| 
									
										
										
										
											2014-07-19 14:55:16 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         TEST_METHOD(EmptyJson) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             char json[] = ""; | 
					
						
							|  |  |  |             JsonParser<1> parser; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             JsonArray a = parser.parse(json); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             int loopCount = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (long i : a) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 loopCount++; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             Assert::AreEqual(0, loopCount); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-07-22 20:33:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         TEST_METHOD(ThreeIntegers) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2014-07-19 14:49:59 +02:00
										 |  |  |             char json [] = "[1,2,3]"; | 
					
						
							| 
									
										
										
										
											2014-07-22 20:33:17 +02:00
										 |  |  |             long expected [] = {1, 2, 3}; | 
					
						
							| 
									
										
										
										
											2014-07-19 14:49:59 +02:00
										 |  |  |             JsonParser<4> parser; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-19 14:55:16 +02:00
										 |  |  |             JsonArray a = parser.parse(json); | 
					
						
							| 
									
										
										
										
											2014-07-17 13:58:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-18 16:10:19 +02:00
										 |  |  |             int index = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-19 14:49:59 +02:00
										 |  |  |             for (long i : a) | 
					
						
							| 
									
										
										
										
											2014-07-17 13:58:30 +02:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2014-07-19 14:49:59 +02:00
										 |  |  |                 Assert::AreEqual(expected[index++], i); | 
					
						
							| 
									
										
										
										
											2014-07-17 13:58:30 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2014-07-22 20:33:17 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-07-19 16:15:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         TEST_METHOD(ThreeStrings) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             char json[] = "[\"1\",\"2\",\"3\"]"; | 
					
						
							| 
									
										
										
										
											2014-07-22 20:33:17 +02:00
										 |  |  |             char* expected[] = {"1", "2", "3"}; | 
					
						
							| 
									
										
										
										
											2014-07-19 16:15:57 +02:00
										 |  |  |             JsonParser<4> parser; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             JsonArray a = parser.parse(json); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             int index = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (const char* i : a) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 Assert::AreEqual(expected[index++], i); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-07-22 20:33:17 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2014-07-17 13:58:30 +02:00
										 |  |  | } |