Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
jsoncheckertest.cpp File Reference
#include "unittest.h"
#include "rapidjson/document.h"
Include dependency graph for jsoncheckertest.cpp:

Go to the source code of this file.

Classes

struct  NoOpHandler
 

Functions

 TEST (JsonChecker, Reader)
 

Function Documentation

◆ TEST()

TEST ( JsonChecker ,
Reader  )

Definition at line 69 of file jsoncheckertest.cpp.

69 {
70 char filename[256];
71
72 // jsonchecker/failXX.json
73 for (int i = 1; i <= 33; i++) {
74 if (i == 1) // fail1.json is valid in rapidjson, which has no limitation on type of root element (RFC 7159).
75 continue;
76 if (i == 18) // fail18.json is valid in rapidjson, which has no limitation on depth of nesting.
77 continue;
78
79 sprintf(filename, "fail%d.json", i);
80 size_t length;
81 char* json = ReadFile(filename, length);
82 if (!json) {
83 printf("jsonchecker file %s not found", filename);
85 continue;
86 }
87
88 // Test stack-based parsing.
89 GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
90 document.Parse(json);
91 EXPECT_TRUE(document.HasParseError()) << filename;
92
93 // Test iterative parsing.
94 document.Parse<kParseIterativeFlag>(json);
95 EXPECT_TRUE(document.HasParseError()) << filename;
96
97 // Test iterative pull-parsing.
98 Reader reader;
99 StringStream ss(json);
100 NoOpHandler h;
101 reader.IterativeParseInit();
102 while (!reader.IterativeParseComplete()) {
103 if (!reader.IterativeParseNext<kParseDefaultFlags>(ss, h))
104 break;
105 }
106 EXPECT_TRUE(reader.HasParseError()) << filename;
107
108 free(json);
109 }
110
111 // passX.json
112 for (int i = 1; i <= 3; i++) {
113 sprintf(filename, "pass%d.json", i);
114 size_t length;
115 char* json = ReadFile(filename, length);
116 if (!json) {
117 printf("jsonchecker file %s not found", filename);
118 continue;
119 }
120
121 // Test stack-based parsing.
122 GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
123 document.Parse(json);
124 EXPECT_FALSE(document.HasParseError()) << filename;
125
126 // Test iterative parsing.
127 document.Parse<kParseIterativeFlag>(json);
128 EXPECT_FALSE(document.HasParseError()) << filename;
129
130 // Test iterative pull-parsing.
131 Reader reader;
132 StringStream ss(json);
133 NoOpHandler h;
134 reader.IterativeParseInit();
135 while (!reader.IterativeParseComplete()) {
136 if (!reader.IterativeParseNext<kParseDefaultFlags>(ss, h))
137 break;
138 }
139 EXPECT_FALSE(reader.HasParseError()) << filename;
140
141 free(json);
142 }
143}
C-runtime library allocator.
Definition allocators.h:75
A document for parsing JSON text as DOM.
Definition document.h:2124
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition document.h:2388
GenericDocument & Parse(const typename SourceEncoding::Ch *str)
Parse JSON text from a read-only string (with Encoding conversion)
Definition document.h:2325
bool IterativeParseNext(InputStream &is, Handler &handler)
Parse one token from JSON text.
Definition reader.h:618
void IterativeParseInit()
Initialize JSON text token-by-token parsing.
Definition reader.h:605
RAPIDJSON_FORCEINLINE bool IterativeParseComplete() const
Check if token-by-token parsing JSON text is complete.
Definition reader.h:675
bool HasParseError() const
Whether a parse error has occurred in the last parsing.
Definition reader.h:680
#define EXPECT_TRUE(condition)
Definition gtest.h:1895
#define ADD_FAILURE()
Definition gtest.h:1844
#define EXPECT_FALSE(condition)
Definition gtest.h:1898
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
static const Segment ss(Segment::ss)
@ kParseDefaultFlags
Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS.
Definition reader.h:156
@ kParseIterativeFlag
Iterative(constant complexity in terms of function call stack size) parsing.
Definition reader.h:149
Read-only string stream.
Definition stream.h:154
Here is the call graph for this function: