OpenEnroth 73e68f7
|
#include <string>
#include "Testing/Unit/UnitTest.h"
#include "Library/Serialization/Serialization.h"
#include "Library/Serialization/EnumSerialization.h"
Namespaces | |
namespace | detail |
Enumerations | |
enum class | TestEnum { VALUE_1 = 1 , VALUE_2 = 2 , VALUE_3 = 3 , FLAGS_00FF = 0x00FF , FLAGS_0FF0 = 0x0FF0 , FLAGS_FF00 = 0xFF00 , FLAGS_F00F = 0xF00F , ALL_FLAGS = 0xFFFF , UNSERIALIZABLE = 0x11111111 } |
enum class | TestEnum2 { TEST_0 = 0 , TEST_1 = 1 , TEST_2 = 2 , TEST_3 = 3 , TEST_4 = 4 } |
enum class | BrokenFlag0 { BROKEN_FLAG_123 = 123 } |
enum class | MagicEnum { MAGIC_A = 0 , MAGIC_B = 1 , MAGIC_C = 2 , MAGIC_D = 3 , MAGIC_E = 4 } |
Functions | |
UNIT_TEST (Serialization, Standard) | |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS (TestEnum, CASE_SENSITIVE, { {VALUE_1, "1"}, {VALUE_2, "2"}, {VALUE_3, "3"}, {FLAGS_00FF, "00FF"}, {FLAGS_0FF0, "0FF0"}, {FLAGS_FF00, "FF00"}, {FLAGS_F00F, "F00F"}, {ALL_FLAGS, "FFFF"}, {FLAGS_00FF, "FIRST"}, {FLAGS_0FF0, "SECOND"}, {FLAGS_FF00, "THIRD"}, {ALL_FLAGS, "ZUGZUG"} }) UNIT_TEST(Serialization | |
EXPECT_EQ (toString(TestFlags()), "0") | |
EXPECT_EQ (fromString< TestFlags >("0"), TestFlags()) | |
EXPECT_EQ (fromString< TestFlags >(toString(VALUE_1|VALUE_2)), VALUE_3) | |
EXPECT_EQ (fromString< TestFlags >(toString(FLAGS_F00F|FLAGS_00FF)), FLAGS_F00F|FLAGS_00FF) | |
EXPECT_EQ (toString(ALL_FLAGS), "FFFF") | |
EXPECT_EQ (toString(FLAGS_FF00|FLAGS_0FF0|VALUE_1), "1|0FF0|FF00") | |
EXPECT_EQ (fromString< TestFlags >(" 1 | 0FF0 | FF00 "), FLAGS_FF00|FLAGS_0FF0|VALUE_1) | |
EXPECT_EQ (fromString< TestFlags >(" 1 | 1 | 1 | 1 | 1"), VALUE_1) | |
EXPECT_EQ (fromString< TestFlags >(" 1 "), VALUE_1) | |
EXPECT_ANY_THROW (toString(UNSERIALIZABLE)) | |
EXPECT_ANY_THROW (toString(TestFlags(UNSERIALIZABLE))) | |
EXPECT_ANY_THROW (fromString< TestEnum >(" 1")) | |
EXPECT_ANY_THROW (fromString< TestEnum >("1 ")) | |
EXPECT_ANY_THROW (fromString< TestFlags >(" 1 2 ")) | |
UNIT_TEST (Serialization, EnumMultiString) | |
UNIT_TEST (Serialization, CaseInsensitiveEnumWithNamespace) | |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS (BrokenFlag0, CASE_SENSITIVE, { {BROKEN_FLAG_123, "0"} }) enum class BrokenFlag1 | |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS (BrokenFlag1, CASE_SENSITIVE, { {BROKEN_FLAG_1, "LOL"}, {BROKEN_FLAG_2, "WUT"}, {BROKEN_FLAG_3, "LOL|WUT"} }) enum class BrokenFlag2 | |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS (BrokenFlag2, CASE_SENSITIVE, { {BROKEN_FLAG_OOOF, " S P A C E S "} }) enum class NonBrokenFlag1 | |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS (NonBrokenFlag1, CASE_SENSITIVE, { {NON_BROKEN_FLAG_0, "0"} }) UNIT_TEST(Serialization | |
EXPECT_FALSE (serializer(std::type_identity< BrokenFlag2 >()).isUsableWithFlags()) | |
EXPECT_TRUE (serializer(std::type_identity< NonBrokenFlag1 >()).isUsableWithFlags()) | |
UNIT_TEST (Serialization, MagicEnum) | |
Variables | |
Enum | |
BrokenFlags | |
|
strong |
|
strong |
|
strong |
|
strong |
EXPECT_ANY_THROW | ( | fromString< TestEnum > | " 1" | ) |
EXPECT_ANY_THROW | ( | fromString< TestEnum > | "1 " | ) |
EXPECT_ANY_THROW | ( | fromString< TestFlags > | " 1 2 " | ) |
EXPECT_ANY_THROW | ( | toString(TestFlags(UNSERIALIZABLE)) | ) |
EXPECT_ANY_THROW | ( | toString(UNSERIALIZABLE) | ) |
EXPECT_EQ | ( | fromString< TestFlags > | " 1 ", |
VALUE_1 | |||
) |
EXPECT_EQ | ( | fromString< TestFlags > | " 1 | 0FF0 | FF00 ", |
FLAGS_FF00|FLAGS_0FF0| | VALUE_1 | ||
) |
EXPECT_EQ | ( | fromString< TestFlags > | " 1 | 1 | 1 | 1 | 1", |
VALUE_1 | |||
) |
EXPECT_EQ | ( | fromString< TestFlags > | "0", |
TestFlags() | |||
) |
EXPECT_EQ | ( | fromString< TestFlags > | toString(FLAGS_F00F|FLAGS_00FF), |
FLAGS_F00F| | FLAGS_00FF | ||
) |
EXPECT_EQ | ( | fromString< TestFlags > | toString(VALUE_1|VALUE_2), |
VALUE_3 | |||
) |
EXPECT_EQ | ( | toString(FLAGS_FF00|FLAGS_0FF0|VALUE_1) | , |
"1|0FF0|FF00" | |||
) |
EXPECT_EQ | ( | toString(TestFlags()) | , |
"0" | |||
) |
EXPECT_FALSE | ( | serializer(std::type_identity< BrokenFlag2 >()).isUsableWithFlags() | ) |
EXPECT_TRUE | ( | serializer(std::type_identity< NonBrokenFlag1 >()).isUsableWithFlags() | ) |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS | ( | BrokenFlag0 | , |
CASE_SENSITIVE | , | ||
{ {BROKEN_FLAG_123, "0"} } | |||
) |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS | ( | BrokenFlag1 | , |
CASE_SENSITIVE | , | ||
{ {BROKEN_FLAG_1, "LOL"}, {BROKEN_FLAG_2, "WUT"}, {BROKEN_FLAG_3, "LOL|WUT"} } | |||
) |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS | ( | BrokenFlag2 | , |
CASE_SENSITIVE | , | ||
{ {BROKEN_FLAG_OOOF, " S P A C E S "} } | |||
) |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS | ( | NonBrokenFlag1 | , |
CASE_SENSITIVE | , | ||
{ {NON_BROKEN_FLAG_0, "0"} } | |||
) |
MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS | ( | TestEnum | , |
CASE_SENSITIVE | , | ||
{ {VALUE_1, "1"}, {VALUE_2, "2"}, {VALUE_3, "3"}, {FLAGS_00FF, "00FF"}, {FLAGS_0FF0, "0FF0"}, {FLAGS_FF00, "FF00"}, {FLAGS_F00F, "F00F"}, {ALL_FLAGS, "FFFF"}, {FLAGS_00FF, "FIRST"}, {FLAGS_0FF0, "SECOND"}, {FLAGS_FF00, "THIRD"}, {ALL_FLAGS, "ZUGZUG"} } | |||
) |
UNIT_TEST | ( | Serialization | , |
CaseInsensitiveEnumWithNamespace | |||
) |
UNIT_TEST | ( | Serialization | , |
EnumMultiString | |||
) |
UNIT_TEST | ( | Serialization | , |
MagicEnum | |||
) |
UNIT_TEST | ( | Serialization | , |
Standard | |||
) |
BrokenFlags |