no_memory.cpp 973 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ARDUINOJSON_NAMESPACE;
  7. struct NoMemoryAllocator {
  8. void* allocate(size_t) {
  9. return NULL;
  10. }
  11. void deallocate(void*) {}
  12. };
  13. TEST_CASE("DynamicMemoryPool no memory") {
  14. DynamicMemoryPoolBase<NoMemoryAllocator> _memoryPool;
  15. typedef DynamicMemoryPoolBase<NoMemoryAllocator>::StringBuilder StringBuilder;
  16. SECTION("FixCodeCoverage") {
  17. // call this function to fix code coverage
  18. NoMemoryAllocator().deallocate(NULL);
  19. }
  20. // TODO: uncomment
  21. // SECTION("deserializeJson()") {
  22. // char json[] = "{[]}";
  23. // DynamicJsonDocument obj;
  24. // DeserializationError err = deserializeJson(obj, json);
  25. // REQUIRE(err != DeserializationError::Ok);
  26. // }
  27. SECTION("startString()") {
  28. StringBuilder str = _memoryPool.startString();
  29. str.append('!');
  30. REQUIRE(str.complete().isNull());
  31. }
  32. }