Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test driver for GUI. #918

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ project(gpsbabel LANGUAGES C CXX VERSION ${GB.VERSION})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

enable_testing()

# Do this after we set up common variables but before creating other
# variables that will be inherited.
add_subdirectory(gui)
Expand Down Expand Up @@ -455,7 +457,6 @@ list(SORT TESTS)
if(UNIX)
# This test only works if the pwd is top level source dir due to the
# file name getting embedded in the file nonexistent.err.
enable_testing()
foreach(TESTNAME IN LISTS TESTS)
add_test(NAME test-${TESTNAME}
COMMAND ${CMAKE_SOURCE_DIR}/testo -p $<TARGET_FILE:gpsbabel> ${TESTNAME}
Expand Down
67 changes: 59 additions & 8 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@ set(CMAKE_AUTOUIC ON)
# Handle the Qt rcc code generator automatically
set(CMAKE_AUTORCC ON)

add_executable(gpsbabelfe WIN32 MACOSX_BUNDLE)
add_library(gpsbabelfe_lib STATIC)

set(CMAKE_AUTOMOC OFF)
set(CMAKE_AUTOUIC OFF)

add_executable(gpsbabelfe WIN32 MACOSX_BUNDLE main.cc)
if(NOT UNIX OR APPLE)
set_target_properties(gpsbabelfe PROPERTIES OUTPUT_NAME GPSBabelFE)
endif()

# Don't set WIN32 on TESTTARGET, we want to see qDebug messages.
add_executable(gpsbabelfe_test MACOSX_BUNDLE EXCLUDE_FROM_ALL test_main.cc test_main.h)

# Find the QtCore library
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Network SerialPort Widgets Xml REQUIRED)
list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::SerialPort Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Xml)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Network SerialPort Widgets Xml Test REQUIRED)
list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::SerialPort Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Xml Qt${QT_VERSION_MAJOR}::Test)
if(${Qt${QT_VERSION_MAJOR}Core_VERSION} VERSION_LESS 5.12)
message(FATAL_ERROR "Qt version ${Qt${QT_VERSION_MAJOR}Core_VERSION} found, but version 5.12 or newer is required.")
else()
Expand All @@ -36,11 +44,19 @@ if (GPSBABEL_MAPPREVIEW)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebEngineWidgets WebChannel REQUIRED)
list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::WebEngineWidgets Qt${QT_VERSION_MAJOR}::WebChannel)
else()
target_compile_definitions(gpsbabelfe PRIVATE DISABLE_MAPPREVIEW)
target_compile_definitions(gpsbabelfe_lib PRIVATE DISABLE_MAPPREVIEW)
endif()

if (${QT_VERSION_MAJOR} EQUAL "5")
qt5_wrap_cpp(TESTTARGET_MOC test_main.h TARGET gpsbabelfe_test)
else()
qt_wrap_cpp(TESTTARGET_MOC test_main.h TARGET gpsbabelfe_test)
endif()
target_sources(gpsbabelfe_test PRIVATE ${TESTTARGET_MOC})

if(UNIX AND NOT APPLE)
set_target_properties(gpsbabelfe PROPERTIES RUNTIME_OUTPUT_DIRECTORY GPSBabelFE)
set_target_properties(gpsbabelfe_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY GPSBabelFE_test)
endif()

# RESOURCES
Expand Down Expand Up @@ -82,7 +98,6 @@ if (GPSBABEL_MAPPREVIEW)
endif()
list(APPEND SOURCES help.cc)
list(APPEND SOURCES latlng.cc)
list(APPEND SOURCES main.cc)
list(APPEND SOURCES mainwindow.cc)
if (GPSBABEL_MAPPREVIEW)
list(APPEND SOURCES map.cc)
Expand Down Expand Up @@ -137,28 +152,52 @@ else()
endif()
if (GPSBABEL_EMBED_TRANSLATIONS)
list(APPEND RESOURCES translations.qrc)
target_compile_definitions(gpsbabelfe PRIVATE HAVE_EMBEDDED_TRANSLATIONS)
target_compile_definitions(gpsbabelfe_test PRIVATE HAVE_EMBEDDED_TRANSLATIONS)
endif()
if (GPSBABEL_EMBED_MAP)
list(APPEND RESOURCES map.qrc)
target_compile_definitions(gpsbabelfe PRIVATE HAVE_EMBEDDED_MAP)
target_compile_definitions(gpsbabelfe_test PRIVATE HAVE_EMBEDDED_MAP)
endif()

