Просмотр исходного кода

Fixed JsonArrayIterator unit test

Benoit Blanchon 11 лет назад
Родитель
Сommit
5d2ffc49fd
2 измененных файлов с 15 добавлено и 24 удалено
  1. 10 19
      JsonParser/JsonArrayIterator.h
  2. 5 5
      JsonParserTests/JsonArrayIteratorTests.cpp

+ 10 - 19
JsonParser/JsonArrayIterator.h

@@ -16,43 +16,34 @@ namespace ArduinoJson
 
 
         class JsonArrayIterator
         class JsonArrayIterator
         {
         {
-            friend class JsonArray;
-
         public:
         public:
 
 
-            JsonArrayIterator operator++()
+            JsonArrayIterator(char* json, Internal::JsonToken& token)
+                : json(json), token(token)
+            {
+
+            }
+
+            const JsonArrayIterator& operator++()
             {
             {
-                JsonArrayIterator prev = *this;
                 token = token.nextSibling();
                 token = token.nextSibling();
-                return prev;
+                return *this;
             }
             }
 
 
-            JsonValue operator*()
+            JsonValue operator*() const
             {
             {
                 return JsonValue(json, token);
                 return JsonValue(json, token);
             }
             }
 
 
             bool operator !=(const JsonArrayIterator& other)
             bool operator !=(const JsonArrayIterator& other)
             {
             {
-                return token != other.token || json != other.json;
+                return token != other.token;
             }
             }
 
 
         private:
         private:
 
 
             char* json;
             char* json;
             Internal::JsonToken token;
             Internal::JsonToken token;
-
-            JsonArrayIterator()
-                : json(0), token(0)
-            {
-
-            }
-
-            JsonArrayIterator(char* json, Internal::JsonToken& token)
-                : json(json), token(token)
-            {
-
-            }
         };
         };
     }
     }
 }
 }

+ 5 - 5
JsonParserTests/JsonArrayIteratorTests.cpp

@@ -14,16 +14,16 @@ namespace JsonParserTests
 		TEST_METHOD(ThreeIntegers)
 		TEST_METHOD(ThreeIntegers)
 		{
 		{
             char json [] = "[1,2,3]";
             char json [] = "[1,2,3]";
+            long expected [] = { 1, 2, 3 };
             JsonParser<4> parser;
             JsonParser<4> parser;
 
 
             JsonArray a = parser.parse(json);
             JsonArray a = parser.parse(json);
-            
-            long expected = 1;
 
 
-            for (auto i : a)
+            int index = 0;
+
+            for (long i : a)
             {
             {
-                Assert::AreEqual(expected, (long)*i);
-                expected++;
+                Assert::AreEqual(expected[index++], i);
             }
             }
 		}
 		}