DynamicJsonBuffer_NoMemory_Tests.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright Benoit Blanchon 2014-2017
  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 <ArduinoJson.h>
  8. #include <gtest/gtest.h>
  9. class NoMemoryAllocator {
  10. public:
  11. void* allocate(size_t) {
  12. return NULL;
  13. }
  14. void deallocate(void*) {}
  15. };
  16. class DynamicJsonBuffer_NoMemory_Tests : public ::testing::Test {
  17. protected:
  18. DynamicJsonBufferBase<NoMemoryAllocator> _jsonBuffer;
  19. };
  20. TEST_F(DynamicJsonBuffer_NoMemory_Tests, FixCodeCoverage) {
  21. // call this function to fix code coverage
  22. NoMemoryAllocator().deallocate(NULL);
  23. }
  24. TEST_F(DynamicJsonBuffer_NoMemory_Tests, CreateArray) {
  25. ASSERT_FALSE(_jsonBuffer.createArray().success());
  26. }
  27. TEST_F(DynamicJsonBuffer_NoMemory_Tests, CreateObject) {
  28. ASSERT_FALSE(_jsonBuffer.createObject().success());
  29. }
  30. TEST_F(DynamicJsonBuffer_NoMemory_Tests, ParseArray) {
  31. char json[] = "[]";
  32. ASSERT_FALSE(_jsonBuffer.parseArray(json).success());
  33. }
  34. TEST_F(DynamicJsonBuffer_NoMemory_Tests, ParseObject) {
  35. char json[] = "{}";
  36. ASSERT_FALSE(_jsonBuffer.parseObject(json).success());
  37. }