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

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

BlueMix用のフィアルを追加

File size: 2.3 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 StaticJsonBuffer_ParseArray_Tests : public testing::Test {
12 protected:
13 void with(JsonBuffer& jsonBuffer) { _jsonBuffer = &jsonBuffer; }
14
15 void whenInputIs(const char* json) { strcpy(_jsonString, json); }
16
17 void parseMustSucceed() {
18 EXPECT_TRUE(_jsonBuffer->parseArray(_jsonString).success());
19 }
20
21 void parseMustFail() {
22 EXPECT_FALSE(_jsonBuffer->parseArray(_jsonString).success());
23 }
24
25 private:
26 JsonBuffer* _jsonBuffer;
27 char _jsonString[256];
28};
29
30TEST_F(StaticJsonBuffer_ParseArray_Tests, TooSmallBufferForEmptyArray) {
31 StaticJsonBuffer<JSON_ARRAY_SIZE(0) - 1> bufferTooSmall;
32 with(bufferTooSmall);
33 whenInputIs("[]");
34 parseMustFail();
35}
36
37TEST_F(StaticJsonBuffer_ParseArray_Tests, BufferOfTheRightSizeForEmptyArray) {
38 StaticJsonBuffer<JSON_ARRAY_SIZE(0)> bufferOfRightSize;
39 with(bufferOfRightSize);
40 whenInputIs("[]");
41 parseMustSucceed();
42}
43
44TEST_F(StaticJsonBuffer_ParseArray_Tests, TooSmallBufferForArrayWithOneValue) {
45 StaticJsonBuffer<JSON_ARRAY_SIZE(1) - 1> bufferTooSmall;
46 with(bufferTooSmall);
47 whenInputIs("[1]");
48 parseMustFail();
49}
50
51TEST_F(StaticJsonBuffer_ParseArray_Tests,
52 BufferOfTheRightSizeForArrayWithOneValue) {
53 StaticJsonBuffer<JSON_ARRAY_SIZE(1)> bufferOfRightSize;
54 with(bufferOfRightSize);
55 whenInputIs("[1]");
56 parseMustSucceed();
57}
58
59TEST_F(StaticJsonBuffer_ParseArray_Tests,
60 TooSmallBufferForArrayWithNestedObject) {
61 StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0) - 1> bufferTooSmall;
62 with(bufferTooSmall);
63 whenInputIs("[{}]");
64 parseMustFail();
65}
66
67TEST_F(StaticJsonBuffer_ParseArray_Tests,
68 BufferOfTheRightSizeForArrayWithNestedObject) {
69 StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0)> bufferOfRightSize;
70 with(bufferOfRightSize);
71 whenInputIs("[{}]");
72 parseMustSucceed();
73}
74
75TEST_F(StaticJsonBuffer_ParseArray_Tests, CharPtrNull) {
76 ASSERT_FALSE(StaticJsonBuffer<100>().parseArray((char*)0).success());
77}
78
79TEST_F(StaticJsonBuffer_ParseArray_Tests, ConstCharPtrNull) {
80 ASSERT_FALSE(StaticJsonBuffer<100>().parseArray((const char*)0).success());
81}
Note: See TracBrowser for help on using the repository browser.