mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-14 23:07:58 +02:00
enum support had been incomplete. This fix made enum support complete. Replaced int with auto on c++11 scoped enum. Replaced template specializations with function overloads on operator<< and operator>> for enum. enum can convert to object with and without zone. When you want to adapt enum, you need to write as follows: // NOT msgpack.hpp enum yourenum { elem }; MSGPACK_ADD_ENUM(yourenum); // msgpack.hpp should be included after MSGPACK_ADD_ENUM(...) int main() { msgpack::object obj(yourenum::elem); }
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#include <msgpack.hpp>
|
||||
#include <msgpack_fwd.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
#include <cmath>
|
||||
|
||||
@@ -6,6 +6,43 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
enum enum_test {
|
||||
elem
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(enum_test);
|
||||
|
||||
struct outer_enum {
|
||||
enum enum_test {
|
||||
elem
|
||||
};
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(outer_enum::enum_test);
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
enum class enum_class_test {
|
||||
elem
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(enum_class_test);
|
||||
|
||||
struct outer_enum_class {
|
||||
enum class enum_class_test {
|
||||
elem
|
||||
};
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(outer_enum_class::enum_class_test);
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
const unsigned int kLoop = 1000;
|
||||
@@ -615,8 +652,62 @@ TEST(object_with_zone, user_defined)
|
||||
EXPECT_EQ(v1.s, v2.s);
|
||||
}
|
||||
|
||||
TEST(object_with_zone, construct_enum)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(elem, z);
|
||||
EXPECT_EQ(msgpack::type::POSITIVE_INTEGER, obj.type);
|
||||
EXPECT_EQ(elem, obj.via.u64);
|
||||
}
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
TEST(object_with_zone, construct_enum_newstyle)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(enum_test::elem, z);
|
||||
EXPECT_EQ(msgpack::type::POSITIVE_INTEGER, obj.type);
|
||||
EXPECT_EQ(elem, obj.via.u64);
|
||||
}
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
TEST(object_with_zone, construct_enum_outer)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(outer_enum::elem, z);
|
||||
EXPECT_EQ(msgpack::type::POSITIVE_INTEGER, obj.type);
|
||||
EXPECT_EQ(elem, obj.via.u64);
|
||||
}
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
TEST(object_with_zone, construct_enum_outer_newstyle)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(outer_enum::enum_test::elem, z);
|
||||
EXPECT_EQ(msgpack::type::POSITIVE_INTEGER, obj.type);
|
||||
EXPECT_EQ(elem, obj.via.u64);
|
||||
}
|
||||
|
||||
TEST(object_with_zone, construct_class_enum)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(enum_class_test::elem, z);
|
||||
EXPECT_EQ(msgpack::type::POSITIVE_INTEGER, obj.type);
|
||||
EXPECT_EQ(elem, obj.via.u64);
|
||||
}
|
||||
|
||||
|
||||
TEST(object_with_zone, construct_class_enum_outer)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(outer_enum_class::enum_class_test::elem, z);
|
||||
EXPECT_EQ(msgpack::type::POSITIVE_INTEGER, obj.type);
|
||||
EXPECT_EQ(elem, obj.via.u64);
|
||||
}
|
||||
|
||||
|
||||
TEST(object_with_zone, array)
|
||||
{
|
||||
typedef array<int, kElements> test_t;
|
||||
|
Reference in New Issue
Block a user