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

Go to the source code of this file.

Classes

struct  ScanCopyUnescapedStringHandler
 

Macros

#define RAPIDJSON_NAMESPACE   rapidjson_simd
 
#define SIMD_SUFFIX(name)
 

Functions

template<typename StreamType >
void TestSkipWhitespace ()
 
 TEST (SIMD, SIMD_SUFFIX(SkipWhitespace))
 
 TEST (SIMD, SIMD_SUFFIX(SkipWhitespace_EncodedMemoryStream))
 
template<unsigned parseFlags, typename StreamType >
void TestScanCopyUnescapedString ()
 
 TEST (SIMD, SIMD_SUFFIX(ScanCopyUnescapedString))
 
 TEST (SIMD, SIMD_SUFFIX(ScanWriteUnescapedString))
 

Macro Definition Documentation

◆ RAPIDJSON_NAMESPACE

#define RAPIDJSON_NAMESPACE   rapidjson_simd

Definition at line 28 of file simdtest.cpp.

◆ SIMD_SUFFIX

#define SIMD_SUFFIX ( name)
Value:
std::string name

Definition at line 49 of file simdtest.cpp.

Function Documentation

◆ TEST() [1/4]

TEST ( SIMD ,
SIMD_SUFFIX(ScanCopyUnescapedString)  )

Definition at line 164 of file simdtest.cpp.

Here is the call graph for this function:

◆ TEST() [2/4]

TEST ( SIMD ,
SIMD_SUFFIX(ScanWriteUnescapedString)  )

Definition at line 169 of file simdtest.cpp.

169 {
170 char buffer[2048 + 1 + 32];
171 for (size_t offset = 0; offset < 32; offset++) {
172 for (size_t step = 0; step < 1024; step++) {
173 char* s = buffer + offset;
174 char* p = s;
175 for (size_t i = 0; i < step; i++)
176 *p++ = "ABCD"[i % 4];
177 char escape = "\0\n\\\""[step % 4];
178 *p++ = escape;
179 for (size_t i = 0; i < step; i++)
180 *p++ = "ABCD"[i % 4];
181
182 StringBuffer sb;
183 Writer<StringBuffer> writer(sb);
184 writer.String(s, SizeType(step * 2 + 1));
185 const char* q = sb.GetString();
186 EXPECT_EQ('\"', *q++);
187 for (size_t i = 0; i < step; i++)
188 EXPECT_EQ("ABCD"[i % 4], *q++);
189 if (escape == '\0') {
190 EXPECT_EQ('\\', *q++);
191 EXPECT_EQ('u', *q++);
192 EXPECT_EQ('0', *q++);
193 EXPECT_EQ('0', *q++);
194 EXPECT_EQ('0', *q++);
195 EXPECT_EQ('0', *q++);
196 }
197 else if (escape == '\n') {
198 EXPECT_EQ('\\', *q++);
199 EXPECT_EQ('n', *q++);
200 }
201 else if (escape == '\\') {
202 EXPECT_EQ('\\', *q++);
203 EXPECT_EQ('\\', *q++);
204 }
205 else if (escape == '\"') {
206 EXPECT_EQ('\\', *q++);
207 EXPECT_EQ('\"', *q++);
208 }
209 for (size_t i = 0; i < step; i++)
210 EXPECT_EQ("ABCD"[i % 4], *q++);
211 EXPECT_EQ('\"', *q++);
212 EXPECT_EQ('\0', *q++);
213 }
214 }
215}
const mie::Vuint & p
Definition bn.cpp:27
const Ch * GetString() const
JSON writer.
Definition writer.h:89
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition rapidjson.h:384
char * s
Here is the call graph for this function:

◆ TEST() [3/4]

TEST ( SIMD ,
SIMD_SUFFIX(SkipWhitespace)  )

Definition at line 75 of file simdtest.cpp.

Here is the call graph for this function:

◆ TEST() [4/4]

TEST ( SIMD ,
SIMD_SUFFIX(SkipWhitespace_EncodedMemoryStream)  )

