2016-08-23 10:41:08 +00:00
|
|
|
#define BOOST_TEST_MODULE StrongTypedef
|
|
|
|
|
|
|
|
#include <common/strong_typedef.h>
|
|
|
|
#include <set>
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <memory>
|
|
|
|
#include <type_traits>
|
|
|
|
|
2017-03-22 16:59:02 +00:00
|
|
|
#include <gtest/gtest.h>
|
2016-08-23 10:41:08 +00:00
|
|
|
|
|
|
|
|
2017-03-22 16:59:02 +00:00
|
|
|
TEST(StrongTypedefSuite, TypedefsOfTheSameType)
|
2016-08-23 10:41:08 +00:00
|
|
|
{
|
|
|
|
/// check that strong typedefs of same type differ
|
|
|
|
STRONG_TYPEDEF(int, Int);
|
|
|
|
STRONG_TYPEDEF(int, AnotherInt);
|
|
|
|
|
2017-03-22 16:59:02 +00:00
|
|
|
EXPECT_TRUE(!(std::is_same<Int, AnotherInt>::value));
|
2016-08-23 10:41:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 16:59:02 +00:00
|
|
|
TEST(StrongTypedefSuite, Map)
|
2016-08-23 10:41:08 +00:00
|
|
|
{
|
|
|
|
STRONG_TYPEDEF(int, Int);
|
|
|
|
|
|
|
|
/// check that this code compiles
|
|
|
|
std::set<Int> int_set;
|
|
|
|
int_set.insert(Int(1));
|
|
|
|
std::unordered_set<Int> int_unorderd_set;
|
|
|
|
int_unorderd_set.insert(Int(2));
|
|
|
|
}
|
|
|
|
|
2017-03-22 16:59:02 +00:00
|
|
|
TEST(StrongTypedefSuite, CopyAndMoveCtor)
|
2016-08-23 10:41:08 +00:00
|
|
|
{
|
|
|
|
STRONG_TYPEDEF(int, Int);
|
|
|
|
Int a(1);
|
|
|
|
Int b(2);
|
|
|
|
a = b;
|
2017-03-22 16:59:02 +00:00
|
|
|
EXPECT_EQ(a.t, 2);
|
2016-08-23 10:41:08 +00:00
|
|
|
|
|
|
|
STRONG_TYPEDEF(std::unique_ptr<int>, IntPtr);
|
|
|
|
{
|
|
|
|
IntPtr ptr;
|
|
|
|
ptr = IntPtr(std::make_unique<int>(3));
|
2017-03-22 16:59:02 +00:00
|
|
|
EXPECT_EQ(*ptr.t, 3);
|
2016-08-23 10:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
IntPtr ptr(std::make_unique<int>(3));
|
2017-03-22 16:59:02 +00:00
|
|
|
EXPECT_EQ(*ptr.t, 3);
|
2016-08-23 10:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-22 16:59:02 +00:00
|
|
|
TEST(StrongTypedefSuite, NoDefaultCtor)
|
2016-08-23 10:41:08 +00:00
|
|
|
{
|
|
|
|
struct NoDefaultCtor
|
|
|
|
{
|
|
|
|
NoDefaultCtor(int i) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
STRONG_TYPEDEF(NoDefaultCtor, MyStruct);
|
|
|
|
MyStruct m(1);
|
|
|
|
}
|