Commit 83410955 authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

readertest.cpp: use CRTP to activate "ADD_FAILURE()" calls in handlers

parent 3755470f
...@@ -31,7 +31,7 @@ RAPIDJSON_DIAG_OFF(effc++) ...@@ -31,7 +31,7 @@ RAPIDJSON_DIAG_OFF(effc++)
#endif #endif
template<bool expect> template<bool expect>
struct ParseBoolHandler : BaseReaderHandler<> { struct ParseBoolHandler : BaseReaderHandler<UTF8<>, ParseBoolHandler<expect> > {
ParseBoolHandler() : step_(0) {} ParseBoolHandler() : step_(0) {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
// gcc 4.8.x generates warning in EXPECT_EQ(bool, bool) on this gtest version. // gcc 4.8.x generates warning in EXPECT_EQ(bool, bool) on this gtest version.
...@@ -66,7 +66,7 @@ struct ParseIntHandler : BaseReaderHandler<UTF8<>, ParseIntHandler> { ...@@ -66,7 +66,7 @@ struct ParseIntHandler : BaseReaderHandler<UTF8<>, ParseIntHandler> {
int actual_; int actual_;
}; };
struct ParseUintHandler : BaseReaderHandler<> { struct ParseUintHandler : BaseReaderHandler<UTF8<>, ParseUintHandler> {
ParseUintHandler() : step_(0), actual_() {} ParseUintHandler() : step_(0), actual_() {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
bool Uint(unsigned i) { actual_ = i; step_++; return true; } bool Uint(unsigned i) { actual_ = i; step_++; return true; }
...@@ -75,7 +75,7 @@ struct ParseUintHandler : BaseReaderHandler<> { ...@@ -75,7 +75,7 @@ struct ParseUintHandler : BaseReaderHandler<> {
unsigned actual_; unsigned actual_;
}; };
struct ParseInt64Handler : BaseReaderHandler<> { struct ParseInt64Handler : BaseReaderHandler<UTF8<>, ParseInt64Handler> {
ParseInt64Handler() : step_(0), actual_() {} ParseInt64Handler() : step_(0), actual_() {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
bool Int64(int64_t i) { actual_ = i; step_++; return true; } bool Int64(int64_t i) { actual_ = i; step_++; return true; }
...@@ -84,7 +84,7 @@ struct ParseInt64Handler : BaseReaderHandler<> { ...@@ -84,7 +84,7 @@ struct ParseInt64Handler : BaseReaderHandler<> {
int64_t actual_; int64_t actual_;
}; };
struct ParseUint64Handler : BaseReaderHandler<> { struct ParseUint64Handler : BaseReaderHandler<UTF8<>, ParseUint64Handler> {
ParseUint64Handler() : step_(0), actual_() {} ParseUint64Handler() : step_(0), actual_() {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
bool Uint64(uint64_t i) { actual_ = i; step_++; return true; } bool Uint64(uint64_t i) { actual_ = i; step_++; return true; }
...@@ -93,7 +93,7 @@ struct ParseUint64Handler : BaseReaderHandler<> { ...@@ -93,7 +93,7 @@ struct ParseUint64Handler : BaseReaderHandler<> {
uint64_t actual_; uint64_t actual_;
}; };
struct ParseDoubleHandler : BaseReaderHandler<> { struct ParseDoubleHandler : BaseReaderHandler<UTF8<>, ParseDoubleHandler> {
ParseDoubleHandler() : step_(0), actual_() {} ParseDoubleHandler() : step_(0), actual_() {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
bool Double(double d) { actual_ = d; step_++; return true; } bool Double(double d) { actual_ = d; step_++; return true; }
...@@ -209,7 +209,7 @@ TEST(Reader, ParseNumber_Error) { ...@@ -209,7 +209,7 @@ TEST(Reader, ParseNumber_Error) {
} }
template <typename Encoding> template <typename Encoding>
struct ParseStringHandler : BaseReaderHandler<Encoding> { struct ParseStringHandler : BaseReaderHandler<Encoding, ParseStringHandler<Encoding> > {
ParseStringHandler() : str_(0), length_(0), copy_() {} ParseStringHandler() : str_(0), length_(0), copy_() {}
~ParseStringHandler() { EXPECT_TRUE(str_ != 0); if (copy_) free(const_cast<typename Encoding::Ch*>(str_)); } ~ParseStringHandler() { EXPECT_TRUE(str_ != 0); if (copy_) free(const_cast<typename Encoding::Ch*>(str_)); }
...@@ -431,7 +431,7 @@ TEST(Reader, ParseString_Error) { ...@@ -431,7 +431,7 @@ TEST(Reader, ParseString_Error) {
} }
template <unsigned count> template <unsigned count>
struct ParseArrayHandler : BaseReaderHandler<> { struct ParseArrayHandler : BaseReaderHandler<UTF8<>, ParseArrayHandler<count> > {
ParseArrayHandler() : step_(0) {} ParseArrayHandler() : step_(0) {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
...@@ -482,9 +482,10 @@ TEST(Reader, ParseArray_Error) { ...@@ -482,9 +482,10 @@ TEST(Reader, ParseArray_Error) {
#undef TEST_ARRAY_ERROR #undef TEST_ARRAY_ERROR
} }
struct ParseObjectHandler : BaseReaderHandler<> { struct ParseObjectHandler : BaseReaderHandler<UTF8<>, ParseObjectHandler> {
ParseObjectHandler() : step_(0) {} ParseObjectHandler() : step_(0) {}
bool Default() { ADD_FAILURE(); return false; }
bool Null() { EXPECT_EQ(8u, step_); step_++; return true; } bool Null() { EXPECT_EQ(8u, step_); step_++; return true; }
bool Bool(bool b) { bool Bool(bool b) {
switch(step_) { switch(step_) {
...@@ -549,7 +550,7 @@ TEST(Reader, ParseObject) { ...@@ -549,7 +550,7 @@ TEST(Reader, ParseObject) {
} }
} }
struct ParseEmptyObjectHandler : BaseReaderHandler<> { struct ParseEmptyObjectHandler : BaseReaderHandler<UTF8<>, ParseEmptyObjectHandler> {
ParseEmptyObjectHandler() : step_(0) {} ParseEmptyObjectHandler() : step_(0) {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
...@@ -567,7 +568,7 @@ TEST(Reader, Parse_EmptyObject) { ...@@ -567,7 +568,7 @@ TEST(Reader, Parse_EmptyObject) {
EXPECT_EQ(2u, h.step_); EXPECT_EQ(2u, h.step_);
} }
struct ParseMultipleRootHandler : BaseReaderHandler<> { struct ParseMultipleRootHandler : BaseReaderHandler<UTF8<>, ParseMultipleRootHandler> {
ParseMultipleRootHandler() : step_(0) {} ParseMultipleRootHandler() : step_(0) {}
bool Default() { ADD_FAILURE(); return false; } bool Default() { ADD_FAILURE(); return false; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment