mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-12-24 14:19:09 +01:00
@@ -29,6 +29,7 @@ LIST (APPEND check_PROGRAMS
|
||||
msgpack_c.cpp
|
||||
reference.cpp
|
||||
limit.cpp
|
||||
json.cpp
|
||||
)
|
||||
|
||||
IF (MSGPACK_BOOST)
|
||||
|
||||
@@ -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
32
test/json.cpp
Normal 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\"");
|
||||
}
|
||||
Reference in New Issue
Block a user