strdup.cpp 625 B

1234567891011121314151617181920212223242526
  1. // Copyright Benoit Blanchon 2014-2017
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://bblanchon.github.io/ArduinoJson/
  6. // If you like this project, please add a star!
  7. #include <ArduinoJson.h>
  8. #include <catch.hpp>
  9. TEST_CASE("DynamicJsonBuffer::strdup()") {
  10. DynamicJsonBuffer buffer;
  11. SECTION("Should return a copy") {
  12. char original[] = "hello";
  13. char* copy = buffer.strdup(original);
  14. strcpy(original, "world");
  15. REQUIRE(std::string("hello") == copy);
  16. }
  17. SECTION("Given NULL, return NULL") {
  18. const char* original = NULL;
  19. char* copy = buffer.strdup(original);
  20. REQUIRE(0 == copy);
  21. }
  22. }