Issue34.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright Benoit Blanchon 2014-2017
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. // If you like this project, please add a star!
  7. #include <ArduinoJson.h>
  8. #include <gtest/gtest.h>
  9. class Issue34 : public testing::Test {
  10. protected:
  11. template <typename T>
  12. void test_with_value(T expected) {
  13. StaticJsonBuffer<JSON_OBJECT_SIZE(1)> jsonBuffer;
  14. JsonObject& jsonObject = jsonBuffer.createObject();
  15. jsonObject["key"] = expected;
  16. T actual = jsonObject["key"];
  17. ASSERT_EQ(expected, actual);
  18. }
  19. };
  20. TEST_F(Issue34, int8_t) {
  21. test_with_value<int8_t>(1);
  22. }
  23. TEST_F(Issue34, uint8_t) {
  24. test_with_value<uint8_t>(2);
  25. }
  26. TEST_F(Issue34, int16_t) {
  27. test_with_value<int16_t>(3);
  28. }
  29. TEST_F(Issue34, uint16_t) {
  30. test_with_value<uint16_t>(4);
  31. }
  32. TEST_F(Issue34, int32_t) {
  33. test_with_value<int32_t>(5);
  34. }
  35. TEST_F(Issue34, uint32_t) {
  36. test_with_value<uint32_t>(6);
  37. }
  38. TEST_F(Issue34, float) {
  39. test_with_value<float>(7);
  40. }
  41. TEST_F(Issue34, double) {
  42. test_with_value<double>(8);
  43. }