Unverified Commit 8a96a95d authored by Milo Yip's avatar Milo Yip Committed by GitHub

Merge branch 'master' into fix-noexcept

parents f54f6b5a f5f6052c
...@@ -92,26 +92,26 @@ public: ...@@ -92,26 +92,26 @@ public:
*/ */
//@{ //@{
bool Null() { PrettyPrefix(kNullType); return Base::WriteNull(); } bool Null() { PrettyPrefix(kNullType); return Base::EndValue(Base::WriteNull()); }
bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::WriteBool(b); } bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::EndValue(Base::WriteBool(b)); }
bool Int(int i) { PrettyPrefix(kNumberType); return Base::WriteInt(i); } bool Int(int i) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt(i)); }
bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::WriteUint(u); } bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint(u)); }
bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::WriteInt64(i64); } bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt64(i64)); }
bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::WriteUint64(u64); } bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint64(u64)); }
bool Double(double d) { PrettyPrefix(kNumberType); return Base::WriteDouble(d); } bool Double(double d) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteDouble(d)); }
bool RawNumber(const Ch* str, SizeType length, bool copy = false) { bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
RAPIDJSON_ASSERT(str != 0); RAPIDJSON_ASSERT(str != 0);
(void)copy; (void)copy;
PrettyPrefix(kNumberType); PrettyPrefix(kNumberType);
return Base::WriteString(str, length); return Base::EndValue(Base::WriteString(str, length));
} }
bool String(const Ch* str, SizeType length, bool copy = false) { bool String(const Ch* str, SizeType length, bool copy = false) {
RAPIDJSON_ASSERT(str != 0); RAPIDJSON_ASSERT(str != 0);
(void)copy; (void)copy;
PrettyPrefix(kStringType); PrettyPrefix(kStringType);
return Base::WriteString(str, length); return Base::EndValue(Base::WriteString(str, length));
} }
#if RAPIDJSON_HAS_STDSTRING #if RAPIDJSON_HAS_STDSTRING
...@@ -146,7 +146,7 @@ public: ...@@ -146,7 +146,7 @@ public:
Base::os_->Put('\n'); Base::os_->Put('\n');
WriteIndent(); WriteIndent();
} }
bool ret = Base::WriteEndObject(); bool ret = Base::EndValue(Base::WriteEndObject());
(void)ret; (void)ret;
RAPIDJSON_ASSERT(ret == true); RAPIDJSON_ASSERT(ret == true);
if (Base::level_stack_.Empty()) // end of json text if (Base::level_stack_.Empty()) // end of json text
...@@ -170,7 +170,7 @@ public: ...@@ -170,7 +170,7 @@ public:
Base::os_->Put('\n'); Base::os_->Put('\n');
WriteIndent(); WriteIndent();
} }
bool ret = Base::WriteEndArray(); bool ret = Base::EndValue(Base::WriteEndArray());
(void)ret; (void)ret;
RAPIDJSON_ASSERT(ret == true); RAPIDJSON_ASSERT(ret == true);
if (Base::level_stack_.Empty()) // end of json text if (Base::level_stack_.Empty()) // end of json text
...@@ -201,7 +201,7 @@ public: ...@@ -201,7 +201,7 @@ public:
bool RawValue(const Ch* json, size_t length, Type type) { bool RawValue(const Ch* json, size_t length, Type type) {
RAPIDJSON_ASSERT(json != 0); RAPIDJSON_ASSERT(json != 0);
PrettyPrefix(type); PrettyPrefix(type);
return Base::WriteRawValue(json, length); return Base::EndValue(Base::WriteRawValue(json, length));
} }
protected: protected:
......
...@@ -269,16 +269,11 @@ ...@@ -269,16 +269,11 @@
/*! \ingroup RAPIDJSON_CONFIG /*! \ingroup RAPIDJSON_CONFIG
\param x pointer to align \param x pointer to align
Some machines require strict data alignment. Currently the default uses 4 bytes Some machines require strict data alignment. The default is 8 bytes.
alignment on 32-bit platforms and 8 bytes alignment for 64-bit platforms.
User can customize by defining the RAPIDJSON_ALIGN function macro. User can customize by defining the RAPIDJSON_ALIGN function macro.
*/ */
#ifndef RAPIDJSON_ALIGN #ifndef RAPIDJSON_ALIGN
#if RAPIDJSON_64BIT == 1 #define RAPIDJSON_ALIGN(x) (((x) + static_cast<size_t>(7u)) & ~static_cast<size_t>(7u))
#define RAPIDJSON_ALIGN(x) (((x) + static_cast<uint64_t>(7u)) & ~static_cast<uint64_t>(7u))
#else
#define RAPIDJSON_ALIGN(x) (((x) + 3u) & ~3u)
#endif
#endif #endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -617,6 +612,19 @@ RAPIDJSON_NAMESPACE_END ...@@ -617,6 +612,19 @@ RAPIDJSON_NAMESPACE_END
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT #endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
#endif // RAPIDJSON_NOEXCEPT_ASSERT #endif // RAPIDJSON_NOEXCEPT_ASSERT
///////////////////////////////////////////////////////////////////////////////
// RAPIDJSON_NOEXCEPT_ASSERT
#ifdef RAPIDJSON_ASSERT_THROWS
#if RAPIDJSON_HAS_CXX11_NOEXCEPT
#define RAPIDJSON_NOEXCEPT_ASSERT(x)
#else
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
#endif // RAPIDJSON_HAS_CXX11_NOEXCEPT
#else
#define RAPIDJSON_NOEXCEPT_ASSERT(x) RAPIDJSON_ASSERT(x)
#endif // RAPIDJSON_ASSERT_THROWS
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// new/delete // new/delete
......
...@@ -606,7 +606,7 @@ public: ...@@ -606,7 +606,7 @@ public:
parseResult_.Clear(); parseResult_.Clear();
state_ = IterativeParsingStartState; state_ = IterativeParsingStartState;
} }
//! Parse one token from JSON text //! Parse one token from JSON text
/*! \tparam InputStream Type of input stream, implementing Stream concept /*! \tparam InputStream Type of input stream, implementing Stream concept
\tparam Handler Type of handler, implementing Handler concept. \tparam Handler Type of handler, implementing Handler concept.
...@@ -618,11 +618,11 @@ public: ...@@ -618,11 +618,11 @@ public:
bool IterativeParseNext(InputStream& is, Handler& handler) { bool IterativeParseNext(InputStream& is, Handler& handler) {
while (RAPIDJSON_LIKELY(is.Peek() != '\0')) { while (RAPIDJSON_LIKELY(is.Peek() != '\0')) {
SkipWhitespaceAndComments<parseFlags>(is); SkipWhitespaceAndComments<parseFlags>(is);
Token t = Tokenize(is.Peek()); Token t = Tokenize(is.Peek());
IterativeParsingState n = Predict(state_, t); IterativeParsingState n = Predict(state_, t);
IterativeParsingState d = Transit<parseFlags>(state_, t, n, is, handler); IterativeParsingState d = Transit<parseFlags>(state_, t, n, is, handler);
// If we've finished or hit an error... // If we've finished or hit an error...
if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) { if (RAPIDJSON_UNLIKELY(IsIterativeParsingCompleteState(d))) {
// Report errors. // Report errors.
...@@ -630,11 +630,11 @@ public: ...@@ -630,11 +630,11 @@ public:
HandleError(state_, is); HandleError(state_, is);
return false; return false;
} }
// Transition to the finish state. // Transition to the finish state.
RAPIDJSON_ASSERT(d == IterativeParsingFinishState); RAPIDJSON_ASSERT(d == IterativeParsingFinishState);
state_ = d; state_ = d;
// If StopWhenDone is not set... // If StopWhenDone is not set...
if (!(parseFlags & kParseStopWhenDoneFlag)) { if (!(parseFlags & kParseStopWhenDoneFlag)) {
// ... and extra non-whitespace data is found... // ... and extra non-whitespace data is found...
...@@ -645,11 +645,11 @@ public: ...@@ -645,11 +645,11 @@ public:
return false; return false;
} }
} }
// Success! We are done! // Success! We are done!
return true; return true;
} }
// Transition to the new state. // Transition to the new state.
state_ = d; state_ = d;
...@@ -657,7 +657,7 @@ public: ...@@ -657,7 +657,7 @@ public:
if (!IsIterativeParsingDelimiterState(n)) if (!IsIterativeParsingDelimiterState(n))
return true; return true;
} }
// We reached the end of file. // We reached the end of file.
stack_.Clear(); stack_.Clear();
...@@ -665,10 +665,10 @@ public: ...@@ -665,10 +665,10 @@ public:
HandleError(state_, is); HandleError(state_, is);
return false; return false;
} }
return true; return true;
} }
//! Check if token-by-token parsing JSON text is complete //! Check if token-by-token parsing JSON text is complete
/*! \return Whether the JSON has been fully decoded. /*! \return Whether the JSON has been fully decoded.
*/ */
...@@ -1523,7 +1523,7 @@ private: ...@@ -1523,7 +1523,7 @@ private:
} }
} }
} }
if (RAPIDJSON_UNLIKELY(!useNanOrInf)) { if (RAPIDJSON_UNLIKELY(!useNanOrInf)) {
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell()); RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
} }
...@@ -1701,7 +1701,7 @@ private: ...@@ -1701,7 +1701,7 @@ private:
d = internal::StrtodNormalPrecision(d, p); d = internal::StrtodNormalPrecision(d, p);
// Use > max, instead of == inf, to fix bogus warning -Wfloat-equal // Use > max, instead of == inf, to fix bogus warning -Wfloat-equal
if (d > std::numeric_limits<double>::max()) { if (d > (std::numeric_limits<double>::max)()) {
// Overflow // Overflow
// TODO: internal::StrtodX should report overflow (or underflow) // TODO: internal::StrtodX should report overflow (or underflow)
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset); RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
...@@ -1769,12 +1769,12 @@ private: ...@@ -1769,12 +1769,12 @@ private:
// Single value state // Single value state
IterativeParsingValueState, IterativeParsingValueState,
// Delimiter states (at bottom) // Delimiter states (at bottom)
IterativeParsingElementDelimiterState, IterativeParsingElementDelimiterState,
IterativeParsingMemberDelimiterState, IterativeParsingMemberDelimiterState,
IterativeParsingKeyValueDelimiterState, IterativeParsingKeyValueDelimiterState,
cIterativeParsingStateCount cIterativeParsingStateCount
}; };
...@@ -2167,43 +2167,43 @@ private: ...@@ -2167,43 +2167,43 @@ private:
RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) const { RAPIDJSON_FORCEINLINE bool IsIterativeParsingDelimiterState(IterativeParsingState s) const {
return s >= IterativeParsingElementDelimiterState; return s >= IterativeParsingElementDelimiterState;
} }
RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s) const { RAPIDJSON_FORCEINLINE bool IsIterativeParsingCompleteState(IterativeParsingState s) const {
return s <= IterativeParsingErrorState; return s <= IterativeParsingErrorState;
} }
template <unsigned parseFlags, typename InputStream, typename Handler> template <unsigned parseFlags, typename InputStream, typename Handler>
ParseResult IterativeParse(InputStream& is, Handler& handler) { ParseResult IterativeParse(InputStream& is, Handler& handler) {
parseResult_.Clear(); parseResult_.Clear();
ClearStackOnExit scope(*this); ClearStackOnExit scope(*this);
IterativeParsingState state = IterativeParsingStartState; IterativeParsingState state = IterativeParsingStartState;
SkipWhitespaceAndComments<parseFlags>(is); SkipWhitespaceAndComments<parseFlags>(is);
RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
while (is.Peek() != '\0') { while (is.Peek() != '\0') {
Token t = Tokenize(is.Peek()); Token t = Tokenize(is.Peek());
IterativeParsingState n = Predict(state, t); IterativeParsingState n = Predict(state, t);
IterativeParsingState d = Transit<parseFlags>(state, t, n, is, handler); IterativeParsingState d = Transit<parseFlags>(state, t, n, is, handler);
if (d == IterativeParsingErrorState) { if (d == IterativeParsingErrorState) {
HandleError(state, is); HandleError(state, is);
break; break;
} }
state = d; state = d;
// Do not further consume streams if a root JSON has been parsed. // Do not further consume streams if a root JSON has been parsed.
if ((parseFlags & kParseStopWhenDoneFlag) && state == IterativeParsingFinishState) if ((parseFlags & kParseStopWhenDoneFlag) && state == IterativeParsingFinishState)
break; break;
SkipWhitespaceAndComments<parseFlags>(is); SkipWhitespaceAndComments<parseFlags>(is);
RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_); RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
} }
// Handle the end of file. // Handle the end of file.
if (state != IterativeParsingFinishState) if (state != IterativeParsingFinishState)
HandleError(state, is); HandleError(state, is);
return parseResult_; return parseResult_;
} }
......
...@@ -76,7 +76,7 @@ TEST_F(Platform, strlen) { ...@@ -76,7 +76,7 @@ TEST_F(Platform, strlen) {
TEST_F(Platform, memcmp) { TEST_F(Platform, memcmp) {
for (int i = 0; i < kTrialCount; i++) { for (int i = 0; i < kTrialCount; i++) {
EXPECT_EQ(0, memcmp(temp_, json_, length_)); EXPECT_EQ(0u, memcmp(temp_, json_, length_));
} }
} }
......
...@@ -63,23 +63,21 @@ TEST(Allocator, MemoryPoolAllocator) { ...@@ -63,23 +63,21 @@ TEST(Allocator, MemoryPoolAllocator) {
} }
TEST(Allocator, Alignment) { TEST(Allocator, Alignment) {
#if RAPIDJSON_64BIT == 1 if (sizeof(size_t) >= 8) {
EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000000), RAPIDJSON_ALIGN(0)); EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000000), RAPIDJSON_ALIGN(0));
for (uint64_t i = 1; i < 8; i++) { for (uint64_t i = 1; i < 8; i++) {
EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000008), RAPIDJSON_ALIGN(i)); EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000008), RAPIDJSON_ALIGN(i));
EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000010), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0x00000000, 0x00000008) + i)); EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000000, 0x00000010), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0x00000000, 0x00000008) + i));
EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000001, 0x00000000), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0x00000000, 0xFFFFFFF8) + i)); EXPECT_EQ(RAPIDJSON_UINT64_C2(0x00000001, 0x00000000), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0x00000000, 0xFFFFFFF8) + i));
EXPECT_EQ(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFF8), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFF0) + i)); EXPECT_EQ(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFF8), RAPIDJSON_ALIGN(RAPIDJSON_UINT64_C2(0xFFFFFFFF, 0xFFFFFFF0) + i));
}
} }
#else
EXPECT_EQ(0u, RAPIDJSON_ALIGN(0u)); EXPECT_EQ(0u, RAPIDJSON_ALIGN(0u));
for (uint32_t i = 1; i < 4; i++) { for (uint32_t i = 1; i < 8; i++) {
EXPECT_EQ(4u, RAPIDJSON_ALIGN(i)); EXPECT_EQ(8u, RAPIDJSON_ALIGN(i));
EXPECT_EQ(8u, RAPIDJSON_ALIGN(4u + i)); EXPECT_EQ(0xFFFFFFF8u, RAPIDJSON_ALIGN(0xFFFFFFF0u + i));
EXPECT_EQ(0xFFFFFFF8u, RAPIDJSON_ALIGN(0xFFFFFFF4u + i));
EXPECT_EQ(0xFFFFFFFCu, RAPIDJSON_ALIGN(0xFFFFFFF8u + i));
} }
#endif
} }
TEST(Allocator, Issue399) { TEST(Allocator, Issue399) {
......
...@@ -38,8 +38,8 @@ TEST(CursorStreamWrapper, MissingFirstBracket) { ...@@ -38,8 +38,8 @@ TEST(CursorStreamWrapper, MissingFirstBracket) {
size_t col, line; size_t col, line;
bool ret = testJson(json, line, col); bool ret = testJson(json, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 3); EXPECT_EQ(line, 3u);
EXPECT_EQ(col, 0); EXPECT_EQ(col, 0u);
} }
TEST(CursorStreamWrapper, MissingQuotes) { TEST(CursorStreamWrapper, MissingQuotes) {
...@@ -47,8 +47,8 @@ TEST(CursorStreamWrapper, MissingQuotes) { ...@@ -47,8 +47,8 @@ TEST(CursorStreamWrapper, MissingQuotes) {
size_t col, line; size_t col, line;
bool ret = testJson(json, line, col); bool ret = testJson(json, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 1); EXPECT_EQ(line, 1u);
EXPECT_EQ(col, 8); EXPECT_EQ(col, 8u);
} }
TEST(CursorStreamWrapper, MissingColon) { TEST(CursorStreamWrapper, MissingColon) {
...@@ -56,8 +56,8 @@ TEST(CursorStreamWrapper, MissingColon) { ...@@ -56,8 +56,8 @@ TEST(CursorStreamWrapper, MissingColon) {
size_t col, line; size_t col, line;
bool ret = testJson(json, line, col); bool ret = testJson(json, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 3); EXPECT_EQ(line, 3u);
EXPECT_EQ(col, 0); EXPECT_EQ(col, 0u);
} }
TEST(CursorStreamWrapper, MissingSecondQuotes) { TEST(CursorStreamWrapper, MissingSecondQuotes) {
...@@ -65,8 +65,8 @@ TEST(CursorStreamWrapper, MissingSecondQuotes) { ...@@ -65,8 +65,8 @@ TEST(CursorStreamWrapper, MissingSecondQuotes) {
size_t col, line; size_t col, line;
bool ret = testJson(json, line, col); bool ret = testJson(json, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 3); EXPECT_EQ(line, 3u);
EXPECT_EQ(col, 1); EXPECT_EQ(col, 1u);
} }
TEST(CursorStreamWrapper, MissingComma) { TEST(CursorStreamWrapper, MissingComma) {
...@@ -74,8 +74,8 @@ TEST(CursorStreamWrapper, MissingComma) { ...@@ -74,8 +74,8 @@ TEST(CursorStreamWrapper, MissingComma) {
size_t col, line; size_t col, line;
bool ret = testJson(json, line, col); bool ret = testJson(json, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 3); EXPECT_EQ(line, 3u);
EXPECT_EQ(col, 12); EXPECT_EQ(col, 12u);
} }
TEST(CursorStreamWrapper, MissingArrayBracket) { TEST(CursorStreamWrapper, MissingArrayBracket) {
...@@ -83,8 +83,8 @@ TEST(CursorStreamWrapper, MissingArrayBracket) { ...@@ -83,8 +83,8 @@ TEST(CursorStreamWrapper, MissingArrayBracket) {
size_t col, line; size_t col, line;
bool ret = testJson(json, line, col); bool ret = testJson(json, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 4); EXPECT_EQ(line, 4u);
EXPECT_EQ(col, 9); EXPECT_EQ(col, 9u);
} }
TEST(CursorStreamWrapper, MissingArrayComma) { TEST(CursorStreamWrapper, MissingArrayComma) {
...@@ -92,8 +92,8 @@ TEST(CursorStreamWrapper, MissingArrayComma) { ...@@ -92,8 +92,8 @@ TEST(CursorStreamWrapper, MissingArrayComma) {
size_t col, line; size_t col, line;
bool ret = testJson(json, line, col); bool ret = testJson(json, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 4); EXPECT_EQ(line, 4u);
EXPECT_EQ(col, 6); EXPECT_EQ(col, 6u);
} }
TEST(CursorStreamWrapper, MissingLastArrayBracket) { TEST(CursorStreamWrapper, MissingLastArrayBracket) {
...@@ -101,8 +101,8 @@ TEST(CursorStreamWrapper, MissingLastArrayBracket) { ...@@ -101,8 +101,8 @@ TEST(CursorStreamWrapper, MissingLastArrayBracket) {
size_t col, line; size_t col, line;
bool ret = testJson(json8, line, col); bool ret = testJson(json8, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 4); EXPECT_EQ(line, 4u);
EXPECT_EQ(col, 15); EXPECT_EQ(col, 15u);
} }
TEST(CursorStreamWrapper, MissingLastBracket) { TEST(CursorStreamWrapper, MissingLastBracket) {
...@@ -110,6 +110,6 @@ TEST(CursorStreamWrapper, MissingLastBracket) { ...@@ -110,6 +110,6 @@ TEST(CursorStreamWrapper, MissingLastBracket) {
size_t col, line; size_t col, line;
bool ret = testJson(json9, line, col); bool ret = testJson(json9, line, col);
EXPECT_TRUE(ret); EXPECT_TRUE(ret);
EXPECT_EQ(line, 4); EXPECT_EQ(line, 4u);
EXPECT_EQ(col, 16); EXPECT_EQ(col, 16u);
} }
...@@ -35,21 +35,21 @@ static void TestStringStream() { ...@@ -35,21 +35,21 @@ static void TestStringStream() {
{ {
StringStreamType iss; StringStreamType iss;
BasicIStreamWrapper<StringStreamType> is(iss); BasicIStreamWrapper<StringStreamType> is(iss);
EXPECT_EQ(0, is.Tell()); EXPECT_EQ(0u, is.Tell());
if (sizeof(Ch) == 1) { if (sizeof(Ch) == 1) {
EXPECT_EQ(0, is.Peek4()); EXPECT_EQ(0, is.Peek4());
EXPECT_EQ(0, is.Tell()); EXPECT_EQ(0u, is.Tell());
} }
EXPECT_EQ(0, is.Peek()); EXPECT_EQ(0, is.Peek());
EXPECT_EQ(0, is.Take()); EXPECT_EQ(0, is.Take());
EXPECT_EQ(0, is.Tell()); EXPECT_EQ(0u, is.Tell());
} }
{ {
Ch s[] = { 'A', 'B', 'C', '\0' }; Ch s[] = { 'A', 'B', 'C', '\0' };
StringStreamType iss(s); StringStreamType iss(s);
BasicIStreamWrapper<StringStreamType> is(iss); BasicIStreamWrapper<StringStreamType> is(iss);
EXPECT_EQ(0, is.Tell()); EXPECT_EQ(0u, is.Tell());
if (sizeof(Ch) == 1) { if (sizeof(Ch) == 1) {
EXPECT_EQ(0, is.Peek4()); // less than 4 bytes EXPECT_EQ(0, is.Peek4()); // less than 4 bytes
} }
...@@ -59,7 +59,7 @@ static void TestStringStream() { ...@@ -59,7 +59,7 @@ static void TestStringStream() {
EXPECT_EQ('A' + i, is.Peek()); EXPECT_EQ('A' + i, is.Peek());
EXPECT_EQ('A' + i, is.Take()); EXPECT_EQ('A' + i, is.Take());
} }
EXPECT_EQ(3, is.Tell()); EXPECT_EQ(3u, is.Tell());
EXPECT_EQ(0, is.Peek()); EXPECT_EQ(0, is.Peek());
EXPECT_EQ(0, is.Take()); EXPECT_EQ(0, is.Take());
} }
...@@ -72,7 +72,7 @@ static void TestStringStream() { ...@@ -72,7 +72,7 @@ static void TestStringStream() {
const Ch* c = is.Peek4(); const Ch* c = is.Peek4();
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
EXPECT_EQ('A' + i, c[i]); EXPECT_EQ('A' + i, c[i]);
EXPECT_EQ(0, is.Tell()); EXPECT_EQ(0u, is.Tell());
} }
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
EXPECT_EQ(static_cast<size_t>(i), is.Tell()); EXPECT_EQ(static_cast<size_t>(i), is.Tell());
...@@ -80,7 +80,7 @@ static void TestStringStream() { ...@@ -80,7 +80,7 @@ static void TestStringStream() {
EXPECT_EQ('A' + i, is.Peek()); EXPECT_EQ('A' + i, is.Peek());
EXPECT_EQ('A' + i, is.Take()); EXPECT_EQ('A' + i, is.Take());
} }
EXPECT_EQ(5, is.Tell()); EXPECT_EQ(5u, is.Tell());
EXPECT_EQ(0, is.Peek()); EXPECT_EQ(0, is.Peek());
EXPECT_EQ(0, is.Take()); EXPECT_EQ(0, is.Take());
} }
...@@ -129,7 +129,7 @@ TEST(IStreamWrapper, ifstream) { ...@@ -129,7 +129,7 @@ TEST(IStreamWrapper, ifstream) {
Document d; Document d;
EXPECT_TRUE(!d.ParseStream(eis).HasParseError()); EXPECT_TRUE(!d.ParseStream(eis).HasParseError());
EXPECT_TRUE(d.IsObject()); EXPECT_TRUE(d.IsObject());
EXPECT_EQ(5, d.MemberCount()); EXPECT_EQ(5u, d.MemberCount());
} }
TEST(IStreamWrapper, fstream) { TEST(IStreamWrapper, fstream) {
...@@ -140,7 +140,7 @@ TEST(IStreamWrapper, fstream) { ...@@ -140,7 +140,7 @@ TEST(IStreamWrapper, fstream) {
Document d; Document d;
EXPECT_TRUE(!d.ParseStream(eis).HasParseError()); EXPECT_TRUE(!d.ParseStream(eis).HasParseError());
EXPECT_TRUE(d.IsObject()); EXPECT_TRUE(d.IsObject());
EXPECT_EQ(5, d.MemberCount()); EXPECT_EQ(5u, d.MemberCount());
} }
// wifstream/wfstream only works on C++11 with codecvt_utf16 // wifstream/wfstream only works on C++11 with codecvt_utf16
......
// Tencent is pleased to support the open source community by making RapidJSON available. // Tencent is pleased to support the open source community by making RapidJSON available.
// //
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
// //
// Licensed under the MIT License (the "License"); you may not use this file except // Licensed under the MIT License (the "License"); you may not use this file except
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
// //
// http://opensource.org/licenses/MIT // http://opensource.org/licenses/MIT
// //
// Unless required by applicable law or agreed to in writing, software distributed // Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the // CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License. // specific language governing permissions and limitations under the License.
#include "unittest.h" #include "unittest.h"
...@@ -61,7 +61,7 @@ static void VerifyValue(T value, void(*f)(T, char*), char* (*g)(T, char*)) { ...@@ -61,7 +61,7 @@ static void VerifyValue(T value, void(*f)(T, char*), char* (*g)(T, char*)) {
f(value, buffer1); f(value, buffer1);
*g(value, buffer2) = '\0'; *g(value, buffer2) = '\0';
EXPECT_STREQ(buffer1, buffer2); EXPECT_STREQ(buffer1, buffer2);
} }
...@@ -79,12 +79,12 @@ static void Verify(void(*f)(T, char*), char* (*g)(T, char*)) { ...@@ -79,12 +79,12 @@ static void Verify(void(*f)(T, char*), char* (*g)(T, char*)) {
do { do {
VerifyValue<T>(i - 1, f, g); VerifyValue<T>(i - 1, f, g);
VerifyValue<T>(i, f, g); VerifyValue<T>(i, f, g);
if (std::numeric_limits<T>::min() < 0) { if ((std::numeric_limits<T>::min)() < 0) {
VerifyValue<T>(Traits<T>::Negate(i), f, g); VerifyValue<T>(Traits<T>::Negate(i), f, g);
VerifyValue<T>(Traits<T>::Negate(i + 1), f, g); VerifyValue<T>(Traits<T>::Negate(i + 1), f, g);
} }
last = i; last = i;
if (i > static_cast<T>(std::numeric_limits<T>::max() / static_cast<T>(power))) if (i > static_cast<T>((std::numeric_limits<T>::max)() / static_cast<T>(power)))
break; break;
i *= static_cast<T>(power); i *= static_cast<T>(power);
} while (last < i); } while (last < i);
......
...@@ -634,13 +634,13 @@ TEST(Pointer, Get) { ...@@ -634,13 +634,13 @@ TEST(Pointer, Get) {
EXPECT_TRUE(Pointer("/abc").Get(d) == 0); EXPECT_TRUE(Pointer("/abc").Get(d) == 0);
size_t unresolvedTokenIndex; size_t unresolvedTokenIndex;
EXPECT_TRUE(Pointer("/foo/2").Get(d, &unresolvedTokenIndex) == 0); // Out of boundary EXPECT_TRUE(Pointer("/foo/2").Get(d, &unresolvedTokenIndex) == 0); // Out of boundary
EXPECT_EQ(1, unresolvedTokenIndex); EXPECT_EQ(1u, unresolvedTokenIndex);
EXPECT_TRUE(Pointer("/foo/a").Get(d, &unresolvedTokenIndex) == 0); // "/foo" is an array, cannot query by "a" EXPECT_TRUE(Pointer("/foo/a").Get(d, &unresolvedTokenIndex) == 0); // "/foo" is an array, cannot query by "a"
EXPECT_EQ(1, unresolvedTokenIndex); EXPECT_EQ(1u, unresolvedTokenIndex);
EXPECT_TRUE(Pointer("/foo/0/0").Get(d, &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query EXPECT_TRUE(Pointer("/foo/0/0").Get(d, &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query
EXPECT_EQ(2, unresolvedTokenIndex); EXPECT_EQ(2u, unresolvedTokenIndex);
EXPECT_TRUE(Pointer("/foo/0/a").Get(d, &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query EXPECT_TRUE(Pointer("/foo/0/a").Get(d, &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query
EXPECT_EQ(2, unresolvedTokenIndex); EXPECT_EQ(2u, unresolvedTokenIndex);
} }
TEST(Pointer, GetWithDefault) { TEST(Pointer, GetWithDefault) {
...@@ -959,13 +959,13 @@ TEST(Pointer, GetValueByPointer) { ...@@ -959,13 +959,13 @@ TEST(Pointer, GetValueByPointer) {
size_t unresolvedTokenIndex; size_t unresolvedTokenIndex;
EXPECT_TRUE(GetValueByPointer(d, "/foo/2", &unresolvedTokenIndex) == 0); // Out of boundary EXPECT_TRUE(GetValueByPointer(d, "/foo/2", &unresolvedTokenIndex) == 0); // Out of boundary
EXPECT_EQ(1, unresolvedTokenIndex); EXPECT_EQ(1u, unresolvedTokenIndex);
EXPECT_TRUE(GetValueByPointer(d, "/foo/a", &unresolvedTokenIndex) == 0); // "/foo" is an array, cannot query by "a" EXPECT_TRUE(GetValueByPointer(d, "/foo/a", &unresolvedTokenIndex) == 0); // "/foo" is an array, cannot query by "a"
EXPECT_EQ(1, unresolvedTokenIndex); EXPECT_EQ(1u, unresolvedTokenIndex);
EXPECT_TRUE(GetValueByPointer(d, "/foo/0/0", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query EXPECT_TRUE(GetValueByPointer(d, "/foo/0/0", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query
EXPECT_EQ(2, unresolvedTokenIndex); EXPECT_EQ(2u, unresolvedTokenIndex);
EXPECT_TRUE(GetValueByPointer(d, "/foo/0/a", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query EXPECT_TRUE(GetValueByPointer(d, "/foo/0/a", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query
EXPECT_EQ(2, unresolvedTokenIndex); EXPECT_EQ(2u, unresolvedTokenIndex);
// const version // const version
const Value& v = d; const Value& v = d;
...@@ -973,13 +973,13 @@ TEST(Pointer, GetValueByPointer) { ...@@ -973,13 +973,13 @@ TEST(Pointer, GetValueByPointer) {
EXPECT_EQ(&d["foo"][0], GetValueByPointer(v, "/foo/0")); EXPECT_EQ(&d["foo"][0], GetValueByPointer(v, "/foo/0"));
EXPECT_TRUE(GetValueByPointer(v, "/foo/2", &unresolvedTokenIndex) == 0); // Out of boundary EXPECT_TRUE(GetValueByPointer(v, "/foo/2", &unresolvedTokenIndex) == 0); // Out of boundary
EXPECT_EQ(1, unresolvedTokenIndex); EXPECT_EQ(1u, unresolvedTokenIndex);
EXPECT_TRUE(GetValueByPointer(v, "/foo/a", &unresolvedTokenIndex) == 0); // "/foo" is an array, cannot query by "a" EXPECT_TRUE(GetValueByPointer(v, "/foo/a", &unresolvedTokenIndex) == 0); // "/foo" is an array, cannot query by "a"
EXPECT_EQ(1, unresolvedTokenIndex); EXPECT_EQ(1u, unresolvedTokenIndex);
EXPECT_TRUE(GetValueByPointer(v, "/foo/0/0", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query EXPECT_TRUE(GetValueByPointer(v, "/foo/0/0", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query
EXPECT_EQ(2, unresolvedTokenIndex); EXPECT_EQ(2u, unresolvedTokenIndex);
EXPECT_TRUE(GetValueByPointer(v, "/foo/0/a", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query EXPECT_TRUE(GetValueByPointer(v, "/foo/0/a", &unresolvedTokenIndex) == 0); // "/foo/0" is an string, cannot further query
EXPECT_EQ(2, unresolvedTokenIndex); EXPECT_EQ(2u, unresolvedTokenIndex);
} }
......
...@@ -339,6 +339,35 @@ TEST(PrettyWriter, MoveCtor) { ...@@ -339,6 +339,35 @@ TEST(PrettyWriter, MoveCtor) {
} }
#endif #endif
TEST(PrettyWriter, Issue_1336) {
#define T(meth, val, expected) \
{ \
StringBuffer buffer; \
PrettyWriter<StringBuffer> writer(buffer); \
writer.meth(val); \
\
EXPECT_STREQ(expected, buffer.GetString()); \
EXPECT_TRUE(writer.IsComplete()); \
}
T(Bool, false, "false");
T(Bool, true, "true");
T(Int, 0, "0");
T(Uint, 0, "0");
T(Int64, 0, "0");
T(Uint64, 0, "0");
T(Double, 0, "0.0");
T(String, "Hello", "\"Hello\"");
#undef T
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer);
writer.Null();
EXPECT_STREQ("null", buffer.GetString());
EXPECT_TRUE(writer.IsComplete());
}
#ifdef __clang__ #ifdef __clang__
RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_POP
#endif #endif
This diff is collapsed.
...@@ -41,11 +41,11 @@ TEST(StringBuffer, Put) { ...@@ -41,11 +41,11 @@ TEST(StringBuffer, Put) {
TEST(StringBuffer, PutN_Issue672) { TEST(StringBuffer, PutN_Issue672) {
GenericStringBuffer<UTF8<>, MemoryPoolAllocator<> > buffer; GenericStringBuffer<UTF8<>, MemoryPoolAllocator<> > buffer;
EXPECT_EQ(0, buffer.GetSize()); EXPECT_EQ(0u, buffer.GetSize());
EXPECT_EQ(0, buffer.GetLength()); EXPECT_EQ(0u, buffer.GetLength());
rapidjson::PutN(buffer, ' ', 1); rapidjson::PutN(buffer, ' ', 1);
EXPECT_EQ(1, buffer.GetSize()); EXPECT_EQ(1u, buffer.GetSize());
EXPECT_EQ(1, buffer.GetLength()); EXPECT_EQ(1u, buffer.GetLength());
} }
TEST(StringBuffer, Clear) { TEST(StringBuffer, Clear) {
......
...@@ -26,11 +26,11 @@ using namespace rapidjson; ...@@ -26,11 +26,11 @@ using namespace rapidjson;
TEST(Value, Size) { TEST(Value, Size) {
if (sizeof(SizeType) == 4) { if (sizeof(SizeType) == 4) {
#if RAPIDJSON_48BITPOINTER_OPTIMIZATION #if RAPIDJSON_48BITPOINTER_OPTIMIZATION
EXPECT_EQ(16, sizeof(Value)); EXPECT_EQ(16u, sizeof(Value));
#elif RAPIDJSON_64BIT #elif RAPIDJSON_64BIT
EXPECT_EQ(24, sizeof(Value)); EXPECT_EQ(24u, sizeof(Value));
#else #else
EXPECT_EQ(16, sizeof(Value)); EXPECT_EQ(16u, sizeof(Value));
#endif #endif
} }
} }
...@@ -1135,10 +1135,10 @@ TEST(Value, ArrayHelper) { ...@@ -1135,10 +1135,10 @@ TEST(Value, ArrayHelper) {
a.PushBack(1, allocator); a.PushBack(1, allocator);
Value::Array a2(a); // copy constructor Value::Array a2(a); // copy constructor
EXPECT_EQ(1, a2.Size()); EXPECT_EQ(1u, a2.Size());
Value::Array a3 = a; Value::Array a3 = a;
EXPECT_EQ(1, a3.Size()); EXPECT_EQ(1u, a3.Size());
Value::ConstArray y = static_cast<const Value&>(x).GetArray(); Value::ConstArray y = static_cast<const Value&>(x).GetArray();
(void)y; (void)y;
...@@ -1175,7 +1175,7 @@ TEST(Value, ArrayHelper) { ...@@ -1175,7 +1175,7 @@ TEST(Value, ArrayHelper) {
y.PushBack(123, allocator); y.PushBack(123, allocator);
x.PushBack(y.GetArray(), allocator); // Implicit constructor to convert Array to GenericValue x.PushBack(y.GetArray(), allocator); // Implicit constructor to convert Array to GenericValue
EXPECT_EQ(1, x.Size()); EXPECT_EQ(1u, x.Size());
EXPECT_EQ(123, x[0][0].GetInt()); EXPECT_EQ(123, x[0][0].GetInt());
EXPECT_TRUE(y.IsArray()); EXPECT_TRUE(y.IsArray());
EXPECT_TRUE(y.Empty()); EXPECT_TRUE(y.Empty());
...@@ -1424,7 +1424,7 @@ static void TestObject(T& x, Allocator& allocator) { ...@@ -1424,7 +1424,7 @@ static void TestObject(T& x, Allocator& allocator) {
for (; itr != x.MemberEnd(); ++itr) { for (; itr != x.MemberEnd(); ++itr) {
size_t i = static_cast<size_t>((itr - x.MemberBegin())) + 1; size_t i = static_cast<size_t>((itr - x.MemberBegin())) + 1;
EXPECT_STREQ(itr->name.GetString(), keys[i]); EXPECT_STREQ(itr->name.GetString(), keys[i]);
EXPECT_EQ(i, itr->value[0].GetInt()); EXPECT_EQ(static_cast<int>(i), itr->value[0].GetInt());
} }
// Erase the last // Erase the last
...@@ -1435,7 +1435,7 @@ static void TestObject(T& x, Allocator& allocator) { ...@@ -1435,7 +1435,7 @@ static void TestObject(T& x, Allocator& allocator) {
for (; itr != x.MemberEnd(); ++itr) { for (; itr != x.MemberEnd(); ++itr) {
size_t i = static_cast<size_t>(itr - x.MemberBegin()) + 1; size_t i = static_cast<size_t>(itr - x.MemberBegin()) + 1;
EXPECT_STREQ(itr->name.GetString(), keys[i]); EXPECT_STREQ(itr->name.GetString(), keys[i]);
EXPECT_EQ(i, itr->value[0].GetInt()); EXPECT_EQ(static_cast<int>(i), itr->value[0].GetInt());
} }
// Erase the middle // Erase the middle
...@@ -1447,7 +1447,7 @@ static void TestObject(T& x, Allocator& allocator) { ...@@ -1447,7 +1447,7 @@ static void TestObject(T& x, Allocator& allocator) {
size_t i = static_cast<size_t>(itr - x.MemberBegin()); size_t i = static_cast<size_t>(itr - x.MemberBegin());
i += (i < 4) ? 1 : 2; i += (i < 4) ? 1 : 2;
EXPECT_STREQ(itr->name.GetString(), keys[i]); EXPECT_STREQ(itr->name.GetString(), keys[i]);
EXPECT_EQ(i, itr->value[0].GetInt()); EXPECT_EQ(static_cast<int>(i), itr->value[0].GetInt());
} }
// EraseMember(ConstMemberIterator, ConstMemberIterator) // EraseMember(ConstMemberIterator, ConstMemberIterator)
...@@ -1516,10 +1516,10 @@ TEST(Value, ObjectHelper) { ...@@ -1516,10 +1516,10 @@ TEST(Value, ObjectHelper) {
o.AddMember("1", 1, allocator); o.AddMember("1", 1, allocator);
Value::Object o2(o); // copy constructor Value::Object o2(o); // copy constructor
EXPECT_EQ(1, o2.MemberCount()); EXPECT_EQ(1u, o2.MemberCount());
Value::Object o3 = o; Value::Object o3 = o;
EXPECT_EQ(1, o3.MemberCount()); EXPECT_EQ(1u, o3.MemberCount());
Value::ConstObject y = static_cast<const Value&>(x).GetObject(); Value::ConstObject y = static_cast<const Value&>(x).GetObject();
(void)y; (void)y;
......
Subproject commit 0a439623f75c029912728d80cb7f1b8b48739ca4 Subproject commit ba96d0b1161f540656efdaed035b3c062b60e006
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