no_memory.cpp 965 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2018
  3. // MIT License
  4. #include <ArduinoJson/Memory/DynamicMemoryPool.hpp>
  5. #include <ArduinoJson/Memory/StringBuilder.hpp>
  6. #include <catch.hpp>
  7. using namespace ARDUINOJSON_NAMESPACE;
  8. struct NoMemoryAllocator {
  9. void* allocate(size_t) {
  10. return NULL;
  11. }
  12. void deallocate(void*) {}
  13. };
  14. TEST_CASE("DynamicMemoryPool no memory") {
  15. DynamicMemoryPoolBase<NoMemoryAllocator> _memoryPool;
  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("StringBuilder returns null") {
  28. StringBuilder str(&_memoryPool);
  29. str.append('!');
  30. REQUIRE(str.complete().isNull());
  31. }
  32. }