Add some more unit tests.

This commit is contained in:
Stephen Kelly 2011-08-25 19:01:04 +02:00
parent 83ce7c4d3c
commit 93d8d1992e
10 changed files with 114 additions and 0 deletions

View File

@ -152,6 +152,8 @@ add_subdirectory(lib_shared_and_static)
add_subdirectory(lib_shared_and_statictest)
add_subdirectory(override_symbol)
add_subdirectory(nodeprecated)
add_subdirectory(prefix)
if (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} MATCHES Clang))
# We deliberately call deprecated methods, and test for that elsewhere.

View File

@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 2.8)
project(nodeprecated)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined)
configure_file(CMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined/CMakeLists.txt)
set(DEFINE_NO_DEPRECATED DEFINE_NO_DEPRECATED)
configure_file(CMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined/CMakeLists.txt)
try_compile(Result ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined_build
${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_not_defined
nodeprecated_test
OUTPUT_VARIABLE Out
)
test_pass(Result "Failed to build without no-deprecated define")
try_compile(Result ${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined_build
${CMAKE_CURRENT_BINARY_DIR}/nodeprecated_defined
nodeprecated_test
OUTPUT_VARIABLE Out
)
test_fail(Result "Built even with no-deprecated define")

View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.8)
project(nodeprecated_test)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include(GenerateExportHeader)
add_library(nodeprecatedlib SHARED someclass.cpp)
generate_export_header(nodeprecatedlib @DEFINE_NO_DEPRECATED@)
add_executable(nodeprecatedconsumer main.cpp)
target_link_libraries(nodeprecatedconsumer nodeprecatedlib)

View File

@ -0,0 +1,9 @@
#include "someclass.h"
int main(int, char**)
{
SomeClass sc;
sc.someMethod();
return 0;
}

View File

@ -0,0 +1,9 @@
#include "someclass.h"
#ifndef NODEPRECATEDLIB_NO_DEPRECATED
void SomeClass::someMethod() const
{
}
#endif

View File

@ -0,0 +1,10 @@
#include "nodeprecatedlib_export.h"
class NODEPRECATEDLIB_EXPORT SomeClass
{
public:
#ifndef NODEPRECATEDLIB_NO_DEPRECATED
void someMethod() const;
#endif
};

View File

@ -0,0 +1,15 @@
project(use_prefix)
set(use_prefix_lib_SRCS
useprefixclass.cpp
)
add_library(use_prefix_lib SHARED useprefixclass.cpp)
generate_export_header(use_prefix_lib
PREFIX_NAME MYPREFIX_
)
add_executable(use_prefix main.cpp)
target_link_libraries(use_prefix use_prefix_lib)

View File

@ -0,0 +1,8 @@
#include "useprefixclass.h"
int main(int argc, char **argv)
{
UsePrefixClass upc;
return upc.someMethod();
}

View File

@ -0,0 +1,7 @@
#include "useprefixclass.h"
int UsePrefixClass::someMethod() const
{
return 0;
}

View File

@ -0,0 +1,13 @@
#ifndef USEPREFIXCLASS_H
#define USEPREFIXCLASS_H
#include "use_prefix_lib_export.h"
class MYPREFIX_USE_PREFIX_LIB_EXPORT UsePrefixClass
{
public:
int someMethod() const;
};
#endif