swap.cpp 554 B

123456789101112131415161718192021222324252627
  1. #include <ArduinoJson.h>
  2. #include <catch.hpp>
  3. #include <string>
  4. #include <utility>
  5. using namespace std;
  6. TEST_CASE("std::swap") {
  7. SECTION("DynamicJsonDocument*") {
  8. DynamicJsonDocument *p1, *p2;
  9. swap(p1, p2); // issue #1678
  10. }
  11. SECTION("DynamicJsonDocument") {
  12. DynamicJsonDocument doc1(0x10), doc2(0x20);
  13. doc1.set("hello");
  14. doc2.set("world");
  15. swap(doc1, doc2);
  16. CHECK(doc1.capacity() == 0x20);
  17. CHECK(doc1.as<string>() == "world");
  18. CHECK(doc2.capacity() == 0x10);
  19. CHECK(doc2.as<string>() == "hello");
  20. }
  21. }