complex.cxx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. #include "cmTestConfigure.h"
  2. #include "ExtraSources/file1.h"
  3. #include "file2.h"
  4. #include "sharedFile.h"
  5. #include "cmStandardIncludes.h"
  6. #include "cmSystemTools.h"
  7. int passed = 0;
  8. int failed = 0;
  9. // ======================================================================
  10. void Failed(const char* Message, const char* m2= "")
  11. {
  12. std::cerr << "Failed: " << Message << m2 << "\n";
  13. failed++;
  14. }
  15. // ======================================================================
  16. void Passed(const char* Message, const char* m2="")
  17. {
  18. std::cout << "Passed: " << Message << m2 << "\n";
  19. passed++;
  20. }
  21. // ======================================================================
  22. void TestAndRemoveFile(const char* filename)
  23. {
  24. if (!cmSystemTools::FileExists(filename))
  25. {
  26. Failed("Could not find file: ", filename);
  27. }
  28. else
  29. {
  30. if (!cmSystemTools::RemoveFile(filename))
  31. {
  32. Failed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename);
  33. }
  34. else
  35. {
  36. Passed("Find and remove file: ", filename);
  37. }
  38. }
  39. }
  40. // ======================================================================
  41. void TestDir(const char* filename)
  42. {
  43. if (!cmSystemTools::FileExists(filename))
  44. {
  45. Failed("Could not find dir: ", filename);
  46. }
  47. else
  48. {
  49. if (!cmSystemTools::FileIsDirectory(filename))
  50. {
  51. Failed("Unable to check if file is a directory: ", filename);
  52. }
  53. else
  54. {
  55. Passed("Find dir: ", filename);
  56. }
  57. }
  58. }
  59. // ======================================================================
  60. int main()
  61. {
  62. if(sharedFunction() != 1)
  63. {
  64. Failed("Call to sharedFunction from shared library failed.");
  65. }
  66. else
  67. {
  68. Passed("Call to sharedFunction from shared library worked.");
  69. }
  70. if(file1() != 1)
  71. {
  72. Failed("Call to file1 function from library failed.");
  73. }
  74. else
  75. {
  76. Passed("Call to file1 function returned 1.");
  77. }
  78. if(file2() != 1)
  79. {
  80. Failed("Call to file2 function from library failed.");
  81. }
  82. else
  83. {
  84. Passed("Call to file2 function returned 1.");
  85. }
  86. // ----------------------------------------------------------------------
  87. // Test ADD_DEFINITIONS
  88. #ifndef CMAKE_IS_FUN
  89. Failed("CMake is not fun, so it is broken and should be fixed.");
  90. #else
  91. Passed("CMAKE_IS_FUN is defined.");
  92. #endif
  93. // ----------------------------------------------------------------------
  94. // Test SET, VARIABLE_REQUIRES
  95. #ifdef SHOULD_NOT_BE_DEFINED
  96. Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
  97. #else
  98. Passed("SHOULD_NOT_BE_DEFINED is not defined.");
  99. #endif
  100. #ifndef SHOULD_BE_DEFINED
  101. Failed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
  102. #else
  103. Passed("SHOULD_BE_DEFINED is defined.");
  104. #endif
  105. #ifndef ONE_VAR
  106. Failed("cmakedefine is broken, ONE_VAR is not defined.");
  107. #else
  108. Passed("ONE_VAR is defined.");
  109. #endif
  110. #ifndef ONE_VAR_IS_DEFINED
  111. Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
  112. "ONE_VAR_IS_DEFINED is not defined.");
  113. #else
  114. Passed("ONE_VAR_IS_DEFINED is defined.");
  115. #endif
  116. #ifdef ZERO_VAR
  117. Failed("cmakedefine is broken, ZERO_VAR is defined.");
  118. #else
  119. Passed("ZERO_VAR is not defined.");
  120. #endif
  121. #ifndef STRING_VAR
  122. Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
  123. #else
  124. if(strcmp(STRING_VAR, "CMake is great") != 0)
  125. {
  126. Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
  127. STRING_VAR);
  128. }
  129. else
  130. {
  131. Passed("STRING_VAR == ", STRING_VAR);
  132. }
  133. #endif
  134. // ----------------------------------------------------------------------
  135. // Test various IF/ELSE combinations
  136. #ifdef SHOULD_NOT_BE_DEFINED_AND
  137. Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined.");
  138. #else
  139. Passed("SHOULD_NOT_BE_DEFINED_AND is not defined.");
  140. #endif
  141. #ifndef SHOULD_BE_DEFINED_AND
  142. Failed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n");
  143. #else
  144. Passed("SHOULD_BE_DEFINED_AND is defined.");
  145. #endif
  146. #ifdef SHOULD_NOT_BE_DEFINED_OR
  147. Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined.");
  148. #else
  149. Passed("SHOULD_NOT_BE_DEFINED_OR is not defined.");
  150. #endif
  151. #ifndef SHOULD_BE_DEFINED_OR
  152. Failed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n");
  153. #else
  154. Passed("SHOULD_BE_DEFINED_OR is defined.");
  155. #endif
  156. #ifdef SHOULD_NOT_BE_DEFINED_MATCHES
  157. Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined.");
  158. #else
  159. Passed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined.");
  160. #endif
  161. #ifndef SHOULD_BE_DEFINED_MATCHES
  162. Failed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n");
  163. #else
  164. Passed("SHOULD_BE_DEFINED_MATCHES is defined.");
  165. #endif
  166. // ----------------------------------------------------------------------
  167. // Test FOREACH
  168. #ifndef FOREACH_VAR1
  169. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  170. "FOREACH_VAR1 is not defined.");
  171. #else
  172. if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
  173. {
  174. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  175. "FOREACH_VAR1 == ", FOREACH_VAR1);
  176. }
  177. else
  178. {
  179. Passed("FOREACH_VAR1 == ", FOREACH_VAR1);
  180. }
  181. #endif
  182. #ifndef FOREACH_VAR2
  183. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  184. "FOREACH_VAR2 is not defined.");
  185. #else
  186. if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
  187. {
  188. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  189. "FOREACH_VAR2 == ", FOREACH_VAR2);
  190. }
  191. else
  192. {
  193. Passed("FOREACH_VAR2 == ", FOREACH_VAR2);
  194. }
  195. #endif
  196. // ----------------------------------------------------------------------
  197. // Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations
  198. #ifndef FILENAME_VAR_PATH_NAME
  199. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  200. "FILENAME_VAR_PATH_NAME is not defined.");
  201. #else
  202. if(strcmp(FILENAME_VAR_PATH_NAME, "Complex") != 0)
  203. {
  204. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  205. "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
  206. }
  207. else
  208. {
  209. Passed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
  210. }
  211. #endif
  212. #ifndef FILENAME_VAR_NAME
  213. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  214. "FILENAME_VAR_NAME is not defined.");
  215. #else
  216. if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0)
  217. {
  218. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  219. "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
  220. }
  221. else
  222. {
  223. Passed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
  224. }
  225. #endif
  226. #ifndef FILENAME_VAR_EXT
  227. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  228. "FILENAME_VAR_EXT is not defined.");
  229. #else
  230. if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0)
  231. {
  232. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  233. "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
  234. }
  235. else
  236. {
  237. Passed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
  238. }
  239. #endif
  240. #ifndef FILENAME_VAR_NAME_WE
  241. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  242. "FILENAME_VAR_NAME_WE is not defined.");
  243. #else
  244. if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
  245. {
  246. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  247. "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
  248. }
  249. else
  250. {
  251. Passed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
  252. }
  253. #endif
  254. #ifndef PATH_VAR_NAME
  255. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  256. "PATH_VAR_NAME is not defined.");
  257. #else
  258. if(strcmp(PATH_VAR_NAME, "Complex") != 0)
  259. {
  260. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  261. "PATH_VAR_NAME == ", PATH_VAR_NAME);
  262. }
  263. else
  264. {
  265. Passed("PATH_VAR_NAME == ", PATH_VAR_NAME);
  266. }
  267. #endif
  268. // ----------------------------------------------------------------------
  269. // Test LOAD_CACHE
  270. #ifndef CACHE_TEST_VAR1
  271. Failed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  272. "CACHE_TEST_VAR1 is not defined.");
  273. #else
  274. if(strcmp(CACHE_TEST_VAR1, "foo") != 0)
  275. {
  276. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  277. "CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
  278. }
  279. else
  280. {
  281. Passed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1);
  282. }
  283. #endif
  284. #ifndef CACHE_TEST_VAR2
  285. Failed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  286. "CACHE_TEST_VAR2 is not defined.");
  287. #else
  288. if(strcmp(CACHE_TEST_VAR2, "bar") != 0)
  289. {
  290. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  291. "CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
  292. }
  293. else
  294. {
  295. Passed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2);
  296. }
  297. #endif
  298. #ifndef CACHE_TEST_VAR3
  299. Failed("the LOAD_CACHE or CONFIGURE_FILE command is broken, "
  300. "CACHE_TEST_VAR3 is not defined.");
  301. #else
  302. if(strcmp(CACHE_TEST_VAR3, "1") != 0)
  303. {
  304. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  305. "CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
  306. }
  307. else
  308. {
  309. Passed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3);
  310. }
  311. #endif
  312. // ----------------------------------------------------------------------
  313. // A post-build custom-command has been attached to the lib (see Library/).
  314. // It runs ${CREATE_FILE_EXE} which will create a file.
  315. TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt");
  316. // ----------------------------------------------------------------------
  317. // A custom target has been created (see Library/).
  318. // It runs ${CREATE_FILE_EXE} which will create a file.
  319. TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt");
  320. // ----------------------------------------------------------------------
  321. // A directory has been created.
  322. TestDir(BINARY_DIR "/make_dir");
  323. // ----------------------------------------------------------------------
  324. // Summary
  325. std::cout << "Passed: " << passed << "\n";
  326. if(failed)
  327. {
  328. std::cout << "Failed: " << failed << "\n";
  329. return failed;
  330. }
  331. return 0;
  332. }