Commit 9c68ce98 authored by miloyip@gmail.com's avatar miloyip@gmail.com

Fixed a lots of vc2008/vs2010 and gcc3/4 warnings with the maximum warning level.

git-svn-id: https://rapidjson.googlecode.com/svn/trunk@67 c5894555-1306-4e8d-425f-1f6f381ee07c
parent 821c6ab7
...@@ -50,6 +50,7 @@ solution "test" ...@@ -50,6 +50,7 @@ solution "test"
location ("./" .. (_ACTION or "")) location ("./" .. (_ACTION or ""))
language "C++" language "C++"
flags { "ExtraWarnings" }
configuration "debug" configuration "debug"
defines { "DEBUG" } defines { "DEBUG" }
...@@ -134,6 +135,7 @@ solution "example" ...@@ -134,6 +135,7 @@ solution "example"
platforms { "x32", "x64" } platforms { "x32", "x64" }
location ("./" .. (_ACTION or "")) location ("./" .. (_ACTION or ""))
language "C++" language "C++"
flags { "ExtraWarnings" }
includedirs "../include/" includedirs "../include/"
configuration "debug" configuration "debug"
......
...@@ -49,7 +49,7 @@ class CrtAllocator { ...@@ -49,7 +49,7 @@ class CrtAllocator {
public: public:
static const bool kNeedFree = true; static const bool kNeedFree = true;
void* Malloc(size_t size) { return malloc(size); } void* Malloc(size_t size) { return malloc(size); }
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { return realloc(originalPtr, newSize); } void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) { (void)originalSize; return realloc(originalPtr, newSize); }
static void Free(void *ptr) { free(ptr); } static void Free(void *ptr) { free(ptr); }
}; };
...@@ -184,7 +184,7 @@ public: ...@@ -184,7 +184,7 @@ public:
} }
//! Frees a memory block (concept Allocator) //! Frees a memory block (concept Allocator)
static void Free(void *ptr) {} // Do nothing static void Free(void *ptr) { (void)ptr; } // Do nothing
private: private:
//! Creates a new chunk. //! Creates a new chunk.
......
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
#include "reader.h" #include "reader.h"
#include "internal/strfunc.h" #include "internal/strfunc.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
namespace rapidjson { namespace rapidjson {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -413,16 +418,16 @@ int z = a[0u].GetInt(); // This works too. ...@@ -413,16 +418,16 @@ int z = a[0u].GetInt(); // This works too.
//!@name Number //!@name Number
//@{ //@{
int GetInt() const { RAPIDJSON_ASSERT(flags_ & kIntFlag); return data_.n.i; } int GetInt() const { RAPIDJSON_ASSERT(flags_ & kIntFlag); return data_.n.i.i; }
unsigned GetUint() const { RAPIDJSON_ASSERT(flags_ & kUintFlag); return data_.n.u; } unsigned GetUint() const { RAPIDJSON_ASSERT(flags_ & kUintFlag); return data_.n.u.u; }
int64_t GetInt64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.i64; } int64_t GetInt64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.i64; }
int64_t GetUint64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.u64; } int64_t GetUint64() const { RAPIDJSON_ASSERT(flags_ & kInt64Flag); return data_.n.u64; }
double GetDouble() const { double GetDouble() const {
RAPIDJSON_ASSERT(IsNumber()); RAPIDJSON_ASSERT(IsNumber());
if ((flags_ & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion. if ((flags_ & kDoubleFlag) != 0) return data_.n.d; // exact type, no conversion.
if ((flags_ & kIntFlag) != 0) return data_.n.i; // int -> double if ((flags_ & kIntFlag) != 0) return data_.n.i.i; // int -> double
if ((flags_ & kUintFlag) != 0) return data_.n.u; // unsigned -> double if ((flags_ & kUintFlag) != 0) return data_.n.u.u; // unsigned -> double
if ((flags_ & kInt64Flag) != 0) return (double)data_.n.i64; // int64_t -> double (may lose precision) if ((flags_ & kInt64Flag) != 0) return (double)data_.n.i64; // int64_t -> double (may lose precision)
RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return (double)data_.n.u64; // uint64_t -> double (may lose precision) RAPIDJSON_ASSERT((flags_ & kUint64Flag) != 0); return (double)data_.n.u64; // uint64_t -> double (may lose precision)
} }
...@@ -512,8 +517,8 @@ int z = a[0u].GetInt(); // This works too. ...@@ -512,8 +517,8 @@ int z = a[0u].GetInt(); // This works too.
break; break;
case kNumberType: case kNumberType:
if (IsInt()) handler.Int(data_.n.i); if (IsInt()) handler.Int(data_.n.i.i);
else if (IsUint()) handler.Uint(data_.n.u); else if (IsUint()) handler.Uint(data_.n.u.u);
else if (IsInt64()) handler.Int64(data_.n.i64); else if (IsInt64()) handler.Int64(data_.n.i64);
else if (IsUint64()) handler.Uint64(data_.n.i64); else if (IsUint64()) handler.Uint64(data_.n.i64);
else handler.Double(data_.n.d); else handler.Double(data_.n.d);
...@@ -566,23 +571,23 @@ private: ...@@ -566,23 +571,23 @@ private:
// By using proper binary layout, retrieval of different integer types do not need conversions. // By using proper binary layout, retrieval of different integer types do not need conversions.
union Number { union Number {
#if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN #if RAPIDJSON_ENDIAN == RAPIDJSON_LITTLEENDIAN
struct { struct I {
int i; int i;
char padding[4]; char padding[4];
}; }i;
struct { struct U {
unsigned u; unsigned u;
char padding2[4]; char padding2[4];
}; }u;
#else #else
struct { struct I {
char padding[4]; char padding[4];
int i; int i;
}; }i;
struct { struct U {
char padding2[4]; char padding2[4];
unsigned u; unsigned u;
}; }u;
#endif #endif
int64_t i64; int64_t i64;
uint64_t u64; uint64_t u64;
...@@ -814,4 +819,8 @@ typedef GenericDocument<UTF8<> > Document; ...@@ -814,4 +819,8 @@ typedef GenericDocument<UTF8<> > Document;
} // namespace rapidjson } // namespace rapidjson
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // RAPIDJSON_DOCUMENT_H_ #endif // RAPIDJSON_DOCUMENT_H_
...@@ -22,7 +22,7 @@ public: ...@@ -22,7 +22,7 @@ public:
Ch Peek() const { return current_; } Ch Peek() const { return current_; }
Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; } Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; }
size_t Tell() const { is_.Tell(); } size_t Tell() const { return is_.Tell(); }
// Not implemented // Not implemented
void Put(Ch c) { RAPIDJSON_ASSERT(false); } void Put(Ch c) { RAPIDJSON_ASSERT(false); }
...@@ -31,6 +31,9 @@ public: ...@@ -31,6 +31,9 @@ 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& operator=(const EncodedInputStream&);
InputByteStream& is_; InputByteStream& is_;
Ch current_; Ch current_;
}; };
...@@ -57,11 +60,14 @@ public: ...@@ -57,11 +60,14 @@ public:
// Not implemented // Not implemented
Ch Peek() const { RAPIDJSON_ASSERT(false); } Ch Peek() const { RAPIDJSON_ASSERT(false); }
Ch Take() { RAPIDJSON_ASSERT(false); } Ch Take() { RAPIDJSON_ASSERT(false); }
size_t Tell() const { RAPIDJSON_ASSERT(false); } size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
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& operator=(const EncodedOutputStream&);
OutputByteStream& os_; OutputByteStream& os_;
}; };
...@@ -149,6 +155,9 @@ private: ...@@ -149,6 +155,9 @@ private:
// RUntime check whether the size of character type is sufficient. It only perform checks with assertion. // RUntime check whether the size of character type is sufficient. It only perform checks with assertion.
switch (type_) { switch (type_) {
case kUTF8:
// Do nothing
break;
case kUTF16LE: case kUTF16LE:
case kUTF16BE: case kUTF16BE:
RAPIDJSON_ASSERT(sizeof(Ch) >= 2); RAPIDJSON_ASSERT(sizeof(Ch) >= 2);
...@@ -196,6 +205,9 @@ public: ...@@ -196,6 +205,9 @@ public:
case kUTF32BE: case kUTF32BE:
RAPIDJSON_ASSERT(sizeof(Ch) >= 4); RAPIDJSON_ASSERT(sizeof(Ch) >= 4);
break; break;
case kUTF8:
// Do nothing
break;
} }
static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) }; static const PutFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Put) };
...@@ -213,7 +225,7 @@ public: ...@@ -213,7 +225,7 @@ public:
// Not implemented // Not implemented
Ch Peek() const { RAPIDJSON_ASSERT(false); } Ch Peek() const { RAPIDJSON_ASSERT(false); }
Ch Take() { RAPIDJSON_ASSERT(false); } Ch Take() { RAPIDJSON_ASSERT(false); }
size_t Tell() const { RAPIDJSON_ASSERT(false); } size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
......
...@@ -193,7 +193,7 @@ struct UTF8 { ...@@ -193,7 +193,7 @@ struct UTF8 {
template <typename OutputByteStream> template <typename OutputByteStream>
static void Put(OutputByteStream& os, Ch c) { static void Put(OutputByteStream& os, Ch c) {
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1); RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
os.Put(c); os.Put(static_cast<typename OutputByteStream::Ch>(c));
} }
}; };
...@@ -219,12 +219,12 @@ struct UTF16 { ...@@ -219,12 +219,12 @@ struct UTF16 {
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2); RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
if (codepoint <= 0xFFFF) { if (codepoint <= 0xFFFF) {
RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair RAPIDJSON_ASSERT(codepoint < 0xD800 || codepoint > 0xDFFF); // Code point itself cannot be surrogate pair
os.Put(codepoint); os.Put(static_cast<wchar_t>(codepoint));
} }
else { else {
RAPIDJSON_ASSERT(codepoint <= 0x10FFFF); RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
unsigned v = codepoint - 0x10000; unsigned v = codepoint - 0x10000;
os.Put((v >> 10) | 0xD800); os.Put(static_cast<wchar_t>((v >> 10) | 0xD800));
os.Put((v & 0x3FF) | 0xDC00); os.Put((v & 0x3FF) | 0xDC00);
} }
} }
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
size_t Tell() const { return count_ + (current_ - buffer_); } size_t Tell() const { return count_ + (current_ - buffer_); }
// Not implemented // Not implemented
void Put(Ch c) { RAPIDJSON_ASSERT(false); } void Put(Ch) { RAPIDJSON_ASSERT(false); }
void Flush() { RAPIDJSON_ASSERT(false); } void Flush() { RAPIDJSON_ASSERT(false); }
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
......
...@@ -49,9 +49,9 @@ public: ...@@ -49,9 +49,9 @@ public:
} }
// Not implemented // Not implemented
char Peek() const { RAPIDJSON_ASSERT(false); } char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
char Take() { RAPIDJSON_ASSERT(false); } char Take() { RAPIDJSON_ASSERT(false); return 0; }
size_t Tell() const { RAPIDJSON_ASSERT(false); } size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
......
...@@ -49,6 +49,7 @@ public: ...@@ -49,6 +49,7 @@ public:
PrettyWriter& Double(double d) { PrettyPrefix(kNumberType); Base::WriteDouble(d); return *this; } PrettyWriter& Double(double d) { PrettyPrefix(kNumberType); Base::WriteDouble(d); return *this; }
PrettyWriter& String(const Ch* str, SizeType length, bool copy = false) { PrettyWriter& String(const Ch* str, SizeType length, bool copy = false) {
(void)copy;
PrettyPrefix(kStringType); PrettyPrefix(kStringType);
Base::WriteString(str, length); Base::WriteString(str, length);
return *this; return *this;
...@@ -62,6 +63,7 @@ public: ...@@ -62,6 +63,7 @@ public:
} }
PrettyWriter& EndObject(SizeType memberCount = 0) { PrettyWriter& EndObject(SizeType memberCount = 0) {
(void)memberCount;
RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
RAPIDJSON_ASSERT(!Base::level_stack_.template Top<typename Base::Level>()->inArray); RAPIDJSON_ASSERT(!Base::level_stack_.template Top<typename Base::Level>()->inArray);
bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0; bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
...@@ -84,6 +86,7 @@ public: ...@@ -84,6 +86,7 @@ public:
} }
PrettyWriter& EndArray(SizeType memberCount = 0) { PrettyWriter& EndArray(SizeType memberCount = 0) {
(void)memberCount;
RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level)); RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
RAPIDJSON_ASSERT(Base::level_stack_.template Top<typename Base::Level>()->inArray); RAPIDJSON_ASSERT(Base::level_stack_.template Top<typename Base::Level>()->inArray);
bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0; bool empty = Base::level_stack_.template Pop<typename Base::Level>(1)->valueCount == 0;
...@@ -105,6 +108,7 @@ public: ...@@ -105,6 +108,7 @@ public:
protected: protected:
void PrettyPrefix(Type type) { void PrettyPrefix(Type type) {
(void)type;
if (Base::level_stack_.GetSize() != 0) { // this value is not at root if (Base::level_stack_.GetSize() != 0) { // this value is not at root
typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>(); typename Base::Level* level = Base::level_stack_.template Top<typename Base::Level>();
......
...@@ -115,6 +115,13 @@ template<int x> struct StaticAssertTest {}; ...@@ -115,6 +115,13 @@ template<int x> struct StaticAssertTest {};
RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__)
#endif #endif
///////////////////////////////////////////////////////////////////////////////
// Helpers
#define RAPIDJSON_MULTILINEMACRO_BEGIN do {
#define RAPIDJSON_MULTILINEMACRO_END \
} while((void)0, 0)
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Allocators and Encodings // Allocators and Encodings
...@@ -189,9 +196,9 @@ struct GenericStringStream { ...@@ -189,9 +196,9 @@ struct GenericStringStream {
size_t Tell() const { return src_ - head_; } size_t Tell() const { return src_ - head_; }
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
void Put(Ch c) { RAPIDJSON_ASSERT(false); } void Put(Ch) { RAPIDJSON_ASSERT(false); }
void Flush() { RAPIDJSON_ASSERT(false); } void Flush() { RAPIDJSON_ASSERT(false); }
size_t PutEnd(Ch* begin) { RAPIDJSON_ASSERT(false); return 0; } size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
const Ch* src_; //!< Current read position. const Ch* src_; //!< Current read position.
const Ch* head_; //!< Original head of the string. const Ch* head_; //!< Original head of the string.
......
...@@ -16,8 +16,18 @@ ...@@ -16,8 +16,18 @@
#include <emmintrin.h> #include <emmintrin.h>
#endif #endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
#ifndef RAPIDJSON_PARSE_ERROR #ifndef RAPIDJSON_PARSE_ERROR
#define RAPIDJSON_PARSE_ERROR(msg, offset) do { parseError_ = msg; errorOffset_ = offset; longjmp(jmpbuf_, 1); } while(false) #define RAPIDJSON_PARSE_ERROR(msg, offset) \
RAPIDJSON_MULTILINEMACRO_BEGIN \
parseError_ = msg; \
errorOffset_ = offset; \
longjmp(jmpbuf_, 1); \
RAPIDJSON_MULTILINEMACRO_END
#endif #endif
namespace rapidjson { namespace rapidjson {
...@@ -69,17 +79,17 @@ struct BaseReaderHandler { ...@@ -69,17 +79,17 @@ struct BaseReaderHandler {
void Default() {} void Default() {}
void Null() { Default(); } void Null() { Default(); }
void Bool(bool b) { Default(); } void Bool(bool) { Default(); }
void Int(int i) { Default(); } void Int(int) { Default(); }
void Uint(unsigned i) { Default(); } void Uint(unsigned) { Default(); }
void Int64(int64_t i) { Default(); } void Int64(int64_t) { Default(); }
void Uint64(uint64_t i) { Default(); } void Uint64(uint64_t) { Default(); }
void Double(double d) { Default(); } void Double(double) { Default(); }
void String(const Ch* str, SizeType length, bool copy) { Default(); } void String(const Ch*, SizeType, bool) { Default(); }
void StartObject() { Default(); } void StartObject() { Default(); }
void EndObject(SizeType memberCount) { Default(); } void EndObject(SizeType) { Default(); }
void StartArray() { Default(); } void StartArray() { Default(); }
void EndArray(SizeType elementCount) { Default(); } void EndArray(SizeType) { Default(); }
}; };
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -215,7 +225,14 @@ public: ...@@ -215,7 +225,14 @@ public:
parseError_ = 0; parseError_ = 0;
errorOffset_ = 0; errorOffset_ = 0;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
#endif
if (setjmp(jmpbuf_)) { if (setjmp(jmpbuf_)) {
#ifdef _MSC_VER
#pragma warning(pop)
#endif
stack_.Clear(); stack_.Clear();
return false; return false;
} }
...@@ -365,7 +382,8 @@ private: ...@@ -365,7 +382,8 @@ private:
return codepoint; return codepoint;
} }
struct StackStream { class StackStream {
public:
typedef typename TargetEncoding::Ch Ch; typedef typename TargetEncoding::Ch Ch;
StackStream(internal::Stack<Allocator>& stack) : stack_(stack), length_(0) {} StackStream(internal::Stack<Allocator>& stack) : stack_(stack), length_(0) {}
...@@ -375,6 +393,10 @@ private: ...@@ -375,6 +393,10 @@ private:
} }
internal::Stack<Allocator>& stack_; internal::Stack<Allocator>& stack_;
SizeType length_; SizeType length_;
private:
// Prohibit assignment for VC C4512 warning
StackStream& operator=(const StackStream&);
}; };
// Parse string and generate String event. Different code paths for kParseInsituFlag. // Parse string and generate String event. Different code paths for kParseInsituFlag.
...@@ -640,4 +662,8 @@ typedef GenericReader<UTF8<>, UTF8<> > Reader; ...@@ -640,4 +662,8 @@ typedef GenericReader<UTF8<>, UTF8<> > Reader;
} // namespace rapidjson } // namespace rapidjson
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // RAPIDJSON_READER_H_ #endif // RAPIDJSON_READER_H_
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
#include <cstdio> // snprintf() or _sprintf_s() #include <cstdio> // snprintf() or _sprintf_s()
#include <new> // placement new #include <new> // placement new
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#endif
namespace rapidjson { namespace rapidjson {
//! JSON writer //! JSON writer
...@@ -43,6 +48,7 @@ public: ...@@ -43,6 +48,7 @@ public:
Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; } Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; }
Writer& String(const Ch* str, SizeType length, bool copy = false) { Writer& String(const Ch* str, SizeType length, bool copy = false) {
(void)copy;
Prefix(kStringType); Prefix(kStringType);
WriteString(str, length); WriteString(str, length);
return *this; return *this;
...@@ -56,6 +62,7 @@ public: ...@@ -56,6 +62,7 @@ public:
} }
Writer& EndObject(SizeType memberCount = 0) { Writer& EndObject(SizeType memberCount = 0) {
(void)memberCount;
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray); RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray);
level_stack_.template Pop<Level>(1); level_stack_.template Pop<Level>(1);
...@@ -73,6 +80,7 @@ public: ...@@ -73,6 +80,7 @@ public:
} }
Writer& EndArray(SizeType elementCount = 0) { Writer& EndArray(SizeType elementCount = 0) {
(void)elementCount;
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray); RAPIDJSON_ASSERT(level_stack_.template Top<Level>()->inArray);
level_stack_.template Pop<Level>(1); level_stack_.template Pop<Level>(1);
...@@ -207,6 +215,7 @@ protected: ...@@ -207,6 +215,7 @@ protected:
void WriteEndArray() { os_.Put(']'); } void WriteEndArray() { os_.Put(']'); }
void Prefix(Type type) { void Prefix(Type type) {
(void)type;
if (level_stack_.GetSize() != 0) { // this value is not at root if (level_stack_.GetSize() != 0) { // this value is not at root
Level* level = level_stack_.template Top<Level>(); Level* level = level_stack_.template Top<Level>();
if (level->valueCount > 0) { if (level->valueCount > 0) {
...@@ -225,8 +234,16 @@ protected: ...@@ -225,8 +234,16 @@ protected:
OutputStream& os_; OutputStream& os_;
internal::Stack<Allocator> level_stack_; internal::Stack<Allocator> level_stack_;
private:
// Prohibit assignment for VC C4512 warning
Writer& operator=(const Writer& w);
}; };
} // namespace rapidjson } // namespace rapidjson
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // RAPIDJSON_RAPIDJSON_H_ #endif // RAPIDJSON_RAPIDJSON_H_
...@@ -7,4 +7,4 @@ int main(int argc, char **argv) { ...@@ -7,4 +7,4 @@ int main(int argc, char **argv) {
#endif #endif
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
\ No newline at end of file
...@@ -42,7 +42,7 @@ protected: ...@@ -42,7 +42,7 @@ protected:
}; };
TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler)) { TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler)) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
memcpy(temp_, json_, length_ + 1); memcpy(temp_, json_, length_ + 1);
InsituStringStream s(temp_); InsituStringStream s(temp_);
BaseReaderHandler<> h; BaseReaderHandler<> h;
...@@ -52,7 +52,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler)) { ...@@ -52,7 +52,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler)) {
} }
TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler_ValidateEncoding)) { TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler_ValidateEncoding)) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
memcpy(temp_, json_, length_ + 1); memcpy(temp_, json_, length_ + 1);
InsituStringStream s(temp_); InsituStringStream s(temp_);
BaseReaderHandler<> h; BaseReaderHandler<> h;
...@@ -62,7 +62,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler_ValidateEncoding)) ...@@ -62,7 +62,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParseInsitu_DummyHandler_ValidateEncoding))
} }
TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler)) { TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler)) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
StringStream s(json_); StringStream s(json_);
BaseReaderHandler<> h; BaseReaderHandler<> h;
Reader reader; Reader reader;
...@@ -71,7 +71,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler)) { ...@@ -71,7 +71,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler)) {
} }
TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_ValidateEncoding)) { TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_ValidateEncoding)) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
StringStream s(json_); StringStream s(json_);
BaseReaderHandler<> h; BaseReaderHandler<> h;
Reader reader; Reader reader;
...@@ -83,7 +83,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParseInsitu_MemoryPoolAllocator)) { ...@@ -83,7 +83,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParseInsitu_MemoryPoolAllocator)) {
//const size_t userBufferSize = 128 * 1024; //const size_t userBufferSize = 128 * 1024;
//char* userBuffer = (char*)malloc(userBufferSize); //char* userBuffer = (char*)malloc(userBufferSize);
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
memcpy(temp_, json_, length_ + 1); memcpy(temp_, json_, length_ + 1);
//MemoryPoolAllocator<> allocator(userBuffer, userBufferSize); //MemoryPoolAllocator<> allocator(userBuffer, userBufferSize);
//Document doc(&allocator); //Document doc(&allocator);
...@@ -106,7 +106,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) { ...@@ -106,7 +106,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) {
//const size_t userBufferSize = 128 * 1024; //const size_t userBufferSize = 128 * 1024;
//char* userBuffer = (char*)malloc(userBufferSize); //char* userBuffer = (char*)malloc(userBufferSize);
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
//MemoryPoolAllocator<> allocator(userBuffer, userBufferSize); //MemoryPoolAllocator<> allocator(userBuffer, userBufferSize);
//Document doc(&allocator); //Document doc(&allocator);
Document doc; Document doc;
...@@ -125,7 +125,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) { ...@@ -125,7 +125,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_MemoryPoolAllocator)) {
} }
TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_CrtAllocator)) { TEST_F(RapidJson, SIMD_SUFFIX(DoucmentParse_CrtAllocator)) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
memcpy(temp_, json_, length_ + 1); memcpy(temp_, json_, length_ + 1);
GenericDocument<UTF8<>, CrtAllocator> doc; GenericDocument<UTF8<>, CrtAllocator> doc;
doc.Parse<0>(temp_); doc.Parse<0>(temp_);
...@@ -148,14 +148,18 @@ size_t Traverse(const T& value) { ...@@ -148,14 +148,18 @@ size_t Traverse(const T& value) {
for (typename T::ConstValueIterator itr = value.Begin(); itr != value.End(); ++itr) for (typename T::ConstValueIterator itr = value.Begin(); itr != value.End(); ++itr)
count += Traverse(*itr); count += Traverse(*itr);
break; break;
default:
// Do nothing.
break;
} }
return count; return count;
} }
TEST_F(RapidJson, DocumentTraverse) { TEST_F(RapidJson, DocumentTraverse) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
size_t count = Traverse(doc_); size_t count = Traverse(doc_);
EXPECT_EQ(4339, count); EXPECT_EQ(4339u, count);
//if (i == 0) //if (i == 0)
// std::cout << count << std::endl; // std::cout << count << std::endl;
} }
...@@ -171,22 +175,22 @@ struct ValueCounter : public BaseReaderHandler<> { ...@@ -171,22 +175,22 @@ struct ValueCounter : public BaseReaderHandler<> {
}; };
TEST_F(RapidJson, DocumentAccept) { TEST_F(RapidJson, DocumentAccept) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
ValueCounter counter; ValueCounter counter;
doc_.Accept(counter); doc_.Accept(counter);
EXPECT_EQ(4339, counter.count_); EXPECT_EQ(4339u, counter.count_);
} }
} }
struct NullStream { struct NullStream {
NullStream() /*: length_(0)*/ {} NullStream() /*: length_(0)*/ {}
void Put(char c) { /*++length_;*/ } void Put(char) { /*++length_;*/ }
void Flush() {} void Flush() {}
//size_t length_; //size_t length_;
}; };
TEST_F(RapidJson, Writer_NullStream) { TEST_F(RapidJson, Writer_NullStream) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
NullStream s; NullStream s;
Writer<NullStream> writer(s); Writer<NullStream> writer(s);
doc_.Accept(writer); doc_.Accept(writer);
...@@ -196,23 +200,25 @@ TEST_F(RapidJson, Writer_NullStream) { ...@@ -196,23 +200,25 @@ TEST_F(RapidJson, Writer_NullStream) {
} }
TEST_F(RapidJson, Writer_StringBuffer) { TEST_F(RapidJson, Writer_StringBuffer) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
StringBuffer s(0, 1024 * 1024); StringBuffer s(0, 1024 * 1024);
Writer<StringBuffer> writer(s); Writer<StringBuffer> writer(s);
doc_.Accept(writer); doc_.Accept(writer);
const char* str = s.GetString(); const char* str = s.GetString();
(void)str;
//if (i == 0) //if (i == 0)
// std::cout << strlen(str) << std::endl; // std::cout << strlen(str) << std::endl;
} }
} }
TEST_F(RapidJson, PrettyWriter_StringBuffer) { TEST_F(RapidJson, PrettyWriter_StringBuffer) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
StringBuffer s(0, 2048 * 1024); StringBuffer s(0, 2048 * 1024);
PrettyWriter<StringBuffer> writer(s); PrettyWriter<StringBuffer> writer(s);
writer.SetIndent(' ', 1); writer.SetIndent(' ', 1);
doc_.Accept(writer); doc_.Accept(writer);
const char* str = s.GetString(); const char* str = s.GetString();
(void)str;
//if (i == 0) //if (i == 0)
// std::cout << strlen(str) << std::endl; // std::cout << strlen(str) << std::endl;
} }
...@@ -220,13 +226,13 @@ TEST_F(RapidJson, PrettyWriter_StringBuffer) { ...@@ -220,13 +226,13 @@ TEST_F(RapidJson, PrettyWriter_StringBuffer) {
TEST_F(RapidJson, internal_Pow10) { TEST_F(RapidJson, internal_Pow10) {
double sum = 0; double sum = 0;
for (int i = 0; i < kTrialCount * kTrialCount; i++) for (size_t i = 0; i < kTrialCount * kTrialCount; i++)
sum += internal::Pow10(i & 255); sum += internal::Pow10(i & 255);
EXPECT_GT(sum, 0.0); EXPECT_GT(sum, 0.0);
} }
TEST_F(RapidJson, SIMD_SUFFIX(Whitespace)) { TEST_F(RapidJson, SIMD_SUFFIX(Whitespace)) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
Document doc; Document doc;
ASSERT_TRUE(doc.Parse<0>(whitespace_).IsArray()); ASSERT_TRUE(doc.Parse<0>(whitespace_).IsArray());
} }
...@@ -235,7 +241,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(Whitespace)) { ...@@ -235,7 +241,7 @@ TEST_F(RapidJson, SIMD_SUFFIX(Whitespace)) {
TEST_F(RapidJson, UTF8_Validate) { TEST_F(RapidJson, UTF8_Validate) {
NullStream os; NullStream os;
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
StringStream is(json_); StringStream is(json_);
bool result = true; bool result = true;
while (is.Peek() != '\0') while (is.Peek() != '\0')
...@@ -246,7 +252,7 @@ TEST_F(RapidJson, UTF8_Validate) { ...@@ -246,7 +252,7 @@ TEST_F(RapidJson, UTF8_Validate) {
// Depreciated. // Depreciated.
//TEST_F(RapidJson, FileStream_Read) { //TEST_F(RapidJson, FileStream_Read) {
// for (int i = 0; i < kTrialCount; i++) { // for (size_t i = 0; i < kTrialCount; i++) {
// FILE *fp = fopen(filename_, "rb"); // FILE *fp = fopen(filename_, "rb");
// FileStream s(fp); // FileStream s(fp);
// while (s.Take() != '\0') // while (s.Take() != '\0')
...@@ -256,7 +262,7 @@ TEST_F(RapidJson, UTF8_Validate) { ...@@ -256,7 +262,7 @@ TEST_F(RapidJson, UTF8_Validate) {
//} //}
TEST_F(RapidJson, FileReadStream) { TEST_F(RapidJson, FileReadStream) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
FILE *fp = fopen(filename_, "rb"); FILE *fp = fopen(filename_, "rb");
char buffer[65536]; char buffer[65536];
FileReadStream s(fp, buffer, sizeof(buffer)); FileReadStream s(fp, buffer, sizeof(buffer));
...@@ -267,7 +273,7 @@ TEST_F(RapidJson, FileReadStream) { ...@@ -267,7 +273,7 @@ TEST_F(RapidJson, FileReadStream) {
} }
TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_FileReadStream)) { TEST_F(RapidJson, SIMD_SUFFIX(ReaderParse_DummyHandler_FileReadStream)) {
for (int i = 0; i < kTrialCount; i++) { for (size_t i = 0; i < kTrialCount; i++) {
FILE *fp = fopen(filename_, "rb"); FILE *fp = fopen(filename_, "rb");
char buffer[65536]; char buffer[65536];
FileReadStream s(fp, buffer, sizeof(buffer)); FileReadStream s(fp, buffer, sizeof(buffer));
......
...@@ -42,7 +42,7 @@ TEST(Document, Parse) { ...@@ -42,7 +42,7 @@ TEST(Document, Parse) {
EXPECT_TRUE(doc.HasMember("a")); EXPECT_TRUE(doc.HasMember("a"));
Value& a = doc["a"]; Value& a = doc["a"];
EXPECT_TRUE(a.IsArray()); EXPECT_TRUE(a.IsArray());
EXPECT_EQ(4, a.Size()); EXPECT_EQ(4u, a.Size());
for (SizeType i = 0; i < 4; i++) for (SizeType i = 0; i < 4; i++)
EXPECT_EQ(i + 1, a[i].GetUint()); EXPECT_EQ(i + 1, a[i].GetUint());
} }
......
...@@ -225,8 +225,8 @@ static const unsigned kCodepointRanges[] = { ...@@ -225,8 +225,8 @@ static const unsigned kCodepointRanges[] = {
// Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de> // Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de>
// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. // See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
#define UTF8_ACCEPT 0 #define UTF8_ACCEPT 0u
#define UTF8_REJECT 12 #define UTF8_REJECT 12u
static const unsigned char utf8d[] = { static const unsigned char utf8d[] = {
// The first part of the table maps bytes to character classes that // The first part of the table maps bytes to character classes that
...@@ -260,14 +260,14 @@ static unsigned inline decode(unsigned* state, unsigned* codep, unsigned byte) { ...@@ -260,14 +260,14 @@ static unsigned inline decode(unsigned* state, unsigned* codep, unsigned byte) {
return *state; return *state;
} }
static bool IsUTF8(unsigned char* s) { //static bool IsUTF8(unsigned char* s) {
unsigned codepoint, state = 0; // unsigned codepoint, state = 0;
//
while (*s) // while (*s)
decode(&state, &codepoint, *s++); // decode(&state, &codepoint, *s++);
//
return state == UTF8_ACCEPT; // return state == UTF8_ACCEPT;
} //}
TEST(EncodingsTest, UTF8) { TEST(EncodingsTest, UTF8) {
StringBuffer os, os2; StringBuffer os, os2;
...@@ -279,7 +279,7 @@ TEST(EncodingsTest, UTF8) { ...@@ -279,7 +279,7 @@ TEST(EncodingsTest, UTF8) {
// Decode with Hoehrmann // Decode with Hoehrmann
{ {
unsigned decodedCodepoint; unsigned decodedCodepoint = 0;
unsigned state = 0; unsigned state = 0;
unsigned decodedCount = 0; unsigned decodedCount = 0;
...@@ -290,7 +290,7 @@ TEST(EncodingsTest, UTF8) { ...@@ -290,7 +290,7 @@ TEST(EncodingsTest, UTF8) {
} }
if (*encodedStr) // This decoder cannot handle U+0000 if (*encodedStr) // This decoder cannot handle U+0000
EXPECT_EQ(1, decodedCount); // Should only contain one code point EXPECT_EQ(1u, decodedCount); // Should only contain one code point
EXPECT_EQ(UTF8_ACCEPT, state); EXPECT_EQ(UTF8_ACCEPT, state);
if (UTF8_ACCEPT != state) if (UTF8_ACCEPT != state)
...@@ -337,7 +337,7 @@ TEST(EncodingsTest, UTF16) { ...@@ -337,7 +337,7 @@ TEST(EncodingsTest, UTF16) {
UTF8<>::Encode(utf8os, codepoint); UTF8<>::Encode(utf8os, codepoint);
// transcode from UTF8 to UTF16 with Hoehrmann's code // transcode from UTF8 to UTF16 with Hoehrmann's code
unsigned decodedCodepoint; unsigned decodedCodepoint = 0;
unsigned state = 0; unsigned state = 0;
UTF16<>::Ch buffer[3], *p = &buffer[0]; UTF16<>::Ch buffer[3], *p = &buffer[0];
for (const char* s = utf8os.GetString(); *s; ++s) { for (const char* s = utf8os.GetString(); *s; ++s) {
...@@ -346,11 +346,11 @@ TEST(EncodingsTest, UTF16) { ...@@ -346,11 +346,11 @@ TEST(EncodingsTest, UTF16) {
} }
if (codepoint <= 0xFFFF) if (codepoint <= 0xFFFF)
*p++ = decodedCodepoint; *p++ = static_cast<UTF16<>::Ch>(decodedCodepoint);
else { else {
// Encode code points above U+FFFF as surrogate pair. // Encode code points above U+FFFF as surrogate pair.
*p++ = 0xD7C0 + (decodedCodepoint >> 10); *p++ = static_cast<UTF16<>::Ch>(0xD7C0 + (decodedCodepoint >> 10));
*p++ = 0xDC00 + (decodedCodepoint & 0x3FF); *p++ = static_cast<UTF16<>::Ch>(0xDC00 + (decodedCodepoint & 0x3FF));
} }
*p++ = '\0'; *p++ = '\0';
......
...@@ -30,11 +30,12 @@ TEST(JsonChecker, Reader) { ...@@ -30,11 +30,12 @@ TEST(JsonChecker, Reader) {
continue; continue;
sprintf(filename, "jsonchecker/fail%d.json", i); sprintf(filename, "jsonchecker/fail%d.json", i);
char* json;
size_t length; size_t length;
if (!(json = ReadFile(filename, length))) { char* json = ReadFile(filename, length);
if (!json) {
sprintf(filename, "../../bin/jsonchecker/fail%d.json", i); sprintf(filename, "../../bin/jsonchecker/fail%d.json", i);
if (!(json = ReadFile(filename, length))) { json = ReadFile(filename, length);
if (!json) {
printf("jsonchecker file %s not found", filename); printf("jsonchecker file %s not found", filename);
continue; continue;
} }
...@@ -50,11 +51,12 @@ TEST(JsonChecker, Reader) { ...@@ -50,11 +51,12 @@ TEST(JsonChecker, Reader) {
// passX.json // passX.json
for (int i = 1; i <= 3; i++) { for (int i = 1; i <= 3; i++) {
sprintf(filename, "jsonchecker/pass%d.json", i); sprintf(filename, "jsonchecker/pass%d.json", i);
char* json;
size_t length; size_t length;
if (!(json = ReadFile(filename, length))) { char* json = ReadFile(filename, length);
if (!json) {
sprintf(filename, "../../bin/jsonchecker/pass%d.json", i); sprintf(filename, "../../bin/jsonchecker/pass%d.json", i);
if (!(json = ReadFile(filename, length))) { json = ReadFile(filename, length);
if (!json) {
printf("jsonchecker file %s not found", filename); printf("jsonchecker file %s not found", filename);
continue; continue;
} }
...@@ -65,4 +67,4 @@ TEST(JsonChecker, Reader) { ...@@ -65,4 +67,4 @@ TEST(JsonChecker, Reader) {
EXPECT_TRUE(!document.HasParseError()); EXPECT_TRUE(!document.HasParseError());
free(json); free(json);
} }
} }
\ No newline at end of file
...@@ -19,7 +19,7 @@ TEST(Reader, ParseTrue) { ...@@ -19,7 +19,7 @@ TEST(Reader, ParseTrue) {
ParseBoolHandler<true> h; ParseBoolHandler<true> h;
Reader reader; Reader reader;
reader.ParseTrue<0>(s, h); reader.ParseTrue<0>(s, h);
EXPECT_EQ(1, h.step_); EXPECT_EQ(1u, h.step_);
} }
TEST(Reader, ParseFalse) { TEST(Reader, ParseFalse) {
...@@ -27,7 +27,7 @@ TEST(Reader, ParseFalse) { ...@@ -27,7 +27,7 @@ TEST(Reader, ParseFalse) {
ParseBoolHandler<false> h; ParseBoolHandler<false> h;
Reader reader; Reader reader;
reader.ParseFalse<0>(s, h); reader.ParseFalse<0>(s, h);
EXPECT_EQ(1, h.step_); EXPECT_EQ(1u, h.step_);
} }
struct ParseIntHandler : BaseReaderHandler<> { struct ParseIntHandler : BaseReaderHandler<> {
...@@ -82,8 +82,8 @@ TEST(Reader, ParseNumberHandler) { ...@@ -82,8 +82,8 @@ TEST(Reader, ParseNumberHandler) {
Handler h; \ Handler h; \
Reader reader; \ Reader reader; \
reader.ParseNumber<0>(s, h); \ reader.ParseNumber<0>(s, h); \
EXPECT_EQ(1, h.step_); \ EXPECT_EQ(1u, h.step_); \
EXPECT_EQ(x, h.actual_); \ EXPECT_EQ(double(x), h.actual_); \
} }
#define TEST_DOUBLE(str, x) \ #define TEST_DOUBLE(str, x) \
...@@ -92,7 +92,7 @@ TEST(Reader, ParseNumberHandler) { ...@@ -92,7 +92,7 @@ TEST(Reader, ParseNumberHandler) {
ParseDoubleHandler h; \ ParseDoubleHandler h; \
Reader reader; \ Reader reader; \
reader.ParseNumber<0>(s, h); \ reader.ParseNumber<0>(s, h); \
EXPECT_EQ(1, h.step_); \ EXPECT_EQ(1u, h.step_); \
EXPECT_DOUBLE_EQ(x, h.actual_); \ EXPECT_DOUBLE_EQ(x, h.actual_); \
} }
...@@ -273,7 +273,7 @@ TEST(Reader, ParseString) { ...@@ -273,7 +273,7 @@ TEST(Reader, ParseString) {
Reader reader; Reader reader;
reader.ParseString<0>(s, h); reader.ParseString<0>(s, h);
EXPECT_EQ(0, memcmp(e, h.str_, h.length_ + 1)); EXPECT_EQ(0, memcmp(e, h.str_, h.length_ + 1));
EXPECT_EQ(11, h.length_); EXPECT_EQ(11u, h.length_);
} }
} }
...@@ -294,7 +294,7 @@ TEST(Reader, ParseString_NonDestructive) { ...@@ -294,7 +294,7 @@ TEST(Reader, ParseString_NonDestructive) {
Reader reader; Reader reader;
reader.ParseString<0>(s, h); reader.ParseString<0>(s, h);
EXPECT_EQ(0, StrCmp("Hello\nWorld", h.str_)); EXPECT_EQ(0, StrCmp("Hello\nWorld", h.str_));
EXPECT_EQ(11, h.length_); EXPECT_EQ(11u, h.length_);
} }
bool TestString(const char* str) { bool TestString(const char* str) {
...@@ -327,8 +327,8 @@ TEST(Reader, ParseString_Error) { ...@@ -327,8 +327,8 @@ TEST(Reader, ParseString_Error) {
char e[] = { '[', '\"', 0, '\"', ']', '\0' }; char e[] = { '[', '\"', 0, '\"', ']', '\0' };
for (unsigned char c = 0x80u; c <= 0xBFu; c++) { for (unsigned char c = 0x80u; c <= 0xBFu; c++) {
e[2] = c; e[2] = c;
bool b; bool b = TestString(e);
EXPECT_FALSE(b = TestString(e)); EXPECT_FALSE(b);
if (b) if (b)
std::cout << (unsigned)(unsigned char)c << std::endl; std::cout << (unsigned)(unsigned char)c << std::endl;
} }
...@@ -381,8 +381,8 @@ struct ParseArrayHandler : BaseReaderHandler<> { ...@@ -381,8 +381,8 @@ struct ParseArrayHandler : BaseReaderHandler<> {
void Default() { FAIL(); } void Default() { FAIL(); }
void Uint(unsigned i) { EXPECT_EQ(step_, i); step_++; } void Uint(unsigned i) { EXPECT_EQ(step_, i); step_++; }
void StartArray() { EXPECT_EQ(0, step_); step_++; } void StartArray() { EXPECT_EQ(0u, step_); step_++; }
void EndArray(SizeType elementCount) { step_++; } void EndArray(SizeType) { step_++; }
unsigned step_; unsigned step_;
}; };
...@@ -393,7 +393,7 @@ TEST(Reader, ParseEmptyArray) { ...@@ -393,7 +393,7 @@ TEST(Reader, ParseEmptyArray) {
ParseArrayHandler<0> h; ParseArrayHandler<0> h;
Reader reader; Reader reader;
reader.ParseArray<0>(s, h); reader.ParseArray<0>(s, h);
EXPECT_EQ(2, h.step_); EXPECT_EQ(2u, h.step_);
free(json); free(json);
} }
...@@ -403,7 +403,7 @@ TEST(Reader, ParseArray) { ...@@ -403,7 +403,7 @@ TEST(Reader, ParseArray) {
ParseArrayHandler<4> h; ParseArrayHandler<4> h;
Reader reader; Reader reader;
reader.ParseArray<0>(s, h); reader.ParseArray<0>(s, h);
EXPECT_EQ(6, h.step_); EXPECT_EQ(6u, h.step_);
free(json); free(json);
} }
...@@ -429,7 +429,7 @@ TEST(Reader, ParseArray_Error) { ...@@ -429,7 +429,7 @@ TEST(Reader, ParseArray_Error) {
struct ParseObjectHandler : BaseReaderHandler<> { struct ParseObjectHandler : BaseReaderHandler<> {
ParseObjectHandler() : step_(0) {} ParseObjectHandler() : step_(0) {}
void Null() { EXPECT_EQ(8, step_); step_++; } void Null() { EXPECT_EQ(8u, step_); step_++; }
void Bool(bool b) { void Bool(bool b) {
switch(step_) { switch(step_) {
case 4: EXPECT_TRUE(b); step_++; break; case 4: EXPECT_TRUE(b); step_++; break;
...@@ -447,8 +447,8 @@ struct ParseObjectHandler : BaseReaderHandler<> { ...@@ -447,8 +447,8 @@ struct ParseObjectHandler : BaseReaderHandler<> {
} }
} }
void Uint(unsigned i) { Int(i); } void Uint(unsigned i) { Int(i); }
void Double(double d) { EXPECT_EQ(12, step_); EXPECT_EQ(3.1416, d); step_++; } void Double(double d) { EXPECT_EQ(12u, step_); EXPECT_EQ(3.1416, d); step_++; }
void String(const char* str, size_t length, bool copy) { void String(const char* str, size_t, bool) {
switch(step_) { switch(step_) {
case 1: EXPECT_STREQ("hello", str); step_++; break; case 1: EXPECT_STREQ("hello", str); step_++; break;
case 2: EXPECT_STREQ("world", str); step_++; break; case 2: EXPECT_STREQ("world", str); step_++; break;
...@@ -461,10 +461,10 @@ struct ParseObjectHandler : BaseReaderHandler<> { ...@@ -461,10 +461,10 @@ struct ParseObjectHandler : BaseReaderHandler<> {
default: FAIL(); default: FAIL();
} }
} }
void StartObject() { EXPECT_EQ(0, step_); step_++; } void StartObject() { EXPECT_EQ(0u, step_); step_++; }
void EndObject(SizeType memberCount) { EXPECT_EQ(19, step_); EXPECT_EQ(7, memberCount); step_++;} void EndObject(SizeType memberCount) { EXPECT_EQ(19u, step_); EXPECT_EQ(7u, memberCount); step_++;}
void StartArray() { EXPECT_EQ(14, step_); step_++; } void StartArray() { EXPECT_EQ(14u, step_); step_++; }
void EndArray(SizeType elementCount) { EXPECT_EQ(18, step_); EXPECT_EQ(3, elementCount); step_++;} void EndArray(SizeType elementCount) { EXPECT_EQ(18u, step_); EXPECT_EQ(3u, elementCount); step_++;}
unsigned step_; unsigned step_;
}; };
...@@ -479,7 +479,7 @@ TEST(Reader, ParseObject) { ...@@ -479,7 +479,7 @@ TEST(Reader, ParseObject) {
ParseObjectHandler h; ParseObjectHandler h;
Reader reader; Reader reader;
reader.ParseObject<kParseInsituFlag>(s, h); reader.ParseObject<kParseInsituFlag>(s, h);
EXPECT_EQ(20, h.step_); EXPECT_EQ(20u, h.step_);
free(json2); free(json2);
} }
...@@ -489,7 +489,7 @@ TEST(Reader, ParseObject) { ...@@ -489,7 +489,7 @@ TEST(Reader, ParseObject) {
ParseObjectHandler h; ParseObjectHandler h;
Reader reader; Reader reader;
reader.ParseObject<0>(s, h); reader.ParseObject<0>(s, h);
EXPECT_EQ(20, h.step_); EXPECT_EQ(20u, h.step_);
} }
} }
...@@ -497,8 +497,8 @@ struct ParseEmptyObjectHandler : BaseReaderHandler<> { ...@@ -497,8 +497,8 @@ struct ParseEmptyObjectHandler : BaseReaderHandler<> {
ParseEmptyObjectHandler() : step_(0) {} ParseEmptyObjectHandler() : step_(0) {}
void Default() { FAIL(); } void Default() { FAIL(); }
void StartObject() { EXPECT_EQ(0, step_); step_++; } void StartObject() { EXPECT_EQ(0u, step_); step_++; }
void EndObject(SizeType memberCount) { EXPECT_EQ(1, step_); step_++; } void EndObject(SizeType) { EXPECT_EQ(1u, step_); step_++; }
unsigned step_; unsigned step_;
}; };
...@@ -508,7 +508,7 @@ TEST(Reader, Parse_EmptyObject) { ...@@ -508,7 +508,7 @@ TEST(Reader, Parse_EmptyObject) {
ParseEmptyObjectHandler h; ParseEmptyObjectHandler h;
Reader reader; Reader reader;
reader.ParseObject<0>(s, h); reader.ParseObject<0>(s, h);
EXPECT_EQ(2, h.step_); EXPECT_EQ(2u, h.step_);
} }
TEST(Reader, ParseObject_Error) { TEST(Reader, ParseObject_Error) {
......
...@@ -105,9 +105,9 @@ TEST(Value, Int) { ...@@ -105,9 +105,9 @@ TEST(Value, Int) {
Value x(1234); Value x(1234);
EXPECT_EQ(kNumberType, x.GetType()); EXPECT_EQ(kNumberType, x.GetType());
EXPECT_EQ(1234, x.GetInt()); EXPECT_EQ(1234, x.GetInt());
EXPECT_EQ(1234, x.GetUint()); EXPECT_EQ(1234u, x.GetUint());
EXPECT_EQ(1234, x.GetInt64()); EXPECT_EQ(1234, x.GetInt64());
EXPECT_EQ(1234, x.GetUint64()); EXPECT_EQ(1234u, x.GetUint64());
EXPECT_EQ(1234, x.GetDouble()); EXPECT_EQ(1234, x.GetDouble());
//EXPECT_EQ(1234, (int)x); //EXPECT_EQ(1234, (int)x);
//EXPECT_EQ(1234, (unsigned)x); //EXPECT_EQ(1234, (unsigned)x);
...@@ -157,9 +157,9 @@ TEST(Value, Uint) { ...@@ -157,9 +157,9 @@ TEST(Value, Uint) {
// Constructor with int // Constructor with int
Value x(1234u); Value x(1234u);
EXPECT_EQ(kNumberType, x.GetType()); EXPECT_EQ(kNumberType, x.GetType());
EXPECT_EQ(1234u, x.GetInt()); EXPECT_EQ(1234, x.GetInt());
EXPECT_EQ(1234u, x.GetUint()); EXPECT_EQ(1234u, x.GetUint());
EXPECT_EQ(1234u, x.GetInt64()); EXPECT_EQ(1234, x.GetInt64());
EXPECT_EQ(1234u, x.GetUint64()); EXPECT_EQ(1234u, x.GetUint64());
EXPECT_TRUE(x.IsNumber()); EXPECT_TRUE(x.IsNumber());
EXPECT_TRUE(x.IsInt()); EXPECT_TRUE(x.IsInt());
...@@ -180,11 +180,11 @@ TEST(Value, Uint) { ...@@ -180,11 +180,11 @@ TEST(Value, Uint) {
// SetUint() // SetUint()
Value z; Value z;
z.SetUint(1234); z.SetUint(1234);
EXPECT_EQ(1234, z.GetUint()); EXPECT_EQ(1234u, z.GetUint());
// operator=(unsigned) // operator=(unsigned)
z = 5678u; z = 5678u;
EXPECT_EQ(5678, z.GetUint()); EXPECT_EQ(5678u, z.GetUint());
z = 2147483648u; // 2^31, cannot cast as int z = 2147483648u; // 2^31, cannot cast as int
EXPECT_EQ(2147483648u, z.GetUint()); EXPECT_EQ(2147483648u, z.GetUint());
...@@ -196,9 +196,9 @@ TEST(Value, Int64) { ...@@ -196,9 +196,9 @@ TEST(Value, Int64) {
Value x(int64_t(1234LL)); Value x(int64_t(1234LL));
EXPECT_EQ(kNumberType, x.GetType()); EXPECT_EQ(kNumberType, x.GetType());
EXPECT_EQ(1234, x.GetInt()); EXPECT_EQ(1234, x.GetInt());
EXPECT_EQ(1234, x.GetUint()); EXPECT_EQ(1234u, x.GetUint());
EXPECT_EQ(1234, x.GetInt64()); EXPECT_EQ(1234, x.GetInt64());
EXPECT_EQ(1234, x.GetUint64()); EXPECT_EQ(1234u, x.GetUint64());
EXPECT_TRUE(x.IsNumber()); EXPECT_TRUE(x.IsNumber());
EXPECT_TRUE(x.IsInt()); EXPECT_TRUE(x.IsInt());
EXPECT_TRUE(x.IsUint()); EXPECT_TRUE(x.IsUint());
...@@ -241,9 +241,9 @@ TEST(Value, Uint64) { ...@@ -241,9 +241,9 @@ TEST(Value, Uint64) {
Value x(uint64_t(1234LL)); Value x(uint64_t(1234LL));
EXPECT_EQ(kNumberType, x.GetType()); EXPECT_EQ(kNumberType, x.GetType());
EXPECT_EQ(1234, x.GetInt()); EXPECT_EQ(1234, x.GetInt());
EXPECT_EQ(1234, x.GetUint()); EXPECT_EQ(1234u, x.GetUint());
EXPECT_EQ(1234, x.GetInt64()); EXPECT_EQ(1234, x.GetInt64());
EXPECT_EQ(1234, x.GetUint64()); EXPECT_EQ(1234u, x.GetUint64());
EXPECT_TRUE(x.IsNumber()); EXPECT_TRUE(x.IsNumber());
EXPECT_TRUE(x.IsInt()); EXPECT_TRUE(x.IsInt());
EXPECT_TRUE(x.IsUint()); EXPECT_TRUE(x.IsUint());
...@@ -310,7 +310,7 @@ TEST(Value, String) { ...@@ -310,7 +310,7 @@ TEST(Value, String) {
EXPECT_EQ(kStringType, x.GetType()); EXPECT_EQ(kStringType, x.GetType());
EXPECT_TRUE(x.IsString()); EXPECT_TRUE(x.IsString());
EXPECT_STREQ("Hello", x.GetString()); EXPECT_STREQ("Hello", x.GetString());
EXPECT_EQ(5, x.GetStringLength()); EXPECT_EQ(5u, x.GetStringLength());
EXPECT_FALSE(x.IsNumber()); EXPECT_FALSE(x.IsNumber());
EXPECT_FALSE(x.IsNull()); EXPECT_FALSE(x.IsNull());
...@@ -326,20 +326,20 @@ TEST(Value, String) { ...@@ -326,20 +326,20 @@ TEST(Value, String) {
//x.SetString("World"); //x.SetString("World");
x.SetString("World", 5); x.SetString("World", 5);
EXPECT_STREQ("Hello", c.GetString()); EXPECT_STREQ("Hello", c.GetString());
EXPECT_EQ(5, c.GetStringLength()); EXPECT_EQ(5u, c.GetStringLength());
// Constructor with type // Constructor with type
Value y(kStringType); Value y(kStringType);
EXPECT_TRUE(y.IsString()); EXPECT_TRUE(y.IsString());
EXPECT_EQ(0, y.GetString()); EXPECT_EQ(0, y.GetString());
EXPECT_EQ(0, y.GetStringLength()); EXPECT_EQ(0u, y.GetStringLength());
// SetConsttring() // SetConsttring()
Value z; Value z;
//z.SetString("Hello"); //z.SetString("Hello");
z.SetString("Hello", 5); z.SetString("Hello", 5);
EXPECT_STREQ("Hello", z.GetString()); EXPECT_STREQ("Hello", z.GetString());
EXPECT_EQ(5, z.GetStringLength()); EXPECT_EQ(5u, z.GetStringLength());
// SetString() // SetString()
char s[] = "World"; char s[] = "World";
...@@ -347,7 +347,7 @@ TEST(Value, String) { ...@@ -347,7 +347,7 @@ TEST(Value, String) {
w.SetString(s, (SizeType)strlen(s), allocator); w.SetString(s, (SizeType)strlen(s), allocator);
s[0] = '\0'; s[0] = '\0';
EXPECT_STREQ("World", w.GetString()); EXPECT_STREQ("World", w.GetString());
EXPECT_EQ(5, w.GetStringLength()); EXPECT_EQ(5u, w.GetStringLength());
} }
TEST(Value, Array) { TEST(Value, Array) {
...@@ -358,10 +358,10 @@ TEST(Value, Array) { ...@@ -358,10 +358,10 @@ TEST(Value, Array) {
EXPECT_EQ(kArrayType, x.GetType()); EXPECT_EQ(kArrayType, x.GetType());
EXPECT_TRUE(x.IsArray()); EXPECT_TRUE(x.IsArray());
EXPECT_TRUE(x.Empty()); EXPECT_TRUE(x.Empty());
EXPECT_EQ(0, x.Size()); EXPECT_EQ(0u, x.Size());
EXPECT_TRUE(y.IsArray()); EXPECT_TRUE(y.IsArray());
EXPECT_TRUE(y.Empty()); EXPECT_TRUE(y.Empty());
EXPECT_EQ(0, y.Size()); EXPECT_EQ(0u, y.Size());
EXPECT_FALSE(x.IsNull()); EXPECT_FALSE(x.IsNull());
EXPECT_FALSE(x.IsBool()); EXPECT_FALSE(x.IsBool());
...@@ -381,9 +381,9 @@ TEST(Value, Array) { ...@@ -381,9 +381,9 @@ TEST(Value, Array) {
x.PushBack(v, allocator); x.PushBack(v, allocator);
EXPECT_FALSE(x.Empty()); EXPECT_FALSE(x.Empty());
EXPECT_EQ(4, x.Size()); EXPECT_EQ(4u, x.Size());
EXPECT_FALSE(y.Empty()); EXPECT_FALSE(y.Empty());
EXPECT_EQ(4, y.Size()); EXPECT_EQ(4u, y.Size());
EXPECT_TRUE(x[SizeType(0)].IsNull()); EXPECT_TRUE(x[SizeType(0)].IsNull());
EXPECT_TRUE(x[1u].IsTrue()); EXPECT_TRUE(x[1u].IsTrue());
EXPECT_TRUE(x[2u].IsFalse()); EXPECT_TRUE(x[2u].IsFalse());
...@@ -427,7 +427,7 @@ TEST(Value, Array) { ...@@ -427,7 +427,7 @@ TEST(Value, Array) {
// PopBack() // PopBack()
x.PopBack(); x.PopBack();
EXPECT_EQ(3, x.Size()); EXPECT_EQ(3u, x.Size());
EXPECT_TRUE(y[SizeType(0)].IsNull()); EXPECT_TRUE(y[SizeType(0)].IsNull());
EXPECT_TRUE(y[1].IsTrue()); EXPECT_TRUE(y[1].IsTrue());
EXPECT_TRUE(y[2].IsFalse()); EXPECT_TRUE(y[2].IsFalse());
...@@ -435,9 +435,9 @@ TEST(Value, Array) { ...@@ -435,9 +435,9 @@ TEST(Value, Array) {
// Clear() // Clear()
x.Clear(); x.Clear();
EXPECT_TRUE(x.Empty()); EXPECT_TRUE(x.Empty());
EXPECT_EQ(0, x.Size()); EXPECT_EQ(0u, x.Size());
EXPECT_TRUE(y.Empty()); EXPECT_TRUE(y.Empty());
EXPECT_EQ(0, y.Size()); EXPECT_EQ(0u, y.Size());
// SetArray() // SetArray()
Value z; Value z;
...@@ -589,4 +589,4 @@ TEST(Value, RemoveLastElement) { ...@@ -589,4 +589,4 @@ TEST(Value, RemoveLastElement) {
EXPECT_TRUE(objVal.HasMember("var3")); EXPECT_TRUE(objVal.HasMember("var3"));
objVal.RemoveMember("var3"); // Assertion here in r61 objVal.RemoveMember("var3"); // Assertion here in r61
EXPECT_FALSE(objVal.HasMember("var3")); EXPECT_FALSE(objVal.HasMember("var3"));
} }
\ No newline at end of file
...@@ -12,7 +12,7 @@ TEST(Writer, Compact) { ...@@ -12,7 +12,7 @@ TEST(Writer, Compact) {
Reader reader; Reader reader;
reader.Parse<0>(s, writer); reader.Parse<0>(s, writer);
EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", buffer.GetString()); EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", buffer.GetString());
EXPECT_EQ(77, buffer.GetSize()); EXPECT_EQ(77u, buffer.GetSize());
} }
// json -> parse -> writer -> json // json -> parse -> writer -> json
...@@ -64,4 +64,4 @@ TEST(Writer, Transcode) { ...@@ -64,4 +64,4 @@ TEST(Writer, Transcode) {
GenericReader<UTF8<>, UTF16<> > reader; GenericReader<UTF8<>, UTF16<> > reader;
reader.Parse<0>(s, writer); reader.Parse<0>(s, writer);
EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"dollar\":\"\x24\",\"cents\":\"\xC2\xA2\",\"euro\":\"\xE2\x82\xAC\",\"gclef\":\"\xF0\x9D\x84\x9E\"}", buffer.GetString()); EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3],\"dollar\":\"\x24\",\"cents\":\"\xC2\xA2\",\"euro\":\"\xE2\x82\xAC\",\"gclef\":\"\xF0\x9D\x84\x9E\"}", buffer.GetString());
} }
\ No newline at end of file
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