Definition at line 80 of file simdtest.cpp.

80 {
81 for (size_t step = 1; step < 32; step++) {
82 char buffer[1024];
83 for (size_t i = 0; i < 1024; i++)
84 buffer[i] = " \t\r\n"[i % 4];
85 for (size_t i = 0; i < 1024; i += step)
86 buffer[i] = 'X';
87
88 MemoryStream ms(buffer, 1024);
90 size_t i = 0;
91 for (;;) {
93 if (s.Peek() == '\0')
94 break;
95 //EXPECT_EQ(i, s.Tell());
96 EXPECT_EQ('X', s.Take());
97 i += step;
98 }
99 }
100}
Input byte stream wrapper with a statically bound encoding.
void SkipWhitespace(InputStream &is)
Skip the JSON white spaces in a stream.
Definition reader.h:264
Represents an in-memory input byte stream.
Here is the call graph for this function:

◆ TestScanCopyUnescapedString()

template<unsigned parseFlags, typename StreamType >
void TestScanCopyUnescapedString ( )

Definition at line 111 of file simdtest.cpp.

111 {
112 char buffer[1024u + 5 + 32];
113 char backup[1024u + 5 + 32];
114
115 // Test "ABCDABCD...\\"
116 for (size_t offset = 0; offset < 32; offset++) {
117 for (size_t step = 0; step < 1024; step++) {
118 char* json = buffer + offset;
119 char *p = json;
120 *p++ = '\"';
121 for (size_t i = 0; i < step; i++)
122 *p++ = "ABCD"[i % 4];
123 *p++ = '\\';
124 *p++ = '\\';
125 *p++ = '\"';
126 *p++ = '\0';
127 strcpy(backup, json); // insitu parsing will overwrite buffer, so need to backup first
128
129 StreamType s(json);
130 Reader reader;
132 reader.Parse<parseFlags>(s, h);
133 EXPECT_TRUE(memcmp(h.buffer, backup + 1, step) == 0);
134 EXPECT_EQ('\\', h.buffer[step]); // escaped
135 EXPECT_EQ('\0', h.buffer[step + 1]);
136 }
137 }
138
139 // Test "\\ABCDABCD..."
140 for (size_t offset = 0; offset < 32; offset++) {
141 for (size_t step = 0; step < 1024; step++) {
142 char* json = buffer + offset;
143 char *p = json;
144 *p++ = '\"';
145 *p++ = '\\';
146 *p++ = '\\';
147 for (size_t i = 0; i < step; i++)
148 *p++ = "ABCD"[i % 4];
149 *p++ = '\"';
150 *p++ = '\0';
151 strcpy(backup, json); // insitu parsing will overwrite buffer, so need to backup first
152
153 StreamType s(json);
154 Reader reader;
156 reader.Parse<parseFlags>(s, h);
157 EXPECT_TRUE(memcmp(h.buffer + 1, backup + 3, step) == 0);
158 EXPECT_EQ('\\', h.buffer[0]); // escaped
159 EXPECT_EQ('\0', h.buffer[step + 1]);
160 }
161 }
162}
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Definition reader.h:557
#define EXPECT_TRUE(condition)
Definition gtest.h:1895
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestSkipWhitespace()

template<typename StreamType >
void TestSkipWhitespace ( )

Definition at line 53 of file simdtest.cpp.

53 {
54 for (size_t step = 1; step < 32; step++) {
55 char buffer[1025];
56 for (size_t i = 0; i < 1024; i++)
57 buffer[i] = " \t\r\n"[i % 4];
58 for (size_t i = 0; i < 1024; i += step)
59 buffer[i] = 'X';
60 buffer[1024] = '\0';
61
62 StreamType s(buffer);
63 size_t i = 0;
64 for (;;) {
66 if (s.Peek() == '\0')
67 break;
68 EXPECT_EQ(i, s.Tell());
69 EXPECT_EQ('X', s.Take());
70 i += step;
71 }
72 }
73}
Here is the call graph for this function:
Here is the caller graph for this function: