Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-07-14 08:10:35 -07:00
commit cf329ca131
7 changed files with 126 additions and 47 deletions

View file

@ -1,4 +1,4 @@
- tests: add qml test harness
- Dive media: sort thumbnails by timestamp
- Dive media: don't recalculate all pictures on drag & drop
- Profile: immediately update thumbnail positions on deletion

View file

@ -224,9 +224,9 @@ if(BTSUPPORT)
list(APPEND QT_EXTRA_LIBRARIES Qt5::Bluetooth)
endif()
find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network Svg Test LinguistTools Positioning Quick Location ${QT_EXTRA_COMPONENTS})
find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network Svg Test QuickTest LinguistTools Positioning Quick Location ${QT_EXTRA_COMPONENTS})
set(QT_LIBRARIES Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network Qt5::Svg Qt5::Positioning Qt5::Quick Qt5::Location ${QT_EXTRA_LIBRARIES})
set(QT_TEST_LIBRARIES ${QT_LIBRARIES} Qt5::Test)
set(QT_TEST_LIBRARIES ${QT_LIBRARIES} Qt5::Test Qt5::QuickTest)
#disable bluetooth if Qt version is ancient.
if (BTSUPPORT AND Qt5Widgets_VERSION VERSION_LESS 5.4.0)

View file

@ -28,6 +28,7 @@
#include "core/pluginmanager.h"
#endif
#ifndef SUBSURFACE_TEST_DATA
QObject *qqWindowObject = NULL;
void init_ui()
@ -39,14 +40,14 @@ void init_ui()
MainWindow *window = new MainWindow();
window->setTitle();
#endif
#endif // SUBSURFACE_MOBILE
}
void exit_ui()
{
#ifndef SUBSURFACE_MOBILE
delete MainWindow::instance();
#endif
#endif // SUBSURFACE_MOBILE
delete qApp;
free((void *)existing_filename);
}
@ -57,45 +58,6 @@ double get_screen_dpi()
return mydesk->physicalDpiX();
}
void register_qml_types()
{
int rc;
rc = qmlRegisterType<qPref>("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register Prefs (class qPref), QML will not work!!";
rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!";
#ifdef SUBSURFACE_MOBILE
rc = qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
if (rc < 0)
qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!";
rc = qmlRegisterType<QMLPrefs>("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!";
rc = qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
if (rc < 0)
qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!";
rc = qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
if (rc < 0)
qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!";
rc = qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
if (rc < 0)
qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!";
#endif
rc = qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
if (rc < 0)
qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!";
rc = qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
if (rc < 0)
qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!";
rc = qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
if (rc < 0)
qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!";
}
void run_ui()
{
@ -115,7 +77,7 @@ void run_ui()
engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
}
qDebug() << "QML import path" << engine.importPathList();
#endif
#endif // __APPLE__ not Q_OS_IOS
engine.addImportPath("qrc://imports");
DiveListModel diveListModel;
LOG_STP("run_ui diveListModel started");
@ -167,11 +129,53 @@ void run_ui()
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
qml_window->setHeight(1200);
qml_window->setWidth(800);
#endif
#endif // not Q_OS_ANDROID and not Q_OS_IOS
qml_window->show();
LOG_STP("run_ui running exec");
#else
MainWindow::instance()->show();
#endif
#endif // SUBSURFACE_MOBILE
qApp->exec();
}
#endif // not SUBSURFACE_TEST_DATA
void register_qml_types()
{
int rc;
rc = qmlRegisterType<qPref>("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register Prefs (class qPref), QML will not work!!";
rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!";
#ifndef SUBSURFACE_TEST_DATA
#ifdef SUBSURFACE_MOBILE
rc = qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
if (rc < 0)
qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!";
rc = qmlRegisterType<QMLPrefs>("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs");
if (rc < 0)
qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!";
rc = qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
if (rc < 0)
qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!";
rc = qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
if (rc < 0)
qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!";
rc = qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
if (rc < 0)
qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!";
#endif // not SUBSURFACE_MOBILE
rc = qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
if (rc < 0)
qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!";
rc = qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
if (rc < 0)
qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!";
rc = qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
if (rc < 0)
qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!";
#endif // not SUBSURFACE_TEST_DATA
}

1
tests/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.qmlc

View file

@ -76,6 +76,18 @@ enable_testing()
add_definitions(-g)
add_definitions(-DSUBSURFACE_TEST_DATA="${SUBSURFACE_TEST_DATA}")
# Build QML test runner
# add_executable demands relative path, therefore ../
add_executable(TestQML testqml.cpp ../subsurface-helper.cpp )
target_link_libraries(
TestQML
subsurface_corelib
RESOURCE_LIBRARY
${QT_TEST_LIBRARIES}
${SUBSURFACE_LINK_LIBRARIES}
)
# SSRF test cases (TBD, convert to standard qTest setup)
TEST(TestUnitConversion testunitconversion.cpp)
TEST(TestProfile testprofile.cpp)
TEST(TestGpsCoords testgpscoords.cpp)
@ -88,6 +100,7 @@ TEST(TestPreferences testpreferences.cpp)
TEST(TestPicture testpicture.cpp)
TEST(TestMerge testmerge.cpp)
TEST(TestTagList testtaglist.cpp)
add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> ${SUBSURFACE_SOURCE}/tests)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
@ -104,6 +117,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestPicture
TestMerge
TestTagList
TestQML
)
# useful for debugging CMake issues

43
tests/testqml.cpp Normal file
View file

@ -0,0 +1,43 @@
// SPDX-License-Identifier: GPL-2.0
#include <QQmlEngine>
#include <QtQuickTest>
#include <QtTest>
#include <QQmlEngine>
#include <QQmlContext>
#include "core/settings/qPref.h"
#include "core/qt-gui.h"
// this is the content of QUICK_TEST_MAIN amended with
// registration of ssrf classes
int main(int argc, char **argv)
{
// QML testing is not supported in the oldest Qt versions we support
// if running with Qt version less than 5.10 then skip test
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
QTEST_ADD_GPU_BLACKLIST_SUPPORT
QTEST_SET_MAIN_SOURCE_PATH
// check that qPref exists
new qPref;
// check that we have a directory
if (argc < 2) {
qDebug() << "ERROR: missing tst_* directory";
return -1;
}
// save tst_dir and pass rest to Qt
const char *tst_dir = argv[1];
for (int i = 1; i < argc; i++)
argv[i] = argv[i+1];
argc--;
// Register types
register_qml_types();
// Run all tst_*.qml files
return quick_test_main(argc, argv, "TestQML", tst_dir);
#else
return 0;
#endif
}

17
tests/tst_qPref.qml Normal file
View file

@ -0,0 +1,17 @@
// SPDX-License-Identifier: GPL-2.0
import QtQuick 2.6
import QtTest 1.2
import org.subsurfacedivelog.mobile 1.0
TestCase {
name: "qPref"
SsrfPrefs {
id: prefs
}
function test_register() {
var x = prefs.mobile_version
compare(x, prefs.mobile_version)
}
}