mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-14 06:55:50 +02:00
Added std::reference_wrapper packing and making object and object_with_zone support.
Fixed #370.
This commit is contained in:
66
test/reference_wrapper_cpp11.cpp
Normal file
66
test/reference_wrapper_cpp11.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <msgpack.hpp>
|
||||
#include <sstream>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
TEST(MSGPACK_REFERENCE_WRAPPER, pack)
|
||||
{
|
||||
int i1 = 42;
|
||||
std::reference_wrapper<int> val1(i1);
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, val1);
|
||||
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
int i2= oh.get().as<int>();
|
||||
EXPECT_EQ(val1, i2);
|
||||
EXPECT_EQ(i1, i2);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_REFERENCE_WRAPPER, pack_vector)
|
||||
{
|
||||
int i1 = 42;
|
||||
std::vector<std::reference_wrapper<int>> val1{i1};
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, val1);
|
||||
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
std::vector<int> val2 = oh.get().as<std::vector<int>>();
|
||||
EXPECT_EQ(val2.size(), 1);
|
||||
EXPECT_EQ(val1[0], val2[0]);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_REFERENCE_WRAPPER, object)
|
||||
{
|
||||
int i1 = 42;
|
||||
std::reference_wrapper<int> val1(i1);
|
||||
msgpack::object o(val1);
|
||||
int i2= o.as<int>();
|
||||
EXPECT_EQ(val1, i2);
|
||||
EXPECT_EQ(i1, i2);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_REFERENCE_WRAPPER, object_with_zone)
|
||||
{
|
||||
int i1 = 42;
|
||||
std::reference_wrapper<int> val1(i1);
|
||||
msgpack::zone z;
|
||||
msgpack::object o(val1, z);
|
||||
int i2= o.as<int>();
|
||||
EXPECT_EQ(val1, i2);
|
||||
EXPECT_EQ(i1, i2);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_REFERENCE_WRAPPER, object_with_zone_string)
|
||||
{
|
||||
std::string s1 = "ABC";
|
||||
std::reference_wrapper<std::string> val1(s1);
|
||||
msgpack::zone z;
|
||||
msgpack::object o(val1, z);
|
||||
std::string s2= o.as<std::string>();
|
||||
EXPECT_EQ(s1, s2);
|
||||
}
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
Reference in New Issue
Block a user