Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
20.meta.help.cpp
Go to the documentation of this file.
1// -*- C++ -*-
2
30#include <rw_driver.h>
31#include <rw/_defs.h>
32
33// compile out all test code if extensions disabled
34#ifndef _RWSTD_NO_EXT_CXX_0X
35
36#include <type_traits>
37
38
40template <class T, class U>
42{
43 return 0;
44}
45
46template <class T>
48{
49 return 1;
50}
51
52template <class T>
54{
55 return 0;
56}
57
58template <class T>
59bool test_is_const (const T&)
60{
61 return 1;
62}
63
64template <class T, class U>
66{
67 enum { value = 0 };
68};
69
70template <class T>
72{
73 enum { value = 1 };
74};
75
76enum enum_t {
78};
79
80
82template <typename Type, Type Value>
83void test_integral_constant(const char* name, const char* value)
84{
85 typedef std::integral_constant<Type, Value>
86 integral_constant_type;
87
88 // verify the type of value is the same as Type
89 const bool a =
90 test_is_same_type (integral_constant_type::value, Type ());
91 rw_assert (a, 0, __LINE__,
92 "integral_constant<%s, %s>::value is%{?}n't%{;} "
93 "of type %s", name, value, !a, name);
94
95 // verify the value is as expected
96 const bool b =
97 integral_constant_type::value == Value;
98 rw_assert (b, 0, __LINE__,
99 "integral_constant<%s, %s>::value is%{?}n't%{;} "
100 "equal to %s", name, value, !b, value);
101
102 // verify that the value is const
103 const bool d =
104 test_is_const (std::integral_constant<Type,Value>::value);
105 rw_assert (d, 0, __LINE__,
106 "integral_constant<%s, %s>::value is%{?}n't%{;} "
107 "a constant", name, value, !d);
108
109 // verify that the type typedef is correct
110 const bool e =
111 test_is_same<typename integral_constant_type::type,
112 integral_constant_type>::value;
113 rw_assert (e, 0, __LINE__,
114 "integral_constant<%s, %s>::type is%{?}n't%{;} "
115 "same as integral_constant<%s, %s>",
116 name, value, !e, name, value);
117
118 // note: compiler should never allow an instantiation of
119 // integral_constant<T, V> if T is not an integral type.
120}
121
122template <typename Type, bool Value>
123void test_required_type (const char* name, const char* value)
124{
125 typedef Type integral_constant_type;
126
127 // verify the type of the type typedef
128 const bool a =
130 rw_assert (a, 0, __LINE__,
131 "%s::value_type is%{?}n't%{;} same as bool",
132 name, !a);
133
134 // verify the value is as expected
135 const bool b =
136 integral_constant_type::value == Value;
137 rw_assert (b, 0, __LINE__,
138 "%s::value is%{?}n't%{;} equal to %s",
139 name, !b, value);
140
141 // verify that Type is same as integral_constant<bool, Value>
142 const bool c =
144 rw_assert (c, 0, __LINE__,
145 "%s is%{?}n't%{;} of type integral_constant<bool, %s>",
146 name, !c, value);
147
148 test_integral_constant<typename integral_constant_type::value_type,
149 Value>("bool", value);
150}
151
152
154static int run_test (int, char*[])
155{
156#define TEST_INTEGRAL_CONSTANT(Type,Value) \
157 test_integral_constant<Type, Value>(#Type,#Value)
158
159 TEST_INTEGRAL_CONSTANT (bool, true);
160 TEST_INTEGRAL_CONSTANT (bool, false);
161
162 TEST_INTEGRAL_CONSTANT (char, '\0');
163 TEST_INTEGRAL_CONSTANT (char, _RWSTD_CHAR_MIN);
164 TEST_INTEGRAL_CONSTANT (char, _RWSTD_CHAR_MAX);
165
166#ifndef _RWSTD_NO_WCHAR_T
167 TEST_INTEGRAL_CONSTANT (wchar_t, L'\0');
168 TEST_INTEGRAL_CONSTANT (wchar_t, _RWSTD_WCHAR_MIN);
169 TEST_INTEGRAL_CONSTANT (wchar_t, _RWSTD_WCHAR_MAX);
170#endif // _RWSTD_NO_WCHAR_T
171
172 TEST_INTEGRAL_CONSTANT (signed char, 0);
173 TEST_INTEGRAL_CONSTANT (signed char, _RWSTD_SCHAR_MIN);
174 TEST_INTEGRAL_CONSTANT (signed char, _RWSTD_SCHAR_MAX);
175
176 TEST_INTEGRAL_CONSTANT (signed short, 0);
177 TEST_INTEGRAL_CONSTANT (signed short, _RWSTD_SHRT_MIN);
178 TEST_INTEGRAL_CONSTANT (signed short, _RWSTD_SHRT_MAX);
179
180 TEST_INTEGRAL_CONSTANT (signed int, 0);
181 TEST_INTEGRAL_CONSTANT (signed int, _RWSTD_INT_MIN);
182 TEST_INTEGRAL_CONSTANT (signed int, _RWSTD_INT_MAX);
183
184 TEST_INTEGRAL_CONSTANT (signed long, 0);
185 TEST_INTEGRAL_CONSTANT (signed long, _RWSTD_LONG_MIN);
186 TEST_INTEGRAL_CONSTANT (signed long, _RWSTD_LONG_MAX);
187
188#ifndef _RWSTD_NO_LONG_LONG
189 TEST_INTEGRAL_CONSTANT (signed long long, 0);
190 TEST_INTEGRAL_CONSTANT (signed long long, _RWSTD_LLONG_MIN);
191 TEST_INTEGRAL_CONSTANT (signed long long, _RWSTD_LLONG_MAX);
192#endif // _RWSTD_NO_LONG_LONG
193
194 TEST_INTEGRAL_CONSTANT (unsigned char, 1);
195 TEST_INTEGRAL_CONSTANT (unsigned char, _RWSTD_UCHAR_MIN);
196 TEST_INTEGRAL_CONSTANT (unsigned char, _RWSTD_UCHAR_MAX);
197
198 TEST_INTEGRAL_CONSTANT (unsigned short, 1);
199 TEST_INTEGRAL_CONSTANT (unsigned short, _RWSTD_USHRT_MIN);
200 TEST_INTEGRAL_CONSTANT (unsigned short, _RWSTD_USHRT_MAX);
201
202 TEST_INTEGRAL_CONSTANT (unsigned int, 1);
203 TEST_INTEGRAL_CONSTANT (unsigned int, _RWSTD_UINT_MIN);
204 TEST_INTEGRAL_CONSTANT (unsigned int, _RWSTD_UINT_MAX);
205
206 TEST_INTEGRAL_CONSTANT (unsigned long, 1);
207 TEST_INTEGRAL_CONSTANT (unsigned long, _RWSTD_UINT_MIN);
208 TEST_INTEGRAL_CONSTANT (unsigned long, _RWSTD_UINT_MAX);
209
210#ifndef _RWSTD_NO_LONG_LONG
211 TEST_INTEGRAL_CONSTANT (unsigned long long, 1);
212 TEST_INTEGRAL_CONSTANT (unsigned long long, _RWSTD_ULLONG_MIN);
213 TEST_INTEGRAL_CONSTANT (unsigned long long, _RWSTD_ULLONG_MAX);
214#endif // _RWSTD_NO_LONG_LONG
215
219
220#ifdef _ILL_FORMED
221 TEST_INTEGRAL_CONSTANT (float, 1.f);
222#endif // _ILL_FORMED
223
224#define TEST_REQUIRED_TYPE(Type,Value) \
225 test_required_type<Type, Value>(#Type, #Value);
226
227 TEST_REQUIRED_TYPE (std::true_type , true);
228 TEST_REQUIRED_TYPE (std::false_type, false);
229
230 return 0;
231}
232
233
235#else // _RWSTD_NO_EXT_CXX_0X
236
237
239static int run_test (int, char*[])
240{
241 rw_warn (0, 0, __LINE__,
242 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
243 return 0;
244}
245
246#endif // !_RWSTD_NO_EXT_CXX_0X
247
248
250int main (int argc, char *argv[])
251{
252 return rw_test (argc, argv, __FILE__,
253 "meta.help",
254 0 /* no comment */,
255 run_test,
256 0);
257}
#define T
Definition 17.names.cpp:163
#define d
Definition 17.names.cpp:115
#define e
Definition 17.names.cpp:118
#define a
Definition 17.names.cpp:109
#define c
Definition 17.names.cpp:111
#define b
Definition 17.names.cpp:110
#define U
Definition 17.names.cpp:164
enum_t
@ E_b
@ E_a
@ E_c
void test_integral_constant(const char *name, const char *value)
void test_required_type(const char *name, const char *value)
#define TEST_REQUIRED_TYPE(Type, Value)
#define TEST_INTEGRAL_CONSTANT(Type, Value)
bool test_is_same_type(T, U)
void test_is_const()
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
T value(const T &val)
#define main
const char * name
Definition codecvt1.cpp:72
_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 *,...)
Definition driver.cpp:1630
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)
Definition driver.cpp:1647