@@ -277,9 +277,11 @@ if(BUILD_TESTING)
277277 tests/PythonQtTests.h
278278 )
279279
280- QT4_WRAP_CPP(PythonQtTests_sources
280+ QT4_WRAP_CPP(_tmp_moc_sources
281281 tests/PythonQtTests.h
282282 )
283+ list (APPEND PythonQtTests_sources ${_tmp_moc_sources} )
284+ list (APPEND moc_sources ${_tmp_moc_sources} )
283285
284286 if (PythonQt_Wrap_Qtcore)
285287 include_directories (generated_cpp${generated_cpp_suffix} )
@@ -288,15 +290,73 @@ if(BUILD_TESTING)
288290 tests/PythonQtTestCleanup.cpp
289291 tests/PythonQtTestCleanup.h
290292 )
291- QT4_WRAP_CPP(test_sources
293+ QT4_WRAP_CPP(_tmp_moc_sources
292294 tests/PythonQtTestCleanup.h
293295 )
296+ list (APPEND test_sources ${_tmp_moc_sources} )
297+ list (APPEND moc_sources ${_tmp_moc_sources} )
294298
295299 set_property (SOURCE tests/PythonQtTestMain.cpp APPEND PROPERTY COMPILE_DEFINITIONS "PythonQt_Wrap_Qtcore" )
296300 endif ()
297301
302+ add_custom_target (PythonQtTestsWrapCpp DEPENDS ${moc_sources} )
303+
304+ set (PythonQtTestApi_cases
305+ testCall
306+ testVariables
307+ testRedirect
308+ testImporter
309+ testQColorDecorators
310+ testQtNamespace
311+ testConnects
312+ testProperties
313+ testDynamicProperties
314+ )
315+
316+ set (PythonQtTestSlotCalling_cases
317+ testNoArgSlotCall
318+ testPODSlotCalls
319+ testCPPSlotCalls
320+ testQVariantSlotCalls
321+ testQListSlotCalls
322+ testQMapSlotCalls
323+ testObjectSlotCalls
324+ testMultiArgsSlotCall
325+ testPyObjectSlotCall
326+ testOverloadedCall
327+ #testCppFactory # XXX Fix this. Running this test standalone is failing.
328+ testInheritance
329+ testAutoConversion
330+ testProperties
331+ )
332+
333+ set (PythonQtTestSignalHandler_cases
334+ testSignalHandler
335+ testRecursiveSignalHandler
336+ )
337+
338+ foreach (suite Api SlotCalling SignalHandler)
339+ set (_compile_definition "${suite} _TEST_SUITE" )
340+ set (_suffix "_${suite} " )
341+
342+ add_executable (PythonQtCppTests${_suffix} ${test_sources} ${PythonQtTests_sources} )
343+ target_link_libraries (PythonQtCppTests${_suffix} PythonQt)
344+ set_target_properties (PythonQtCppTests${_suffix} PROPERTIES COMPILE_DEFINITIONS ${_compile_definition} )
345+ add_dependencies (PythonQtCppTests${_suffix} PythonQtTestsWrapCpp)
346+
347+ # Add one test for each test suite case
348+ foreach (case ${PythonQtTest${suite} _cases})
349+ add_test (
350+ NAME tests_PythonQtTestMain_${suite} _${case}
351+ COMMAND ${Slicer_LAUNCH_COMMAND} $<TARGET_FILE:PythonQtCppTests_${suite} > tests/PythonQtTestMain ${case}
352+ )
353+ endforeach ()
354+ endforeach ()
355+
356+ # suite: ALL
298357 add_executable (PythonQtCppTests ${test_sources} ${PythonQtTests_sources} )
299358 target_link_libraries (PythonQtCppTests PythonQt)
359+ add_dependencies (PythonQtCppTests PythonQtTestsWrapCpp)
300360
301361 add_test (
302362 NAME tests_PythonQtTestMain
@@ -353,6 +413,8 @@ if(UNIX)
353413else()
354414 set(ENV{PATH} \"\$ ENV{PATH};.\" )
355415endif()
416+ set(ENV{SUITE} \"\$ {SUITE}\" )
417+ set(ENV{CASE} \"\$ {CASE}\" )
356418execute_process(COMMAND \$ {TARGET_FILE} RESULT_VARIABLE result)
357419if(NOT result EQUAL 0)
358420 message(FATAL_ERROR \" test failed ! [result: \$ {result}]\" )
@@ -361,27 +423,52 @@ endif()
361423
362424 function (_add_dynamic_loading_test run_testsuite_in_static_initializer)
363425
426+ macro (_add_targets extra_compile_definitions)
427+
428+ add_library (PythonQtDynamicLoaderSharedLibrary_${suffix}${suite_suffix} SHARED
429+ tests/PythonQtDynamicLoaderSharedLibrary.cpp
430+ ${PythonQtTests_sources}
431+ )
432+ target_link_libraries (PythonQtDynamicLoaderSharedLibrary_${suffix}${suite_suffix} PythonQt)
433+ add_dependencies (PythonQtDynamicLoaderSharedLibrary_${suffix}${suite_suffix} PythonQtTestsWrapCpp)
434+
435+ add_executable (PythonQtDynamicLoader_${suffix}${suite_suffix} tests/PythonQtDynamicLoader.cpp)
436+ target_link_libraries (PythonQtDynamicLoader_${suffix}${suite_suffix} ${QT_LIBRARIES} )
437+
438+ if (run_testsuite_in_static_initializer)
439+ set_property (TARGET
440+ PythonQtDynamicLoaderSharedLibrary_${suffix}${suite_suffix}
441+ PythonQtDynamicLoader_${suffix}${suite_suffix}
442+ PROPERTY COMPILE_DEFINITIONS "RUN_TESTSUITE_IN_STATIC_INITIALIZER" ${extra_compile_definitions}
443+ )
444+ endif ()
445+ endmacro ()
446+
364447 set (suffix 0)
365448 if (run_testsuite_in_static_initializer)
366449 set (suffix 1)
367450 endif ()
368451
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} )
452+ foreach (suite Api SlotCalling SignalHandler)
453+ set (_compile_definition "${suite} _TEST_SUITE" )
454+ set (suite_suffix "_${suite} " )
455+
456+ _add_targets("${_compile_definition} " )
457+
458+ # Add one test for each test suite case
459+ foreach (case ${PythonQtTest${suite} _cases})
460+ add_test (
461+ NAME tests_PythonQtDynamicLoading_RUN_TESTSUITE_IN_STATIC_INITIALIZER_${suffix} _${suite} _${case}
462+ COMMAND ${CMAKE_COMMAND}
463+ -DTARGET_FILE=$<TARGET_FILE:PythonQtDynamicLoader_${suffix}${suite_suffix} >
464+ -DSUITE=${suite} -DCASE=${case} -P ${test_wrapper}
465+ )
466+ endforeach ()
467+ endforeach ()
377468
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 ()
469+ # suite: ALL
470+ set (suite_suffix "" )
471+ _add_targets("" )
385472
386473 add_test (
387474 NAME tests_PythonQtDynamicLoading_RUN_TESTSUITE_IN_STATIC_INITIALIZER_${suffix}
0 commit comments