std::vector<unsigned char> and std::array<unsigned char> are mapped to BIN.
std::vector<uint8_t> and std::array<uint8_t> are mapped to BIN if uint8_t is the same type of unsigned char, otherwise mapped to ARRAY.

Added array_ref. When client wraps BIN mapped types above with array_ref as msgpack::type::array_ref<std::vector<char> >, the type is mapped to ARRAY.
This commit is contained in:
Takatoshi Kondo
2015-08-31 13:45:59 +09:00
parent 9ee1168cc4
commit 96f145812f
13 changed files with 833 additions and 0 deletions

View File

@@ -240,6 +240,39 @@ TEST(object_without_zone, vector_char)
}
}
// vector_unsgined_char
TEST(object_with_zone, vector_unsigned_char)
{
if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
for (unsigned int k = 0; k < kLoop; k++) {
vector<unsigned char> v1;
v1.push_back(1);
for (unsigned int i = 1; i < kElements; i++)
v1.push_back(static_cast<unsigned char>(i));
msgpack::zone z;
msgpack::object obj(v1, z);
EXPECT_EQ(obj.as<vector<unsigned char> >(), v1);
v1.front() = 42;
EXPECT_EQ(obj.as<vector<unsigned char> >().front(), 1);
}
}
TEST(object_without_zone, vector_unsigned_char)
{
if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
for (unsigned int k = 0; k < kLoop; k++) {
vector<unsigned char> v1;
v1.push_back(1);
for (unsigned int i = 1; i < kElements; i++)
v1.push_back(static_cast<unsigned char>(i));
msgpack::object obj(v1);
EXPECT_EQ(obj.as<vector<unsigned char> >(), v1);
v1.front() = 42;
// obj refer to v1
EXPECT_EQ(obj.as<vector<unsigned char> >().front(), 42);
}
}
// list
TEST(object_with_zone, list)
{
@@ -830,6 +863,40 @@ TEST(object_without_zone, array_char)
}
}
TEST(object_with_zone, array_unsigned_char)
{
if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
typedef array<unsigned char, kElements> test_t;
for (unsigned int k = 0; k < kLoop; k++) {
test_t v1;
v1[0] = 1;
for (unsigned int i = 1; i < kElements; i++)
v1[i] = rand();
msgpack::zone z;
msgpack::object obj(v1, z);
EXPECT_EQ(obj.as<test_t>(), v1);
v1.front() = 42;
EXPECT_EQ(obj.as<test_t>().front(), 1);
}
}
TEST(object_without_zone, array_unsigned_char)
{
if (!msgpack::is_same<uint8_t, unsigned char>::value) return;
typedef array<unsigned char, kElements> test_t;
for (unsigned int k = 0; k < kLoop; k++) {
test_t v1;
v1[0] = 1;
for (unsigned int i = 1; i < kElements; i++)
v1[i] = rand();
msgpack::object obj(v1);
EXPECT_EQ(obj.as<test_t>(), v1);
v1.front() = 42;
// obj refer to v1
EXPECT_EQ(obj.as<test_t>().front(), 42);
}
}
TEST(object_with_zone, forward_list)
{