no_memory.cpp 1.1 KB

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