// Copyright Benoit Blanchon 2014-2016 // MIT License // // Arduino JSON library // https://github.com/bblanchon/ArduinoJson // If you like this project, please add a star! #include #include class StaticJsonBuffer_ParseObject_Tests : public testing::Test { protected: void with(JsonBuffer& jsonBuffer) { _jsonBuffer = &jsonBuffer; } void whenInputIs(const char* json) { strcpy(_jsonString, json); } void parseMustSucceed() { EXPECT_TRUE(_jsonBuffer->parseObject(_jsonString).success()); } void parseMustFail() { EXPECT_FALSE(_jsonBuffer->parseObject(_jsonString).success()); } private: JsonBuffer* _jsonBuffer; char _jsonString[256]; }; TEST_F(StaticJsonBuffer_ParseObject_Tests, TooSmallBufferForEmptyObject) { StaticJsonBuffer bufferTooSmall; with(bufferTooSmall); whenInputIs("{}"); parseMustFail(); } TEST_F(StaticJsonBuffer_ParseObject_Tests, BufferOfTheRightSizeForEmptyObject) { StaticJsonBuffer bufferOfRightSize; with(bufferOfRightSize); whenInputIs("{}"); parseMustSucceed(); } TEST_F(StaticJsonBuffer_ParseObject_Tests, TooSmallBufferForObjectWithOneValue) { StaticJsonBuffer bufferTooSmall; with(bufferTooSmall); whenInputIs("{\"a\":1}"); parseMustFail(); } TEST_F(StaticJsonBuffer_ParseObject_Tests, BufferOfTheRightSizeForObjectWithOneValue) { StaticJsonBuffer bufferOfRightSize; with(bufferOfRightSize); whenInputIs("{\"a\":1}"); parseMustSucceed(); } TEST_F(StaticJsonBuffer_ParseObject_Tests, TooSmallBufferForObjectWithNestedObject) { StaticJsonBuffer bufferTooSmall; with(bufferTooSmall); whenInputIs("{\"a\":[]}"); parseMustFail(); } TEST_F(StaticJsonBuffer_ParseObject_Tests, BufferOfTheRightSizeForObjectWithNestedObject) { StaticJsonBuffer bufferOfRightSize; with(bufferOfRightSize); whenInputIs("{\"a\":[]}"); parseMustSucceed(); } TEST_F(StaticJsonBuffer_ParseObject_Tests, CharPtrNull) { ASSERT_FALSE(StaticJsonBuffer<100>().parseObject((char*)0).success()); } TEST_F(StaticJsonBuffer_ParseObject_Tests, ConstCharPtrNull) { ASSERT_FALSE(StaticJsonBuffer<100>().parseObject((const char*)0).success()); }