complex.cxx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "cmTestConfigure.h"
  2. #include "ExtraSources/file1.h"
  3. #include "file2.h"
  4. #include "sharedFile.h"
  5. #include "cmStandardIncludes.h"
  6. #include <sys/stat.h>
  7. #include <stdio.h>
  8. #if defined(_MSC_VER) || defined(__BORLANDC__)
  9. #define _unlink unlink
  10. #else
  11. #include <sys/types.h>
  12. #include <fcntl.h>
  13. #include <unistd.h>
  14. #endif
  15. int passed = 0;
  16. int failed = 0;
  17. void Failed(const char* Message, const char* m2= "")
  18. {
  19. std::cerr << "Failed: " << Message << m2 << "\n";
  20. failed++;
  21. }
  22. void Passed(const char* Message, const char* m2="")
  23. {
  24. std::cout << "Passed: " << Message << m2 << "\n";
  25. passed++;
  26. }
  27. void TestAndRemoveFile(const char* filename)
  28. {
  29. struct stat fs;
  30. if (stat(filename, &fs) != 0)
  31. {
  32. Failed("Could not find file: ", filename);
  33. }
  34. else
  35. {
  36. if (unlink(filename) != 0)
  37. {
  38. 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);
  39. }
  40. else
  41. {
  42. Passed("Find and remove file: ", filename);
  43. }
  44. }
  45. }
  46. int main()
  47. {
  48. if(sharedFunction() != 1)
  49. {
  50. Failed("Call to sharedFunction from shared library failed.");
  51. }
  52. else
  53. {
  54. Passed("Call to sharedFunction from shared library worked.");
  55. }
  56. if(file1() != 1)
  57. {
  58. Failed("Call to file1 function from library failed.");
  59. }
  60. else
  61. {
  62. Passed("Call to file1 function returned 1.");
  63. }
  64. if(file2() != 1)
  65. {
  66. Failed("Call to file2 function from library failed.");
  67. }
  68. else
  69. {
  70. Passed("Call to file2 function returned 1.");
  71. }
  72. #ifndef CMAKE_IS_FUN
  73. Failed("CMake is not fun, so it is broken and should be fixed.");
  74. #else
  75. Passed("CMAKE_IS_FUN is defined.");
  76. #endif
  77. #ifdef SHOULD_NOT_BE_DEFINED
  78. Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
  79. #else
  80. Passed("SHOULD_NOT_BE_DEFINED is not defined.");
  81. #endif
  82. #ifndef SHOULD_BE_DEFINED
  83. Failed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
  84. #else
  85. Passed("SHOULD_BE_DEFINED is defined.");
  86. #endif
  87. #ifndef ONE_VAR
  88. Failed("cmakedefine is broken, ONE_VAR is not defined.");
  89. #else
  90. Passed("ONE_VAR is defined.");
  91. #endif
  92. #ifndef ONE_VAR_IS_DEFINED
  93. Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
  94. "ONE_VAR_IS_DEFINED is not defined.");
  95. #else
  96. Passed("ONE_VAR_IS_DEFINED is defined.");
  97. #endif
  98. #ifdef ZERO_VAR
  99. Failed("cmakedefine is broken, ZERO_VAR is defined.");
  100. #else
  101. Passed("ZERO_VAR is not defined.");
  102. #endif
  103. #ifndef STRING_VAR
  104. Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
  105. #else
  106. if(strcmp(STRING_VAR, "CMake is great") != 0)
  107. {
  108. Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
  109. STRING_VAR);
  110. }
  111. else
  112. {
  113. Passed("STRING_VAR == ", STRING_VAR);
  114. }
  115. #endif
  116. #ifndef FOREACH_VAR1
  117. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  118. "FOREACH_VAR1 is not defined.");
  119. #else
  120. if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
  121. {
  122. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  123. "FOREACH_VAR1 == ", FOREACH_VAR1);
  124. }
  125. else
  126. {
  127. Passed("FOREACH_VAR1 == ", FOREACH_VAR1);
  128. }
  129. #endif
  130. #ifndef FOREACH_VAR2
  131. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  132. "FOREACH_VAR2 is not defined.");
  133. #else
  134. if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
  135. {
  136. Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
  137. "FOREACH_VAR2 == ", FOREACH_VAR2);
  138. }
  139. else
  140. {
  141. Passed("FOREACH_VAR2 == ", FOREACH_VAR2);
  142. }
  143. #endif
  144. #ifndef FILENAME_VAR_PATH_NAME
  145. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  146. "FILENAME_VAR_PATH_NAME is not defined.");
  147. #else
  148. if(strcmp(FILENAME_VAR_PATH_NAME, "Complex") != 0)
  149. {
  150. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  151. "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
  152. }
  153. else
  154. {
  155. Passed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
  156. }
  157. #endif
  158. #ifndef FILENAME_VAR_NAME
  159. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  160. "FILENAME_VAR_NAME is not defined.");
  161. #else
  162. if(strcmp(FILENAME_VAR_NAME, "VarTests.txt") != 0)
  163. {
  164. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  165. "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
  166. }
  167. else
  168. {
  169. Passed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
  170. }
  171. #endif
  172. #ifndef FILENAME_VAR_EXT
  173. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  174. "FILENAME_VAR_EXT is not defined.");
  175. #else
  176. if(strcmp(FILENAME_VAR_EXT, ".txt") != 0)
  177. {
  178. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  179. "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
  180. }
  181. else
  182. {
  183. Passed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
  184. }
  185. #endif
  186. #ifndef FILENAME_VAR_NAME_WE
  187. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  188. "FILENAME_VAR_NAME_WE is not defined.");
  189. #else
  190. if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
  191. {
  192. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  193. "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
  194. }
  195. else
  196. {
  197. Passed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
  198. }
  199. #endif
  200. #ifndef PATH_VAR_NAME
  201. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  202. "PATH_VAR_NAME is not defined.");
  203. #else
  204. if(strcmp(PATH_VAR_NAME, "Complex") != 0)
  205. {
  206. Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
  207. "PATH_VAR_NAME == ", PATH_VAR_NAME);
  208. }
  209. else
  210. {
  211. Passed("PATH_VAR_NAME == ", PATH_VAR_NAME);
  212. }
  213. #endif
  214. // A post-build custom-command has been attached to the lib.
  215. // It run ${CREATE_FILE_EXE} which will create the file
  216. // ${Complex_BINARY_DIR}/postbuild.txt.
  217. TestAndRemoveFile(BINARY_DIR "/postbuild.txt");
  218. // A custom target has been created.
  219. // It run ${CREATE_FILE_EXE} which will create the file
  220. // ${Complex_BINARY_DIR}/custom_target1.txt.
  221. TestAndRemoveFile(BINARY_DIR "/custom_target1.txt");
  222. std::cout << "Passed: " << passed << "\n";
  223. if(failed)
  224. {
  225. std::cout << "Failed: " << failed << "\n";
  226. return failed;
  227. }
  228. return 0;
  229. }