source: castxml/trunk/fuentes/src/kwsys/kwsysPlatformTestsCXX.cxx @ 6513

Last change on this file since 6513 was 6513, checked in by mabarracus, 2 years ago

Initial port to lliurex from ubuntu

File size: 14.2 KB
Line 
1/*============================================================================
2  KWSys - Kitware System Library
3  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5  Distributed under the OSI-approved BSD License (the "License");
6  see accompanying file Copyright.txt for details.
7
8  This software is distributed WITHOUT ANY WARRANTY; without even the
9  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  See the License for more information.
11============================================================================*/
12// Setup for tests that use result of stl namespace test.
13#if defined(KWSYS_STL_HAVE_STD)
14# if KWSYS_STL_HAVE_STD
15#  define kwsys_stl std
16# else
17#  define kwsys_stl
18# endif
19#endif
20
21// Setup for tests that use iostreams.
22#if defined(KWSYS_IOS_USE_ANSI) && defined(KWSYS_IOS_HAVE_STD)
23# if defined(_MSC_VER)
24#  pragma warning (push,1)
25# endif
26# if KWSYS_IOS_USE_ANSI
27#  include <iostream>
28# else
29#  include <iostream.h>
30# endif
31# if defined(_MSC_VER)
32#  pragma warning (pop)
33# endif
34# if KWSYS_IOS_HAVE_STD
35#  define kwsys_ios std
36# else
37#  define kwsys_ios
38# endif
39#endif
40
41#ifdef TEST_KWSYS_STL_HAVE_STD
42#include <list>
43void f(std ::list<int>*) {}
44int main() { return 0; }
45#endif
46
47#ifdef TEST_KWSYS_IOS_USE_ANSI
48#include <iosfwd>
49int main() { return 0; }
50#endif
51
52#ifdef TEST_KWSYS_IOS_HAVE_STD
53#include <iosfwd>
54void f(std ::ostream*) {}
55int main() { return 0; }
56#endif
57
58#ifdef TEST_KWSYS_IOS_USE_SSTREAM
59#include <sstream>
60#if defined(__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ == 96
61# error "GCC 2.96 stringstream is buggy"
62#endif
63int main()
64{
65  std ::ostringstream ostr;
66  ostr << "hello";
67  if(ostr.str().size() == 5)
68    {
69    return 0;
70    }
71  return -1;
72}
73#endif
74
75#ifdef TEST_KWSYS_IOS_USE_STRSTREAM_H
76#include <strstream.h>
77int main() { return 0; }
78#endif
79
80#ifdef TEST_KWSYS_IOS_USE_STRSTREA_H
81#include <strstrea.h>
82int main() { return 0; }
83#endif
84
85#ifdef TEST_KWSYS_STL_STRING_HAVE_OSTREAM
86# include <iostream.h>
87# include <string>
88void f(ostream& os, const kwsys_stl::string& s) { os << s; }
89int main() { return 0; }
90#endif
91
92#ifdef TEST_KWSYS_STL_STRING_HAVE_ISTREAM
93# include <iostream.h>
94# include <string>
95void f(istream& is, kwsys_stl::string& s) { is >> s; }
96int main() { return 0; }
97#endif
98
99#ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
100# include <string>
101bool f(const kwsys_stl::string& s) { return s != ""; }
102int main() { return 0; }
103#endif
104
105#ifdef TEST_KWSYS_CXX_HAS_CSTDIO
106#include <cstdio>
107int main() { return 0; }
108#endif
109
110#ifdef TEST_KWSYS_CXX_HAS_CSTDDEF
111#include <cstddef>
112void f(size_t) {}
113int main() { return 0; }
114#endif
115
116#ifdef TEST_KWSYS_CXX_HAS_LONG_LONG
117long long f(long long n) { return n; }
118int main()
119{
120  long long n = 0;
121  return static_cast<int>(f(n));
122}
123#endif
124
125#ifdef TEST_KWSYS_CXX_HAS___INT64
126__int64 f(__int64 n) { return n; }
127int main()
128{
129  __int64 n = 0;
130  return static_cast<int>(f(n));
131}
132#endif
133
134#ifdef TEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
135template <class T> class A;
136template <class T> int f(A<T>&);
137template <class T> class A
138{
139public:
140  // "friend int f<>(A<T>&)" would conform
141  friend int f(A<T>&);
142private:
143  int x;
144};
145
146template <class T> int f(A<T>& a) { return a.x = 0; }
147template int f(A<int>&);
148
149int main()
150{
151  A<int> a;
152  return f(a);
153}
154#endif
155
156#ifdef TEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES
157template <class U>
158class A
159{
160public:
161  U u;
162  A(): u(0) {}
163  template <class V> V m(V* p) { return *p = u; }
164};
165
166int main()
167{
168  A<short> a;
169  int s = 1;
170  return a.m(&s);
171}
172#endif
173
174#ifdef TEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION
175template <class T> struct A {};
176template <> struct A<int*>
177{
178  static int f() { return 0; }
179};
180int main() { return A<int*>::f(); }
181#endif
182
183#ifdef TEST_KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
184namespace N
185{
186  class A {};
187  int f(A*) { return 0; }
188}
189void f(void*);
190int main()
191{
192  N::A* a = 0;
193  return f(a);
194}
195#endif
196
197#ifdef TEST_KWSYS_STL_HAS_ITERATOR_TRAITS
198#include <iterator>
199#include <list>
200void f(kwsys_stl::iterator_traits<kwsys_stl::list<int>::iterator>::iterator_category const&) {}
201int main() { return 0; }
202#endif
203
204#ifdef TEST_KWSYS_STL_HAS_ITERATOR_CATEGORY
205#include <iterator>
206#include <list>
207void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::iterator_category(x); }
208int main() { return 0; }
209#endif
210
211#ifdef TEST_KWSYS_STL_HAS___ITERATOR_CATEGORY
212#include <iterator>
213#include <list>
214void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::__iterator_category(x); }
215int main() { return 0; }
216#endif
217
218#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
219#include <memory>
220template <class Alloc>
221void f(const Alloc&)
222{
223  typedef typename Alloc::size_type alloc_size_type;
224}
225int main()
226{
227  f(kwsys_stl::allocator<char>());
228  return 0;
229}
230#endif
231
232#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
233#include <memory>
234void f(kwsys_stl::allocator::size_type const&) {}
235int main() { return 0; }
236#endif
237
238#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
239#include <memory>
240template <class T, class Alloc>
241void f(const T&, const Alloc&)
242{
243  typedef typename Alloc::template rebind<T>::other alloc_type;
244}
245int main()
246{
247  f(0, kwsys_stl::allocator<char>());
248  return 0;
249}
250#endif
251
252#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
253#include <memory>
254void f(kwsys_stl::allocator<char> const& a)
255{
256  a.max_size(sizeof(int));
257}
258int main()
259{
260  f(kwsys_stl::allocator<char>());
261  return 0;
262}
263#endif
264
265#ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_OBJECTS
266#include <vector>
267void f(kwsys_stl::vector<int> const& v1)
268{
269  kwsys_stl::vector<int>(1, 1, v1.get_allocator());
270}
271int main()
272{
273  f(kwsys_stl::vector<int>());
274  return 0;
275}
276#endif
277
278#ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
279#include <sys/types.h>
280#include <sys/stat.h>
281#include <unistd.h>
282int main()
283{
284  struct stat stat1;
285  (void)stat1.st_mtim.tv_sec;
286  (void)stat1.st_mtim.tv_nsec;
287  return 0;
288}
289#endif
290
291#ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
292void function(long**) {}
293int main()
294{
295  __int64** p = 0;
296  function(p);
297  return 0;
298}
299#endif
300
301#ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
302void function(long long**) {}
303int main()
304{
305  __int64** p = 0;
306  function(p);
307  return 0;
308}
309#endif
310
311#ifdef TEST_KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
312void function(double& l, unsigned __int64 const& r)
313{
314  l = static_cast<double>(r);
315}
316
317int main()
318{
319  double tTo = 0.0;
320  unsigned __int64 tFrom = 0;
321  function(tTo, tFrom);
322  return 0;
323}
324#endif
325
326#ifdef TEST_KWSYS_IOS_HAVE_BINARY
327int test_binary(int, ...)
328{
329  return 0;
330}
331int main()
332{
333  return test_binary(1, kwsys_ios::ios::binary);
334}
335#endif
336
337#ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
338int test_istream(kwsys_ios::istream& is, long long& x)
339{
340  return (is >> x)? 1:0;
341}
342int main()
343{
344  long long x = 0;
345  return test_istream(kwsys_ios::cin, x);
346}
347#endif
348
349#ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
350int test_ostream(kwsys_ios::ostream& os, long long x)
351{
352  return (os << x)? 1:0;
353}
354int main()
355{
356  long long x = 0;
357  return test_ostream(kwsys_ios::cout, x);
358}
359#endif
360
361#ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64
362int test_istream(kwsys_ios::istream& is, __int64& x)
363{
364  return (is >> x)? 1:0;
365}
366int main()
367{
368  __int64 x = 0;
369  return test_istream(kwsys_ios::cin, x);
370}
371#endif
372
373#ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64
374int test_ostream(kwsys_ios::ostream& os, __int64 x)
375{
376  return (os << x)? 1:0;
377}
378int main()
379{
380  __int64 x = 0;
381  return test_ostream(kwsys_ios::cout, x);
382}
383#endif
384
385#ifdef TEST_KWSYS_CHAR_IS_SIGNED
386/* Return 0 for char signed and 1 for char unsigned.  */
387int main()
388{
389  unsigned char uc = 255;
390  return (*reinterpret_cast<char*>(&uc) < 0)?0:1;
391}
392#endif
393
394#ifdef TEST_KWSYS_LFS_WORKS
395/* Return 0 when LFS is available and 1 otherwise.  */
396#define _LARGEFILE_SOURCE
397#define _LARGEFILE64_SOURCE
398#define _LARGE_FILES
399#define _FILE_OFFSET_BITS 64
400#include <sys/types.h>
401#include <sys/stat.h>
402#include <assert.h>
403#if KWSYS_CXX_HAS_CSTDIO
404# include <cstdio>
405#endif
406#include <stdio.h>
407
408int main(int, char **argv)
409{
410  /* check that off_t can hold 2^63 - 1 and perform basic operations... */
411#define OFF_T_64 (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
412  if (OFF_T_64 % 2147483647 != 1)
413    return 1;
414
415  // stat breaks on SCO OpenServer
416  struct stat buf;
417  stat( argv[0], &buf );
418  if (!S_ISREG(buf.st_mode))
419    return 2;
420
421  FILE *file = fopen( argv[0], "r" );
422  off_t offset = ftello( file );
423  fseek( file, offset, SEEK_CUR );
424  fclose( file );
425  return 0;
426}
427#endif
428
429#ifdef TEST_KWSYS_CXX_HAS_SETENV
430#include <stdlib.h>
431int main()
432{
433  return setenv("A", "B", 1);
434}
435#endif
436
437#ifdef TEST_KWSYS_CXX_HAS_UNSETENV
438#include <stdlib.h>
439int main()
440{
441  unsetenv("A");
442  return 0;
443}
444#endif
445
446#ifdef TEST_KWSYS_CXX_HAS_ENVIRON_IN_STDLIB_H
447#include <stdlib.h>
448int main()
449{
450  char* e = environ[0];
451  return e? 0:1;
452}
453#endif
454
455#ifdef TEST_KWSYS_CXX_HAS_GETLOADAVG
456// Match feature definitions from SystemInformation.cxx
457#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
458# define _GNU_SOURCE
459#endif
460#include <stdlib.h>
461int main()
462{
463  double loadavg[3] = { 0.0, 0.0, 0.0 };
464  return getloadavg(loadavg, 3);
465}
466#endif
467
468#ifdef TEST_KWSYS_CXX_HAS_RLIMIT64
469# if defined(KWSYS_HAS_LFS)
470#  define _LARGEFILE_SOURCE
471#  define _LARGEFILE64_SOURCE
472#  define _LARGE_FILES
473#  define _FILE_OFFSET_BITS 64
474# endif
475# include <sys/resource.h>
476int main()
477{
478  struct rlimit64 rlim;
479  return getrlimit64(0,&rlim);
480}
481#endif
482
483#ifdef TEST_KWSYS_CXX_HAS_ATOLL
484#include <stdlib.h>
485int main()
486{
487  const char *str="1024";
488  return static_cast<int>(atoll(str));
489}
490#endif
491
492#ifdef TEST_KWSYS_CXX_HAS_ATOL
493#include <stdlib.h>
494int main()
495{
496  const char *str="1024";
497  return static_cast<int>(atol(str));
498}
499#endif
500
501#ifdef TEST_KWSYS_CXX_HAS__ATOI64
502#include <stdlib.h>
503int main()
504{
505  const char *str="1024";
506  return static_cast<int>(_atoi64(str));
507}
508#endif
509
510#ifdef TEST_KWSYS_CXX_HAS_UTIMES
511#include <sys/time.h>
512int main()
513{
514  struct timeval* current_time = 0;
515  return utimes("/example", current_time);
516}
517#endif
518
519#ifdef TEST_KWSYS_CXX_HAS_UTIMENSAT
520#include <fcntl.h>
521#include <sys/stat.h>
522int main()
523{
524  struct timespec times[2] = {{0,UTIME_OMIT},{0,UTIME_NOW}};
525  return utimensat(AT_FDCWD, "/example", times, AT_SYMLINK_NOFOLLOW);
526}
527#endif
528
529#ifdef TEST_KWSYS_CXX_HAS_BACKTRACE
530#if defined(__PATHSCALE__) || defined(__PATHCC__) \
531  || (defined(__LSB_VERSION__) && (__LSB_VERSION__ < 41))
532backtrace doesnt work with this compiler or os
533#endif
534#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
535# define _GNU_SOURCE
536#endif
537#include <execinfo.h>
538int main()
539{
540  void *stackSymbols[256];
541  backtrace(stackSymbols,256);
542  backtrace_symbols(&stackSymbols[0],1);
543  return 0;
544}
545#endif
546
547#ifdef TEST_KWSYS_CXX_HAS_DLADDR
548#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
549# define _GNU_SOURCE
550#endif
551#include <dlfcn.h>
552int main()
553{
554  Dl_info info;
555  int ierr=dladdr((void*)main,&info);
556  return 0;
557}
558#endif
559
560#ifdef TEST_KWSYS_CXX_HAS_CXXABI
561#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE)
562# define _GNU_SOURCE
563#endif
564#if defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5130 \
565     && __linux && __SUNPRO_CC_COMPAT == 'G'
566#  include <iostream>
567#endif
568#include <cxxabi.h>
569int main()
570{
571  int status = 0;
572  size_t bufferLen = 512;
573  char buffer[512] = {'\0'};
574  const char *function="_ZN5kwsys17SystemInformation15GetProgramStackEii";
575  char *demangledFunction =
576    abi::__cxa_demangle(function, buffer, &bufferLen, &status);
577  return status;
578}
579#endif
580
581#ifdef TEST_KWSYS_CXX_TYPE_INFO
582/* Collect fundamental type information and save it to a CMake script.  */
583
584/* Include limits.h to get macros indicating long long and __int64.
585   Note that certain compilers need special macros to define these
586   macros in limits.h.  */
587#if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
588# define _MSC_EXTENSIONS
589#endif
590#if defined(__GNUC__) && __GNUC__ < 3
591# define _GNU_SOURCE
592#endif
593#include <limits.h>
594
595#include <stdio.h>
596#include <string.h>
597
598/* Due to shell differences and limitations of ADD_DEFINITIONS the
599   KWSYS_CXX_TYPE_INFO_FILE macro will sometimes have double quotes
600   and sometimes not.  This macro will make sure the value is treated
601   as a double-quoted string.  */
602#define TO_STRING(x) TO_STRING0(x)
603#define TO_STRING0(x) TO_STRING1(x)
604#define TO_STRING1(x) #x
605
606void f() {}
607
608int main()
609{
610  /* Construct the output file name.  Some preprocessors will add an
611     extra level of double quotes, so strip them.  */
612  char fbuf[] = TO_STRING(KWSYS_CXX_TYPE_INFO_FILE);
613  char* fname = fbuf;
614  if(fname[0] == '"')
615    {
616    ++fname;
617    int len = static_cast<int>(strlen(fname));
618    if(len > 0 && fname[len-1] == '"')
619      {
620      fname[len-1] = 0;
621      }
622    }
623
624  /* Try to open the output file.  */
625  if(FILE* fout = fopen(fname, "w"))
626    {
627    /* Set the size of standard types.  */
628    fprintf(fout, "SET(KWSYS_SIZEOF_CHAR %d)\n", static_cast<int>(sizeof(char)));
629    fprintf(fout, "SET(KWSYS_SIZEOF_SHORT %d)\n", static_cast<int>(sizeof(short)));
630    fprintf(fout, "SET(KWSYS_SIZEOF_INT %d)\n", static_cast<int>(sizeof(int)));
631    fprintf(fout, "SET(KWSYS_SIZEOF_LONG %d)\n", static_cast<int>(sizeof(long)));
632
633    /* Set the size of some non-standard but common types.  */
634    /* Check for a limits.h macro for long long to see if the type exists.  */
635#if defined(LLONG_MAX) || defined(LONG_LONG_MAX) || defined(LONGLONG_MAX)
636    fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG %d)\n", static_cast<int>(sizeof(long long)));
637#else
638    fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG 0) # No long long available.\n");
639#endif
640    /* Check for a limits.h macro for __int64 to see if the type exists.  */
641#if defined(_I64_MIN)
642    fprintf(fout, "SET(KWSYS_SIZEOF___INT64 %d)\n", static_cast<int>(sizeof(__int64)));
643#else
644    fprintf(fout, "SET(KWSYS_SIZEOF___INT64 0) # No __int64 available.\n");
645#endif
646
647    /* Set the size of some pointer types.  */
648    fprintf(fout, "SET(KWSYS_SIZEOF_PDATA %d)\n", static_cast<int>(sizeof(void*)));
649    fprintf(fout, "SET(KWSYS_SIZEOF_PFUNC %d)\n", static_cast<int>(sizeof(&f)));
650
651    /* Set whether the native type "char" is signed or unsigned.  */
652    unsigned char uc = 255;
653    fprintf(fout, "SET(KWSYS_CHAR_IS_SIGNED %d)\n",
654            (*reinterpret_cast<char*>(&uc) < 0)?1:0);
655
656    fclose(fout);
657    return 0;
658    }
659  else
660    {
661    fprintf(stderr, "Failed to write fundamental type info to \"%s\".\n",
662            fname);
663    return 1;
664    }
665}
666#endif
667
668#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM
669int main()
670{
671  int a = 1;
672  __asm {
673    xor EBX, EBX;
674    mov a, EBX;
675  }
676
677  return a;
678}
679#endif
680
681#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID
682int main()
683{
684  int a = 0;
685  __asm {
686    xor EAX, EAX;
687    cpuid;
688    mov a, EAX;
689  }
690
691  return a;
692}
693#endif
694
695#ifdef TEST_KWSYS_STL_HAS_WSTRING
696#include <string>
697void f(std ::wstring*) {}
698int main() { return 0; }
699#endif
Note: See TracBrowser for help on using the repository browser.