kwsysPlatformTestsCXX.cxx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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
  9. // Setup for tests that use iostreams.
  10. #if defined(KWSYS_IOS_USE_ANSI) && defined(KWSYS_IOS_HAVE_STD)
  11. # if defined(_MSC_VER)
  12. # pragma warning (push,1)
  13. # endif
  14. # if KWSYS_IOS_USE_ANSI
  15. # include <iostream>
  16. # else
  17. # include <iostream.h>
  18. # endif
  19. # if defined(_MSC_VER)
  20. # pragma warning (pop)
  21. # endif
  22. # if KWSYS_IOS_HAVE_STD
  23. # define kwsys_ios std
  24. # else
  25. # define kwsys_ios
  26. # endif
  27. #endif
  28. #ifdef TEST_KWSYS_STL_HAVE_STD
  29. #include <list>
  30. void f(std ::list<int>*) {}
  31. int main() { return 0; }
  32. #endif
  33. #ifdef TEST_KWSYS_IOS_USE_ANSI
  34. #include <iosfwd>
  35. int main() { return 0; }
  36. #endif
  37. #ifdef TEST_KWSYS_IOS_HAVE_STD
  38. #include <iosfwd>
  39. void f(std ::ostream*) {}
  40. int main() { return 0; }
  41. #endif
  42. #ifdef TEST_KWSYS_IOS_USE_SSTREAM
  43. #include <sstream>
  44. #if defined(__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ == 96
  45. # error "GCC 2.96 stringstream is buggy"
  46. #endif
  47. int main()
  48. {
  49. std ::ostringstream ostr;
  50. ostr << "hello";
  51. if(ostr.str().size() == 5)
  52. {
  53. return 0;
  54. }
  55. return -1;
  56. }
  57. #endif
  58. #ifdef TEST_KWSYS_IOS_USE_STRSTREAM_H
  59. #include <strstream.h>
  60. int main() { return 0; }
  61. #endif
  62. #ifdef TEST_KWSYS_IOS_USE_STRSTREA_H
  63. #include <strstrea.h>
  64. int main() { return 0; }
  65. #endif
  66. #ifdef TEST_KWSYS_STL_STRING_HAVE_OSTREAM
  67. # include <iostream.h>
  68. # include <string>
  69. void f(ostream& os, const kwsys_stl::string& s) { os << s; }
  70. int main() { return 0; }
  71. #endif
  72. #ifdef TEST_KWSYS_STL_STRING_HAVE_ISTREAM
  73. # include <iostream.h>
  74. # include <string>
  75. void f(istream& is, kwsys_stl::string& s) { is >> s; }
  76. int main() { return 0; }
  77. #endif
  78. #ifdef TEST_KWSYS_STL_STRING_HAVE_NEQ_CHAR
  79. # include <string>
  80. bool f(const kwsys_stl::string& s) { return s != ""; }
  81. int main() { return 0; }
  82. #endif
  83. #ifdef TEST_KWSYS_CXX_HAS_CSTDIO
  84. #include <cstdio>
  85. int main() { return 0; }
  86. #endif
  87. #ifdef TEST_KWSYS_CXX_HAS_CSTDDEF
  88. #include <cstddef>
  89. void f(size_t) {}
  90. int main() { return 0; }
  91. #endif
  92. #ifdef TEST_KWSYS_CXX_HAS_NULL_TEMPLATE_ARGS
  93. template <class T> class A;
  94. template <class T> int f(A<T>&);
  95. template <class T> class A
  96. {
  97. public:
  98. // "friend int f<>(A<T>&)" would conform
  99. friend int f(A<T>&);
  100. private:
  101. int x;
  102. };
  103. template <class T> int f(A<T>& a) { return a.x = 0; }
  104. template int f(A<int>&);
  105. int main()
  106. {
  107. A<int> a;
  108. return f(a);
  109. }
  110. #endif
  111. #ifdef TEST_KWSYS_CXX_HAS_MEMBER_TEMPLATES
  112. template <class U>
  113. class A
  114. {
  115. public:
  116. U u;
  117. A(): u(0) {}
  118. template <class V> V m(V* p) { return *p = u; }
  119. };
  120. int main()
  121. {
  122. A<short> a;
  123. int s = 1;
  124. return a.m(&s);
  125. }
  126. #endif
  127. #ifdef TEST_KWSYS_CXX_HAS_FULL_SPECIALIZATION
  128. template <class T> struct A {};
  129. template <> struct A<int*>
  130. {
  131. static int f() { return 0; }
  132. };
  133. int main() { return A<int*>::f(); }
  134. #endif
  135. #ifdef TEST_KWSYS_CXX_HAS_ARGUMENT_DEPENDENT_LOOKUP
  136. namespace N
  137. {
  138. class A {};
  139. int f(A*) { return 0; }
  140. }
  141. void f(void*);
  142. int main()
  143. {
  144. N::A* a = 0;
  145. return f(a);
  146. }
  147. #endif
  148. #ifdef TEST_KWSYS_STL_HAS_ITERATOR_TRAITS
  149. #include <iterator>
  150. #include <list>
  151. void f(kwsys_stl::iterator_traits<kwsys_stl::list<int>::iterator>::iterator_category const&) {}
  152. int main() { return 0; }
  153. #endif
  154. #ifdef TEST_KWSYS_STL_HAS_ITERATOR_CATEGORY
  155. #include <iterator>
  156. #include <list>
  157. void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::iterator_category(x); }
  158. int main() { return 0; }
  159. #endif
  160. #ifdef TEST_KWSYS_STL_HAS___ITERATOR_CATEGORY
  161. #include <iterator>
  162. #include <list>
  163. void f(kwsys_stl::list<int>::iterator x) { kwsys_stl::__iterator_category(x); }
  164. int main() { return 0; }
  165. #endif
  166. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_TEMPLATE
  167. #include <memory>
  168. template <class Alloc>
  169. void f(const Alloc&)
  170. {
  171. typedef typename Alloc::size_type alloc_size_type;
  172. }
  173. int main()
  174. {
  175. f(kwsys_stl::allocator<char>());
  176. return 0;
  177. }
  178. #endif
  179. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_NONTEMPLATE
  180. #include <memory>
  181. void f(kwsys_stl::allocator::size_type const&) {}
  182. int main() { return 0; }
  183. #endif
  184. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_REBIND
  185. #include <memory>
  186. template <class T, class Alloc>
  187. void f(const T&, const Alloc&)
  188. {
  189. typedef typename Alloc::template rebind<T>::other alloc_type;
  190. }
  191. int main()
  192. {
  193. f(0, kwsys_stl::allocator<char>());
  194. return 0;
  195. }
  196. #endif
  197. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_MAX_SIZE_ARGUMENT
  198. #include <memory>
  199. void f(kwsys_stl::allocator<char> const& a)
  200. {
  201. a.max_size(sizeof(int));
  202. }
  203. int main()
  204. {
  205. f(kwsys_stl::allocator<char>());
  206. return 0;
  207. }
  208. #endif
  209. #ifdef TEST_KWSYS_STL_HAS_ALLOCATOR_OBJECTS
  210. #include <vector>
  211. void f(kwsys_stl::vector<int> const& v1)
  212. {
  213. kwsys_stl::vector<int>(1, 1, v1.get_allocator());
  214. }
  215. int main()
  216. {
  217. f(kwsys_stl::vector<int>());
  218. return 0;
  219. }
  220. #endif
  221. #ifdef TEST_KWSYS_STAT_HAS_ST_MTIM
  222. #include <sys/types.h>
  223. #include <sys/stat.h>
  224. #include <unistd.h>
  225. int main()
  226. {
  227. struct stat stat1;
  228. (void)stat1.st_mtim.tv_sec;
  229. (void)stat1.st_mtim.tv_nsec;
  230. return 0;
  231. }
  232. #endif
  233. #ifdef TEST_KWSYS_CXX_SAME_LONG_AND___INT64
  234. void function(long**) {}
  235. int main()
  236. {
  237. __int64** p = 0;
  238. function(p);
  239. return 0;
  240. }
  241. #endif
  242. #ifdef TEST_KWSYS_CXX_SAME_LONG_LONG_AND___INT64
  243. void function(long long**) {}
  244. int main()
  245. {
  246. __int64** p = 0;
  247. function(p);
  248. return 0;
  249. }
  250. #endif
  251. #ifdef TEST_KWSYS_CAN_CONVERT_UI64_TO_DOUBLE
  252. void function(double& l, unsigned __int64 const& r)
  253. {
  254. l = static_cast<double>(r);
  255. }
  256. int main()
  257. {
  258. double tTo = 0.0;
  259. unsigned __int64 tFrom = 0;
  260. function(tTo, tFrom);
  261. return 0;
  262. }
  263. #endif
  264. #ifdef TEST_KWSYS_IOS_HAVE_BINARY
  265. int test_binary(int, ...)
  266. {
  267. return 0;
  268. }
  269. int main()
  270. {
  271. return test_binary(1, kwsys_ios::ios::binary);
  272. }
  273. #endif
  274. #ifdef TEST_KWSYS_IOS_HAS_ISTREAM_LONG_LONG
  275. int test_istream(kwsys_ios::istream& is, long long& x)
  276. {
  277. return (is >> x)? 1:0;
  278. }
  279. int main()
  280. {
  281. long long x = 0;
  282. return test_istream(kwsys_ios::cin, x);
  283. }
  284. #endif
  285. #ifdef TEST_KWSYS_IOS_HAS_OSTREAM_LONG_LONG
  286. int test_ostream(kwsys_ios::ostream& os, long long x)
  287. {
  288. return (os << x)? 1:0;
  289. }
  290. int main()
  291. {
  292. long long x = 0;
  293. return test_ostream(kwsys_ios::cout, x);
  294. }
  295. #endif
  296. #ifdef TEST_KWSYS_CHAR_IS_SIGNED
  297. /* Return 0 for char signed and 1 for char unsigned. */
  298. int main()
  299. {
  300. unsigned char uc = 255;
  301. return (*reinterpret_cast<char*>(&uc) < 0)?0:1;
  302. }
  303. #endif
  304. #ifdef TEST_KWSYS_LFS_WORKS
  305. /* Return 0 when LFS is available and 1 otherwise. */
  306. #define _LARGEFILE_SOURCE
  307. #define _LARGEFILE64_SOURCE
  308. #define _LARGE_FILES
  309. #define _FILE_OFFSET_BITS 64
  310. #include <sys/types.h>
  311. #include <sys/stat.h>
  312. #include <assert.h>
  313. #if KWSYS_CXX_HAS_CSTDIO
  314. # include <cstdio>
  315. #endif
  316. #include <stdio.h>
  317. int main(int, char **argv)
  318. {
  319. /* check that off_t can hold 2^63 - 1 and perform basic operations... */
  320. #define OFF_T_64 (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
  321. if (OFF_T_64 % 2147483647 != 1)
  322. return 1;
  323. // stat breaks on SCO OpenServer
  324. struct stat buf;
  325. stat( argv[0], &buf );
  326. if (!S_ISREG(buf.st_mode))
  327. return 2;
  328. FILE *file = fopen( argv[0], "r" );
  329. off_t offset = ftello( file );
  330. fseek( file, offset, SEEK_CUR );
  331. fclose( file );
  332. return 0;
  333. }
  334. #endif
  335. #ifdef TEST_KWSYS_CXX_TYPE_INFO
  336. /* Collect fundamental type information and save it to a CMake script. */
  337. /* Include limits.h to get macros indicating long long and __int64.
  338. Note that certain compilers need special macros to define these
  339. macros in limits.h. */
  340. #if defined(_MSC_VER) && !defined(_MSC_EXTENSIONS)
  341. # define _MSC_EXTENSIONS
  342. #endif
  343. #if defined(__GNUC__) && __GNUC__ < 3
  344. # define _GNU_SOURCE
  345. #endif
  346. #include <limits.h>
  347. #include <stdio.h>
  348. #include <string.h>
  349. /* Due to shell differences and limitations of ADD_DEFINITIONS the
  350. KWSYS_CXX_TYPE_INFO_FILE macro will sometimes have double quotes
  351. and sometimes not. This macro will make sure the value is treated
  352. as a double-quoted string. */
  353. #define TO_STRING(x) TO_STRING0(x)
  354. #define TO_STRING0(x) TO_STRING1(x)
  355. #define TO_STRING1(x) #x
  356. void f() {}
  357. int main()
  358. {
  359. /* Construct the output file name. Some preprocessors will add an
  360. extra level of double quotes, so strip them. */
  361. char fbuf[] = TO_STRING(KWSYS_CXX_TYPE_INFO_FILE);
  362. char* fname = fbuf;
  363. if(fname[0] == '"')
  364. {
  365. ++fname;
  366. int len = static_cast<int>(strlen(fname));
  367. if(len > 0 && fname[len-1] == '"')
  368. {
  369. fname[len-1] = 0;
  370. }
  371. }
  372. /* Try to open the output file. */
  373. if(FILE* fout = fopen(fname, "w"))
  374. {
  375. /* Set the size of standard types. */
  376. fprintf(fout, "SET(KWSYS_SIZEOF_CHAR %d)\n", static_cast<int>(sizeof(char)));
  377. fprintf(fout, "SET(KWSYS_SIZEOF_SHORT %d)\n", static_cast<int>(sizeof(short)));
  378. fprintf(fout, "SET(KWSYS_SIZEOF_INT %d)\n", static_cast<int>(sizeof(int)));
  379. fprintf(fout, "SET(KWSYS_SIZEOF_LONG %d)\n", static_cast<int>(sizeof(long)));
  380. /* Set the size of some non-standard but common types. */
  381. /* Check for a limits.h macro for long long to see if the type exists. */
  382. #if defined(LLONG_MAX) || defined(LONG_LONG_MAX) || defined(LONGLONG_MAX)
  383. fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG %d)\n", static_cast<int>(sizeof(long long)));
  384. #else
  385. fprintf(fout, "SET(KWSYS_SIZEOF_LONG_LONG 0) # No long long available.\n");
  386. #endif
  387. /* Check for a limits.h macro for __int64 to see if the type exists. */
  388. #if defined(_I64_MIN)
  389. fprintf(fout, "SET(KWSYS_SIZEOF___INT64 %d)\n", static_cast<int>(sizeof(__int64)));
  390. #else
  391. fprintf(fout, "SET(KWSYS_SIZEOF___INT64 0) # No __int64 available.\n");
  392. #endif
  393. /* Set the size of some pointer types. */
  394. fprintf(fout, "SET(KWSYS_SIZEOF_PDATA %d)\n", static_cast<int>(sizeof(void*)));
  395. fprintf(fout, "SET(KWSYS_SIZEOF_PFUNC %d)\n", static_cast<int>(sizeof(&f)));
  396. /* Set whether the native type "char" is signed or unsigned. */
  397. unsigned char uc = 255;
  398. fprintf(fout, "SET(KWSYS_CHAR_IS_SIGNED %d)\n",
  399. (*reinterpret_cast<char*>(&uc) < 0)?1:0);
  400. fclose(fout);
  401. return 0;
  402. }
  403. else
  404. {
  405. fprintf(stderr, "Failed to write fundamental type info to \"%s\".\n",
  406. fname);
  407. return 1;
  408. }
  409. }
  410. #endif