no_memory.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2023
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. using namespace ArduinoJson::Internals;
  7. struct NoMemoryAllocator {
  8. void* allocate(size_t) {
  9. return NULL;
  10. }
  11. void deallocate(void*) {}
  12. };
  13. TEST_CASE("DynamicJsonBuffer no memory") {
  14. DynamicJsonBufferBase<NoMemoryAllocator> _jsonBuffer;
  15. SECTION("FixCodeCoverage") {
  16. // call this function to fix code coverage
  17. NoMemoryAllocator().deallocate(NULL);
  18. }
  19. SECTION("createArray()") {
  20. REQUIRE_FALSE(_jsonBuffer.createArray().success());
  21. }
  22. SECTION("createObject()") {
  23. REQUIRE_FALSE(_jsonBuffer.createObject().success());
  24. }
  25. SECTION("parseArray()") {
  26. char json[] = "[]";
  27. REQUIRE_FALSE(_jsonBuffer.parseArray(json).success());
  28. }
  29. SECTION("parseObject()") {
  30. char json[] = "{}";
  31. REQUIRE_FALSE(_jsonBuffer.parseObject(json).success());
  32. }
  33. SECTION("startString()") {
  34. DynamicJsonBufferBase<NoMemoryAllocator>::String str =
  35. _jsonBuffer.startString();
  36. str.append('!');
  37. REQUIRE(0 == str.c_str());
  38. }
  39. }