Skip to content
Snippets Groups Projects
Commit 3a3b5567 authored by Bill Hoffman's avatar Bill Hoffman
Browse files

ENH: try to get better test coverage

parent bd4c5cf3
No related branches found
No related tags found
No related merge requests found
Showing
with 341 additions and 0 deletions
# a simple test case
PROJECT (Complex)
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
SUBDIRS(Library Executable)
SUBDIR_DEPENDS(Executable Library)
INCLUDE(${Complex_SOURCE_DIR}/VarTests.txt)
CONFIGURE_FILE(
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
${Complex_BINARY_DIR}/cmTestConfigure.h)
INCLUDE_DIRECTORIES(
${Complex_BINARY_DIR}
${Complex_SOURCE_DIR}/Library
${Complex_SOURCE_DIR}/../../Source
)
LINK_DIRECTORIES(
${Complex_BINARY_DIR}/Library
)
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
SET (LIBRARY_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all executables.")
ADD_EXECUTABLE(complex complex)
TARGET_LINK_LIBRARIES(complex CMakeTestLibrary)
TARGET_LINK_LIBRARIES(complex CMakeTestLibraryShared)
#include "cmTestConfigure.h"
#include "ExtraSources/file1.h"
#include "file2.h"
#include "sharedFile.h"
#include "cmStandardIncludes.h"
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++;
}
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
#ifdef ZERO_VAR
Failed("cmakedefine is broken, ZERO_VAR is defined.");
#else
Passed("ZERO_VAR is not defined.");
#endif
#ifndef STRING_VAR
Failed("configureFile is broken, STRING_VAR is not defined.");
#else
if(strcmp(STRING_VAR, "CMake is great") != 0)
{
Failed("CMake is not great, so the SET command,"
"or the configurefile comand is broken. STRING_VAR== ",
STRING_VAR);
}
else
{
Passed("STRING_VAR == ", STRING_VAR);
}
#endif
std::cout << "Passed:" << passed << "\n";
if(failed)
{
std::cout << "Failed: " << failed << "\n";
return failed;
}
return 0;
}
AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
SOURCE_FILES(LibrarySources file2)
ADD_LIBRARY(CMakeTestLibrary LibrarySources)
SOURCE_FILES(SharedLibrarySources sharedFile)
ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources)
int file1()
{
return 1;
}
int file1();
int file2()
{
return 1;
}
int file2();
#include "sharedFile.h"
int sharedFunction()
{
return 1;
}
#if defined(_WIN32) || defined(WIN32) /* Win32 version */
#ifdef CMakeTestLibraryShared_EXPORTS
# define CMakeTest_EXPORT __declspec(dllexport)
#else
# define CMakeTest_EXPORT __declspec(dllimport)
#endif
#else
// unix needs nothing
#define CMakeTest_EXPORT
#endif
CMakeTest_EXPORT int sharedFunction();
SET (ZERO_VAR 0)
IF(ZERO_VAR)
ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED)
ELSE(ZERO_VAR)
ADD_DEFINITIONS(-DSHOULD_BE_DEFINED)
ENDIF(ZERO_VAR)
SET(ONE_VAR 1)
SET(STRING_VAR "CMake is great" CACHE STRING "test a cache variable")
#cmakedefine ONE_VAR
#cmakedefine ZERO_VAR
#define STRING_VAR "${STRING_VAR}"
int main ()
{
return 0;
}
# a simple test case
PROJECT (Complex)
ADD_DEFINITIONS(-DCMAKE_IS_FUN)
SUBDIRS(Library Executable)
SUBDIR_DEPENDS(Executable Library)
INCLUDE(${Complex_SOURCE_DIR}/VarTests.txt)
CONFIGURE_FILE(
${Complex_SOURCE_DIR}/cmTestConfigure.h.in
${Complex_BINARY_DIR}/cmTestConfigure.h)
INCLUDE_DIRECTORIES(
${Complex_BINARY_DIR}
${Complex_SOURCE_DIR}/Library
${Complex_SOURCE_DIR}/../../Source
)
LINK_DIRECTORIES(
${Complex_BINARY_DIR}/Library
)
INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile).*$")
SET (LIBRARY_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${Complex_BINARY_DIR}/bin/ CACHE PATH "Single output directory for building all executables.")
ADD_EXECUTABLE(complex complex)
TARGET_LINK_LIBRARIES(complex CMakeTestLibrary)
TARGET_LINK_LIBRARIES(complex CMakeTestLibraryShared)
#include "cmTestConfigure.h"
#include "ExtraSources/file1.h"
#include "file2.h"
#include "sharedFile.h"
#include "cmStandardIncludes.h"
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++;
}
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
#ifdef ZERO_VAR
Failed("cmakedefine is broken, ZERO_VAR is defined.");
#else
Passed("ZERO_VAR is not defined.");
#endif
#ifndef STRING_VAR
Failed("configureFile is broken, STRING_VAR is not defined.");
#else
if(strcmp(STRING_VAR, "CMake is great") != 0)
{
Failed("CMake is not great, so the SET command,"
"or the configurefile comand is broken. STRING_VAR== ",
STRING_VAR);
}
else
{
Passed("STRING_VAR == ", STRING_VAR);
}
#endif
std::cout << "Passed:" << passed << "\n";
if(failed)
{
std::cout << "Failed: " << failed << "\n";
return failed;
}
return 0;
}
AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources)
SOURCE_FILES(LibrarySources file2)
ADD_LIBRARY(CMakeTestLibrary LibrarySources)
SOURCE_FILES(SharedLibrarySources sharedFile)
ADD_LIBRARY(CMakeTestLibraryShared SHARED SharedLibrarySources)
int file1()
{
return 1;
}
int file1();
int file2()
{
return 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment