no_memory.cpp 1.0 KB

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