source: rtos_arduino/trunk/arduino_lib/libraries/ArduinoJson/test/JsonObject_Set_Tests.cpp@ 209

Last change on this file since 209 was 209, checked in by ertl-honda, 8 years ago

BlueMix用のフィアルを追加

File size: 2.5 KB
Line 
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 <gtest/gtest.h>
9#include <ArduinoJson.h>
10
11class JsonObject_Set_Tests : public ::testing::Test {
12 public:
13 JsonObject_Set_Tests() : _object(_jsonBuffer.createObject()) {}
14
15 protected:
16 DynamicJsonBuffer _jsonBuffer;
17 JsonObject& _object;
18};
19
20#define TEST_(name) TEST_F(JsonObject_Set_Tests, name)
21
22TEST_(SizeIncreased_WhenValuesAreAdded) {
23 _object.set("hello", 42);
24 EXPECT_EQ(1, _object.size());
25}
26
27TEST_(SizeUntouched_WhenSameValueIsAdded) {
28 _object["hello"] = 1;
29 _object["hello"] = 2;
30 EXPECT_EQ(1, _object.size());
31}
32
33TEST_(StoreInteger) {
34 _object.set("hello", 123);
35
36 EXPECT_EQ(123, _object["hello"].as<int>());
37 EXPECT_TRUE(_object["hello"].is<int>());
38 EXPECT_FALSE(_object["hello"].is<double>());
39}
40
41TEST_(StoreDouble) {
42 _object.set("hello", 123.45);
43
44 EXPECT_EQ(123.45, _object["hello"].as<double>());
45 EXPECT_TRUE(_object["hello"].is<double>());
46 EXPECT_FALSE(_object["hello"].is<long>());
47}
48
49TEST_(StoreDoubleWithDigits) {
50 _object.set("hello", 123.45, 2);
51
52 EXPECT_EQ(123.45, _object["hello"].as<double>());
53 EXPECT_TRUE(_object["hello"].is<double>());
54 EXPECT_FALSE(_object["hello"].is<long>());
55}
56
57TEST_(StoreBoolean) {
58 _object.set("hello", true);
59
60 EXPECT_TRUE(_object["hello"].as<bool>());
61 EXPECT_TRUE(_object["hello"].is<bool>());
62 EXPECT_FALSE(_object["hello"].is<long>());
63}
64
65TEST_(StoreString) {
66 _object.set("hello", "h3110");
67
68 EXPECT_STREQ("h3110", _object["hello"].as<const char*>());
69 EXPECT_TRUE(_object["hello"].is<const char*>());
70 EXPECT_FALSE(_object["hello"].is<long>());
71}
72
73TEST_(StoreArray) {
74 JsonArray& arr = _jsonBuffer.createArray();
75
76 _object.set("hello", arr);
77
78 EXPECT_EQ(&arr, &_object["hello"].asArray());
79 EXPECT_TRUE(_object["hello"].is<JsonArray&>());
80 EXPECT_FALSE(_object["hello"].is<JsonObject&>());
81}
82
83TEST_(StoreObject) {
84 JsonObject& obj = _jsonBuffer.createObject();
85
86 _object.set("hello", obj);
87
88 EXPECT_EQ(&obj, &_object["hello"].asObject());
89 EXPECT_TRUE(_object["hello"].is<JsonObject&>());
90 EXPECT_FALSE(_object["hello"].is<JsonArray&>());
91}
92
93TEST_(StoreArraySubscript) {
94 JsonArray& arr = _jsonBuffer.createArray();
95 arr.add(42);
96
97 _object.set("a", arr[0]);
98
99 EXPECT_EQ(42, _object["a"]);
100}
101
102TEST_(StoreObjectSubscript) {
103 JsonObject& obj = _jsonBuffer.createObject();
104 obj.set("x", 42);
105
106 _object.set("a", obj["x"]);
107
108 EXPECT_EQ(42, _object["a"]);
109}
Note: See TracBrowser for help on using the repository browser.