Changed unit testing framework from Google Test to Catch

This commit is contained in:
Benoit Blanchon
2017-04-18 18:22:24 +02:00
parent f2ef338cb8
commit df541a2a22
266 changed files with 15955 additions and 146149 deletions

View File

@ -6,91 +6,69 @@
// If you like this project, please add a star!
#include <ArduinoJson.h>
#include <gtest/gtest.h>
#include <catch.hpp>
class StaticJsonBuffer_ParseArray_Tests : public testing::Test {
protected:
void with(StaticJsonBufferBase& jsonBuffer) {
_jsonBuffer = &jsonBuffer;
TEST_CASE("StaticJsonBuffer::parseArray()") {
SECTION("TooSmallBufferForEmptyArray") {
StaticJsonBuffer<JSON_ARRAY_SIZE(0) - 1> bufferTooSmall;
char input[] = "[]";
JsonArray& arr = bufferTooSmall.parseArray(input);
REQUIRE_FALSE(arr.success());
}
void whenInputIs(const char* json) {
strcpy(_jsonString, json);
SECTION("BufferOfTheRightSizeForEmptyArray") {
StaticJsonBuffer<JSON_ARRAY_SIZE(0)> bufferOfRightSize;
char input[] = "[]";
JsonArray& arr = bufferOfRightSize.parseArray(input);
REQUIRE(arr.success());
}
void parseMustSucceed() {
EXPECT_TRUE(_jsonBuffer->parseArray(_jsonString).success());
SECTION("TooSmallBufferForArrayWithOneValue") {
StaticJsonBuffer<JSON_ARRAY_SIZE(1) - 1> bufferTooSmall;
char input[] = "[1]";
JsonArray& arr = bufferTooSmall.parseArray(input);
REQUIRE_FALSE(arr.success());
}
void parseMustFail() {
EXPECT_FALSE(_jsonBuffer->parseArray(_jsonString).success());
SECTION("BufferOfTheRightSizeForArrayWithOneValue") {
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> bufferOfRightSize;
char input[] = "[1]";
JsonArray& arr = bufferOfRightSize.parseArray(input);
REQUIRE(arr.success());
}
private:
StaticJsonBufferBase* _jsonBuffer;
char _jsonString[256];
};
SECTION("TooSmallBufferForArrayWithNestedObject") {
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0) - 1>
bufferTooSmall;
char input[] = "[{}]";
JsonArray& arr = bufferTooSmall.parseArray(input);
REQUIRE_FALSE(arr.success());
}
TEST_F(StaticJsonBuffer_ParseArray_Tests, TooSmallBufferForEmptyArray) {
StaticJsonBuffer<JSON_ARRAY_SIZE(0) - 1> bufferTooSmall;
with(bufferTooSmall);
whenInputIs("[]");
parseMustFail();
}
SECTION("BufferOfTheRightSizeForArrayWithNestedObject") {
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0)>
bufferOfRightSize;
char input[] = "[{}]";
JsonArray& arr = bufferOfRightSize.parseArray(input);
REQUIRE(arr.success());
}
TEST_F(StaticJsonBuffer_ParseArray_Tests, BufferOfTheRightSizeForEmptyArray) {
StaticJsonBuffer<JSON_ARRAY_SIZE(0)> bufferOfRightSize;
with(bufferOfRightSize);
whenInputIs("[]");
parseMustSucceed();
}
SECTION("CharPtrNull") {
REQUIRE_FALSE(
StaticJsonBuffer<100>().parseArray(static_cast<char*>(0)).success());
}
TEST_F(StaticJsonBuffer_ParseArray_Tests, TooSmallBufferForArrayWithOneValue) {
StaticJsonBuffer<JSON_ARRAY_SIZE(1) - 1> bufferTooSmall;
with(bufferTooSmall);
whenInputIs("[1]");
parseMustFail();
}
SECTION("ConstCharPtrNull") {
REQUIRE_FALSE(StaticJsonBuffer<100>()
.parseArray(static_cast<const char*>(0))
.success());
}
TEST_F(StaticJsonBuffer_ParseArray_Tests,
BufferOfTheRightSizeForArrayWithOneValue) {
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> bufferOfRightSize;
with(bufferOfRightSize);
whenInputIs("[1]");
parseMustSucceed();
}
TEST_F(StaticJsonBuffer_ParseArray_Tests,
TooSmallBufferForArrayWithNestedObject) {
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0) - 1> bufferTooSmall;
with(bufferTooSmall);
whenInputIs("[{}]");
parseMustFail();
}
TEST_F(StaticJsonBuffer_ParseArray_Tests,
BufferOfTheRightSizeForArrayWithNestedObject) {
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0)> bufferOfRightSize;
with(bufferOfRightSize);
whenInputIs("[{}]");
parseMustSucceed();
}
TEST_F(StaticJsonBuffer_ParseArray_Tests, CharPtrNull) {
ASSERT_FALSE(
StaticJsonBuffer<100>().parseArray(static_cast<char*>(0)).success());
}
TEST_F(StaticJsonBuffer_ParseArray_Tests, ConstCharPtrNull) {
ASSERT_FALSE(StaticJsonBuffer<100>()
.parseArray(static_cast<const char*>(0))
.success());
}
TEST_F(StaticJsonBuffer_ParseArray_Tests, CopyStringNotSpaces) {
StaticJsonBuffer<100> jsonBuffer;
jsonBuffer.parseArray(" [ \"1234567\" ] ");
ASSERT_EQ(JSON_ARRAY_SIZE(1) + sizeof("1234567"), jsonBuffer.size());
// note we use a string of 8 bytes to be sure that the StaticJsonBuffer
// will not insert bytes to enforce alignement
SECTION("CopyStringNotSpaces") {
StaticJsonBuffer<100> jsonBuffer;
jsonBuffer.parseArray(" [ \"1234567\" ] ");
REQUIRE(JSON_ARRAY_SIZE(1) + sizeof("1234567") == jsonBuffer.size());
// note we use a string of 8 bytes to be sure that the StaticJsonBuffer
// will not insert bytes to enforce alignement
}
}