Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / kwsys / kwsysPlatformTestsCXX.cxx
blobf0a2dfccbcfe84f6d5a9f8a44fbe3578980cc78a
1 // Setup for tests that use result of stl namespace test.
2 #if defined(KWSYS_STL_HAVE_STD)
3 # if KWSYS_STL_HAVE_STD
4 # define kwsys_stl std
5 # else
6 # define kwsys_stl
7 # endif
8 #endif
10 // Setup for tests that use iostreams.
11 #if defined(KWSYS_IOS_USE_ANSI) && defined(KWSYS_IOS_HAVE_STD)
12 # if defined(_MSC_VER)
13 # pragma warning (push,1)
14 # endif
15 # if KWSYS_IOS_USE_ANSI
16 # include <iostream>
17 # else
18 # include <iostream.h>
19 # endif
20 # if defined(_MSC_VER)
21 # pragma warning (pop)
22 # endif
23 # if KWSYS_IOS_HAVE_STD
24 # define kwsys_ios std
25 # else
26 # define kwsys_ios
27 # endif
28 #endif
30 #ifdef TEST_KWSYS_STL_HAVE_STD
31 #include <list>
32 void f(std ::list<int>*) {}
33 int main() { return 0; }
34 #endif
36 #ifdef TEST_KWSYS_IOS_USE_ANSI
37 #include <iosfwd>
38 int main() { return 0; }
39 #endif
41 #ifdef TEST_KWSYS_IOS_HAVE_STD
42 #include <iosfwd>
43 void f(std ::ostream*) {}
44 int main() { return 0; }
45 #endif
47 #ifdef TEST_KWSYS_IOS_USE_SSTREAM
48 #include <sstream>
49 #if defined(__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ == 96
50 # error "GCC 2.96 stringstream is buggy"
51 #endif
52 int main()
54 std ::ostringstream ostr;
55 ostr << "hello";
56 if(ostr.str().size() == 5)
58 return 0;
60 return -1;
62 #endif
64 #ifdef TEST_KWSYS_IOS_USE_STRSTREAM_H
65 #include <strstream.h>
66 int main() { return 0; }
67 #endif
69 #ifdef TEST_KWSYS_IOS_USE_STRSTREA_H
70 #include <strstrea.h>
71 int main() { return 0; }
72 #endif
74 #ifdef TEST_KWSYS_STL_STRING_HAVE_OSTREAM
75 # include <iostream.h>
76 # include <string>
77 void f(ostream& os, const kwsys_stl::string& s) { os << s; }
78 int main() { return 0; }
79 #endif
81 #ifdef TEST_KWSYS_STL_STRING_HAVE_ISTREAM
82 # include <iostream.h>
83 # include <string>
84 void f(istream& is, kwsys_stl::string& s) { is >> s; }
85 int main() { return 0; }
86 #endif
88 #ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
89 # include <string>
90 bool f(const kwsys_stl::string& s) { return s != ""; }
91 int main() { return 0; }
92 #endif
94 #ifdef TEST_KWSYS_CXX_HAS_CSTDDEF
95 #include <cstddef>
96 void f(size_t) {}
97 int main() { return 0; }
98 #endif
100 #ifdef TEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
101 template <class T> class A;
102 template <class T> int f(A<T>&);
103 template <class T> class A
105 public:
106 // "friend int f<>(A<T>&)" would conform
107 friend int f(A<T>&);
108 private:
109 int x;
112 template <class T> int f(A<T>& a) { return a.x = 0; }
113 template int f(A<int>&);
115 int main()
117 A<int> a;
118 return f(a);
120 #endif
122 #ifdef TEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES
123 template <class U>
124 class A
126 public:
127 U u;
128 A(): u(0) {}
129 template <class V> V m(V* p) { return *p = u; }
132 int main()
134 A<short> a;
135 int s = 1;
136 return a.m(&s);
138 #endif
140 #ifdef TEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION
141 template <class T> struct A {};
142 template <> struct A<int*>
144 static int f() { return 0; }
146 int main() { return A<int*>::f(); }
147 #endif
149 #ifdef TEST_KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
150 namespace N
152 class A {};
153 int f(A*) { return 0; }
155 void f(void*);
156 int main()
158 N::A* a = 0;
159 return f(a);
161 #endif
163 #ifdef TEST_KWSYS_STL_HAS_ITERATOR_TRAITS
164 #include <iterator>
165 #include <list>
166 void f(kwsys_stl::iterator_traits<kwsys_stl::list<int>::iterator>::iterator_category const&) {}
167 int main() { return 0; }
168 #endif
170 #ifdef TEST_KWSYS_STL_HAS_ITERATOR_CATEGORY
171 #include <iterator>
172 #include <list>
173 void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::iterator_category(x); }
174 int main() { return 0; }
175 #endif
177 #ifdef TEST_KWSYS_STL_HAS___ITERATOR_CATEGORY
178 #include <iterator>
179 #include <list>
180 void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::__iterator_category(x); }
181 int main() { return 0; }
182 #endif
184 #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
185 #include <memory>
186 template <class Alloc>
187 void f(const Alloc&)
189 typedef typename Alloc::size_type alloc_size_type;
191 int main()
193 f(kwsys_stl::allocator<char>());
194 return 0;
196 #endif
198 #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
199 #include <memory>
200 void f(kwsys_stl::allocator::size_type const&) {}
201 int main() { return 0; }
202 #endif
204 #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
205 #include <memory>
206 template <class T, class Alloc>
207 void f(const T&, const Alloc&)
209 typedef typename Alloc::template rebind<T>::other alloc_type;
211 int main()
213 f(0, kwsys_stl::allocator<char>());
214 return 0;
216 #endif
218 #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
219 #include <memory>
220 void f(kwsys_stl::allocator<char> const& a)
222 a.max_size(sizeof(int));
224 int main()
226 f(kwsys_stl::allocator<char>());
227 return 0;
229 #endif
231 #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_OBJECTS
232 #include <vector>
233 void f(kwsys_stl::vector<int> const& v1)
235 kwsys_stl::vector<int>(1, 1, v1.get_allocator());
237 int main()
239 f(kwsys_stl::vector<int>());
240 return 0;
242 #endif
244 #ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
245 #include <sys/types.h>
246 #include <sys/stat.h>
247 #include <unistd.h>
248 int main()
250 struct stat stat1;
251 (void)stat1.st_mtim.tv_sec;
252 (void)stat1.st_mtim.tv_nsec;
253 return 0;
255 #endif
257 #ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
258 void function(long**) {}
259 int main()
261 __int64** p = 0;
262 function(p);
263 return 0;
265 #endif
267 #ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
268 void function(long long**) {}
269 int main()
271 __int64** p = 0;
272 function(p);
273 return 0;
275 #endif
277 #ifdef TEST_KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
278 void function(double& l, unsigned __int64 const& r)
280 l = static_cast<double>(r);
283 int main()
285 double tTo = 0.0;
286 unsigned __int64 tFrom = 0;
287 function(tTo, tFrom);
288 return 0;
290 #endif
292 #ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
293 int test_istream(kwsys_ios::istream& is, long long& x)
295 return (is >> x)? 1:0;
297 int main()
299 long long x = 0;
300 return test_istream(kwsys_ios::cin, x);
302 #endif
304 #ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
305 int test_ostream(kwsys_ios::ostream& os, long long x)
307 return (os << x)? 1:0;
309 int main()
311 long long x = 0;
312 return test_ostream(kwsys_ios::cout, x);
314 #endif
316 #ifdef TEST_KWSYS_CHAR_IS_SIGNED
317 /* Return 0 for char signed and 1 for char unsigned. */
318 int main()
320 unsigned char uc = 255;
321 return (*reinterpret_cast<char*>(&uc) < 0)?0:1;
323 #endif
325 #ifdef TEST_KWSYS_LFS_WORKS
326 /* Return 0 when LFS is available and 1 otherwise. */
327 #define _LARGEFILE_SOURCE
328 #define _LARGEFILE64_SOURCE
329 #define _LARGE_FILES
330 #define _FILE_OFFSET_BITS 64
331 #include <sys/types.h>
332 #include <sys/stat.h>
333 #include <assert.h>
334 #include <stdio.h>
336 int main(int, char **argv)
338 /* check that off_t can hold 2^63 - 1 and perform basic operations... */
339 #define OFF_T_64 (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
340 if (OFF_T_64 % 2147483647 != 1)
341 return 1;
343 // stat breaks on SCO OpenServer
344 struct stat buf;
345 stat( argv[0], &buf );
346 if (!S_ISREG(buf.st_mode))
347 return 2;
349 FILE *file = fopen( argv[0], "r" );
350 off_t offset = ftello( file );
351 fseek( file, offset, SEEK_CUR );
352 fclose( file );
353 return 0;
355 #endif
357 #ifdef TEST_KWSYS_CXX_TYPE_INFO
358 /* Collect fundamental type information and save it to a CMake script. */
360 /* Include limits.h to get macros indicating long long and __int64.
361 Note that certain compilers need special macros to define these
362 macros in limits.h. */
363 #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
364 # define _MSC_EXTENSIONS
365 #endif
366 #if defined(__GNUC__) && __GNUC__ < 3
367 # define _GNU_SOURCE
368 #endif
369 #include <limits.h>
371 #include <stdio.h>
372 #include <string.h>
374 /* Due to shell differences and limitations of ADD_DEFINITIONS the
375 KWSYS_CXX_TYPE_INFO_FILE macro will sometimes have double quotes
376 and sometimes not. This macro will make sure the value is treated
377 as a double-quoted string. */
378 #define TO_STRING(x) TO_STRING0(x)
379 #define TO_STRING0(x) TO_STRING1(x)
380 #define TO_STRING1(x) #x
382 void f() {}
384 int main()
386 /* Construct the output file name. Some preprocessors will add an
387 extra level of double quotes, so strip them. */
388 char fbuf[] = TO_STRING(KWSYS_CXX_TYPE_INFO_FILE);
389 char* fname = fbuf;
390 if(fname[0] == '"')
392 ++fname;
393 int len = static_cast<int>(strlen(fname));
394 if(len > 0 && fname[len-1] == '"')
396 fname[len-1] = 0;
400 /* Try to open the output file. */
401 if(FILE* fout = fopen(fname, "w"))
403 /* Set the size of standard types. */
404 fprintf(fout, "SET(KWSYS_SIZEOF_CHAR %d)\n", static_cast<int>(sizeof(char)));
405 fprintf(fout, "SET(KWSYS_SIZEOF_SHORT %d)\n", static_cast<int>(sizeof(short)));
406 fprintf(fout, "SET(KWSYS_SIZEOF_INT %d)\n", static_cast<int>(sizeof(int)));
407 fprintf(fout, "SET(KWSYS_SIZEOF_LONG %d)\n", static_cast<int>(sizeof(long)));
409 /* Set the size of some non-standard but common types. */
410 /* Check for a limits.h macro for long long to see if the type exists. */
411 #if defined(LLONG_MAX) || defined(LONG_LONG_MAX) || defined(LONGLONG_MAX)
412 fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG %d)\n", static_cast<int>(sizeof(long long)));
413 #else
414 fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG 0) # No long long available.\n");
415 #endif
416 /* Check for a limits.h macro for __int64 to see if the type exists. */
417 #if defined(_I64_MIN)
418 fprintf(fout, "SET(KWSYS_SIZEOF___INT64 %d)\n", static_cast<int>(sizeof(__int64)));
419 #else
420 fprintf(fout, "SET(KWSYS_SIZEOF___INT64 0) # No __int64 available.\n");
421 #endif
423 /* Set the size of some pointer types. */
424 fprintf(fout, "SET(KWSYS_SIZEOF_PDATA %d)\n", static_cast<int>(sizeof(void*)));
425 fprintf(fout, "SET(KWSYS_SIZEOF_PFUNC %d)\n", static_cast<int>(sizeof(&f)));
427 /* Set whether the native type "char" is signed or unsigned. */
428 unsigned char uc = 255;
429 fprintf(fout, "SET(KWSYS_CHAR_IS_SIGNED %d)\n",
430 (*reinterpret_cast<char*>(&uc) < 0)?1:0);
432 fclose(fout);
433 return 0;
435 else
437 fprintf(stderr, "Failed to write fundamental type info to \"%s\".\n",
438 fname);
439 return 1;
442 #endif