Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
cursorstreamwrappertest.cpp
Go to the documentation of this file.
1// Tencent is pleased to support the open source community by making RapidJSON available.
2//
3// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4//
5// Licensed under the MIT License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// http://opensource.org/licenses/MIT
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#include "unittest.h"
16#include "rapidjson/document.h"
18
19using namespace rapidjson;
20
21// static const char json[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}";
22
23bool testJson(const char *json, size_t &line, size_t &col) {
24 StringStream ss(json);
26 Document document;
27 document.ParseStream(csw);
28 bool ret = document.HasParseError();
29 if (ret) {
30 col = csw.GetColumn();
31 line = csw.GetLine();
32 }
33 return ret;
34}
35
36TEST(CursorStreamWrapper, MissingFirstBracket) {
37 const char json[] = "\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}";
38 size_t col, line;
39 bool ret = testJson(json, line, col);
41 EXPECT_EQ(line, 3u);
42 EXPECT_EQ(col, 0u);
43}
44
45TEST(CursorStreamWrapper, MissingQuotes) {
46 const char json[] = "{\"string\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}";
47 size_t col, line;
48 bool ret = testJson(json, line, col);
50 EXPECT_EQ(line, 1u);
51 EXPECT_EQ(col, 8u);
52}
53
54TEST(CursorStreamWrapper, MissingColon) {
55 const char json[] = "{\"string\"\n\n\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}";
56 size_t col, line;
57 bool ret = testJson(json, line, col);
59 EXPECT_EQ(line, 3u);
60 EXPECT_EQ(col, 0u);
61}
62
63TEST(CursorStreamWrapper, MissingSecondQuotes) {
64 const char json[] = "{\"string\"\n\n:my string\",\"array\"\n:[\"1\", \"2\", \"3\"]}";
65 size_t col, line;
66 bool ret = testJson(json, line, col);
68 EXPECT_EQ(line, 3u);
69 EXPECT_EQ(col, 1u);
70}
71
72TEST(CursorStreamWrapper, MissingComma) {
73 const char json[] = "{\"string\"\n\n:\"my string\"\"array\"\n:[\"1\", \"2\", \"3\"]}";
74 size_t col, line;
75 bool ret = testJson(json, line, col);
77 EXPECT_EQ(line, 3u);
78 EXPECT_EQ(col, 12u);
79}
80
81TEST(CursorStreamWrapper, MissingArrayBracket) {
82 const char json[] = "{\"string\"\n\n:\"my string\",\"array\"\n:\"1\", \"2\", \"3\"]}";
83 size_t col, line;
84 bool ret = testJson(json, line, col);
86 EXPECT_EQ(line, 4u);
87 EXPECT_EQ(col, 9u);
88}
89
90TEST(CursorStreamWrapper, MissingArrayComma) {
91 const char json[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\" \"2\", \"3\"]}";
92 size_t col, line;
93 bool ret = testJson(json, line, col);
95 EXPECT_EQ(line, 4u);
96 EXPECT_EQ(col, 6u);
97}
98
99TEST(CursorStreamWrapper, MissingLastArrayBracket) {
100 const char json8[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"}";
101 size_t col, line;
102 bool ret = testJson(json8, line, col);
104 EXPECT_EQ(line, 4u);
105 EXPECT_EQ(col, 15u);
106}
107
108TEST(CursorStreamWrapper, MissingLastBracket) {
109 const char json9[] = "{\"string\"\n\n:\"my string\",\"array\"\n:[\"1\", \"2\", \"3\"]";
110 size_t col, line;
111 bool ret = testJson(json9, line, col);
113 EXPECT_EQ(line, 4u);
114 EXPECT_EQ(col, 16u);
115}
Cursor stream wrapper for counting line and column number if error exists.
size_t GetLine() const
Get the error line number, if error exists.
size_t GetColumn() const
Get the error column number, if error exists.
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition document.h:2388
GenericDocument & ParseStream(InputStream &is)
Parse JSON text from an input stream (with Encoding conversion)
Definition document.h:2259
bool testJson(const char *json, size_t &line, size_t &col)
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954
#define EXPECT_TRUE(condition)
Definition gtest.h:1895
#define TEST(test_case_name, test_name)
Definition gtest.h:2275
main RapidJSON namespace
Read-only string stream.
Definition stream.h:154
CK_RV ret