complex.cxx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #include <io.h>
  9. #if defined(_MSC_VER) || defined(__BORLANDC__)
  10. #define _unlink unlink
  11. #else
  12. #include <sys/types.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #endif
  16. int passed = 0;
  17. int failed = 0;
  18. void Failed(const char* Message, const char* m2= "")
  19. {
  20. std::cerr << "Failed: " << Message << m2 << "\n";
  21. failed++;
  22. }
  23. void Passed(const char* Message, const char* m2="")
  24. {
  25. std::cout << "Passed: " << Message << m2 << "\n";
  26. passed++;
  27. }
  28. int main()
  29. {
  30. if(sharedFunction() != 1)
  31. {
  32. Failed("Call to sharedFunction from shared library failed.");
  33. }
  34. else
  35. {
  36. Passed("Call to sharedFunction from shared library worked.");
  37. }
  38. if(file1() != 1)
  39. {
  40. Failed("Call to file1 function from library failed.");
  41. }
  42. else
  43. {
  44. Passed("Call to file1 function returned 1.");
  45. }
  46. if(file2() != 1)
  47. {
  48. Failed("Call to file2 function from library failed.");
  49. }
  50. else
  51. {
  52. Passed("Call to file2 function returned 1.");
  53. }
  54. #ifndef CMAKE_IS_FUN
  55. Failed("CMake is not fun, so it is broken and should be fixed.");
  56. #else
  57. Passed("CMAKE_IS_FUN is defined.");
  58. #endif
  59. #ifdef SHOULD_NOT_BE_DEFINED
  60. Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
  61. #else
  62. Passed("SHOULD_NOT_BE_DEFINED is not defined.");
  63. #endif
  64. #ifndef SHOULD_BE_DEFINED
  65. Failed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
  66. #else
  67. Passed("SHOULD_BE_DEFINED is defined.");
  68. #endif
  69. #ifndef ONE_VAR
  70. Failed("cmakedefine is broken, ONE_VAR is not defined.");
  71. #else
  72. Passed("ONE_VAR is defined.");
  73. #endif
  74. #ifdef ZERO_VAR
  75. Failed("cmakedefine is broken, ZERO_VAR is defined.");
  76. #else
  77. Passed("ZERO_VAR is not defined.");
  78. #endif
  79. #ifndef STRING_VAR
  80. Failed("configureFile is broken, STRING_VAR is not defined.");
  81. #else
  82. if(strcmp(STRING_VAR, "CMake is great") != 0)
  83. {
  84. Failed("CMake is not great, so the SET command,"
  85. "or the configurefile comand is broken. STRING_VAR== ",
  86. STRING_VAR);
  87. }
  88. else
  89. {
  90. Passed("STRING_VAR == ", STRING_VAR);
  91. }
  92. #endif
  93. // Attach a post-build custom-command to the lib.
  94. // It run ${CREATE_FILE_EXE} which will create the file
  95. // ${Complex_BINARY_DIR}/postbuild.txt.
  96. // The 'complex' executable will then test if this file exists,
  97. // and remove it.
  98. struct stat fs;
  99. if (stat(BINARY_DIR "/postbuild.txt", &fs) != 0)
  100. {
  101. Failed("Could not find " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib).");
  102. }
  103. else
  104. {
  105. if (unlink(BINARY_DIR "/postbuild.txt") != 0)
  106. {
  107. Failed("Unable to remove " BINARY_DIR "/postbuild.txt (does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed).");
  108. }
  109. else
  110. {
  111. Passed("Find and remove " BINARY_DIR "/postbuild.txt (created as a post-build custom command for the shared lib).");
  112. }
  113. }
  114. std::cout << "Passed: " << passed << "\n";
  115. if(failed)
  116. {
  117. std::cout << "Failed: " << failed << "\n";
  118. return failed;
  119. }
  120. return 0;
  121. }