Skip to content

Commit

Permalink
Run regular PythonQt tests from dynamically loaded shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfr committed Feb 16, 2016
1 parent 2e61822 commit 2f35310
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ if(BUILD_TESTING)

set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain")

list(APPEND test_sources
list(APPEND PythonQtTests_sources
tests/PythonQtTests.cpp
tests/PythonQtTests.h
)

QT4_WRAP_CPP(test_sources
QT4_WRAP_CPP(PythonQtTests_sources
tests/PythonQtTests.h
)

Expand All @@ -295,7 +295,7 @@ if(BUILD_TESTING)
set_property(SOURCE tests/PythonQtTestMain.cpp APPEND PROPERTY COMPILE_DEFINITIONS "PythonQt_Wrap_Qtcore")
endif()

add_executable(PythonQtCppTests ${test_sources})
add_executable(PythonQtCppTests ${test_sources} ${PythonQtTests_sources})
target_link_libraries(PythonQtCppTests PythonQt)

add_test(
Expand All @@ -308,7 +308,10 @@ if(BUILD_TESTING)
# PythonQt) properly initializes PythonQt.
#

add_library(PythonQtDynamicLoaderSharedLibrary SHARED tests/PythonQtDynamicLoaderSharedLibrary.cpp)
add_library(PythonQtDynamicLoaderSharedLibrary SHARED
tests/PythonQtDynamicLoaderSharedLibrary.cpp
${PythonQtTests_sources}
)
target_link_libraries(PythonQtDynamicLoaderSharedLibrary PythonQt)

add_executable(PythonQtDynamicLoader tests/PythonQtDynamicLoader.cpp)
Expand Down
24 changes: 24 additions & 0 deletions tests/PythonQtDynamicLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ int main(int argc, char* argv[])
<< std::endl;
return EXIT_FAILURE;
}

//
// Resolve and invoke 'run_pythonqt_tests' function.
//
typedef int (*FUNC_ARGC_ARGV_RETURNS_INT_TYPE)(int argc, char* argv[]);
FUNC_ARGC_ARGV_RETURNS_INT_TYPE func2 =
(FUNC_ARGC_ARGV_RETURNS_INT_TYPE) library.resolve("run_pythonqt_tests");
if (!func2)
{
std::cerr << "Failed to resolve symbol 'run_pythonqt_tests'" << std::endl;
return EXIT_FAILURE;
}

result = func2(argc, argv);
expected = 0;
if (result != expected)
{
std::cerr << "Problem with function 'run_pythonqt_tests':\n"
<< "\tresult: " << result << "\n"
<< "\texpected: " << expected
<< std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

21 changes: 21 additions & 0 deletions tests/PythonQtDynamicLoaderSharedLibrary.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


#include "PythonQt.h"
#include "PythonQtTests.h"

#ifdef Q_OS_WIN
#define MY_EXPORT __declspec(dllexport)
Expand All @@ -16,6 +17,26 @@ extern "C"
return 42;
}

int MY_EXPORT run_pythonqt_tests(int argc, char* argv[])
{
// Copied from PythonQtTestMain.cpp
int failCount = 0;
PythonQtTestApi api;
failCount += QTest::qExec(&api, argc, argv);
PythonQtTestSignalHandler signalHandler;
failCount += QTest::qExec(&signalHandler, argc, argv);
PythonQtTestSlotCalling slotCalling;
failCount += QTest::qExec(&slotCalling, argc, argv);

PythonQt::cleanup();

if (Py_IsInitialized()) {
Py_Finalize();
}

return failCount;
}

}

struct StaticInitializer
Expand Down

0 comments on commit 2f35310

Please sign in to comment.