OpenEnroth 73e68f7
Loading...
Searching...
No Matches
Namespaces | Enumerations | Functions | Variables
Serialization_ut.cpp File Reference
#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
 

Enumeration Type Documentation

◆ BrokenFlag0

enum class BrokenFlag0
strong
Enumerator
BROKEN_FLAG_123 

◆ MagicEnum

enum class MagicEnum
strong
Enumerator
MAGIC_A 
MAGIC_B 
MAGIC_C 
MAGIC_D 
MAGIC_E 

◆ TestEnum

enum class TestEnum
strong
Enumerator
VALUE_1 
VALUE_2 
VALUE_3 
FLAGS_00FF 
FLAGS_0FF0 
FLAGS_FF00 
FLAGS_F00F 
ALL_FLAGS 
UNSERIALIZABLE 

◆ TestEnum2

enum class TestEnum2
strong
Enumerator
TEST_0 
TEST_1 
TEST_2 
TEST_3 
TEST_4 

Function Documentation

◆ EXPECT_ANY_THROW() [1/5]

EXPECT_ANY_THROW ( fromString< TestEnum " 1")

◆ EXPECT_ANY_THROW() [2/5]

EXPECT_ANY_THROW ( fromString< TestEnum "1 ")

◆ EXPECT_ANY_THROW() [3/5]

EXPECT_ANY_THROW ( fromString< TestFlags >  " 1 2 ")

◆ EXPECT_ANY_THROW() [4/5]

EXPECT_ANY_THROW ( toString(TestFlags(UNSERIALIZABLE))  )

◆ EXPECT_ANY_THROW() [5/5]

EXPECT_ANY_THROW ( toString(UNSERIALIZABLE )

◆ EXPECT_EQ() [1/9]

EXPECT_EQ ( fromString< TestFlags >  " 1 ",
VALUE_1   
)

◆ EXPECT_EQ() [2/9]

EXPECT_EQ ( fromString< TestFlags >  " 1 | 0FF0 | FF00 ",
FLAGS_FF00|FLAGS_0FF0 VALUE_1 
)

◆ EXPECT_EQ() [3/9]

EXPECT_EQ ( fromString< TestFlags >  " 1 | 1 | 1 | 1 | 1",
VALUE_1   
)

◆ EXPECT_EQ() [4/9]

EXPECT_EQ ( fromString< TestFlags >  "0",
TestFlags()   
)

◆ EXPECT_EQ() [5/9]

EXPECT_EQ ( fromString< TestFlags >  toString(FLAGS_F00F|FLAGS_00FF),
FLAGS_F00F FLAGS_00FF 
)

◆ EXPECT_EQ() [6/9]

EXPECT_EQ ( fromString< TestFlags >  toString(VALUE_1|VALUE_2),
VALUE_3   
)

◆ EXPECT_EQ() [7/9]

EXPECT_EQ ( toString(ALL_FLAGS ,
"FFFF"   
)

◆ EXPECT_EQ() [8/9]

EXPECT_EQ ( toString(FLAGS_FF00|FLAGS_0FF0|VALUE_1 ,
"1|0FF0|FF00"   
)

◆ EXPECT_EQ() [9/9]

EXPECT_EQ ( toString(TestFlags())  ,
"0"   
)

◆ EXPECT_FALSE()

EXPECT_FALSE ( serializer(std::type_identity< BrokenFlag2 >()).isUsableWithFlags()  )

◆ EXPECT_TRUE()

EXPECT_TRUE ( serializer(std::type_identity< NonBrokenFlag1 >()).isUsableWithFlags()  )

◆ MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS() [1/5]

MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS ( BrokenFlag0  ,
CASE_SENSITIVE  ,
{ {BROKEN_FLAG_123, "0"} }   
)

◆ MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS() [2/5]

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() [3/5]

MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS ( BrokenFlag2  ,
CASE_SENSITIVE  ,
{ {BROKEN_FLAG_OOOF, " S P A C E S "} }   
)

◆ MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS() [4/5]

MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS ( NonBrokenFlag1  ,
CASE_SENSITIVE  ,
{ {NON_BROKEN_FLAG_0, "0"} }   
)

◆ MM_DEFINE_ENUM_SERIALIZATION_FUNCTIONS() [5/5]

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() [1/4]

UNIT_TEST ( Serialization  ,
CaseInsensitiveEnumWithNamespace   
)

◆ UNIT_TEST() [2/4]

UNIT_TEST ( Serialization  ,
EnumMultiString   
)

◆ UNIT_TEST() [3/4]

UNIT_TEST ( Serialization  ,
MagicEnum   
)

◆ UNIT_TEST() [4/4]

UNIT_TEST ( Serialization  ,
Standard   
)

Variable Documentation

◆ BrokenFlags

BrokenFlags
Initial value:
{
EXPECT_FALSE(serializer(std::type_identity<BrokenFlag0>()).isUsableWithFlags())
EXPECT_FALSE(serializer(std::type_identity< BrokenFlag2 >()).isUsableWithFlags())

◆ Enum

Enum
Initial value:
{
EXPECT_EQ(fromString<TestEnum>(toString(VALUE_1)), VALUE_1)
constexpr detail::StringSerializer toString
Definition: Serialization.h:40
EXPECT_EQ(toString(TestFlags()), "0")