@@ -304,19 +304,46 @@ if(BUILD_TESTING)
304304 )
305305
306306 #
307- # tests_PythonQtDynamicLoading: This test checks that a dynamically loaded library (itself linked against
308- # PythonQt) properly initializes PythonQt.
307+ # PythonQtDynamicLoading tests
309308 #
309+ # These tests check that a dynamically loaded library (itself linked against PythonQt) properly
310+ # initializes PythonQt and allow the PythonQt testing suites to complete.
311+ #
312+ # Infrastructure:
313+ #
314+ # * PythonQtDynamicLoaderSharedLibrary:
315+ # - Shared library linked against PythonQt
316+ # - export two "C compatible" symbols:
317+ # 'this_function_returns_42': function that is expected to return the integer 42
318+ # 'run_pythonqt_tests' : function running python test suite if RUN_TESTSUITE_IN_STATIC_INITIALIZER is 0
319+ # - contain a statically initialized structure named 'StaticInitializer':
320+ # - always call 'PythonQt::init()'
321+ # - running python test suite if RUN_TESTSUITE_IN_STATIC_INITIALIZER is 1
322+ #
323+ #
324+ # * PythonQtDynamicLoader: Executable loading the 'PythonQtDynamicLoaderSharedLibrary' using QLibrary
325+ # - resolve symbols 'this_function_returns_42' and 'run_pythonqt_tests' and call the corresponding function.
326+ #
327+ #
328+ # To summarize, two cases are considered:
329+ #
330+ # (a) RUN_TESTSUITE_IN_STATIC_INITIALIZER = 0
331+ #
332+ # - PythonQt::init(...) called in StaticInitializer
333+ # - Python test suite executed in function 'run_pythonqt_tests'
334+ #
335+ # Name of test: tests_PythonQtDynamicLoading_RUN_TESTSUITE_IN_STATIC_INITIALIZER_0
336+ #
337+ #
338+ # (b) RUN_TESTSUITE_IN_STATIC_INITIALIZER = 1
339+ #
340+ # - PythonQt::init(...) called in 'StaticInitializer'
341+ # - Python test suite executed in 'StaticInitializer'
342+ #
343+ # Name of test: tests_PythonQtDynamicLoading_RUN_TESTSUITE_IN_STATIC_INITIALIZER_1
310344
311- add_library (PythonQtDynamicLoaderSharedLibrary SHARED
312- tests/PythonQtDynamicLoaderSharedLibrary.cpp
313- ${PythonQtTests_sources}
314- )
315- target_link_libraries (PythonQtDynamicLoaderSharedLibrary PythonQt)
316-
317- add_executable (PythonQtDynamicLoader tests/PythonQtDynamicLoader.cpp)
318- target_link_libraries (PythonQtDynamicLoader ${QT_LIBRARIES} )
319-
345+ # Configure 'test_wrapper' common to all 'PythonQtDynamicLoading' tests
346+ #
320347 # Since setting the ENVIRONMENT property value with semicolon (e.g. PATH) is not supported, we
321348 # generate a wrapper script to update PATH and LD_LIBRARY_PATH.
322349 set (test_wrapper "${CMAKE_CURRENT_BINARY_DIR} /test_wrapper.cmake" )
@@ -332,10 +359,42 @@ if(NOT result EQUAL 0)
332359endif()
333360" )
334361
335- add_test (
336- NAME tests_PythonQtDynamicLoading
337- COMMAND ${CMAKE_COMMAND} -DTARGET_FILE=$<TARGET_FILE:PythonQtDynamicLoader> -P ${test_wrapper}
338- )
362+ function (_add_dynamic_loading_test run_testsuite_in_static_initializer)
363+
364+ set (suffix 0)
365+ if (run_testsuite_in_static_initializer)
366+ set (suffix 1)
367+ endif ()
368+
369+ add_library (PythonQtDynamicLoaderSharedLibrary_${suffix} SHARED
370+ tests/PythonQtDynamicLoaderSharedLibrary.cpp
371+ ${PythonQtTests_sources}
372+ )
373+ target_link_libraries (PythonQtDynamicLoaderSharedLibrary_${suffix} PythonQt)
374+
375+ add_executable (PythonQtDynamicLoader_${suffix} tests/PythonQtDynamicLoader.cpp)
376+ target_link_libraries (PythonQtDynamicLoader_${suffix} ${QT_LIBRARIES} )
377+
378+ if (run_testsuite_in_static_initializer)
379+ set_target_properties (
380+ PythonQtDynamicLoaderSharedLibrary_${suffix}
381+ PythonQtDynamicLoader_${suffix}
382+ PROPERTIES COMPILE_DEFINITIONS "RUN_TESTSUITE_IN_STATIC_INITIALIZER"
383+ )
384+ endif ()
385+
386+ add_test (
387+ NAME tests_PythonQtDynamicLoading_RUN_TESTSUITE_IN_STATIC_INITIALIZER_${suffix}
388+ COMMAND ${CMAKE_COMMAND} -DTARGET_FILE=$<TARGET_FILE:PythonQtDynamicLoader_${suffix} > -P ${test_wrapper}
389+ )
390+
391+ endfunction ()
392+
393+ # RUN_TESTSUITE_IN_STATIC_INITIALIZER = 0
394+ _add_dynamic_loading_test(0)
395+
396+ # RUN_TESTSUITE_IN_STATIC_INITIALIZER = 1
397+ _add_dynamic_loading_test(1)
339398
340399endif ()
341400
0 commit comments