2016-02-25 03:08:02 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
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-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);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-03-04 12:12:37 +00:00
|
|
|
TEST(Meta, Bitset)
|
|
|
|
{
|
2016-03-04 12:35:26 +00:00
|
|
|
EC::Bitset<ListComponentsAll, ListTagsAll> bitset;
|
|
|
|
EXPECT_EQ(bitset.size(), ListComponentsAll::size + ListTagsAll::size);
|
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);
|
|
|
|
}
|
|
|
|
|