| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- #include "cmTestConfigure.h"
- #include "ExtraSources/file1.h"
- #include "file2.h"
- #include "sharedFile.h"
- #include "cmStandardIncludes.h"
- #include <sys/stat.h>
- #include <stdio.h>
- #if defined(_MSC_VER) || defined(__BORLANDC__)
- #define _unlink unlink
- #else
- #include <sys/types.h>
- #include <fcntl.h>
- #include <unistd.h>
- #endif
- int passed = 0;
- int failed = 0;
- void Failed(const char* Message, const char* m2= "")
- {
- std::cerr << "Failed: " << Message << m2 << "\n";
- failed++;
- }
- void Passed(const char* Message, const char* m2="")
- {
- std::cout << "Passed: " << Message << m2 << "\n";
- passed++;
- }
- void TestAndRemoveFile(const char* filename)
- {
- struct stat fs;
- if (stat(filename, &fs) != 0)
- {
- Failed("Could not find file: ", filename);
- }
- else
- {
- if (unlink(filename) != 0)
- {
- 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);
- }
- else
- {
- Passed("Find and remove file: ", filename);
- }
- }
- }
- int main()
- {
- if(sharedFunction() != 1)
- {
- Failed("Call to sharedFunction from shared library failed.");
- }
- else
- {
- Passed("Call to sharedFunction from shared library worked.");
- }
-
- if(file1() != 1)
- {
- Failed("Call to file1 function from library failed.");
- }
- else
- {
- Passed("Call to file1 function returned 1.");
- }
- if(file2() != 1)
- {
- Failed("Call to file2 function from library failed.");
- }
- else
- {
- Passed("Call to file2 function returned 1.");
- }
- #ifndef CMAKE_IS_FUN
- Failed("CMake is not fun, so it is broken and should be fixed.");
- #else
- Passed("CMAKE_IS_FUN is defined.");
- #endif
-
- #ifdef SHOULD_NOT_BE_DEFINED
- Failed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined.");
- #else
- Passed("SHOULD_NOT_BE_DEFINED is not defined.");
- #endif
-
- #ifndef SHOULD_BE_DEFINED
- Failed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n");
- #else
- Passed("SHOULD_BE_DEFINED is defined.");
- #endif
-
- #ifndef ONE_VAR
- Failed("cmakedefine is broken, ONE_VAR is not defined.");
- #else
- Passed("ONE_VAR is defined.");
- #endif
-
- #ifndef ONE_VAR_IS_DEFINED
- Failed("cmakedefine, SET or VARIABLE_REQUIRES is broken, "
- "ONE_VAR_IS_DEFINED is not defined.");
- #else
- Passed("ONE_VAR_IS_DEFINED is defined.");
- #endif
-
- #ifdef ZERO_VAR
- Failed("cmakedefine is broken, ZERO_VAR is defined.");
- #else
- Passed("ZERO_VAR is not defined.");
- #endif
-
- #ifndef STRING_VAR
- Failed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined.");
- #else
- if(strcmp(STRING_VAR, "CMake is great") != 0)
- {
- Failed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ",
- STRING_VAR);
- }
- else
- {
- Passed("STRING_VAR == ", STRING_VAR);
- }
- #endif
- #ifndef FOREACH_VAR1
- Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR1 is not defined.");
- #else
- if(strcmp(FOREACH_VAR1, "VALUE1") != 0)
- {
- Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR1 == ", FOREACH_VAR1);
- }
- else
- {
- Passed("FOREACH_VAR1 == ", FOREACH_VAR1);
- }
- #endif
- #ifndef FOREACH_VAR2
- Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR2 is not defined.");
- #else
- if(strcmp(FOREACH_VAR2, "VALUE2") != 0)
- {
- Failed("the FOREACH, SET or CONFIGURE_FILE command is broken, "
- "FOREACH_VAR2 == ", FOREACH_VAR2);
- }
- else
- {
- Passed("FOREACH_VAR2 == ", FOREACH_VAR2);
- }
- #endif
- #ifndef FILENAME_VAR_PATH_NAME
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_PATH_NAME is not defined.");
- #else
- if(strcmp(FILENAME_VAR_PATH_NAME, "Complex") != 0)
- {
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
- }
- else
- {
- Passed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME);
- }
- #endif
- #ifndef FILENAME_VAR_NAME
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME is not defined.");
- #else
- if(strcmp(FILENAME_VAR_NAME, "VarTests.txt") != 0)
- {
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
- }
- else
- {
- Passed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME);
- }
- #endif
- #ifndef FILENAME_VAR_EXT
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_EXT is not defined.");
- #else
- if(strcmp(FILENAME_VAR_EXT, ".txt") != 0)
- {
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
- }
- else
- {
- Passed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT);
- }
- #endif
- #ifndef FILENAME_VAR_NAME_WE
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME_WE is not defined.");
- #else
- if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0)
- {
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
- }
- else
- {
- Passed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE);
- }
- #endif
- #ifndef PATH_VAR_NAME
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "PATH_VAR_NAME is not defined.");
- #else
- if(strcmp(PATH_VAR_NAME, "Complex") != 0)
- {
- Failed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
- "PATH_VAR_NAME == ", PATH_VAR_NAME);
- }
- else
- {
- Passed("PATH_VAR_NAME == ", PATH_VAR_NAME);
- }
- #endif
- // A post-build custom-command has been attached to the lib.
- // It run ${CREATE_FILE_EXE} which will create the file
- // ${Complex_BINARY_DIR}/postbuild.txt.
- TestAndRemoveFile(BINARY_DIR "/postbuild.txt");
- // A custom target has been created.
- // It run ${CREATE_FILE_EXE} which will create the file
- // ${Complex_BINARY_DIR}/custom_target1.txt.
- TestAndRemoveFile(BINARY_DIR "/custom_target1.txt");
- std::cout << "Passed: " << passed << "\n";
- if(failed)
- {
- std::cout << "Failed: " << failed << "\n";
- return failed;
- }
- return 0;
- }
|