Test with a missing closing brace

This commit is contained in:
Benoit Blanchon
2014-10-21 21:50:00 +02:00
parent 9c1b6b80aa
commit cfbe50057a
2 changed files with 40 additions and 6 deletions

View File

@ -151,8 +151,13 @@ JsonNode* JsonParser::parseArray()
JsonNode* JsonParser::parseObject()
{
_ptr+=2;
return _buffer->createObjectNode();
JsonNode* node = _buffer->createObjectNode();
skipOneChar(); // skip the '['
skipSpaces();
if (isObjectStop())
return node;
}
JsonNode *JsonParser::parseBoolean()

View File

@ -7,14 +7,43 @@ class JsonParser_Object_Test : public testing::Test
{
protected:
void whenInputIs(const char* jsonString)
{
strcpy(_jsonString, jsonString);
_object = _jsonBuffer.parseObject(_jsonString);
}
void parseMustSucceed()
{
EXPECT_TRUE(_object.success());
}
void parseMustFail()
{
EXPECT_FALSE(_object.success());
}
void sizeMustBe(int expected)
{
EXPECT_EQ(expected, _object.size());
}
private:
StaticJsonBuffer<10> _jsonBuffer;
JsonObject _object;
char _jsonString[256];
};
TEST_F(JsonParser_Object_Test, EmptyObject)
{
StaticJsonBuffer<10> jsonBuffer;
char jsonString[] = "{}";
JsonObject object = jsonBuffer.parseObject(jsonString);
EXPECT_TRUE(object.success());
whenInputIs("{}");
parseMustSucceed();
sizeMustBe(0);
}
TEST_F(JsonParser_Object_Test, MissingClosingBrace)
{
whenInputIs("{");
parseMustFail();
sizeMustBe(0);
}