34#ifndef _RWSTD_NO_EXT_CXX_0X
89 std::conditional<is_char<T>::val, long,
void>::type selector;
105 "%s<%b, %s, %s>::type is%{?}n't%{;} %s as expected",
106 trait, select, typeT, typeU, !success, select ? typeT : typeU);
110 const char* typeT,
const char* typeU,
114 "%s<%s>::type is%{?}n't%{;} %s as expected",
115 trait, typeT, !success, typeU);
120 const bool success = got == exp;
122 rw_assert (success, 0,
line,
"%s is%{?}n't%{;} %b as expected",
123 typeT, !success, exp);
127 size_t exp_sz,
size_t got_sz,
128 size_t exp_al,
size_t got_al)
132 "std::aligned_storage<%zu, %zu>::type size is %zu; "
133 "expected %zu or more", exp_sz, exp_al, got_sz, exp_sz);
138 "std::aligned_storage<%zu, %zu>::type alignment is %zu; "
139 "expected %zu or more", exp_sz, exp_al, got_al, exp_al);
145 "std::aligned_storage<%zu, %zu>::type alignment is %zu; "
146 "expected %zu or less", exp_sz, exp_al, got_al, exp_sz);
149 const bool is_pow_2 = (got_al & (got_al - 1)) == 0;
151 "std::aligned_storage<%zu, %zu>::type alignment expected "
152 "to be a power-of-two; got %zu", exp_sz, exp_al, got_al);
159#ifdef _RWSTD_NO_ALIGN_TRAITS
162 "test_aligned_storage disabled because "
163 "_RWSTD_NO_ALIGN_TRAITS is defined");
167#define TEST(Size,Align) \
169 typedef std::aligned_storage<Size, Align>::type storage_t; \
170 test_aligned_storage(__LINE__, \
171 Size, sizeof (storage_t), Align, \
172 std::alignment_of<storage_t>::value); \
173 } typedef void __dummy
193 typedef std::aligned_storage<Size>::type storage_t; \
194 test_aligned_storage(__LINE__, \
195 Size, sizeof (storage_t), 0, \
196 std::alignment_of<storage_t>::value); \
197 } typedef void __dummy
222#ifndef _RWSTD_NO_ALIGN_TRAITS
227size_t max8(
size_t a1,
size_t a2,
size_t a3,
size_t a4,
228 size_t a5,
size_t a6,
size_t a7,
size_t a8)
251 const char*
t1 ,
const char*
t2 = 0,
252 const char* t3 = 0,
const char* t4 = 0,
253 const char* t5 = 0,
const char* t6 = 0,
254 const char* t7 = 0,
const char* t8 = 0)
256 const char* arr[] = {
257 t1,
t2, t3, t4, t5, t6, t7, t8
265 for (
size_t i = 0;
i <
sizeof (arr) /
sizeof (*arr); ++
i)
273 typedef std::aligned_union<Len,T1,T2,T3,T4,T5,T6,T7,T8> aligned_t;
274 typedef typename aligned_t::type aligned_type_t;
276 const bool pass1 = std::alignment_of<aligned_type_t>::value
277 == aligned_t::alignment_value;
279 "std::aligned_union<%s>::alignment_value is %zu; "
281 pbuf, aligned_t::alignment_value,
282 std::alignment_of<aligned_type_t>::value);
284 const size_t exp_al =
max8(std::alignment_of<T1>::value,
285 std::alignment_of<T2>::value,
286 std::alignment_of<T3>::value,
287 std::alignment_of<T4>::value,
288 std::alignment_of<T5>::value,
289 std::alignment_of<T6>::value,
290 std::alignment_of<T7>::value,
291 std::alignment_of<T8>::value);
292 const size_t got_al = std::alignment_of<aligned_type_t>::value;
294 const bool pass2 = exp_al == got_al;
296 "std::aligned_union<%s>::type alignment is %zu; "
298 pbuf, got_al, exp_al);
300 const size_t min_sz = Len;
301 const size_t got_sz =
sizeof (aligned_type_t);
303 const bool pass3 = min_sz <= got_sz;
306 "std::aligned_union<%s>::type size is %zu; expected "
308 pbuf, got_sz, min_sz);
319static void test_aligned_union ()
321#ifdef _RWSTD_NO_ALIGN_TRAITS
324 "test_aligned_union disabled because "
325 "_RWSTD_NO_ALIGN_TRAITS is defined");
329#define TEST(Len,T1) \
330 aligned_union_tester<Len,T1>::test(__LINE__,#T1)
348#define TEST(Len,T1,T2) \
349 aligned_union_tester<Len,T1,T2>::test(__LINE__,#T1,#T2)
351 TEST (11,
char,
long);
352 TEST (134,
long,
long);
353 TEST (7,
void*,
long);
356 TEST (2,
char,
long);
357 TEST (2,
long,
long);
358 TEST (2,
void*,
long);
362#define TEST(Len,T1,T2,T3,T4,T5) \
363 aligned_union_tester<Len,T1,T2,T3,T4,T5>::test(__LINE__,#T1,#T2,#T3,#T4,#T5)
365 TEST (12,
char,
short,
int,
long,
void*);
366 TEST (13,
void*,
long,
long,
long,
int);
367 TEST (17,
void (
struct_t::*)(), long, int, void*, char);
376static void test_decay ()
378#define TEST(Trait,TypeT,TypeU) \
379 test_trait(__LINE__, #Trait, #TypeT, #TypeU, \
380 std::is_same<Trait<TypeT>::type, TypeU>::value)
383 TEST (std::decay,
int[ ],
int*);
384 TEST (std::decay,
int[2],
int*);
385 TEST (std::decay,
int[2][2],
int (*)[2]);
388 TEST (std::decay,
int(),
int (*)());
389 TEST (std::decay,
int(
char,
long),
int (*)(
char,
long));
391 TEST (std::decay,
int(&)(),
int (*)());
392 TEST (std::decay,
int(&)(
char,
long),
int (*)(
char,
long));
395 TEST (std::decay,
int,
int);
396 TEST (std::decay,
const int,
int);
397 TEST (std::decay,
volatile int,
int);
398 TEST (std::decay,
const volatile int,
int);
400 TEST (std::decay,
int&,
int);
401 TEST (std::decay,
const int&,
int);
402 TEST (std::decay,
volatile int&,
int);
403 TEST (std::decay,
const volatile int&,
int);
414 typedef std::enable_if<true, int>::type int_type;
416#define TEST(Cond,Expect) \
417 test_enable_if(__LINE__, #Cond, Cond, Expect)
419 TEST (enabled_if_char< char>(), 1);
420 TEST (enabled_if_char< signed char>(), 0);
421 TEST (enabled_if_char<unsigned char>(), 0);
423 TEST (enabled_if_char< short>(), 0);
424 TEST (enabled_if_char< signed short>(), 0);
425 TEST (enabled_if_char<unsigned short>(), 0);
427 TEST (enabled_if_char< int>(), 0);
428 TEST (enabled_if_char< signed int>(), 0);
429 TEST (enabled_if_char<unsigned int>(), 0);
431 TEST (enabled_if_char< long>(), 0);
432 TEST (enabled_if_char< signed long>(), 0);
433 TEST (enabled_if_char<unsigned long>(), 0);
444 TEST (enabled_if_char<enum_t>(), 0);
451static void test_conditional ()
453#define TEST(Cond,Expect) \
454 test_enable_if(__LINE__, #Cond, Cond, Expect)
456 TEST (cond_if_char<void>(), 0);
457 TEST (cond_if_char<char>(), 1);
460#define TEST(Trait,Select,TypeT,TypeU,TypeV) \
461 test_trait(__LINE__, Select, #Trait, #TypeT, #TypeU, \
462 std::is_same<Trait<Select,TypeT,TypeU>::type, TypeV>::value)
464 TEST (std::conditional,
true,
char,
long,
char);
465 TEST (std::conditional,
false,
char,
long,
long);
475 test_aligned_union ();
492 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
500int main (
int argc,
char *argv[])
502 return rw_test (argc, argv, __FILE__,
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
#define _RWSTD_SPECIALIZED_CLASS
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_asnprintf(char **pbuf, _RWSTD_SIZE_T *pbufsize, const char *fmt,...)
static void test(int line, const char *t1, const char *t2=0, const char *t3=0, const char *t4=0, const char *t5=0, const char *t6=0, const char *t7=0, const char *t8=0)