sol::common_type<>: find common type for parameter types
[sol.git] / sol / utility / common_type_test.cpp
blob7356426fe2adba684e1d9a17573e2f3a96b8af14
1 #include <sol/test_main.cpp>
2 #include <sol/utility/common_type.hpp>
5 namespace sol { namespace test {
8 // test that common type for type1 and type2 is expected_type
9 #define TEST_TYPES(type1,type2,expected_type) \
10 do { \
11 sol_equal(typeid(common_type<type1,type2>::type).name() \
12 , typeid(expected_type).name() \
13 ); \
14 sol_equal(typeid(common_type<type2,type1>::type).name() \
15 , typeid(expected_type).name() \
16 ); \
17 } while (0)
20 int
21 run (std::vector<std::string> const &args)
23 using namespace sol;
25 sol_info("bool");
27 typedef bool T;
28 TEST_TYPES(T, T, T);
29 TEST_TYPES(T, char, int);
30 TEST_TYPES(T, unsigned char, int);
31 TEST_TYPES(T, short, int);
32 TEST_TYPES(T, unsigned short, int);
33 TEST_TYPES(T, int, int);
34 TEST_TYPES(T, unsigned int, unsigned int);
35 TEST_TYPES(T, long, long);
36 TEST_TYPES(T, unsigned long, unsigned long);
37 TEST_TYPES(T, long long, long long);
38 TEST_TYPES(T, unsigned long long, unsigned long long);
39 TEST_TYPES(T, float, float);
40 TEST_TYPES(T, double, double);
41 TEST_TYPES(T, long double, long double);
44 sol_info("char");
46 typedef char T;
47 TEST_TYPES(T, bool, int);
48 TEST_TYPES(T, T, T);
49 TEST_TYPES(T, unsigned char, int);
50 TEST_TYPES(T, short, int);
51 TEST_TYPES(T, unsigned short, int);
52 TEST_TYPES(T, int, int);
53 TEST_TYPES(T, unsigned int, unsigned int);
54 TEST_TYPES(T, long, long);
55 TEST_TYPES(T, unsigned long, unsigned long);
56 TEST_TYPES(T, long long, long long);
57 TEST_TYPES(T, unsigned long long, unsigned long long);
58 TEST_TYPES(T, float, float);
59 TEST_TYPES(T, double, double);
60 TEST_TYPES(T, long double, long double);
63 sol_info("unsigned char");
65 typedef unsigned char T;
66 TEST_TYPES(T, bool, int);
67 TEST_TYPES(T, char, int);
68 TEST_TYPES(T, T, T);
69 TEST_TYPES(T, short, int);
70 TEST_TYPES(T, unsigned short, int);
71 TEST_TYPES(T, int, int);
72 TEST_TYPES(T, unsigned int, unsigned int);
73 TEST_TYPES(T, long, long);
74 TEST_TYPES(T, unsigned long, unsigned long);
75 TEST_TYPES(T, long long, long long);
76 TEST_TYPES(T, unsigned long long, unsigned long long);
77 TEST_TYPES(T, float, float);
78 TEST_TYPES(T, double, double);
79 TEST_TYPES(T, long double, long double);
82 sol_info("short");
84 typedef short T;
85 TEST_TYPES(T, bool, int);
86 TEST_TYPES(T, char, int);
87 TEST_TYPES(T, unsigned char, int);
88 TEST_TYPES(T, T, T);
89 TEST_TYPES(T, unsigned short, int);
90 TEST_TYPES(T, int, int);
91 TEST_TYPES(T, unsigned int, unsigned int);
92 TEST_TYPES(T, long, long);
93 TEST_TYPES(T, unsigned long, unsigned long);
94 TEST_TYPES(T, long long, long long);
95 TEST_TYPES(T, unsigned long long, unsigned long long);
96 TEST_TYPES(T, float, float);
97 TEST_TYPES(T, double, double);
98 TEST_TYPES(T, long double, long double);
101 sol_info("unsigned short");
103 typedef unsigned short T;
104 TEST_TYPES(T, bool, int);
105 TEST_TYPES(T, char, int);
106 TEST_TYPES(T, unsigned char, int);
107 TEST_TYPES(T, short, int);
108 TEST_TYPES(T, T, T);
109 TEST_TYPES(T, int, int);
110 TEST_TYPES(T, unsigned int, unsigned int);
111 TEST_TYPES(T, long, long);
112 TEST_TYPES(T, unsigned long, unsigned long);
113 TEST_TYPES(T, long long, long long);
114 TEST_TYPES(T, unsigned long long, unsigned long long);
115 TEST_TYPES(T, float, float);
116 TEST_TYPES(T, double, double);
117 TEST_TYPES(T, long double, long double);
120 sol_info("int");
122 typedef int T;
123 TEST_TYPES(T, bool, int);
124 TEST_TYPES(T, char, int);
125 TEST_TYPES(T, unsigned char, int);
126 TEST_TYPES(T, short, int);
127 TEST_TYPES(T, unsigned short, int);
128 TEST_TYPES(T, T, T);
129 TEST_TYPES(T, unsigned int, unsigned int);
130 TEST_TYPES(T, long, long);
131 TEST_TYPES(T, unsigned long, unsigned long);
132 TEST_TYPES(T, long long, long long);
133 TEST_TYPES(T, unsigned long long, unsigned long long);
134 TEST_TYPES(T, float, float);
135 TEST_TYPES(T, double, double);
136 TEST_TYPES(T, long double, long double);
139 sol_info("unsigned int");
141 typedef unsigned int T;
142 TEST_TYPES(T, bool, unsigned int);
143 TEST_TYPES(T, char, unsigned int);
144 TEST_TYPES(T, unsigned char, unsigned int);
145 TEST_TYPES(T, short, unsigned int);
146 TEST_TYPES(T, unsigned short, unsigned int);
147 TEST_TYPES(T, int, unsigned int);
148 TEST_TYPES(T, T, T);
149 TEST_TYPES(T, long, long);
150 TEST_TYPES(T, unsigned long, unsigned long);
151 TEST_TYPES(T, long long, long long);
152 TEST_TYPES(T, unsigned long long, unsigned long long);
153 TEST_TYPES(T, float, float);
154 TEST_TYPES(T, double, double);
155 TEST_TYPES(T, long double, long double);
158 sol_info("long");
160 typedef long T;
161 TEST_TYPES(T, bool, long);
162 TEST_TYPES(T, char, long);
163 TEST_TYPES(T, unsigned char, long);
164 TEST_TYPES(T, short, long);
165 TEST_TYPES(T, unsigned short, long);
166 TEST_TYPES(T, int, long);
167 TEST_TYPES(T, unsigned int, long);
168 TEST_TYPES(T, T, T);
169 TEST_TYPES(T, unsigned long, unsigned long);
170 TEST_TYPES(T, long long, long long);
171 TEST_TYPES(T, unsigned long long, unsigned long long);
172 TEST_TYPES(T, float, float);
173 TEST_TYPES(T, double, double);
174 TEST_TYPES(T, long double, long double);
177 sol_info("unsigned long");
179 typedef unsigned long T;
180 TEST_TYPES(T, bool, unsigned long);
181 TEST_TYPES(T, char, unsigned long);
182 TEST_TYPES(T, unsigned char, unsigned long);
183 TEST_TYPES(T, short, unsigned long);
184 TEST_TYPES(T, unsigned short, unsigned long);
185 TEST_TYPES(T, int, unsigned long);
186 TEST_TYPES(T, unsigned int, unsigned long);
187 TEST_TYPES(T, long, unsigned long);
188 TEST_TYPES(T, T, T);
189 TEST_TYPES(T, long long, unsigned long long);
190 TEST_TYPES(T, unsigned long long, unsigned long long);
191 TEST_TYPES(T, float, float);
192 TEST_TYPES(T, double, double);
193 TEST_TYPES(T, long double, long double);
196 sol_info("long long");
198 typedef long long T;
199 TEST_TYPES(T, bool, long long);
200 TEST_TYPES(T, char, long long);
201 TEST_TYPES(T, unsigned char, long long);
202 TEST_TYPES(T, short, long long);
203 TEST_TYPES(T, unsigned short, long long);
204 TEST_TYPES(T, int, long long);
205 TEST_TYPES(T, unsigned int, long long);
206 TEST_TYPES(T, long, long long);
207 TEST_TYPES(T, unsigned long, unsigned long long);
208 TEST_TYPES(T, T, T);
209 TEST_TYPES(T, unsigned long long, unsigned long long);
210 TEST_TYPES(T, float, float);
211 TEST_TYPES(T, double, double);
212 TEST_TYPES(T, long double, long double);
215 sol_info("unsigned long long");
217 typedef unsigned long long T;
218 TEST_TYPES(T, bool, unsigned long long);
219 TEST_TYPES(T, char, unsigned long long);
220 TEST_TYPES(T, unsigned char, unsigned long long);
221 TEST_TYPES(T, short, unsigned long long);
222 TEST_TYPES(T, unsigned short, unsigned long long);
223 TEST_TYPES(T, int, unsigned long long);
224 TEST_TYPES(T, unsigned int, unsigned long long);
225 TEST_TYPES(T, long, unsigned long long);
226 TEST_TYPES(T, unsigned long, unsigned long long);
227 TEST_TYPES(T, long long, unsigned long long);
228 TEST_TYPES(T, T, T);
229 TEST_TYPES(T, float, float);
230 TEST_TYPES(T, double, double);
231 TEST_TYPES(T, long double, long double);
234 sol_info("float");
236 typedef float T;
237 TEST_TYPES(T, bool, float);
238 TEST_TYPES(T, char, float);
239 TEST_TYPES(T, unsigned char, float);
240 TEST_TYPES(T, short, float);
241 TEST_TYPES(T, unsigned short, float);
242 TEST_TYPES(T, int, float);
243 TEST_TYPES(T, unsigned int, float);
244 TEST_TYPES(T, long, float);
245 TEST_TYPES(T, unsigned long, float);
246 TEST_TYPES(T, long long, float);
247 TEST_TYPES(T, unsigned long long, float);
248 TEST_TYPES(T, T, T);
249 TEST_TYPES(T, double, double);
250 TEST_TYPES(T, long double, long double);
253 sol_info("double");
255 typedef double T;
256 TEST_TYPES(T, bool, double);
257 TEST_TYPES(T, char, double);
258 TEST_TYPES(T, unsigned char, double);
259 TEST_TYPES(T, short, double);
260 TEST_TYPES(T, unsigned short, double);
261 TEST_TYPES(T, int, double);
262 TEST_TYPES(T, unsigned int, double);
263 TEST_TYPES(T, long, double);
264 TEST_TYPES(T, unsigned long, double);
265 TEST_TYPES(T, long long, double);
266 TEST_TYPES(T, unsigned long long, double);
267 TEST_TYPES(T, float, double);
268 TEST_TYPES(T, T, T);
269 TEST_TYPES(T, long double, long double);
272 sol_info("long double");
274 typedef long double T;
275 TEST_TYPES(T, bool, long double);
276 TEST_TYPES(T, char, long double);
277 TEST_TYPES(T, unsigned char, long double);
278 TEST_TYPES(T, short, long double);
279 TEST_TYPES(T, unsigned short, long double);
280 TEST_TYPES(T, int, long double);
281 TEST_TYPES(T, unsigned int, long double);
282 TEST_TYPES(T, long, long double);
283 TEST_TYPES(T, unsigned long, long double);
284 TEST_TYPES(T, long long, long double);
285 TEST_TYPES(T, unsigned long long, long double);
286 TEST_TYPES(T, float, long double);
287 TEST_TYPES(T, double, long double);
288 TEST_TYPES(T, T, T);
291 return EXIT_SUCCESS;
295 }} // namespace sol::test