JsonString.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2021
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include <sstream>
  7. TEST_CASE("JsonString") {
  8. SECTION("Default constructor creates a null JsonString") {
  9. JsonString s;
  10. CHECK(s.isNull() == true);
  11. CHECK(s.c_str() == 0);
  12. CHECK(s.isStatic() == true);
  13. }
  14. SECTION("Compare null with boolean") {
  15. JsonString s;
  16. CHECK(bool(s) == false);
  17. CHECK(false == bool(s));
  18. CHECK(bool(s) != true);
  19. CHECK(true != bool(s));
  20. }
  21. SECTION("Compare non-null with boolean") {
  22. JsonString s("hello");
  23. CHECK(bool(s) == true);
  24. CHECK(true == bool(s));
  25. CHECK(bool(s) != false);
  26. CHECK(false != bool(s));
  27. }
  28. SECTION("Compare null with null") {
  29. JsonString a, b;
  30. CHECK(a == b);
  31. CHECK_FALSE(a != b);
  32. }
  33. SECTION("Compare null with non-null") {
  34. JsonString a(0), b("hello");
  35. CHECK_FALSE(a == b);
  36. CHECK(a != b);
  37. }
  38. SECTION("Compare non-null with null") {
  39. JsonString a("hello"), b(0);
  40. CHECK_FALSE(a == b);
  41. CHECK(a != b);
  42. }
  43. SECTION("Compare different strings") {
  44. JsonString a("hello"), b("world");
  45. CHECK_FALSE(a == b);
  46. CHECK(a != b);
  47. }
  48. SECTION("Compare identical by pointer") {
  49. JsonString a("hello"), b("hello");
  50. CHECK(a == b);
  51. CHECK_FALSE(a != b);
  52. }
  53. SECTION("Compare identical by value") {
  54. char s1[] = "hello";
  55. char s2[] = "hello";
  56. JsonString a(s1), b(s2);
  57. CHECK(a == b);
  58. CHECK_FALSE(a != b);
  59. }
  60. SECTION("std::stream") {
  61. std::stringstream ss;
  62. ss << JsonString("hello world!");
  63. CHECK(ss.str() == "hello world!");
  64. }
  65. }