target_sources(gpsbabelfe_lib PRIVATE ${SOURCES} ${HEADERS} ${RESOURCES})
if(APPLE)
set(MACOSX_BUNDLE_ICON_FILE appicon.icns)
set(ICON_FILE images/${MACOSX_BUNDLE_ICON_FILE})
set_source_files_properties(${ICON_FILE} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)

target_sources(gpsbabelfe PRIVATE ${SOURCES} ${HEADERS} ${ICON_FILE} ${RESOURCES})
target_sources(gpsbabelfe PRIVATE ${HEADERS} ${ICON_FILE})
target_sources(gpsbabelfe_test PRIVATE ${HEADERS} ${ICON_FILE})

# Info.plist has not been debugged with the cmake flow, it's a bit different than with the qmake flow.
set_target_properties(gpsbabelfe PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER org.gpsbabel.gpsbabelfe
MACOSX_BUNDLE_ICON_FILE ${MACOSX_BUNDLE_ICON_FILE}
)
set_target_properties(gpsbabelfe_test PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER org.gpsbabel.gpsbabelfe_test
MACOSX_BUNDLE_ICON_FILE ${MACOSX_BUNDLE_ICON_FILE}
)
else()
target_sources(gpsbabelfe PRIVATE ${HEADERS})
target_sources(gpsbabelfe_test PRIVATE ${HEADERS})
endif()

get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set(AUTOGEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/gpsbabelfe_lib_autogen/include_$<CONFIG>)
else()
target_sources(gpsbabelfe PRIVATE ${SOURCES} ${HEADERS} ${RESOURCES})
set(AUTOGEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/gpsbabelfe_lib_autogen/include)
endif()
target_include_directories(gpsbabelfe_lib INTERFACE $<BUILD_INTERFACE:${AUTOGEN_INCLUDE_DIR}>)

target_link_libraries(gpsbabelfe ${QT_LIBRARIES})
target_link_libraries(gpsbabelfe gpsbabelfe_lib ${QT_LIBRARIES})
target_link_libraries(gpsbabelfe_test gpsbabelfe_lib ${QT_LIBRARIES})
target_link_libraries(gpsbabelfe_lib ${QT_LIBRARIES})

get_target_property(idirs gpsbabelfe_lib INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "lib incs \"${idirs}\"")

get_target_property(Srcs gpsbabelfe SOURCES)
message(STATUS "Sources are: \"${Srcs}\"")
Expand All @@ -169,6 +208,18 @@ message(STATUS "Libs are: \"${LnkLibs}\"")
get_target_property(IncDirs gpsbabelfe INCLUDE_DIRECTORIES)
message(STATUS "Include Directores are: \"${IncDirs}\"")

add_custom_command(
TARGET gpsbabelfe_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:gpsbabel>" "$<TARGET_FILE_DIR:gpsbabelfe_test>/gpsbabel"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/gmapbase.html" "$<TARGET_FILE_DIR:gpsbabelfe_test>"
VERBATIM
)

