diff --git a/Foundation/testsuite/CMakeLists.txt b/Foundation/testsuite/CMakeLists.txt index 9f40be23b..2c8e305d8 100644 --- a/Foundation/testsuite/CMakeLists.txt +++ b/Foundation/testsuite/CMakeLists.txt @@ -62,46 +62,51 @@ set_target_properties(TestApp PROPERTIES ) target_link_libraries(TestApp PUBLIC Poco::Foundation) -# TestLibrary -add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h) -set_target_properties(TestLibrary PROPERTIES - DEBUG_POSTFIX "d" - # The test requires the library named TestLibrary. By default it is prefixed with lib. - PREFIX "" -) +add_dependencies(Foundation-testrunner TestApp) -# The test is run in the runtime directory. So the TestLibrary is built there too because it is used by the tests -set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) -target_link_libraries(TestLibrary PUBLIC Poco::Foundation) - -add_dependencies(Foundation-testrunner TestApp TestLibrary) - -# TestLibraryMissingDeps - a library with missing dependencies for testing findMissingDependencies -# Build a stub library that TestLibraryMissingDeps links against -# The test will delete it at runtime to simulate a missing dependency -add_library(NonExistentLibrary SHARED src/NonExistentStub.c) -set_target_properties(NonExistentLibrary PROPERTIES - DEBUG_POSTFIX "d" - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} -) -# For multi-config generators (Visual Studio), set per-configuration archive output -foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER) - set_target_properties(NonExistentLibrary PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER}} +# TestLibrary and related shared libraries - only for shared library builds +# SharedLibrary and ClassLoader tests require dynamically loadable libraries +if(BUILD_SHARED_LIBS) + add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h) + set_target_properties(TestLibrary PROPERTIES + DEBUG_POSTFIX "d" + # The test requires the library named TestLibrary. By default it is prefixed with lib. + PREFIX "" ) -endforeach() -add_library(TestLibraryMissingDeps SHARED src/TestLibraryMissingDeps.cpp) -set_target_properties(TestLibraryMissingDeps PROPERTIES - DEBUG_POSTFIX "d" - PREFIX "" - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} -) -target_link_libraries(TestLibraryMissingDeps PUBLIC Poco::Foundation NonExistentLibrary) -add_dependencies(TestLibraryMissingDeps NonExistentLibrary) + # The test is run in the runtime directory. So the TestLibrary is built there too because it is used by the tests + set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + target_link_libraries(TestLibrary PUBLIC Poco::Foundation) -add_dependencies(Foundation-testrunner TestLibraryMissingDeps) + add_dependencies(Foundation-testrunner TestLibrary) + + # TestLibraryMissingDeps - a library with missing dependencies for testing findMissingDependencies + # Build a stub library that TestLibraryMissingDeps links against + # The test will delete it at runtime to simulate a missing dependency + add_library(NonExistentLibrary SHARED src/NonExistentStub.c) + set_target_properties(NonExistentLibrary PROPERTIES + DEBUG_POSTFIX "d" + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} + ) + # For multi-config generators (Visual Studio), set per-configuration archive output + foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG_UPPER) + set_target_properties(NonExistentLibrary PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG_UPPER}} + ) + endforeach() + + add_library(TestLibraryMissingDeps SHARED src/TestLibraryMissingDeps.cpp) + set_target_properties(TestLibraryMissingDeps PROPERTIES + DEBUG_POSTFIX "d" + PREFIX "" + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + ) + target_link_libraries(TestLibraryMissingDeps PUBLIC Poco::Foundation NonExistentLibrary) + add_dependencies(TestLibraryMissingDeps NonExistentLibrary) + + add_dependencies(Foundation-testrunner TestLibraryMissingDeps) +endif() diff --git a/Foundation/testsuite/src/ClassLoaderTest.cpp b/Foundation/testsuite/src/ClassLoaderTest.cpp index 55fbb7f7d..5c2f4080f 100644 --- a/Foundation/testsuite/src/ClassLoaderTest.cpp +++ b/Foundation/testsuite/src/ClassLoaderTest.cpp @@ -49,6 +49,10 @@ template class ClassLoader; void ClassLoaderTest::testClassLoader1() { +#ifdef POCO_STATIC + return; // Skip test in static builds where TestLibrary is not built +#endif + std::string libraryPath = getFullName("TestLibrary"); ClassLoader cl; @@ -88,6 +92,10 @@ void ClassLoaderTest::testClassLoader1() void ClassLoaderTest::testClassLoader2() { +#ifdef POCO_STATIC + return; // Skip test in static builds where TestLibrary is not built +#endif + std::string libraryPath = getFullName("TestLibrary"); ClassLoader cl; cl.loadLibrary(libraryPath); @@ -176,6 +184,10 @@ void ClassLoaderTest::testClassLoader2() void ClassLoaderTest::testClassLoader3() { +#ifdef POCO_STATIC + return; // Skip test in static builds where TestLibrary is not built +#endif + std::string libraryPath = getFullName("TestLibrary"); ClassLoader cl; cl.loadLibrary(libraryPath); diff --git a/Foundation/testsuite/src/SharedLibraryTest.cpp b/Foundation/testsuite/src/SharedLibraryTest.cpp index 1bcb7b41a..b8d52f808 100755 --- a/Foundation/testsuite/src/SharedLibraryTest.cpp +++ b/Foundation/testsuite/src/SharedLibraryTest.cpp @@ -50,6 +50,10 @@ SharedLibraryTest::~SharedLibraryTest() void SharedLibraryTest::testSharedLibrary1() { +#ifdef POCO_STATIC + return; // Skip test in static builds where TestLibrary is not built +#endif + std::string libraryPath = getFullName("TestLibrary"); SharedLibrary sl; assertTrue (!sl.isLoaded()); @@ -83,6 +87,10 @@ void SharedLibraryTest::testSharedLibrary1() void SharedLibraryTest::testSharedLibrary2() { +#ifdef POCO_STATIC + return; // Skip test in static builds where TestLibrary is not built +#endif + std::string libraryPath = getFullName("TestLibrary"); SharedLibrary sl(libraryPath); assertTrue (sl.getPath() == libraryPath); @@ -98,6 +106,10 @@ void SharedLibraryTest::testSharedLibrary2() void SharedLibraryTest::testSharedLibrary3() { +#ifdef POCO_STATIC + return; // Skip test in static builds where TestLibrary is not built +#endif + std::string libraryPath = "NonexistentLibrary"; libraryPath.append(libraryPath); SharedLibrary sl; @@ -140,9 +152,12 @@ void SharedLibraryTest::testSharedLibrary3() void SharedLibraryTest::testMissingDependencies() { +#ifdef POCO_STATIC + return; // Skip test in static builds where TestLibrary is not built +#endif + // Test with a valid library - should return empty list (all dependencies found) std::string libraryPath = getFullName("TestLibrary"); - assertTrue (File(libraryPath).exists()); std::vector missing = SharedLibrary::findMissingDependencies(libraryPath); // TestLibrary should have all its dependencies available for (const auto& dep : missing)