JsonObjectTests.cpp 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <gtest/gtest.h>
  2. #include <StaticJsonBuffer.h>
  3. #include <JsonValue.h>
  4. TEST(JsonObjectTests, WhenValueIsAdded_ThenSizeIsIncreasedByOne)
  5. {
  6. StaticJsonBuffer<42> json;
  7. JsonObject object = json.createObject();
  8. object["hello"];
  9. EXPECT_EQ(1, object.size());
  10. object["world"];
  11. EXPECT_EQ(2, object.size());
  12. }
  13. TEST(JsonObjectTests, WhenTheSameValueIsAddedTwice_ThenSizeIsOnlyIncreasedByOne)
  14. {
  15. StaticJsonBuffer<42> json;
  16. JsonObject object = json.createObject();
  17. object["hello"];
  18. EXPECT_EQ(1, object.size());
  19. object["hello"];
  20. EXPECT_EQ(1, object.size());
  21. }
  22. TEST(JsonObjectTests, WhenAnIntegerIsStore_TheSameIntegerIsRetreived)
  23. {
  24. StaticJsonBuffer<42> json;
  25. JsonObject object = json.createObject();
  26. object["hello"] = 123;
  27. object["world"] = 456;
  28. EXPECT_EQ(123, (int) object["hello"]);
  29. EXPECT_EQ(456, (int) object["world"]);
  30. }