2016-02-25 03:08:02 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2016-03-04 13:59:43 +00:00
|
|
|
#include <tuple>
|
2016-03-04 11:20:56 +00:00
|
|
|
#include <EC/Meta/Meta.hpp>
|
2016-03-04 12:12:37 +00:00
|
|
|
#include <EC/EC.hpp>
|
2016-02-25 03:08:02 +00:00
|
|
|
|
2016-02-25 03:27:04 +00:00
|
|
|
struct C0 {};
|
|
|
|
struct C1 {};
|
|
|
|
struct C2 {};
|
|
|
|
struct C3 {};
|
|
|
|
|
2016-03-04 12:12:37 +00:00
|
|
|
struct T0 {};
|
|
|
|
struct T1 {};
|
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
using ListComponentsAll = EC::Meta::TypeList<C0, C1, C2, C3>;
|
|
|
|
using ListComponentsSome = EC::Meta::TypeList<C1, C3>;
|
2016-02-25 03:27:04 +00:00
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
using ListTagsAll = EC::Meta::TypeList<T0, T1>;
|
|
|
|
|
|
|
|
using ListAll = EC::Meta::TypeList<C0, C1, C2, C3, T0, T1>;
|
2016-03-04 12:12:37 +00:00
|
|
|
|
2016-03-13 09:07:49 +00:00
|
|
|
using ListSome = EC::Meta::TypeList<C1, C3, T1>;
|
|
|
|
|
|
|
|
template <typename... STypes>
|
|
|
|
struct Storage
|
|
|
|
{
|
|
|
|
using type = std::tuple<std::vector<STypes>... >;
|
|
|
|
};
|
|
|
|
|
2016-02-25 03:08:02 +00:00
|
|
|
TEST(Meta, Contains)
|
|
|
|
{
|
2016-03-04 12:35:26 +00:00
|
|
|
int size = ListComponentsAll::size;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_EQ(size, 4);
|
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
bool result = EC::Meta::Contains<C0, ListComponentsAll>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_TRUE(result);
|
2016-03-04 12:35:26 +00:00
|
|
|
result = EC::Meta::Contains<C1, ListComponentsAll>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_TRUE(result);
|
2016-03-04 12:35:26 +00:00
|
|
|
result = EC::Meta::Contains<C2, ListComponentsAll>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_TRUE(result);
|
2016-03-04 12:35:26 +00:00
|
|
|
result = EC::Meta::Contains<C3, ListComponentsAll>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_TRUE(result);
|
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
size = ListComponentsSome::size;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_EQ(size, 2);
|
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
result = EC::Meta::Contains<C0, ListComponentsSome>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_FALSE(result);
|
2016-03-04 12:35:26 +00:00
|
|
|
result = EC::Meta::Contains<C1, ListComponentsSome>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_TRUE(result);
|
2016-03-04 12:35:26 +00:00
|
|
|
result = EC::Meta::Contains<C2, ListComponentsSome>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_FALSE(result);
|
2016-03-04 12:35:26 +00:00
|
|
|
result = EC::Meta::Contains<C3, ListComponentsSome>::value;
|
2016-02-25 03:08:02 +00:00
|
|
|
EXPECT_TRUE(result);
|
|
|
|
}
|
2016-02-25 03:27:04 +00:00
|
|
|
|
2016-03-04 12:12:37 +00:00
|
|
|
TEST(Meta, ContainsAll)
|
|
|
|
{
|
2016-03-04 12:35:26 +00:00
|
|
|
bool contains = EC::Meta::ContainsAll<ListComponentsSome, ListComponentsAll>::value;
|
2016-03-04 12:12:37 +00:00
|
|
|
EXPECT_TRUE(contains);
|
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
contains = EC::Meta::ContainsAll<ListComponentsAll, ListComponentsSome>::value;
|
2016-03-04 12:12:37 +00:00
|
|
|
EXPECT_FALSE(contains);
|
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
contains = EC::Meta::ContainsAll<ListComponentsAll, ListComponentsAll>::value;
|
2016-03-04 12:12:37 +00:00
|
|
|
EXPECT_TRUE(contains);
|
|
|
|
}
|
|
|
|
|
2016-02-25 03:27:04 +00:00
|
|
|
TEST(Meta, IndexOf)
|
|
|
|
{
|
2016-03-04 12:35:26 +00:00
|
|
|
int index = EC::Meta::IndexOf<C0, ListComponentsAll>::value;
|
2016-02-25 03:27:04 +00:00
|
|
|
EXPECT_EQ(index, 0);
|
2016-03-04 12:35:26 +00:00
|
|
|
index = EC::Meta::IndexOf<C1, ListComponentsAll>::value;
|
2016-02-25 03:27:04 +00:00
|
|
|
EXPECT_EQ(index, 1);
|
2016-03-04 12:35:26 +00:00
|
|
|
index = EC::Meta::IndexOf<C2, ListComponentsAll>::value;
|
2016-02-25 03:27:04 +00:00
|
|
|
EXPECT_EQ(index, 2);
|
2016-03-04 12:35:26 +00:00
|
|
|
index = EC::Meta::IndexOf<C3, ListComponentsAll>::value;
|
2016-02-25 03:27:04 +00:00
|
|
|
EXPECT_EQ(index, 3);
|
2018-05-17 08:05:49 +00:00
|
|
|
index = EC::Meta::IndexOf<T0, ListComponentsAll>::value;
|
|
|
|
EXPECT_EQ(index, 4);
|
2016-02-25 03:27:04 +00:00
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
index = EC::Meta::IndexOf<C1, ListComponentsSome>::value;
|
2016-02-25 03:27:04 +00:00
|
|
|
EXPECT_EQ(index, 0);
|
2016-03-04 12:35:26 +00:00
|
|
|
index = EC::Meta::IndexOf<C3, ListComponentsSome>::value;
|
2016-02-25 03:27:04 +00:00
|
|
|
EXPECT_EQ(index, 1);
|
2018-05-17 08:05:49 +00:00
|
|
|
index = EC::Meta::IndexOf<C2, ListComponentsSome>::value;
|
|
|
|
EXPECT_EQ(index, 2);
|
2016-02-25 03:27:04 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 12:12:37 +00:00
|
|
|
TEST(Meta, Bitset)
|
|
|
|
{
|
2016-03-04 12:35:26 +00:00
|
|
|
EC::Bitset<ListComponentsAll, ListTagsAll> bitset;
|
2018-05-17 08:05:49 +00:00
|
|
|
EXPECT_EQ(bitset.size(), ListComponentsAll::size + ListTagsAll::size + 1);
|
2016-03-04 12:12:37 +00:00
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
bitset[EC::Meta::IndexOf<C1, ListComponentsAll>::value] = true;
|
2016-03-04 12:12:37 +00:00
|
|
|
EXPECT_TRUE(bitset.getComponentBit<C1>());
|
|
|
|
bitset.flip();
|
|
|
|
EXPECT_FALSE(bitset.getComponentBit<C1>());
|
|
|
|
|
|
|
|
bitset.reset();
|
2016-03-04 12:35:26 +00:00
|
|
|
bitset[ListComponentsAll::size + EC::Meta::IndexOf<T0, ListTagsAll>::value] = true;
|
2016-03-04 12:12:37 +00:00
|
|
|
EXPECT_TRUE(bitset.getTagBit<T0>());
|
|
|
|
bitset.flip();
|
|
|
|
EXPECT_FALSE(bitset.getTagBit<T0>());
|
|
|
|
}
|
|
|
|
|
2016-03-04 12:35:26 +00:00
|
|
|
TEST(Meta, Combine)
|
|
|
|
{
|
|
|
|
using CombinedAll = EC::Meta::Combine<ListComponentsAll, ListTagsAll>;
|
|
|
|
|
|
|
|
int listAllTemp = ListAll::size;
|
|
|
|
int combinedAllTemp = CombinedAll::size;
|
|
|
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
|
|
|
|
|
|
|
listAllTemp = EC::Meta::IndexOf<C0, ListAll>::value;
|
|
|
|
combinedAllTemp = EC::Meta::IndexOf<C0, CombinedAll>::value;
|
|
|
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
|
|
|
|
|
|
|
listAllTemp = EC::Meta::IndexOf<C1, ListAll>::value;
|
|
|
|
combinedAllTemp = EC::Meta::IndexOf<C1, CombinedAll>::value;
|
|
|
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
|
|
|
|
|
|
|
listAllTemp = EC::Meta::IndexOf<C2, ListAll>::value;
|
|
|
|
combinedAllTemp = EC::Meta::IndexOf<C2, CombinedAll>::value;
|
|
|
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
|
|
|
|
|
|
|
listAllTemp = EC::Meta::IndexOf<C3, ListAll>::value;
|
|
|
|
combinedAllTemp = EC::Meta::IndexOf<C3, CombinedAll>::value;
|
|
|
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
|
|
|
|
|
|
|
listAllTemp = EC::Meta::IndexOf<T0, ListAll>::value;
|
|
|
|
combinedAllTemp = EC::Meta::IndexOf<T0, CombinedAll>::value;
|
|
|
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
|
|
|
|
|
|
|
listAllTemp = EC::Meta::IndexOf<T1, ListAll>::value;
|
|
|
|
combinedAllTemp = EC::Meta::IndexOf<T1, CombinedAll>::value;
|
|
|
|
EXPECT_EQ(combinedAllTemp, listAllTemp);
|
2016-03-05 11:16:32 +00:00
|
|
|
|
|
|
|
bool same = std::is_same<CombinedAll, ListAll>::value;
|
|
|
|
EXPECT_TRUE(same);
|
2016-03-04 12:35:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-04 13:59:43 +00:00
|
|
|
TEST(Meta, Morph)
|
|
|
|
{
|
|
|
|
using TupleAll = std::tuple<C0, C1, C2, C3>;
|
|
|
|
using MorphedTuple = EC::Meta::Morph<TupleAll, EC::Meta::TypeList<> >;
|
|
|
|
|
|
|
|
int morphedTupleTemp = MorphedTuple::size;
|
|
|
|
int componentsTemp = ListComponentsAll::size;
|
|
|
|
EXPECT_EQ(morphedTupleTemp, componentsTemp);
|
|
|
|
|
|
|
|
morphedTupleTemp = EC::Meta::IndexOf<C0, MorphedTuple>::value;
|
|
|
|
componentsTemp = EC::Meta::IndexOf<C0, ListComponentsAll>::value;
|
|
|
|
EXPECT_EQ(morphedTupleTemp, componentsTemp);
|
|
|
|
|
|
|
|
morphedTupleTemp = EC::Meta::IndexOf<C1, MorphedTuple>::value;
|
|
|
|
componentsTemp = EC::Meta::IndexOf<C1, ListComponentsAll>::value;
|
|
|
|
EXPECT_EQ(morphedTupleTemp, componentsTemp);
|
|
|
|
|
|
|
|
morphedTupleTemp = EC::Meta::IndexOf<C2, MorphedTuple>::value;
|
|
|
|
componentsTemp = EC::Meta::IndexOf<C2, ListComponentsAll>::value;
|
|
|
|
EXPECT_EQ(morphedTupleTemp, componentsTemp);
|
|
|
|
|
|
|
|
morphedTupleTemp = EC::Meta::IndexOf<C3, MorphedTuple>::value;
|
|
|
|
componentsTemp = EC::Meta::IndexOf<C3, ListComponentsAll>::value;
|
|
|
|
EXPECT_EQ(morphedTupleTemp, componentsTemp);
|
|
|
|
|
|
|
|
using MorphedComponents = EC::Meta::Morph<ListComponentsAll, std::tuple<> >;
|
|
|
|
bool isSame = std::is_same<MorphedComponents, TupleAll>::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
2016-03-13 09:07:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
using ComponentsStorage = EC::Meta::Morph<ListComponentsAll, Storage<> >;
|
|
|
|
|
|
|
|
isSame = std::is_same<ComponentsStorage::type,
|
|
|
|
std::tuple<std::vector<C0>, std::vector<C1>, std::vector<C2>, std::vector<C3> > >::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
2016-03-04 13:59:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 14:33:24 +00:00
|
|
|
TEST(Meta, TypeListGet)
|
|
|
|
{
|
|
|
|
bool isSame = std::is_same<C0, EC::Meta::TypeListGet<ListAll, 0> >::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
|
|
|
|
isSame = std::is_same<C1, EC::Meta::TypeListGet<ListAll, 1> >::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
|
|
|
|
isSame = std::is_same<C2, EC::Meta::TypeListGet<ListAll, 2> >::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
|
|
|
|
isSame = std::is_same<C3, EC::Meta::TypeListGet<ListAll, 3> >::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
|
|
|
|
const unsigned int temp = 4;
|
|
|
|
isSame = std::is_same<T0, EC::Meta::TypeListGet<ListAll, temp> >::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
|
|
|
|
isSame = std::is_same<T1, EC::Meta::TypeListGet<ListAll, 5> >::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
}
|
|
|
|
|
2016-03-13 05:06:57 +00:00
|
|
|
TEST(Meta, ForEach)
|
|
|
|
{
|
|
|
|
EC::Bitset<ListComponentsAll, ListTagsAll> bitset;
|
|
|
|
|
|
|
|
auto setBits = [&bitset] (auto t) {
|
|
|
|
bitset[EC::Meta::IndexOf<decltype(t), ListAll>::value] = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
EC::Meta::forEach<ListComponentsSome>(setBits);
|
|
|
|
|
|
|
|
EXPECT_FALSE(bitset[0]);
|
|
|
|
EXPECT_TRUE(bitset[1]);
|
|
|
|
EXPECT_FALSE(bitset[2]);
|
|
|
|
EXPECT_TRUE(bitset[3]);
|
|
|
|
EXPECT_FALSE(bitset[4]);
|
|
|
|
EXPECT_FALSE(bitset[5]);
|
|
|
|
}
|
|
|
|
|
2016-03-13 09:07:49 +00:00
|
|
|
TEST(Meta, Matching)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using Matched = EC::Meta::Matching<ListComponentsSome, ListComponentsAll>::type;
|
|
|
|
bool isSame = std::is_same<ListComponentsSome, Matched>::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
using Matched = EC::Meta::Matching<ListSome, ListAll>::type;
|
|
|
|
bool isSame = std::is_same<ListSome, Matched>::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
}
|
2016-03-13 09:17:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
using Matched = EC::Meta::Matching<ListTagsAll, ListComponentsAll>::type;
|
|
|
|
bool isSame = std::is_same<EC::Meta::TypeList<>, Matched>::value;
|
|
|
|
EXPECT_TRUE(isSame);
|
|
|
|
}
|
2016-03-13 09:07:49 +00:00
|
|
|
}
|
|
|
|
|