Fixes warnings
This commit is contained in:
parent
5852c42bb9
commit
5a186104f4
@ -64,7 +64,7 @@ solution "test"
|
|||||||
defines { "_CRT_SECURE_NO_WARNINGS" }
|
defines { "_CRT_SECURE_NO_WARNINGS" }
|
||||||
|
|
||||||
configuration "gmake"
|
configuration "gmake"
|
||||||
buildoptions "-msse4.2 -Werror=cast-qual"
|
buildoptions "-msse4.2 -Werror -Wall -Wextra"
|
||||||
|
|
||||||
project "gtest"
|
project "gtest"
|
||||||
kind "StaticLib"
|
kind "StaticLib"
|
||||||
@ -86,6 +86,8 @@ solution "test"
|
|||||||
project "unittest"
|
project "unittest"
|
||||||
kind "ConsoleApp"
|
kind "ConsoleApp"
|
||||||
|
|
||||||
|
buildoptions "-Weffc++"
|
||||||
|
|
||||||
files {
|
files {
|
||||||
"../include/**.h",
|
"../include/**.h",
|
||||||
"../test/unittest/**.cpp",
|
"../test/unittest/**.cpp",
|
||||||
@ -149,8 +151,8 @@ solution "example"
|
|||||||
configuration "vs*"
|
configuration "vs*"
|
||||||
defines { "_CRT_SECURE_NO_WARNINGS" }
|
defines { "_CRT_SECURE_NO_WARNINGS" }
|
||||||
|
|
||||||
-- configuration "gmake"
|
configuration "gmake"
|
||||||
-- buildoptions "-Weverything"
|
buildoptions "-Werror -Wall -Wextra -Weffc++"
|
||||||
|
|
||||||
project "condense"
|
project "condense"
|
||||||
kind "ConsoleApp"
|
kind "ConsoleApp"
|
||||||
|
@ -58,9 +58,17 @@ private:
|
|||||||
class Dependent : public Person {
|
class Dependent : public Person {
|
||||||
public:
|
public:
|
||||||
Dependent(const std::string& name, unsigned age, Education* education = 0) : Person(name, age), education_(education) {}
|
Dependent(const std::string& name, unsigned age, Education* education = 0) : Person(name, age), education_(education) {}
|
||||||
Dependent(const Dependent& rhs) : Person(rhs) { education_ = (rhs.education_ == 0) ? 0 : new Education(*rhs.education_); }
|
Dependent(const Dependent& rhs) : Person(rhs), education_(0) { education_ = (rhs.education_ == 0) ? 0 : new Education(*rhs.education_); }
|
||||||
virtual ~Dependent();
|
virtual ~Dependent();
|
||||||
|
|
||||||
|
Dependent& operator=(const Dependent& rhs) {
|
||||||
|
if (this == &rhs)
|
||||||
|
return *this;
|
||||||
|
delete education_;
|
||||||
|
education_ = (rhs.education_ == 0) ? 0 : new Education(*rhs.education_);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Writer>
|
template <typename Writer>
|
||||||
void Serialize(Writer& writer) const {
|
void Serialize(Writer& writer) const {
|
||||||
writer.StartObject();
|
writer.StartObject();
|
||||||
@ -77,6 +85,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Education *education_;
|
Education *education_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -86,7 +95,7 @@ Dependent::~Dependent() {
|
|||||||
|
|
||||||
class Employee : public Person {
|
class Employee : public Person {
|
||||||
public:
|
public:
|
||||||
Employee(const std::string& name, unsigned age, bool married) : Person(name, age), married_(married) {}
|
Employee(const std::string& name, unsigned age, bool married) : Person(name, age), dependents_(), married_(married) {}
|
||||||
virtual ~Employee();
|
virtual ~Employee();
|
||||||
|
|
||||||
void AddDependent(const Dependent& dependent) {
|
void AddDependent(const Dependent& dependent) {
|
||||||
|
@ -10,6 +10,11 @@
|
|||||||
#pragma warning(disable : 4127) // conditional expression is constant
|
#pragma warning(disable : 4127) // conditional expression is constant
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace rapidjson {
|
namespace rapidjson {
|
||||||
|
|
||||||
// Forward declaration.
|
// Forward declaration.
|
||||||
@ -59,7 +64,7 @@ public:
|
|||||||
//@{
|
//@{
|
||||||
|
|
||||||
//! Default constructor creates a null value.
|
//! Default constructor creates a null value.
|
||||||
GenericValue() : flags_(kNullFlag) {}
|
GenericValue() : data_(), flags_(kNullFlag) {}
|
||||||
|
|
||||||
//! Copy constructor is not permitted.
|
//! Copy constructor is not permitted.
|
||||||
private:
|
private:
|
||||||
@ -72,7 +77,7 @@ public:
|
|||||||
\param type Type of the value.
|
\param type Type of the value.
|
||||||
\note Default content for number is zero.
|
\note Default content for number is zero.
|
||||||
*/
|
*/
|
||||||
GenericValue(Type type) : data_() {
|
GenericValue(Type type) : data_(), flags_() {
|
||||||
static const unsigned defaultFlags[7] = {
|
static const unsigned defaultFlags[7] = {
|
||||||
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
|
kNullFlag, kFalseFlag, kTrueFlag, kObjectFlag, kArrayFlag, kConstStringFlag,
|
||||||
kNumberAnyFlag
|
kNumberAnyFlag
|
||||||
@ -92,24 +97,24 @@ public:
|
|||||||
GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator & allocator);
|
GenericValue(const GenericValue<Encoding,SourceAllocator>& rhs, Allocator & allocator);
|
||||||
|
|
||||||
//! Constructor for boolean value.
|
//! Constructor for boolean value.
|
||||||
explicit GenericValue(bool b) : flags_(b ? kTrueFlag : kFalseFlag) {}
|
explicit GenericValue(bool b) : data_(), flags_(b ? kTrueFlag : kFalseFlag) {}
|
||||||
|
|
||||||
//! Constructor for int value.
|
//! Constructor for int value.
|
||||||
explicit GenericValue(int i) : flags_(kNumberIntFlag) {
|
explicit GenericValue(int i) : data_(), flags_(kNumberIntFlag) {
|
||||||
data_.n.i64 = i;
|
data_.n.i64 = i;
|
||||||
if (i >= 0)
|
if (i >= 0)
|
||||||
flags_ |= kUintFlag | kUint64Flag;
|
flags_ |= kUintFlag | kUint64Flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Constructor for unsigned value.
|
//! Constructor for unsigned value.
|
||||||
explicit GenericValue(unsigned u) : flags_(kNumberUintFlag) {
|
explicit GenericValue(unsigned u) : data_(), flags_(kNumberUintFlag) {
|
||||||
data_.n.u64 = u;
|
data_.n.u64 = u;
|
||||||
if (!(u & 0x80000000))
|
if (!(u & 0x80000000))
|
||||||
flags_ |= kIntFlag | kInt64Flag;
|
flags_ |= kIntFlag | kInt64Flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Constructor for int64_t value.
|
//! Constructor for int64_t value.
|
||||||
explicit GenericValue(int64_t i64) : flags_(kNumberInt64Flag) {
|
explicit GenericValue(int64_t i64) : data_(), flags_(kNumberInt64Flag) {
|
||||||
data_.n.i64 = i64;
|
data_.n.i64 = i64;
|
||||||
if (i64 >= 0) {
|
if (i64 >= 0) {
|
||||||
flags_ |= kNumberUint64Flag;
|
flags_ |= kNumberUint64Flag;
|
||||||
@ -123,7 +128,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Constructor for uint64_t value.
|
//! Constructor for uint64_t value.
|
||||||
explicit GenericValue(uint64_t u64) : flags_(kNumberUint64Flag) {
|
explicit GenericValue(uint64_t u64) : data_(), flags_(kNumberUint64Flag) {
|
||||||
data_.n.u64 = u64;
|
data_.n.u64 = u64;
|
||||||
if (!(u64 & UINT64_C(0x8000000000000000)))
|
if (!(u64 & UINT64_C(0x8000000000000000)))
|
||||||
flags_ |= kInt64Flag;
|
flags_ |= kInt64Flag;
|
||||||
@ -134,10 +139,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Constructor for double value.
|
//! Constructor for double value.
|
||||||
explicit GenericValue(double d) : flags_(kNumberDoubleFlag) { data_.n.d = d; }
|
explicit GenericValue(double d) : data_(), flags_(kNumberDoubleFlag) { data_.n.d = d; }
|
||||||
|
|
||||||
//! Constructor for constant string (i.e. do not make a copy of string)
|
//! Constructor for constant string (i.e. do not make a copy of string)
|
||||||
GenericValue(const Ch* s, SizeType length) {
|
GenericValue(const Ch* s, SizeType length) : data_(), flags_() {
|
||||||
RAPIDJSON_ASSERT(s != NULL);
|
RAPIDJSON_ASSERT(s != NULL);
|
||||||
flags_ = kConstStringFlag;
|
flags_ = kConstStringFlag;
|
||||||
data_.s.str = s;
|
data_.s.str = s;
|
||||||
@ -145,13 +150,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Constructor for constant string (i.e. do not make a copy of string)
|
//! Constructor for constant string (i.e. do not make a copy of string)
|
||||||
explicit GenericValue(const Ch* s) { SetStringRaw(s, internal::StrLen(s)); }
|
explicit GenericValue(const Ch* s) : data_(), flags_() { SetStringRaw(s, internal::StrLen(s)); }
|
||||||
|
|
||||||
//! Constructor for copy-string (i.e. do make a copy of string)
|
//! Constructor for copy-string (i.e. do make a copy of string)
|
||||||
GenericValue(const Ch* s, SizeType length, Allocator& allocator) { SetStringRaw(s, length, allocator); }
|
GenericValue(const Ch* s, SizeType length, Allocator& allocator) : data_(), flags_() { SetStringRaw(s, length, allocator); }
|
||||||
|
|
||||||
//! Constructor for copy-string (i.e. do make a copy of string)
|
//! Constructor for copy-string (i.e. do make a copy of string)
|
||||||
GenericValue(const Ch*s, Allocator& allocator) { SetStringRaw(s, internal::StrLen(s), allocator); }
|
GenericValue(const Ch*s, Allocator& allocator) : data_(), flags_() { SetStringRaw(s, internal::StrLen(s), allocator); }
|
||||||
|
|
||||||
//! Destructor.
|
//! Destructor.
|
||||||
/*! Need to destruct elements of array, members of object, or copy-string.
|
/*! Need to destruct elements of array, members of object, or copy-string.
|
||||||
@ -962,4 +967,8 @@ GenericValue<Encoding,Allocator>::GenericValue(const GenericValue<Encoding,Sourc
|
|||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // RAPIDJSON_DOCUMENT_H_
|
#endif // RAPIDJSON_DOCUMENT_H_
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
#include "rapidjson.h"
|
#include "rapidjson.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace rapidjson {
|
namespace rapidjson {
|
||||||
|
|
||||||
//! Input byte stream wrapper with a statically bound encoding.
|
//! Input byte stream wrapper with a statically bound encoding.
|
||||||
@ -31,7 +36,7 @@ public:
|
|||||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Prohibit assignment for VC C4512 warning
|
EncodedInputStream(const EncodedInputStream&);
|
||||||
EncodedInputStream& operator=(const EncodedInputStream&);
|
EncodedInputStream& operator=(const EncodedInputStream&);
|
||||||
|
|
||||||
InputByteStream& is_;
|
InputByteStream& is_;
|
||||||
@ -65,7 +70,7 @@ public:
|
|||||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Prohibit assignment for VC C4512 warning
|
EncodedOutputStream(const EncodedOutputStream&);
|
||||||
EncodedOutputStream& operator=(const EncodedOutputStream&);
|
EncodedOutputStream& operator=(const EncodedOutputStream&);
|
||||||
|
|
||||||
OutputByteStream& os_;
|
OutputByteStream& os_;
|
||||||
@ -110,6 +115,9 @@ public:
|
|||||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
AutoUTFInputStream(const AutoUTFInputStream&);
|
||||||
|
AutoUTFInputStream& operator=(const AutoUTFInputStream&);
|
||||||
|
|
||||||
// Detect encoding type with BOM or RFC 4627
|
// Detect encoding type with BOM or RFC 4627
|
||||||
void DetectType() {
|
void DetectType() {
|
||||||
// BOM (Byte Order Mark):
|
// BOM (Byte Order Mark):
|
||||||
@ -230,6 +238,9 @@ public:
|
|||||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
AutoUTFOutputStream(const AutoUTFOutputStream&);
|
||||||
|
AutoUTFOutputStream& operator=(const AutoUTFOutputStream&);
|
||||||
|
|
||||||
void PutBOM() {
|
void PutBOM() {
|
||||||
typedef void (*PutBOMFunc)(OutputByteStream&);
|
typedef void (*PutBOMFunc)(OutputByteStream&);
|
||||||
static const PutBOMFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(PutBOM) };
|
static const PutBOMFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(PutBOM) };
|
||||||
@ -247,4 +258,8 @@ private:
|
|||||||
|
|
||||||
} // namespace rapidjson
|
} // namespace rapidjson
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // RAPIDJSON_FILESTREAM_H_
|
#endif // RAPIDJSON_FILESTREAM_H_
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
#include "rapidjson.h"
|
#include "rapidjson.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace rapidjson {
|
namespace rapidjson {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -524,4 +529,8 @@ struct Transcoder<Encoding, Encoding> {
|
|||||||
|
|
||||||
} // namespace rapidjson
|
} // namespace rapidjson
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // RAPIDJSON_ENCODINGS_H_
|
#endif // RAPIDJSON_ENCODINGS_H_
|
||||||
|
@ -69,11 +69,6 @@ private:
|
|||||||
bool eof_;
|
bool eof_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
|
||||||
struct StreamTraits<FileReadStream> {
|
|
||||||
typedef FileReadStream StreamCopyType; // Enable stream copy optimization.
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace rapidjson
|
} // namespace rapidjson
|
||||||
|
|
||||||
#endif // RAPIDJSON_FILESTREAM_H_
|
#endif // RAPIDJSON_FILESTREAM_H_
|
||||||
|
@ -28,6 +28,10 @@ public:
|
|||||||
size_t PutEnd(char*) { return 0; }
|
size_t PutEnd(char*) { return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Prohibit copy constructor & assignment operator.
|
||||||
|
FileStream(const FileStream&);
|
||||||
|
FileStream& operator=(const FileStream&);
|
||||||
|
|
||||||
void Read() {
|
void Read() {
|
||||||
RAPIDJSON_ASSERT(fp_ != 0);
|
RAPIDJSON_ASSERT(fp_ != 0);
|
||||||
int c = fgetc(fp_);
|
int c = fgetc(fp_);
|
||||||
|
@ -56,6 +56,10 @@ public:
|
|||||||
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
|
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Prohibit copy constructor & assignment operator.
|
||||||
|
FileWriteStream(const FileWriteStream&);
|
||||||
|
FileWriteStream& operator=(const FileWriteStream&);
|
||||||
|
|
||||||
FILE* fp_;
|
FILE* fp_;
|
||||||
char *buffer_;
|
char *buffer_;
|
||||||
char *bufferEnd_;
|
char *bufferEnd_;
|
||||||
|
@ -69,6 +69,10 @@ public:
|
|||||||
size_t GetCapacity() const { return stack_capacity_; }
|
size_t GetCapacity() const { return stack_capacity_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Prohibit copy constructor & assignment operator.
|
||||||
|
Stack(const Stack&);
|
||||||
|
Stack& operator=(const Stack&);
|
||||||
|
|
||||||
Allocator* allocator_;
|
Allocator* allocator_;
|
||||||
Allocator* own_allocator_;
|
Allocator* own_allocator_;
|
||||||
char *stack_;
|
char *stack_;
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
#include "writer.h"
|
#include "writer.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace rapidjson {
|
namespace rapidjson {
|
||||||
|
|
||||||
//! Writer with indentation and spacing.
|
//! Writer with indentation and spacing.
|
||||||
@ -162,8 +167,17 @@ protected:
|
|||||||
|
|
||||||
Ch indentChar_;
|
Ch indentChar_;
|
||||||
unsigned indentCharCount_;
|
unsigned indentCharCount_;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Prohibit copy constructor & assignment operator.
|
||||||
|
PrettyWriter(const PrettyWriter&);
|
||||||
|
PrettyWriter& operator=(const PrettyWriter&);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rapidjson
|
} // namespace rapidjson
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // RAPIDJSON_RAPIDJSON_H_
|
#endif // RAPIDJSON_RAPIDJSON_H_
|
||||||
|
@ -284,8 +284,9 @@ protected:
|
|||||||
static const int kDefaultDoublePrecision = 6;
|
static const int kDefaultDoublePrecision = 6;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Prohibit assignment for VC C4512 warning
|
// Prohibit copy constructor & assignment operator.
|
||||||
Writer& operator=(const Writer& w);
|
Writer(const Writer&);
|
||||||
|
Writer& operator=(const Writer&);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace rapidjson
|
} // namespace rapidjson
|
||||||
|
@ -24,8 +24,22 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
// gtest indirectly included inttypes.h, without __STDC_CONSTANT_MACROS.
|
||||||
|
#ifndef __STDC_CONSTANT_MACROS
|
||||||
|
# define __STDC_CONSTANT_MACROS 1 // required by C++ standard
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define _CRTDBG_MAP_ALLOC
|
#define _CRTDBG_MAP_ALLOC
|
||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
@ -35,6 +49,8 @@
|
|||||||
//! Base class for all performance tests
|
//! Base class for all performance tests
|
||||||
class PerfTest : public ::testing::Test {
|
class PerfTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
|
PerfTest() : filename_(), json_(), length_(), whitespace_(), whitespace_length_() {}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
FILE *fp = fopen(filename_ = "data/sample.json", "rb");
|
FILE *fp = fopen(filename_ = "data/sample.json", "rb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
@ -68,8 +84,14 @@ public:
|
|||||||
virtual void TearDown() {
|
virtual void TearDown() {
|
||||||
free(json_);
|
free(json_);
|
||||||
free(whitespace_);
|
free(whitespace_);
|
||||||
|
json_ = 0;
|
||||||
|
whitespace_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
PerfTest(const PerfTest&);
|
||||||
|
PerfTest& operator=(const PerfTest&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char* filename_;
|
const char* filename_;
|
||||||
char *json_;
|
char *json_;
|
||||||
|
@ -21,6 +21,8 @@ using namespace rapidjson;
|
|||||||
|
|
||||||
class RapidJson : public PerfTest {
|
class RapidJson : public PerfTest {
|
||||||
public:
|
public:
|
||||||
|
RapidJson() : temp_(), doc_() {}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
PerfTest::SetUp();
|
PerfTest::SetUp();
|
||||||
|
|
||||||
@ -36,6 +38,10 @@ public:
|
|||||||
free(temp_);
|
free(temp_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
RapidJson(const RapidJson&);
|
||||||
|
RapidJson& operator=(const RapidJson&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
char *temp_;
|
char *temp_;
|
||||||
Document doc_;
|
Document doc_;
|
||||||
@ -165,6 +171,11 @@ TEST_F(RapidJson, DocumentTraverse) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
struct ValueCounter : public BaseReaderHandler<> {
|
struct ValueCounter : public BaseReaderHandler<> {
|
||||||
ValueCounter() : count_(1) {} // root
|
ValueCounter() : count_(1) {} // root
|
||||||
|
|
||||||
@ -174,6 +185,10 @@ struct ValueCounter : public BaseReaderHandler<> {
|
|||||||
SizeType count_;
|
SizeType count_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
TEST_F(RapidJson, DocumentAccept) {
|
TEST_F(RapidJson, DocumentAccept) {
|
||||||
for (size_t i = 0; i < kTrialCount; i++) {
|
for (size_t i = 0; i < kTrialCount; i++) {
|
||||||
ValueCounter counter;
|
ValueCounter counter;
|
||||||
|
@ -8,14 +8,21 @@ using namespace rapidjson;
|
|||||||
|
|
||||||
class EncodedStreamTest : public ::testing::Test {
|
class EncodedStreamTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
|
EncodedStreamTest() : json_(), length_() {}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
json_ = ReadFile("utf8.json", true, &length_);
|
json_ = ReadFile("utf8.json", true, &length_);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void TearDown() {
|
virtual void TearDown() {
|
||||||
free(json_);
|
free(json_);
|
||||||
|
json_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
EncodedStreamTest(const EncodedStreamTest&);
|
||||||
|
EncodedStreamTest& operator=(const EncodedStreamTest&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static FILE* Open(const char* filename) {
|
static FILE* Open(const char* filename) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
@ -131,7 +138,6 @@ protected:
|
|||||||
remove(filename);
|
remove(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* filename_;
|
|
||||||
char *json_;
|
char *json_;
|
||||||
size_t length_;
|
size_t length_;
|
||||||
};
|
};
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
|
||||||
class FileStreamTest : public ::testing::Test {
|
class FileStreamTest : public ::testing::Test {
|
||||||
|
public:
|
||||||
|
FileStreamTest() : filename_(), json_(), length_() {}
|
||||||
|
|
||||||
virtual void SetUp() {
|
virtual void SetUp() {
|
||||||
FILE *fp = fopen(filename_ = "data/sample.json", "rb");
|
FILE *fp = fopen(filename_ = "data/sample.json", "rb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
@ -24,8 +27,13 @@ class FileStreamTest : public ::testing::Test {
|
|||||||
|
|
||||||
virtual void TearDown() {
|
virtual void TearDown() {
|
||||||
free(json_);
|
free(json_);
|
||||||
|
json_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
FileStreamTest(const FileStreamTest&);
|
||||||
|
FileStreamTest& operator=(const FileStreamTest&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char* filename_;
|
const char* filename_;
|
||||||
char *json_;
|
char *json_;
|
||||||
|
@ -5,6 +5,11 @@
|
|||||||
|
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
template<bool expect>
|
template<bool expect>
|
||||||
struct ParseBoolHandler : BaseReaderHandler<> {
|
struct ParseBoolHandler : BaseReaderHandler<> {
|
||||||
ParseBoolHandler() : step_(0) {}
|
ParseBoolHandler() : step_(0) {}
|
||||||
@ -33,7 +38,7 @@ TEST(Reader, ParseFalse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct ParseIntHandler : BaseReaderHandler<> {
|
struct ParseIntHandler : BaseReaderHandler<> {
|
||||||
ParseIntHandler() : step_(0) {}
|
ParseIntHandler() : step_(0), actual_() {}
|
||||||
void Default() { FAIL(); }
|
void Default() { FAIL(); }
|
||||||
void Int(int i) { actual_ = i; step_++; }
|
void Int(int i) { actual_ = i; step_++; }
|
||||||
|
|
||||||
@ -42,7 +47,7 @@ struct ParseIntHandler : BaseReaderHandler<> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ParseUintHandler : BaseReaderHandler<> {
|
struct ParseUintHandler : BaseReaderHandler<> {
|
||||||
ParseUintHandler() : step_(0) {}
|
ParseUintHandler() : step_(0), actual_() {}
|
||||||
void Default() { FAIL(); }
|
void Default() { FAIL(); }
|
||||||
void Uint(unsigned i) { actual_ = i; step_++; }
|
void Uint(unsigned i) { actual_ = i; step_++; }
|
||||||
|
|
||||||
@ -51,7 +56,7 @@ struct ParseUintHandler : BaseReaderHandler<> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ParseInt64Handler : BaseReaderHandler<> {
|
struct ParseInt64Handler : BaseReaderHandler<> {
|
||||||
ParseInt64Handler() : step_(0) {}
|
ParseInt64Handler() : step_(0), actual_() {}
|
||||||
void Default() { FAIL(); }
|
void Default() { FAIL(); }
|
||||||
void Int64(int64_t i) { actual_ = i; step_++; }
|
void Int64(int64_t i) { actual_ = i; step_++; }
|
||||||
|
|
||||||
@ -60,7 +65,7 @@ struct ParseInt64Handler : BaseReaderHandler<> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ParseUint64Handler : BaseReaderHandler<> {
|
struct ParseUint64Handler : BaseReaderHandler<> {
|
||||||
ParseUint64Handler() : step_(0) {}
|
ParseUint64Handler() : step_(0), actual_() {}
|
||||||
void Default() { FAIL(); }
|
void Default() { FAIL(); }
|
||||||
void Uint64(uint64_t i) { actual_ = i; step_++; }
|
void Uint64(uint64_t i) { actual_ = i; step_++; }
|
||||||
|
|
||||||
@ -69,7 +74,7 @@ struct ParseUint64Handler : BaseReaderHandler<> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ParseDoubleHandler : BaseReaderHandler<> {
|
struct ParseDoubleHandler : BaseReaderHandler<> {
|
||||||
ParseDoubleHandler() : step_(0) {}
|
ParseDoubleHandler() : step_(0), actual_() {}
|
||||||
void Default() { FAIL(); }
|
void Default() { FAIL(); }
|
||||||
void Double(double d) { actual_ = d; step_++; }
|
void Double(double d) { actual_ = d; step_++; }
|
||||||
|
|
||||||
@ -183,8 +188,12 @@ TEST(Reader, ParseNumber_Error) {
|
|||||||
|
|
||||||
template <typename Encoding>
|
template <typename Encoding>
|
||||||
struct ParseStringHandler : BaseReaderHandler<Encoding> {
|
struct ParseStringHandler : BaseReaderHandler<Encoding> {
|
||||||
ParseStringHandler() : str_(0), length_(0) {}
|
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_)); }
|
||||||
|
|
||||||
|
ParseStringHandler(const ParseStringHandler&);
|
||||||
|
ParseStringHandler& operator=(const ParseStringHandler&);
|
||||||
|
|
||||||
void Default() { FAIL(); }
|
void Default() { FAIL(); }
|
||||||
void String(const typename Encoding::Ch* str, size_t length, bool copy) {
|
void String(const typename Encoding::Ch* str, size_t length, bool copy) {
|
||||||
EXPECT_EQ(0, str_);
|
EXPECT_EQ(0, str_);
|
||||||
@ -651,3 +660,7 @@ TEST(Reader, CustomStringStream) {
|
|||||||
reader.ParseObject<0>(s, h);
|
reader.ParseObject<0>(s, h);
|
||||||
EXPECT_EQ(20u, h.step_);
|
EXPECT_EQ(20u, h.step_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
@ -1,14 +1,29 @@
|
|||||||
#ifndef UNITTEST_H_
|
#ifndef UNITTEST_H_
|
||||||
#define UNITTEST_H_
|
#define UNITTEST_H_
|
||||||
|
|
||||||
|
|
||||||
|
// gtest indirectly included inttypes.h, without __STDC_CONSTANT_MACROS.
|
||||||
|
#ifndef __STDC_CONSTANT_MACROS
|
||||||
|
# define __STDC_CONSTANT_MACROS 1 // required by C++ standard
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define _CRTDBG_MAP_ALLOC
|
#define _CRTDBG_MAP_ALLOC
|
||||||
#include <crtdbg.h>
|
#include <crtdbg.h>
|
||||||
#pragma warning(disable : 4996) // 'function': was declared deprecated
|
#pragma warning(disable : 4996) // 'function': was declared deprecated
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
template <typename Ch>
|
template <typename Ch>
|
||||||
inline size_t StrLen(const Ch* s) {
|
inline size_t StrLen(const Ch* s) {
|
||||||
const Ch* p = s;
|
const Ch* p = s;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user