mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-14 15:05:37 +02:00
Fixed #243.
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:
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user