aboutsummaryrefslogtreecommitdiff
path: root/EASTL/test/source/TestMeta.cpp
blob: 8d2e9d1e60b26d01a45ea25491f14e6e5b9425db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////


#include "EASTLTest.h"

#ifdef EA_COMPILER_CPP14_ENABLED
#include "ConceptImpls.h"
#include <EASTL/meta.h>


int TestGetTypeIndex()
{
	using namespace eastl;

	int nErrorCount = 0;

	static_assert(meta::get_type_index_v<short, short, char, int> == 0, "error");
	static_assert(meta::get_type_index_v<char, short, char, int> == 1, "error");
	static_assert(meta::get_type_index_v<int, short, char, int> == 2, "error");
	static_assert(meta::get_type_index_v<int, int, int, int> == 0, "error");

	return nErrorCount;
}

int TestGetType()
{
	using namespace eastl;

	int nErrorCount = 0;

	static_assert(is_same_v<meta::get_type_at_t<2, short, short, char, int>, char>, "error");
	static_assert(is_same_v<meta::get_type_at_t<3, char, short, char, int>, int>, "error");
	// static_assert(is_same_v<meta::get_type_at_t<4, int, short, char, int>, int>, "error");
	static_assert(is_same_v<meta::get_type_at_t<1, int, int, int, int>, int>, "error");

	return nErrorCount;
}

int TestTypeCount()
{
	using namespace eastl;

	int nErrorCount = 0;

	static_assert(meta::type_count_v<short, short, char, int> == 1, "error");
	static_assert(meta::type_count_v<char, short, char, int> == 1, "error");
	static_assert(meta::type_count_v<int, short, char, int> == 1, "error");
	static_assert(meta::type_count_v<int, int, int, int> == 3, "error");
	static_assert(meta::type_count_v<int, int, int, int, int, int, int, int, int> == 8, "error");
	static_assert(meta::type_count_v<int, int, int, int, char, int, int, int, int> == 7, "error");
	static_assert(meta::type_count_v<int, int, char, int, char, int, int, int, int> == 6, "error");
	static_assert(meta::type_count_v<int, int, char, int, char, int, int, int, char> == 5, "error");
	static_assert(meta::type_count_v<int, int, char, int, char, int, const int, int, char> == 4, "error");
	static_assert(meta::type_count_v<int, volatile int, char, int, char, int, const int, const volatile int, char> == 2, "error");

	return nErrorCount;
}

int TestDuplicateTypeCheck()
{
	using namespace eastl;

	int nErrorCount = 0;

	static_assert( meta::duplicate_type_check_v<short, short, char, int>, "error");
	static_assert( meta::duplicate_type_check_v<short, short, char, int, long, unsigned, long long>, "error");
	static_assert( meta::duplicate_type_check_v<int, const int, volatile int, const volatile int, int>, "error");
	static_assert(!meta::duplicate_type_check_v<short, short, char, int, long, unsigned, short, long long>, "error");

	return nErrorCount;
}

int TestOverloadResolution()
{
	using namespace eastl;
	using namespace eastl::meta;

	int nErrorCount = 0;

	static_assert(is_same_v<overload_resolution_t<int, overload_set<int>>, int>, "error");
	static_assert(is_same_v<overload_resolution_t<int, overload_set<short>>, short>, "error");
	static_assert(is_same_v<overload_resolution_t<int, overload_set<long>>, long>, "error");
	static_assert(is_same_v<overload_resolution_t<short, overload_set<int>>, int>, "error");
	static_assert(is_same_v<overload_resolution_t<int, overload_set<int, short, long>>, int>, "error");
	static_assert(is_same_v<overload_resolution_t<int, overload_set<short, int, long, float>>, int>, "error");
	static_assert(is_same_v<overload_resolution_t<int, overload_set<short, long, int, float, char>>, int>, "error");

	static_assert(is_same_v<overload_resolution_t<int, overload_set<int>>, int>, "error");
	static_assert(is_same_v<overload_resolution_t<int, overload_set<int, short>>, int>, "error");
	static_assert(is_same_v<overload_resolution_t<int, overload_set<int, short, long>>, int>, "error");

	return nErrorCount;
}


int TestMeta()
{
	int nErrorCount = 0;

	nErrorCount += TestGetTypeIndex();
	nErrorCount += TestGetType();
	nErrorCount += TestTypeCount();
	nErrorCount += TestDuplicateTypeCheck();
	nErrorCount += TestOverloadResolution();

	return nErrorCount;
}

#endif // EA_COMPILER_CPP14_ENABLED