diff options
author | miloyip <miloyip@gmail.com> | 2015-04-13 09:25:05 +0300 |
---|---|---|
committer | miloyip <miloyip@gmail.com> | 2015-04-13 09:25:05 +0300 |
commit | 3c028685dfdb23ba3a8c28defa857640b9c93ed1 (patch) | |
tree | 986a762f8279b0f5482b1f6839995c31cb3fec15 | |
parent | 3d82781a7539a14fe1f04d3d94f9e37eafb1a115 (diff) |
Add tests for Writer API for RAPIDJSON_HAS_STDSTRING
-rw-r--r-- | include/rapidjson/prettywriter.h | 2 | ||||
-rw-r--r-- | include/rapidjson/writer.h | 2 | ||||
-rw-r--r-- | test/unittest/prettywritertest.cpp | 11 | ||||
-rw-r--r-- | test/unittest/writertest.cpp | 9 |
4 files changed, 22 insertions, 2 deletions
diff --git a/include/rapidjson/prettywriter.h b/include/rapidjson/prettywriter.h index 90d19830..14b8477f 100644 --- a/include/rapidjson/prettywriter.h +++ b/include/rapidjson/prettywriter.h @@ -78,7 +78,7 @@ public: #if RAPIDJSON_HAS_STDSTRING
bool String(const std::basic_string<Ch>& str) {
- return String(str.data(), SizeType(str.size()));
+ return String(str.data(), SizeType(str.size()));
}
#endif
diff --git a/include/rapidjson/writer.h b/include/rapidjson/writer.h index 5a4d1566..bf17f3a2 100644 --- a/include/rapidjson/writer.h +++ b/include/rapidjson/writer.h @@ -127,7 +127,7 @@ public: #if RAPIDJSON_HAS_STDSTRING
bool String(const std::basic_string<Ch>& str) {
- return String(str.data(), SizeType(str.size()));
+ return String(str.data(), SizeType(str.size()));
}
#endif
diff --git a/test/unittest/prettywritertest.cpp b/test/unittest/prettywritertest.cpp index d0abf334..fcb11219 100644 --- a/test/unittest/prettywritertest.cpp +++ b/test/unittest/prettywritertest.cpp @@ -79,3 +79,14 @@ TEST(PrettyWriter, SetIndent) { "}", buffer.GetString()); } + +#if RAPIDJSON_HAS_STDSTRING +TEST(PrettyWriter, String_STDSTRING) { + StringBuffer buffer; + PrettyWriter<StringBuffer> writer(buffer); + EXPECT_TRUE(writer.StartArray()); + EXPECT_TRUE(writer.String(std::string("Hello\n"))); + EXPECT_TRUE(writer.EndArray()); + EXPECT_STREQ("[\n \"Hello\\n\"\n]", buffer.GetString()); +} +#endif diff --git a/test/unittest/writertest.cpp b/test/unittest/writertest.cpp index 2a0f4842..7b9fa9a2 100644 --- a/test/unittest/writertest.cpp +++ b/test/unittest/writertest.cpp @@ -89,6 +89,15 @@ TEST(Writer, String) { TEST_ROUNDTRIP("[\"Hello\"]");
TEST_ROUNDTRIP("[\"Hello\\u0000World\"]");
TEST_ROUNDTRIP("[\"\\\"\\\\/\\b\\f\\n\\r\\t\"]");
+
+#if RAPIDJSON_HAS_STDSTRING
+ {
+ StringBuffer buffer;
+ Writer<StringBuffer> writer(buffer);
+ writer.String(std::string("Hello\n"));
+ EXPECT_STREQ("\"Hello\\n\"", buffer.GetString());
+ }
+#endif
}
TEST(Writer, Double) {
|