Skip to content

Commit

Permalink
ENH: Update ctkFileDialogTest1 to check UseNativeDialogs & DoNotUseNa…
Browse files Browse the repository at this point in the history
…tiveDialogs
  • Loading branch information
jcfr committed Jan 13, 2024
1 parent 02d3bf1 commit ca30d69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Libs/Widgets/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ SIMPLE_TEST( ctkExampleUseOfWorkflowWidgetUsingSignalsAndSlots )
SIMPLE_TEST( ctkExpandableWidgetTest1 )
SIMPLE_TEST( ctkExpandButtonTest1 )
SIMPLE_TEST( ctkFlatProxyModelTest )
SIMPLE_TEST( ctkFileDialogTest1 )
set(ctkFileDialogTest1UseNativeDialogs_TEST "ctkFileDialogTest1")
SIMPLE_TEST( ctkFileDialogTest1UseNativeDialogs )
set(ctkFileDialogTest1DoNotUseNativeDialogs_TEST "ctkFileDialogTest1")
SIMPLE_TEST( ctkFileDialogTest1DoNotUseNativeDialogs "--do-not-use-native-dialogs")
SIMPLE_TEST( ctkFittedTextBrowserTest1 )
SIMPLE_TEST( ctkFlowLayoutTest1 )
SIMPLE_TEST( ctkFontButtonTest )
Expand Down
20 changes: 18 additions & 2 deletions Libs/Widgets/Testing/Cpp/ctkFileDialogTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// Qt includes
#include <QApplication>
#include <QCheckBox>
#include <QCommandLineParser>

// CTK includes
#include "ctkCoreTestingMacros.h"
Expand Down Expand Up @@ -80,7 +81,22 @@ int ctkFileDialogTest1(int argc, char * argv [] )
{
QApplication app(argc, argv);

QCommandLineParser parser;
parser.addOptions(
{
{"I", "Run in interactive mode"},
{"do-not-use-native-dialogs", "Do not use native dialogs"},
});
parser.process(app);

QStringList arguments = app.arguments();
arguments.pop_front(); // remove application name

bool skipNativeDialogs = parser.isSet("do-not-use-native-dialogs");
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, skipNativeDialogs);

ctkFileDialog fileDialog;
CHECK_BOOL(fileDialog.testOption(ctkFileDialog::DontUseNativeDialog), skipNativeDialogs);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setNameFilter("Images (*.png *.xpm *.jpg)");
fileDialog.setViewMode(QFileDialog::Detail);
Expand All @@ -89,14 +105,14 @@ int ctkFileDialogTest1(int argc, char * argv [] )

// A bottom widget can be associated with the file dialog only
// if using the non-native dialog.
bool supportBottomWidget = false;
bool supportBottomWidget = skipNativeDialogs;

CHECK_POINTER(fileDialog.bottomWidget(), supportBottomWidget ? checkBox : nullptr);

CHECK_EXIT_SUCCESS(testSelectionMode(&fileDialog, supportBottomWidget));

// the following is only in interactive mode
if (argc < 2 || QString(argv[1]) != "-I" )
if (!parser.isSet("I"))
{
return EXIT_SUCCESS;
}
Expand Down

0 comments on commit ca30d69

Please sign in to comment.