add_test(NAME test-gui
COMMAND gpsbabelfe_test
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

find_package(Qt${QT_VERSION_MAJOR} QUIET COMPONENTS LinguistTools)
if (NOT Qt${QT_VERSION_MAJOR}LinguistTools_FOUND)
message(WARNING "Qt${QT_VERSION_MAJOR}LinguistTools not found, gpsbabelfe translations cannot be updated or released, and application cannot be packaged.")
Expand Down
2 changes: 2 additions & 0 deletions gui/aboutdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

class AboutDlg: public QDialog
{
Q_OBJECT

public:
AboutDlg(QWidget* parent, const QString& ver1,
const QString& ver2, const QString& ver3,
Expand Down
1 change: 1 addition & 0 deletions gui/filterdlg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ FilterDialog::FilterDialog(QWidget* parent, AllFiltersData& fd): QDialog(parent)
ui_.filterList->clear();

widgetStack_ = new QStackedWidget(ui_.frame);
widgetStack_->setObjectName("widgetStack");
auto* layout = new QHBoxLayout(ui_.frame);
layout->addWidget(widgetStack_);
layout->setContentsMargins(2, 2, 2, 2);
Expand Down
8 changes: 8 additions & 0 deletions gui/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ int main(int argc, char** argv)
#error this version of Qt is not supported.
#endif

Q_INIT_RESOURCE(app);
#ifdef HAVE_EMBEDDED_MAP
Q_INIT_RESOURCE(map);
#endif
#ifdef HAVE_EMBEDDED_TRANSLATIONS
Q_INIT_RESOURCE(translations);
#endif

QApplication app(argc, argv);
QApplication::setWindowIcon(QIcon(":/images/appicon.png"));
QApplication::setOrganizationName("GPSBabel");
Expand Down
1 change: 0 additions & 1 deletion gui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,6 @@ void MainWindow::applyActionX()
if (babelData_.previewGmap_) {
this->hide();
GMapDialog dlg(nullptr, tempName, babelData_.debugLevel_ >=1 ? ui_.outputWindow : nullptr);
dlg.show();
dlg.exec();
QFile(tempName).remove();
this->show();
Expand Down
11 changes: 11 additions & 0 deletions gui/optionsdlg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt
}
auto* verticalLayout = new QVBoxLayout(this);
for (int k=0; k<options_.size(); k++) {
QString objName = fmtName_ + '_' + options_[k].getName();
auto* horizontalLayout = new QHBoxLayout();

auto* checkBox = new QCheckBox(this);
checkBox->setObjectName(objName);
checkBox->setText(options_[k].getDescription());
horizontalLayout->addWidget(checkBox);
checkBox->setChecked(options_[k].getSelected());
Expand All @@ -106,6 +108,7 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt
switch (options_[k].getType()) {
case FormatOption::OPTstring: {
auto* lineEdit = new QLineEdit(this);
lineEdit->setObjectName(objName);
SetSizeStuff(lineEdit);
lineEdit->setText(getOptionValue(options_, k).toString());
w = lineEdit;
Expand All @@ -117,7 +120,9 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt
case FormatOption::OPToutFile: {
bool inFile = options_[k].getType() == FormatOption::OPTinFile;
auto* lineEdit = new QLineEdit(this);
lineEdit->setObjectName(objName);
auto* button = new QToolButton(this);
button->setObjectName(objName);
lineEdit->setText(getOptionValue(options_, k).toString());
button->setIcon(QIcon(inFile ? ":/images/open.png" : ":/images/save.png"));
w = lineEdit;
Expand All @@ -136,6 +141,7 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt

case FormatOption::OPTfloat: {
auto* lineEdit = new QLineEdit(this);
lineEdit->setObjectName(objName);
SetSizeStuff(lineEdit);
lineEdit->setText(getOptionValue(options_, k).toString());
w = lineEdit;
Expand All @@ -152,6 +158,7 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt

case FormatOption::OPTint: {
auto* lineEdit = new QLineEdit(this);
lineEdit->setObjectName(objName);
SetSizeStuff(lineEdit);
w = lineEdit;
int minVal = options_[k].getMinValue().toInt();
Expand All @@ -168,6 +175,7 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt

case FormatOption::OPTboundedInt: {
auto* spinBox = new QSpinBox(this);
spinBox->setObjectName(objName);
spinBox->setRange(options_[k].getMinValue().toInt(),
options_[k].getMaxValue().toInt());
spinBox->setValue(getOptionValue(options_, k).toInt());
Expand All @@ -185,6 +193,7 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt
// functions added in Qt5. Not worth it right now, but
// an idea worth picking up later.
QPushButton* help = new QPushButton(tr("Help"), this);
help->setObjectName(objName);
help->setIcon(QIcon(":/images/help.png"));
help->setProperty("page", options[k].getHtml();)
connect(help, SIGNAL(clicked()), this, SLOT(helpClicked()));
Expand All @@ -194,13 +203,15 @@ OptionsDlg::OptionsDlg(QWidget* parent, const QString& fmtName, QList<FormatOpt
verticalLayout->addLayout(horizontalLayout);
}
auto* helpButton = new QPushButton(this);
helpButton->setObjectName("helpButton");
helpButton->setIcon(QIcon(":/images/help.png"));
helpButton->setText(tr("Help"));

auto* lay = new QHBoxLayout();
lay->addWidget(helpButton);

buttonBox_ = new QDialogButtonBox(this);
buttonBox_->setObjectName("buttonBox");
buttonBox_->setOrientation(Qt::Horizontal);
buttonBox_->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
lay->addWidget(buttonBox_);
Expand Down
Loading