DynamicJsonBuffer_NoMemory_Tests.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright Benoit Blanchon 2014-2016
  2. // MIT License
  3. //
  4. // Arduino JSON library
  5. // https://github.com/bblanchon/ArduinoJson
  6. // If you like this project, please add a star!
  7. #include <gtest/gtest.h>
  8. #include <ArduinoJson.h>
  9. class NoMemoryAllocator {
  10. public:
  11. void* allocate(size_t) { return NULL; }
  12. void deallocate(void*) {}
  13. };
  14. class DynamicJsonBuffer_NoMemory_Tests : public ::testing::Test {
  15. protected:
  16. Internals::BlockJsonBuffer<NoMemoryAllocator> _jsonBuffer;
  17. };
  18. TEST_F(DynamicJsonBuffer_NoMemory_Tests, FixCodeCoverage) {
  19. // call this function to fix code coverage
  20. NoMemoryAllocator().deallocate(NULL);
  21. }
  22. TEST_F(DynamicJsonBuffer_NoMemory_Tests, CreateArray) {
  23. ASSERT_FALSE(_jsonBuffer.createArray().success());
  24. }
  25. TEST_F(DynamicJsonBuffer_NoMemory_Tests, CreateObject) {
  26. ASSERT_FALSE(_jsonBuffer.createObject().success());
  27. }
  28. TEST_F(DynamicJsonBuffer_NoMemory_Tests, ParseArray) {
  29. char json[] = "[]";
  30. ASSERT_FALSE(_jsonBuffer.parseArray(json).success());
  31. }
  32. TEST_F(DynamicJsonBuffer_NoMemory_Tests, ParseObject) {
  33. char json[] = "{}";
  34. ASSERT_FALSE(_jsonBuffer.parseObject(json).success());
  35. }