Skip to content

Commit

Permalink
Third trial on writer coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
miloyip committed Apr 16, 2016
1 parent 3da4afd commit a6f9cb8
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions test/unittest/simdtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,47 +136,50 @@ TEST(SIMD, SIMD_SUFFIX(ScanCopyUnescapedString)) {
}

TEST(SIMD, SIMD_SUFFIX(ScanWriteUnescapedString)) {
for (size_t step = 0; step < 1024; step++) {
char s[2048 + 1];
char *p = s;
for (size_t i = 0; i < step; i++)
*p++= "ABCD"[i % 4];
char escape = "\0\n\\\""[step % 4];
*p++ = escape;
for (size_t i = 0; i < step; i++)
*p++= "ABCD"[i % 4];

StringBuffer sb;
Writer<StringBuffer> writer(sb);
writer.String(s, SizeType(step * 2 + 1));
const char* q = sb.GetString();
EXPECT_EQ('\"', *q++);
for (size_t i = 0; i < step; i++)
EXPECT_EQ("ABCD"[i % 4], *q++);
if (escape == '\0') {
EXPECT_EQ('\\', *q++);
EXPECT_EQ('u', *q++);
EXPECT_EQ('0', *q++);
EXPECT_EQ('0', *q++);
EXPECT_EQ('0', *q++);
EXPECT_EQ('0', *q++);
}
else if (escape == '\n') {
EXPECT_EQ('\\', *q++);
EXPECT_EQ('n', *q++);
}
else if (escape == '\\') {
EXPECT_EQ('\\', *q++);
EXPECT_EQ('\\', *q++);
}
else if (escape == '\"') {
EXPECT_EQ('\\', *q++);
char buffer[2048 + 1 + 32];
for (size_t offset = 0; offset < 32; offset++) {
for (size_t step = 0; step < 1024; step++) {
char* s = buffer + offset;
char* p = s;
for (size_t i = 0; i < step; i++)
*p++ = "ABCD"[i % 4];
char escape = "\0\n\\\""[step % 4];
*p++ = escape;
for (size_t i = 0; i < step; i++)
*p++ = "ABCD"[i % 4];

StringBuffer sb;
Writer<StringBuffer> writer(sb);
writer.String(s, SizeType(step * 2 + 1));
const char* q = sb.GetString();
EXPECT_EQ('\"', *q++);
for (size_t i = 0; i < step; i++)
EXPECT_EQ("ABCD"[i % 4], *q++);
if (escape == '\0') {
EXPECT_EQ('\\', *q++);
EXPECT_EQ('u', *q++);
EXPECT_EQ('0', *q++);
EXPECT_EQ('0', *q++);
EXPECT_EQ('0', *q++);
EXPECT_EQ('0', *q++);
}
else if (escape == '\n') {
EXPECT_EQ('\\', *q++);
EXPECT_EQ('n', *q++);
}
else if (escape == '\\') {
EXPECT_EQ('\\', *q++);
EXPECT_EQ('\\', *q++);
}
else if (escape == '\"') {
EXPECT_EQ('\\', *q++);
EXPECT_EQ('\"', *q++);
}
for (size_t i = 0; i < step; i++)
EXPECT_EQ("ABCD"[i % 4], *q++);
EXPECT_EQ('\"', *q++);
EXPECT_EQ('\0', *q++);
}
for (size_t i = 0; i < step; i++)
EXPECT_EQ("ABCD"[i % 4], *q++);
EXPECT_EQ('\"', *q++);
EXPECT_EQ('\0', *q++);
}
}

Expand Down

0 comments on commit a6f9cb8

Please sign in to comment.