mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 03:26:39 +02:00
Added support of non standard JSON input (issue #44)
This commit is contained in:
62
test/StdStream.cpp
Normal file
62
test/StdStream.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright Benoit Blanchon 2014-2015
|
||||
// MIT License
|
||||
//
|
||||
// Arduino JSON library
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
|
||||
#include <sstream>
|
||||
#include <gtest/gtest.h>
|
||||
#define ARDUINOJSON_ENABLE_STD_STREAM
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
TEST(StdStream, JsonVariantFalse) {
|
||||
std::ostringstream os;
|
||||
JsonVariant variant = false;
|
||||
os << variant;
|
||||
ASSERT_EQ("false", os.str());
|
||||
}
|
||||
|
||||
TEST(StdStream, JsonVariantString) {
|
||||
std::ostringstream os;
|
||||
JsonVariant variant = "coucou";
|
||||
os << variant;
|
||||
ASSERT_EQ("\"coucou\"", os.str());
|
||||
}
|
||||
|
||||
TEST(StdStream, JsonObject) {
|
||||
std::ostringstream os;
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& object = jsonBuffer.createObject();
|
||||
object["key"] = "value";
|
||||
os << object;
|
||||
ASSERT_EQ("{\"key\":\"value\"}", os.str());
|
||||
}
|
||||
|
||||
TEST(StdStream, JsonObjectSubscript) {
|
||||
std::ostringstream os;
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& object = jsonBuffer.createObject();
|
||||
object["key"] = "value";
|
||||
os << object["key"];
|
||||
ASSERT_EQ("\"value\"", os.str());
|
||||
}
|
||||
|
||||
TEST(StdStream, JsonArray) {
|
||||
std::ostringstream os;
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonArray& array = jsonBuffer.createArray();
|
||||
array.add("value");
|
||||
os << array;
|
||||
ASSERT_EQ("[\"value\"]", os.str());
|
||||
}
|
||||
|
||||
TEST(StdStream, JsonArraySubscript) {
|
||||
std::ostringstream os;
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonArray& array = jsonBuffer.createArray();
|
||||
array.add("value");
|
||||
os << array[0];
|
||||
ASSERT_EQ("\"value\"", os.str());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user