no_memory.cpp 927 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. SECTION("FixCodeCoverage") {
  16. // call this function to fix code coverage
  17. NoMemoryAllocator().deallocate(NULL);
  18. }
  19. // TODO: uncomment
  20. // SECTION("deserializeJson()") {
  21. // char json[] = "{[]}";
  22. // DynamicJsonDocument obj;
  23. // DeserializationError err = deserializeJson(obj, json);
  24. // REQUIRE(err != DeserializationError::Ok);
  25. // }
  26. SECTION("startString()") {
  27. DynamicMemoryPoolBase<NoMemoryAllocator>::String str =
  28. _memoryPool.startString();
  29. str.append('!');
  30. REQUIRE(0 == str.c_str());
  31. }
  32. }