2001-08-23 21:57:45 +04:00
# include "cmTestConfigure.h"
# include "ExtraSources/file1.h"
# include "file2.h"
# include "sharedFile.h"
# include "cmStandardIncludes.h"
2002-01-19 03:21:43 +03:00
# include "cmSystemTools.h"
2001-08-23 21:57:45 +04:00
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 + + ;
}
2002-01-18 20:03:32 +03:00
void TestAndRemoveFile ( const char * filename )
{
2002-01-19 03:21:43 +03:00
if ( ! cmSystemTools : : FileExists ( filename ) )
2002-01-18 20:03:32 +03:00
{
Failed ( " Could not find file: " , filename ) ;
}
else
{
2002-01-19 03:21:43 +03:00
if ( ! cmSystemTools : : RemoveFile ( filename ) )
2002-01-18 20:03:32 +03:00
{
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 ) ;
}
}
}
2002-01-19 03:21:43 +03:00
void TestDir ( const char * filename )
{
if ( ! cmSystemTools : : FileExists ( filename ) )
{
Failed ( " Could not find dir: " , filename ) ;
}
else
{
if ( ! cmSystemTools : : FileIsDirectory ( filename ) )
{
Failed ( " Unable to check if file is a directory: " , filename ) ;
}
else
{
Passed ( " Find dir: " , filename ) ;
}
}
}
2001-08-24 23:54:06 +04:00
int main ( )
2001-08-23 21:57:45 +04:00
{
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. " ) ;
}
2002-01-17 23:49:08 +03:00
2001-08-23 21:57:45 +04:00
if ( file2 ( ) ! = 1 )
{
Failed ( " Call to file2 function from library failed. " ) ;
}
else
{
Passed ( " Call to file2 function returned 1. " ) ;
}
2002-01-17 23:49:08 +03:00
2001-08-23 21:57:45 +04:00
# 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
2002-01-19 04:32:06 +03:00
# ifdef SHOULD_NOT_BE_DEFINED_AND
Failed ( " IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined. " ) ;
# else
Passed ( " SHOULD_NOT_BE_DEFINED_AND is not defined. " ) ;
# endif
# ifndef SHOULD_BE_DEFINED_AND
Failed ( " IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined. \n " ) ;
# else
Passed ( " SHOULD_BE_DEFINED_AND is defined. " ) ;
# endif
# ifdef SHOULD_NOT_BE_DEFINED_OR
Failed ( " IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined. " ) ;
# else
Passed ( " SHOULD_NOT_BE_DEFINED_OR is not defined. " ) ;
# endif
# ifndef SHOULD_BE_DEFINED_OR
Failed ( " IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined. \n " ) ;
# else
Passed ( " SHOULD_BE_DEFINED_OR is defined. " ) ;
# endif
# ifdef SHOULD_NOT_BE_DEFINED_MATCHES
Failed ( " IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined. " ) ;
# else
Passed ( " SHOULD_NOT_BE_DEFINED_MATCHES is not defined. " ) ;
# endif
# ifndef SHOULD_BE_DEFINED_MATCHES
Failed ( " IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined. \n " ) ;
# else
Passed ( " SHOULD_BE_DEFINED_MATCHES is defined. " ) ;
# endif
2001-08-23 21:57:45 +04:00
# ifndef ONE_VAR
Failed ( " cmakedefine is broken, ONE_VAR is not defined. " ) ;
# else
Passed ( " ONE_VAR is defined. " ) ;
# endif
2002-01-18 20:03:32 +03:00
# 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
2001-08-23 21:57:45 +04:00
# ifdef ZERO_VAR
Failed ( " cmakedefine is broken, ZERO_VAR is defined. " ) ;
# else
Passed ( " ZERO_VAR is not defined. " ) ;
# endif
# ifndef STRING_VAR
2002-01-18 20:03:32 +03:00
Failed ( " the CONFIGURE_FILE command is broken, STRING_VAR is not defined. " ) ;
2001-08-23 21:57:45 +04:00
# else
if ( strcmp ( STRING_VAR , " CMake is great " ) ! = 0 )
{
2002-01-18 20:03:32 +03:00
Failed ( " the SET or CONFIGURE_FILE command is broken. STRING_VAR == " ,
2001-08-23 21:57:45 +04:00
STRING_VAR ) ;
}
else
{
Passed ( " STRING_VAR == " , STRING_VAR ) ;
}
# endif
2002-01-17 23:49:08 +03:00
2002-01-18 20:03:32 +03:00
# 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
2002-01-17 23:49:08 +03:00
2002-01-18 20:03:32 +03:00
# 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 )
2002-01-17 23:49:08 +03:00
{
2002-01-18 20:03:32 +03:00
Failed ( " the FOREACH, SET or CONFIGURE_FILE command is broken, "
" FOREACH_VAR2 == " , FOREACH_VAR2 ) ;
2002-01-17 23:49:08 +03:00
}
else
{
2002-01-18 20:03:32 +03:00
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 ) ;
2002-01-17 23:49:08 +03:00
}
2002-01-18 20:03:32 +03:00
# endif
# ifndef FILENAME_VAR_NAME
Failed ( " the FIND_FILE or GET_FILENAME_COMPONENT command is broken, "
" FILENAME_VAR_NAME is not defined. " ) ;
# else
2002-01-19 04:32:06 +03:00
if ( strcmp ( FILENAME_VAR_NAME , " VarTests.cmake " ) ! = 0 )
2002-01-18 20:03:32 +03:00
{
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
2002-01-19 04:32:06 +03:00
if ( strcmp ( FILENAME_VAR_EXT , " .cmake " ) ! = 0 )
2002-01-18 20:03:32 +03:00
{
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
2002-01-19 03:21:43 +03:00
# ifndef CACHE_TEST_VAR1
Failed ( " the LOAD_CACHE or CONFIGURE_FILE command is broken, "
" CACHE_TEST_VAR1 is not defined. " ) ;
# else
if ( strcmp ( CACHE_TEST_VAR1 , " foo " ) ! = 0 )
{
Failed ( " the FOREACH, SET or CONFIGURE_FILE command is broken, "
" CACHE_TEST_VAR1 == " , CACHE_TEST_VAR1 ) ;
}
else
{
Passed ( " CACHE_TEST_VAR1 == " , CACHE_TEST_VAR1 ) ;
}
# endif
# ifndef CACHE_TEST_VAR2
Failed ( " the LOAD_CACHE or CONFIGURE_FILE command is broken, "
" CACHE_TEST_VAR2 is not defined. " ) ;
# else
if ( strcmp ( CACHE_TEST_VAR2 , " bar " ) ! = 0 )
{
Failed ( " the FOREACH, SET or CONFIGURE_FILE command is broken, "
" CACHE_TEST_VAR2 == " , CACHE_TEST_VAR2 ) ;
}
else
{
Passed ( " CACHE_TEST_VAR2 == " , CACHE_TEST_VAR2 ) ;
}
# endif
# ifndef CACHE_TEST_VAR3
Failed ( " the LOAD_CACHE or CONFIGURE_FILE command is broken, "
" CACHE_TEST_VAR3 is not defined. " ) ;
# else
if ( strcmp ( CACHE_TEST_VAR3 , " 1 " ) ! = 0 )
{
Failed ( " the FOREACH, SET or CONFIGURE_FILE command is broken, "
" CACHE_TEST_VAR3 == " , CACHE_TEST_VAR3 ) ;
}
else
{
Passed ( " CACHE_TEST_VAR3 == " , CACHE_TEST_VAR3 ) ;
}
# endif
// A post-build custom-command has been attached to the lib (see Library/).
2002-01-18 20:03:32 +03:00
// It run ${CREATE_FILE_EXE} which will create the file
2002-01-19 03:21:43 +03:00
// ${Complex_BINARY_DIR}/Library/postbuild.txt.
2002-01-18 20:03:32 +03:00
2002-01-19 03:21:43 +03:00
TestAndRemoveFile ( BINARY_DIR " /Library/postbuild.txt " ) ;
2002-01-18 20:03:32 +03:00
2002-01-19 03:21:43 +03:00
// A custom target has been created (see Library/).
2002-01-18 20:03:32 +03:00
// It run ${CREATE_FILE_EXE} which will create the file
2002-01-19 03:21:43 +03:00
// ${Complex_BINARY_DIR}/Library/custom_target1.txt.
TestAndRemoveFile ( BINARY_DIR " /Library/custom_target1.txt " ) ;
// A directory has been created.
2002-01-18 20:03:32 +03:00
2002-01-19 03:21:43 +03:00
TestDir ( BINARY_DIR " /make_dir " ) ;
2002-01-17 23:49:08 +03:00
2002-01-18 00:36:04 +03:00
std : : cout < < " Passed: " < < passed < < " \n " ;
2001-08-23 21:57:45 +04:00
if ( failed )
{
std : : cout < < " Failed: " < < failed < < " \n " ;
return failed ;
}
2002-01-17 23:49:08 +03:00
2001-08-23 21:57:45 +04:00
return 0 ;
}