Merge pull request #274 from redboltz/fix_issue_273

Fixed #273
This commit is contained in:
Nobuyuki Kubota
2015-04-27 23:47:43 -07:00
4 changed files with 72 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ LIST (APPEND check_PROGRAMS
msgpack_c.cpp
reference.cpp
limit.cpp
json.cpp
)
IF (MSGPACK_BOOST)

View File

@@ -26,6 +26,7 @@ check_PROGRAMS = \
reference_cpp11 \
reference \
limit \
json \
iterator_cpp11 \
boost_optional
@@ -78,6 +79,8 @@ reference_cpp11_SOURCES = reference_cpp11.cpp
limit_SOURCES = limit.cpp
json_SOURCES = json.cpp
iterator_cpp11_SOURCES = iterator_cpp11.cpp
boost_optional_SOURCES = boost_optional.cpp

32
test/json.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <msgpack.hpp>
#include <fstream>
#include <sstream>
#include <gtest/gtest.h>
TEST(json, basic_elements)
{
typedef std::map<std::string, int> map_s_i;
map_s_i msi;
msi.insert(map_s_i::value_type("Hello", 789));
msi.insert(map_s_i::value_type("World", -789));
msgpack::type::tuple<int, int, double, double, bool, bool, std::string, map_s_i>
t1(12, -34, 1.23, -4.56, true, false, "ABC", msi);
msgpack::zone z;
msgpack::object o(t1, z);
std::stringstream ss;
ss << o;
EXPECT_EQ(ss.str(), "[12, -34, 1.23, -4.56, true, false, \"ABC\", {\"Hello\":789, \"World\":-789}]");
}
TEST(json, escape)
{
std::string s = "\"\\/\b\f\n\r\tabc";
msgpack::zone z;
msgpack::object o(s, z);
std::stringstream ss;
ss << o;
EXPECT_EQ(ss.str(), "\"\\\"\\\\\\/\\b\\f\\n\\r\\tabc\"");
}