fix(SharedLibrary): disable shared lib tests in static build #5069

This commit is contained in:
Alex Fabijanic
2025-12-05 15:47:17 -06:00
parent 4904acd257
commit 709601dfa0
3 changed files with 72 additions and 40 deletions

View File

@@ -62,7 +62,11 @@ set_target_properties(TestApp PROPERTIES
) )
target_link_libraries(TestApp PUBLIC Poco::Foundation) target_link_libraries(TestApp PUBLIC Poco::Foundation)
# TestLibrary add_dependencies(Foundation-testrunner TestApp)
# 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) add_library(TestLibrary SHARED src/TestLibrary.cpp src/TestPlugin.cpp src/TestPlugin.h)
set_target_properties(TestLibrary PROPERTIES set_target_properties(TestLibrary PROPERTIES
DEBUG_POSTFIX "d" DEBUG_POSTFIX "d"
@@ -74,7 +78,7 @@ set_target_properties(TestLibrary PROPERTIES
set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) set_target_properties(TestLibrary PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
target_link_libraries(TestLibrary PUBLIC Poco::Foundation) target_link_libraries(TestLibrary PUBLIC Poco::Foundation)
add_dependencies(Foundation-testrunner TestApp TestLibrary) add_dependencies(Foundation-testrunner TestLibrary)
# TestLibraryMissingDeps - a library with missing dependencies for testing findMissingDependencies # TestLibraryMissingDeps - a library with missing dependencies for testing findMissingDependencies
# Build a stub library that TestLibraryMissingDeps links against # Build a stub library that TestLibraryMissingDeps links against
@@ -105,3 +109,4 @@ target_link_libraries(TestLibraryMissingDeps PUBLIC Poco::Foundation NonExistent
add_dependencies(TestLibraryMissingDeps NonExistentLibrary) add_dependencies(TestLibraryMissingDeps NonExistentLibrary)
add_dependencies(Foundation-testrunner TestLibraryMissingDeps) add_dependencies(Foundation-testrunner TestLibraryMissingDeps)
endif()

View File

@@ -49,6 +49,10 @@ template class ClassLoader<TestPlugin>;
void ClassLoaderTest::testClassLoader1() void ClassLoaderTest::testClassLoader1()
{ {
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary"); std::string libraryPath = getFullName("TestLibrary");
ClassLoader<TestPlugin> cl; ClassLoader<TestPlugin> cl;
@@ -88,6 +92,10 @@ void ClassLoaderTest::testClassLoader1()
void ClassLoaderTest::testClassLoader2() void ClassLoaderTest::testClassLoader2()
{ {
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary"); std::string libraryPath = getFullName("TestLibrary");
ClassLoader<TestPlugin> cl; ClassLoader<TestPlugin> cl;
cl.loadLibrary(libraryPath); cl.loadLibrary(libraryPath);
@@ -176,6 +184,10 @@ void ClassLoaderTest::testClassLoader2()
void ClassLoaderTest::testClassLoader3() void ClassLoaderTest::testClassLoader3()
{ {
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary"); std::string libraryPath = getFullName("TestLibrary");
ClassLoader<TestPlugin> cl; ClassLoader<TestPlugin> cl;
cl.loadLibrary(libraryPath); cl.loadLibrary(libraryPath);

View File

@@ -50,6 +50,10 @@ SharedLibraryTest::~SharedLibraryTest()
void SharedLibraryTest::testSharedLibrary1() void SharedLibraryTest::testSharedLibrary1()
{ {
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary"); std::string libraryPath = getFullName("TestLibrary");
SharedLibrary sl; SharedLibrary sl;
assertTrue (!sl.isLoaded()); assertTrue (!sl.isLoaded());
@@ -83,6 +87,10 @@ void SharedLibraryTest::testSharedLibrary1()
void SharedLibraryTest::testSharedLibrary2() void SharedLibraryTest::testSharedLibrary2()
{ {
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = getFullName("TestLibrary"); std::string libraryPath = getFullName("TestLibrary");
SharedLibrary sl(libraryPath); SharedLibrary sl(libraryPath);
assertTrue (sl.getPath() == libraryPath); assertTrue (sl.getPath() == libraryPath);
@@ -98,6 +106,10 @@ void SharedLibraryTest::testSharedLibrary2()
void SharedLibraryTest::testSharedLibrary3() void SharedLibraryTest::testSharedLibrary3()
{ {
#ifdef POCO_STATIC
return; // Skip test in static builds where TestLibrary is not built
#endif
std::string libraryPath = "NonexistentLibrary"; std::string libraryPath = "NonexistentLibrary";
libraryPath.append(libraryPath); libraryPath.append(libraryPath);
SharedLibrary sl; SharedLibrary sl;
@@ -140,9 +152,12 @@ void SharedLibraryTest::testSharedLibrary3()
void SharedLibraryTest::testMissingDependencies() 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) // Test with a valid library - should return empty list (all dependencies found)
std::string libraryPath = getFullName("TestLibrary"); std::string libraryPath = getFullName("TestLibrary");
assertTrue (File(libraryPath).exists());
std::vector<std::string> missing = SharedLibrary::findMissingDependencies(libraryPath); std::vector<std::string> missing = SharedLibrary::findMissingDependencies(libraryPath);
// TestLibrary should have all its dependencies available // TestLibrary should have all its dependencies available
for (const auto& dep : missing) for (const auto& dep : missing)