[209] | 1 | // Copyright Benoit Blanchon 2014-2016
|
---|
| 2 | // MIT License
|
---|
| 3 | //
|
---|
| 4 | // Arduino JSON library
|
---|
| 5 | // https://github.com/bblanchon/ArduinoJson
|
---|
| 6 | // If you like this project, please add a star!
|
---|
| 7 |
|
---|
| 8 | #include <sstream>
|
---|
| 9 | #include <gtest/gtest.h>
|
---|
| 10 | #include <ArduinoJson.h>
|
---|
| 11 |
|
---|
| 12 | TEST(StdStream, JsonVariantFalse) {
|
---|
| 13 | std::ostringstream os;
|
---|
| 14 | JsonVariant variant = false;
|
---|
| 15 | os << variant;
|
---|
| 16 | ASSERT_EQ("false", os.str());
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | TEST(StdStream, JsonVariantString) {
|
---|
| 20 | std::ostringstream os;
|
---|
| 21 | JsonVariant variant = "coucou";
|
---|
| 22 | os << variant;
|
---|
| 23 | ASSERT_EQ("\"coucou\"", os.str());
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | TEST(StdStream, JsonObject) {
|
---|
| 27 | std::ostringstream os;
|
---|
| 28 | DynamicJsonBuffer jsonBuffer;
|
---|
| 29 | JsonObject& object = jsonBuffer.createObject();
|
---|
| 30 | object["key"] = "value";
|
---|
| 31 | os << object;
|
---|
| 32 | ASSERT_EQ("{\"key\":\"value\"}", os.str());
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | TEST(StdStream, JsonObjectSubscript) {
|
---|
| 36 | std::ostringstream os;
|
---|
| 37 | DynamicJsonBuffer jsonBuffer;
|
---|
| 38 | JsonObject& object = jsonBuffer.createObject();
|
---|
| 39 | object["key"] = "value";
|
---|
| 40 | os << object["key"];
|
---|
| 41 | ASSERT_EQ("\"value\"", os.str());
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | TEST(StdStream, JsonArray) {
|
---|
| 45 | std::ostringstream os;
|
---|
| 46 | DynamicJsonBuffer jsonBuffer;
|
---|
| 47 | JsonArray& array = jsonBuffer.createArray();
|
---|
| 48 | array.add("value");
|
---|
| 49 | os << array;
|
---|
| 50 | ASSERT_EQ("[\"value\"]", os.str());
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | TEST(StdStream, JsonArraySubscript) {
|
---|
| 54 | std::ostringstream os;
|
---|
| 55 | DynamicJsonBuffer jsonBuffer;
|
---|
| 56 | JsonArray& array = jsonBuffer.createArray();
|
---|
| 57 | array.add("value");
|
---|
| 58 | os << array[0];
|
---|
| 59 | ASSERT_EQ("\"value\"", os.str());
|
---|
| 60 | }
|
---|