MCPcopy Create free account
hub / github.com/Tencent/rapidjson / TestScanCopyUnescapedString

Function TestScanCopyUnescapedString

test/unittest/simdtest.cpp:107–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105
106template <unsigned parseFlags, typename StreamType>
107void TestScanCopyUnescapedString() {
108 char buffer[1024 + 5 + 32];
109 char backup[1024 + 5 + 32];
110
111 // Test "ABCDABCD...\\"
112 for (size_t offset = 0; offset < 32; offset++) {
113 for (size_t step = 0; step < 1024; step++) {
114 char* json = buffer + offset;
115 char *p = json;
116 *p++ = '\"';
117 for (size_t i = 0; i < step; i++)
118 *p++ = "ABCD"[i % 4];
119 *p++ = '\\';
120 *p++ = '\\';
121 *p++ = '\"';
122 *p++ = '\0';
123 strcpy(backup, json); // insitu parsing will overwrite buffer, so need to backup first
124
125 StreamType s(json);
126 Reader reader;
127 ScanCopyUnescapedStringHandler h;
128 reader.Parse<parseFlags>(s, h);
129 EXPECT_TRUE(memcmp(h.buffer, backup + 1, step) == 0);
130 EXPECT_EQ('\\', h.buffer[step]); // escaped
131 EXPECT_EQ('\0', h.buffer[step + 1]);
132 }
133 }
134
135 // Test "\\ABCDABCD..."
136 for (size_t offset = 0; offset < 32; offset++) {
137 for (size_t step = 0; step < 1024; step++) {
138 char* json = buffer + offset;
139 char *p = json;
140 *p++ = '\"';
141 *p++ = '\\';
142 *p++ = '\\';
143 for (size_t i = 0; i < step; i++)
144 *p++ = "ABCD"[i % 4];
145 *p++ = '\"';
146 *p++ = '\0';
147 strcpy(backup, json); // insitu parsing will overwrite buffer, so need to backup first
148
149 StreamType s(json);
150 Reader reader;
151 ScanCopyUnescapedStringHandler h;
152 reader.Parse<parseFlags>(s, h);
153 EXPECT_TRUE(memcmp(h.buffer + 1, backup + 3, step) == 0);
154 EXPECT_EQ('\\', h.buffer[0]); // escaped
155 EXPECT_EQ('\0', h.buffer[step + 1]);
156 }
157 }
158}
159
160TEST(SIMD, SIMD_SUFFIX(ScanCopyUnescapedString)) {
161 TestScanCopyUnescapedString<kParseDefaultFlags, StringStream>();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected