diff --git a/JsonGeneratorTests/JsonArray.h b/JsonGeneratorTests/JsonArray.h index 72faf572..ef955861 100644 --- a/JsonGeneratorTests/JsonArray.h +++ b/JsonGeneratorTests/JsonArray.h @@ -16,7 +16,7 @@ public: void add(const char* data) { - if (itemCount <= N) + if (itemCount < N) items[itemCount++] = data; } diff --git a/JsonGeneratorTests/JsonArrayTests.cpp b/JsonGeneratorTests/JsonArrayTests.cpp index d372021e..d06d2e75 100644 --- a/JsonGeneratorTests/JsonArrayTests.cpp +++ b/JsonGeneratorTests/JsonArrayTests.cpp @@ -7,7 +7,7 @@ namespace JsonGeneratorTests { TEST_CLASS(JsonArrayTests) { - JsonArray<3> arr; + JsonArray<2> arr; public: @@ -31,6 +31,15 @@ namespace JsonGeneratorTests AssertJsonIs("['hello','world']"); } + TEST_METHOD(OverCapacity) + { + arr.add("hello"); + arr.add("world"); + arr.add("lost"); + + AssertJsonIs("['hello','world']"); + } + void AssertJsonIs(const char* expected) { char buffer[256];