JsonObjectTests.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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, GivenAnIntegerStored_WhenRetreivingTheValue_ThenTheValueIsTheSame)
  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. }
  31. TEST(JsonObjectTests, GivenAnDoubleStored_WhenRetreivingTheValue_ThenTheValueIsTheSame)
  32. {
  33. StaticJsonBuffer<42> json;
  34. JsonObject object = json.createObject();
  35. object["hello"] = 123.45;
  36. object["world"] = 456.78;
  37. EXPECT_EQ(123.45, (double) object["hello"]);
  38. EXPECT_EQ(456.78, (double) object["world"]);
  39. }