Skip to content

Commit 2b086ff

Browse files
committed
BUG: Ensure Qt reserved arguments are passed to the launched application
This commit adds a test checking that Qt reserved arguments are effectively passed to the launched application. It fixes a regression likely introduced in 36e8c12 (Don't instantiate QApplication if no splash screen is used).
1 parent 26ddea4 commit 2b086ff

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

Base/ctkAppLauncher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ void ctkAppLauncher::setApplication(const QCoreApplication& app)
993993
{
994994
Q_D(ctkAppLauncher);
995995
d->Application = app.instance();
996-
if (d->Application)
996+
if (d->Application && d->Arguments.empty())
997997
{
998998
this->setArguments(d->Application->arguments());
999999
}

Testing/Launcher/App4Test/Main.cpp.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,36 @@ int main(int argc, char** argv)
220220
return EXIT_FAILURE;
221221
}
222222
}
223+
else if (argName == "--check-reserved-argument")
224+
{
225+
std::string expectedArgName2("-widgetcount");
226+
int expectedArgCount = 3;
227+
if (argc != expectedArgCount)
228+
{
229+
std::cerr << "Unexpected number of arguments"
230+
<< "\n\texpected: " << expectedArgCount
231+
<< "\n\t current: " << argc
232+
<< std::endl;
233+
std::cerr << "Argument passed:" << argName;
234+
for(int i=2; i < argc; i++)
235+
{
236+
std::cerr << " " << argv[i];
237+
}
238+
std::cerr << std::endl;
239+
return EXIT_FAILURE;
240+
}
241+
std::string argName2(argv[2]);
242+
if (argName2 != expectedArgName2)
243+
{
244+
std::cerr << "Unexpected argument #2:"
245+
<< "\n\texpected: " << expectedArgName2
246+
<< "\n\t current: " << argName2
247+
<< std::endl;
248+
display_arguments(std::cerr, argc, argv);
249+
return EXIT_FAILURE;
250+
}
251+
std::cout << expectedArgName2 << " argument passed" << std::endl;
252+
}
223253
}
224254
else if (argc == 1)
225255
{

Testing/Launcher/AppLauncher-Param-TestQtReservedArgs.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ size=1
1818
set(PRINT_COMMAND 0)
1919

2020
# --------------------------------------------------------------------------
21-
# Make sure the launcher do not consider Qt reserved argument
22-
set(command ${launcher_exe} -widgetcount --launcher-no-splash)
21+
# Make sure that (1) the launcher do not consider Qt reserved argument
22+
# and (2) the launched application consider Qt reserved argument
23+
set(command ${launcher_exe} --check-reserved-argument -widgetcount)
2324
execute_process(
2425
COMMAND ${command}
2526
WORKING_DIRECTORY ${launcher_binary_dir}
@@ -39,3 +40,6 @@ if("${ev}" MATCHES "Widgets left.*")
3940
message(FATAL_ERROR "error_variable [${ev}] shouldn't contain 'Widgets left'")
4041
endif()
4142

43+
if(NOT "${ov}" MATCHES "-widgetcount argument passed")
44+
message(FATAL_ERROR "output_variable [${ov}] should contain '-widgetcount argument passed'")
45+
endif()

Testing/Launcher/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ applauncher_add_test(AppLauncher-Param-TestLauncherTimeout)
147147
applauncher_add_test(AppLauncher-Param-TestLauncherVerbose)
148148
applauncher_add_test(AppLauncher-Param-TestLauncherVersion)
149149
applauncher_add_test(AppLauncher-Param-TestQtReservedArgs)
150+
set_property(TEST "${testname}" APPEND PROPERTY LABELS "XDisplayRequired")
150151

151152
applauncher_add_test(AppLauncher-Settings-TestApplicationArguments)
152153
applauncher_add_test(AppLauncher-Settings-TestApplicationPath)

0 commit comments

Comments
 (0)