JsonVariant_Comparison_Tests.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright Benoit Blanchon 2014
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. #include <gtest/gtest.h>
  7. #include <ArduinoJson/JsonVariant.hpp>
  8. #include "Printers.hpp"
  9. using namespace ArduinoJson;
  10. class JsonVariant_Comparison_Tests : public ::testing::Test {
  11. protected:
  12. template <typename T>
  13. void testValue(T low, T mid, T high) {
  14. setValueTo(mid);
  15. mustBeEqualTo(mid);
  16. mustBeGreaterThan(low);
  17. mustBeLessThan(high);
  18. }
  19. private:
  20. template <typename T>
  21. void setValueTo(T expected) {
  22. actual = expected;
  23. }
  24. template <typename T>
  25. void mustBeEqualTo(T expected) {
  26. EXPECT_EQ(expected, actual); // operator==
  27. EXPECT_EQ(actual, expected); // operator==
  28. EXPECT_LE(expected, actual); // operator<=
  29. EXPECT_LE(actual, expected); // operator<=
  30. EXPECT_GE(expected, actual); // operator>=
  31. EXPECT_GE(actual, expected); // operator>=
  32. }
  33. template <typename T>
  34. void mustBeGreaterThan(T expected) {
  35. EXPECT_GT(actual, expected); // operator>
  36. EXPECT_LT(expected, actual); // operator<
  37. EXPECT_NE(actual, expected); // operator!=
  38. EXPECT_NE(expected, actual); // operator!=
  39. }
  40. template <typename T>
  41. void mustBeLessThan(T expected) {
  42. EXPECT_LT(actual, expected); // operator<
  43. EXPECT_GT(expected, actual); // operator<
  44. EXPECT_NE(actual, expected); // operator!=
  45. EXPECT_NE(expected, actual); // operator!=
  46. }
  47. JsonVariant actual;
  48. };
  49. TEST_F(JsonVariant_Comparison_Tests, Double) {
  50. testValue<double>(123.44, 123.45, 123.46);
  51. }
  52. TEST_F(JsonVariant_Comparison_Tests, Float) {
  53. testValue<float>(123.44f, 123.45f, 123.46f);
  54. }
  55. TEST_F(JsonVariant_Comparison_Tests, SChar) {
  56. testValue<signed char>(122, 123, 124);
  57. }
  58. TEST_F(JsonVariant_Comparison_Tests, SInt) {
  59. testValue<signed int>(122, 123, 124);
  60. }
  61. TEST_F(JsonVariant_Comparison_Tests, SLong) {
  62. testValue<signed long>(122L, 123L, 124L);
  63. }
  64. TEST_F(JsonVariant_Comparison_Tests, SShort) {
  65. testValue<signed short>(122, 123, 124);
  66. }
  67. TEST_F(JsonVariant_Comparison_Tests, UChar) {
  68. testValue<unsigned char>(122, 123, 124);
  69. }
  70. TEST_F(JsonVariant_Comparison_Tests, UInt) {
  71. testValue<unsigned int>(122, 123, 124);
  72. }
  73. TEST_F(JsonVariant_Comparison_Tests, ULong) {
  74. testValue<unsigned long>(122L, 123L, 124L);
  75. }
  76. TEST_F(JsonVariant_Comparison_Tests, UShort) {
  77. testValue<unsigned short>(122, 123, 124);
  78. }