JsonString.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2021
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("JsonString") {
  7. SECTION("Default constructor creates a null JsonString") {
  8. JsonString s;
  9. CHECK(s.isNull() == true);
  10. CHECK(s.c_str() == 0);
  11. CHECK(s.isStatic() == true);
  12. }
  13. SECTION("Compare null with null") {
  14. JsonString a, b;
  15. CHECK(a == b);
  16. CHECK_FALSE(a != b);
  17. }
  18. SECTION("Compare null with non-null") {
  19. JsonString a(0), b("hello");
  20. CHECK_FALSE(a == b);
  21. CHECK(a != b);
  22. }
  23. SECTION("Compare non-null with null") {
  24. JsonString a("hello"), b(0);
  25. CHECK_FALSE(a == b);
  26. CHECK(a != b);
  27. }
  28. SECTION("Compare different strings") {
  29. JsonString a("hello"), b("world");
  30. CHECK_FALSE(a == b);
  31. CHECK(a != b);
  32. }
  33. SECTION("Compare identical by pointer") {
  34. JsonString a("hello"), b("hello");
  35. CHECK(a == b);
  36. CHECK_FALSE(a != b);
  37. }
  38. SECTION("Compare identical by value") {
  39. char s1[] = "hello";
  40. char s2[] = "hello";
  41. JsonString a(s1), b(s2);
  42. CHECK(a == b);
  43. CHECK_FALSE(a != b);
  44. }
  45. }