Skip to content

Commit

Permalink
Test coverage up
Browse files Browse the repository at this point in the history
Add more tests! Good for coverage.
  • Loading branch information
StilesCrisis committed Feb 7, 2017
1 parent 0f8389e commit bd4c282
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/perftest/rapidjsontest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,35 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseIterativeInsitu_DummyHandler)) {
}
}

TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseIterativePull_DummyHandler)) {
for (size_t i = 0; i < kTrialCount; i++) {
StringStream s(json_);
BaseReaderHandler<> h;
Reader reader;
reader.IterativeParseInit();
while (!reader.IterativeParseComplete()) {
if (!reader.IterativeParseNext<kParseDefaultFlags>(s, h))
break;
}
EXPECT_FALSE(reader.HasParseError());
}
}

TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseIterativePullInsitu_DummyHandler)) {
for (size_t i = 0; i < kTrialCount; i++) {
memcpy(temp_, json_, length_ + 1);
InsituStringStream s(temp_);
BaseReaderHandler<> h;
Reader reader;
reader.IterativeParseInit();
while (!reader.IterativeParseComplete()) {
if (!reader.IterativeParseNext<kParseDefaultFlags|kParseInsituFlag>(s, h))
break;
}
EXPECT_FALSE(reader.HasParseError());
}
}

TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_ValidateEncoding)) {
for (size_t i = 0; i < kTrialCount; i++) {
StringStream s(json_);
Expand Down
44 changes: 44 additions & 0 deletions test/unittest/jsoncheckertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ static char* ReadFile(const char* filename, size_t& length) {
return json;
}

struct NoOpHandler {
bool Null() { return true; }
bool Bool(bool) { return true; }
bool Int(int) { return true; }
bool Uint(unsigned) { return true; }
bool Int64(int64_t) { return true; }
bool Uint64(uint64_t) { return true; }
bool Double(double) { return true; }
bool RawNumber(const char*, SizeType, bool) { return true; }
bool String(const char*, SizeType, bool) { return true; }
bool StartObject() { return true; }
bool Key(const char*, SizeType, bool) { return true; }
bool EndObject(SizeType) { return true; }
bool StartArray() { return true; }
bool EndArray(SizeType) { return true; }
};


TEST(JsonChecker, Reader) {
char filename[256];

Expand All @@ -67,13 +85,26 @@ TEST(JsonChecker, Reader) {
continue;
}

// Test stack-based parsing.
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
document.Parse(json);
EXPECT_TRUE(document.HasParseError()) << filename;

// Test iterative parsing.
document.Parse<kParseIterativeFlag>(json);
EXPECT_TRUE(document.HasParseError()) << filename;

// Test iterative pull-parsing.
Reader reader;
StringStream ss(json);
NoOpHandler h;
reader.IterativeParseInit();
while (!reader.IterativeParseComplete()) {
if (!reader.IterativeParseNext<kParseDefaultFlags>(ss, h))
break;
}
EXPECT_TRUE(reader.HasParseError()) << filename;

free(json);
}

Expand All @@ -87,12 +118,25 @@ TEST(JsonChecker, Reader) {
continue;
}

// Test stack-based parsing.
GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
document.Parse(json);
EXPECT_FALSE(document.HasParseError()) << filename;

// Test iterative parsing.
document.Parse<kParseIterativeFlag>(json);
EXPECT_FALSE(document.HasParseError()) << filename;

// Test iterative pull-parsing.
Reader reader;
StringStream ss(json);
NoOpHandler h;
reader.IterativeParseInit();
while (!reader.IterativeParseComplete()) {
if (!reader.IterativeParseNext<kParseDefaultFlags>(ss, h))
break;
}
EXPECT_FALSE(reader.HasParseError()) << filename;

free(json);
}
Expand Down

0 comments on commit bd4c282

Please sign in to comment.