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

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

BlueMix用のフィアルを追加

File size: 1.7 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 JsonArray_PrettyPrintTo_Tests : public testing::Test {
12 public:
13 JsonArray_PrettyPrintTo_Tests() : array(jsonBuffer.createArray()) {}
14
15 protected:
16 DynamicJsonBuffer jsonBuffer;
17 JsonArray& array;
18
19 void outputMustBe(const char* expected) {
20 char actual[256];
21
22 size_t actualLen = array.prettyPrintTo(actual, sizeof(actual));
23 size_t measuredLen = array.measurePrettyLength();
24
25 EXPECT_STREQ(expected, actual);
26 EXPECT_EQ(strlen(expected), actualLen);
27 EXPECT_EQ(strlen(expected), measuredLen);
28 }
29};
30
31TEST_F(JsonArray_PrettyPrintTo_Tests, Empty) { outputMustBe("[]"); }
32
33TEST_F(JsonArray_PrettyPrintTo_Tests, OneElement) {
34 array.add(1);
35
36 outputMustBe(
37 "[\r\n"
38 " 1\r\n"
39 "]");
40}
41
42TEST_F(JsonArray_PrettyPrintTo_Tests, TwoElements) {
43 array.add(1);
44 array.add(2);
45
46 outputMustBe(
47 "[\r\n"
48 " 1,\r\n"
49 " 2\r\n"
50 "]");
51}
52
53TEST_F(JsonArray_PrettyPrintTo_Tests, EmptyNestedArrays) {
54 array.createNestedArray();
55 array.createNestedArray();
56
57 outputMustBe(
58 "[\r\n"
59 " [],\r\n"
60 " []\r\n"
61 "]");
62}
63
64TEST_F(JsonArray_PrettyPrintTo_Tests, NestedArrays) {
65 JsonArray& nested1 = array.createNestedArray();
66 nested1.add(1);
67 nested1.add(2);
68
69 JsonObject& nested2 = array.createNestedObject();
70 nested2["key"] = 3;
71
72 outputMustBe(
73 "[\r\n"
74 " [\r\n"
75 " 1,\r\n"
76 " 2\r\n"
77 " ],\r\n"
78 " {\r\n"
79 " \"key\": 3\r\n"
80 " }\r\n"
81 "]");
82}
Note: See TracBrowser for help on using the repository browser.