Added support for Stream (issue #300)

This commit is contained in:
Benoit Blanchon
2017-01-03 22:03:50 +01:00
parent 3f96e070ce
commit 55669e306e
22 changed files with 407 additions and 191 deletions

View File

@ -351,6 +351,16 @@ TEST_F(JsonParser_Array_Tests, UnfinishedCComment) {
parseMustFail();
}
TEST_F(JsonParser_Array_Tests, EndsInCppComment) {
whenInputIs("[//COMMENT");
parseMustFail();
}
TEST_F(JsonParser_Array_Tests, AfterClosingStar) {
whenInputIs("[/*COMMENT*");
parseMustFail();
}
TEST_F(JsonParser_Array_Tests, DeeplyNested) {
whenInputIs("[[[[[[[[[[[[[[[[[[[\"Not too deep\"]]]]]]]]]]]]]]]]]]]");
parseMustSucceed();

View File

@ -5,25 +5,25 @@
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
#include <sstream>
#include <gtest/gtest.h>
#include <ArduinoJson.h>
#include <gtest/gtest.h>
#include <sstream>
TEST(StdStream, JsonVariantFalse) {
TEST(StdStream_Tests, JsonVariantFalse) {
std::ostringstream os;
JsonVariant variant = false;
os << variant;
ASSERT_EQ("false", os.str());
}
TEST(StdStream, JsonVariantString) {
TEST(StdStream_Tests, JsonVariantString) {
std::ostringstream os;
JsonVariant variant = "coucou";
os << variant;
ASSERT_EQ("\"coucou\"", os.str());
}
TEST(StdStream, JsonObject) {
TEST(StdStream_Tests, JsonObject) {
std::ostringstream os;
DynamicJsonBuffer jsonBuffer;
JsonObject& object = jsonBuffer.createObject();
@ -32,7 +32,7 @@ TEST(StdStream, JsonObject) {
ASSERT_EQ("{\"key\":\"value\"}", os.str());
}
TEST(StdStream, JsonObjectSubscript) {
TEST(StdStream_Tests, JsonObjectSubscript) {
std::ostringstream os;
DynamicJsonBuffer jsonBuffer;
JsonObject& object = jsonBuffer.createObject();
@ -41,7 +41,7 @@ TEST(StdStream, JsonObjectSubscript) {
ASSERT_EQ("\"value\"", os.str());
}
TEST(StdStream, JsonArray) {
TEST(StdStream_Tests, JsonArray) {
std::ostringstream os;
DynamicJsonBuffer jsonBuffer;
JsonArray& array = jsonBuffer.createArray();
@ -50,7 +50,7 @@ TEST(StdStream, JsonArray) {
ASSERT_EQ("[\"value\"]", os.str());
}
TEST(StdStream, JsonArraySubscript) {
TEST(StdStream_Tests, JsonArraySubscript) {
std::ostringstream os;
DynamicJsonBuffer jsonBuffer;
JsonArray& array = jsonBuffer.createArray();
@ -58,3 +58,21 @@ TEST(StdStream, JsonArraySubscript) {
os << array[0];
ASSERT_EQ("\"value\"", os.str());
}
TEST(StdStream_Tests, ParseArray) {
std::istringstream json("[42]");
DynamicJsonBuffer jsonBuffer;
JsonArray& arr = jsonBuffer.parseArray(json);
ASSERT_TRUE(arr.success());
ASSERT_EQ(1, arr.size());
ASSERT_EQ(42, arr[0]);
}
TEST(StdStream_Tests, ParseObject) {
std::istringstream json("{hello:world}");
DynamicJsonBuffer jsonBuffer;
JsonObject& obj = jsonBuffer.parseObject(json);
ASSERT_TRUE(obj.success());
ASSERT_EQ(1, obj.size());
ASSERT_STREQ("world", obj["hello"]);
}

17
test/TypeTraits_Tests.cpp Normal file
View File

@ -0,0 +1,17 @@
// 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 <ArduinoJson.h>
#include <gtest/gtest.h>
#include <sstream>
using namespace ArduinoJson::TypeTraits;
TEST(StdStream, IsBaseOf) {
ASSERT_FALSE((IsBaseOf<std::istream, std::ostringstream>::value));
ASSERT_TRUE((IsBaseOf<std::istream, std::istringstream>::value));
}