StringAdapters.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include "custom_string.hpp"
  7. using namespace ARDUINOJSON_NAMESPACE;
  8. TEST_CASE("ConstRamStringAdapter") {
  9. SECTION("null") {
  10. ConstRamStringAdapter adapter(NULL);
  11. REQUIRE(adapter.compare("bravo") < 0);
  12. REQUIRE(adapter.compare(NULL) == 0);
  13. REQUIRE(adapter.equals(NULL));
  14. REQUIRE_FALSE(adapter.equals("charlie"));
  15. }
  16. SECTION("non-null") {
  17. ConstRamStringAdapter adapter("bravo");
  18. REQUIRE(adapter.compare(NULL) > 0);
  19. REQUIRE(adapter.compare("alpha") > 0);
  20. REQUIRE(adapter.compare("bravo") == 0);
  21. REQUIRE(adapter.compare("charlie") < 0);
  22. REQUIRE(adapter.equals("bravo"));
  23. REQUIRE_FALSE(adapter.equals("charlie"));
  24. }
  25. }
  26. TEST_CASE("std::string") {
  27. std::string str("bravo");
  28. StlStringAdapter<std::string> adapter = adaptString(str);
  29. REQUIRE(adapter.compare(NULL) > 0);
  30. REQUIRE(adapter.compare("alpha") > 0);
  31. REQUIRE(adapter.compare("bravo") == 0);
  32. REQUIRE(adapter.compare("charlie") < 0);
  33. REQUIRE(adapter.equals("bravo"));
  34. REQUIRE_FALSE(adapter.equals("charlie"));
  35. }
  36. TEST_CASE("custom_string") {
  37. custom_string str("bravo");
  38. StlStringAdapter<custom_string> adapter = adaptString(str);
  39. REQUIRE(adapter.compare(NULL) > 0);
  40. REQUIRE(adapter.compare("alpha") > 0);
  41. REQUIRE(adapter.compare("bravo") == 0);
  42. REQUIRE(adapter.compare("charlie") < 0);
  43. REQUIRE(adapter.equals("bravo"));
  44. REQUIRE_FALSE(adapter.equals("charlie"));
  45. }
  46. TEST_CASE("IsString<T>") {
  47. SECTION("std::string") {
  48. REQUIRE(IsString<std::string>::value == true);
  49. }
  50. SECTION("basic_string<wchar_t>") {
  51. REQUIRE(IsString<std::basic_string<wchar_t> >::value == false);
  52. }
  53. SECTION("custom_string") {
  54. REQUIRE(IsString<custom_string>::value == true);
  55. }
  56. }