diff options
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/testqPrefDiveComputer.cpp | 124 | ||||
-rw-r--r-- | tests/testqPrefDiveComputer.h | 20 |
3 files changed, 146 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 855c4174d..10fd7dfe9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -104,6 +104,7 @@ TEST(TestTagList testtaglist.cpp) TEST(TestQPrefAnimations testqPrefAnimations.cpp) TEST(TestQPrefCloudStorage testqPrefCloudStorage.cpp) TEST(TestQPrefDisplay testqPrefDisplay.cpp) +TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp) add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> ${SUBSURFACE_SOURCE}/tests) @@ -125,6 +126,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestQPrefAnimations TestQPrefCloudStorage TestQPrefDisplay + TestQPrefDiveComputer TestQML ) diff --git a/tests/testqPrefDiveComputer.cpp b/tests/testqPrefDiveComputer.cpp new file mode 100644 index 000000000..e95b51432 --- /dev/null +++ b/tests/testqPrefDiveComputer.cpp @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefDiveComputer.h" + +#include "core/settings/qPref.h" +#include "core/pref.h" +#include "core/qthelper.h" + +#include <QTest> + +void TestQPrefDiveComputer::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefDiveComputer"); +} + +void TestQPrefDiveComputer::test_struct_get() +{ + // Test struct pref -> get func. + + auto tst = qPrefDiveComputer::instance(); + + prefs.dive_computer.device = copy_qstring("my device"); + prefs.dive_computer.device_name = copy_qstring("my device name"); + prefs.dive_computer.download_mode = 17; + prefs.dive_computer.product = copy_qstring("my product"); + prefs.dive_computer.vendor = copy_qstring("my vendor"); + + QCOMPARE(tst->device(), QString(prefs.dive_computer.device)); + QCOMPARE(tst->device_name(), QString(prefs.dive_computer.device_name)); + QCOMPARE(tst->download_mode(), prefs.dive_computer.download_mode); + QCOMPARE(tst->product(), QString(prefs.dive_computer.product)); + QCOMPARE(tst->vendor(), QString(prefs.dive_computer.vendor)); +} + +void TestQPrefDiveComputer::test_set_struct() +{ + // Test set func -> struct pref + + auto tst = qPrefDiveComputer::instance(); + + tst->set_device("t2 device"); + tst->set_device_name("t2 device name"); + tst->set_download_mode(27); + tst->set_product("t2 product"); + tst->set_vendor("t2 vendor"); + + QCOMPARE(QString(prefs.dive_computer.device), QString("t2 device")); + QCOMPARE(QString(prefs.dive_computer.device_name), QString("t2 device name")); + QCOMPARE(prefs.dive_computer.download_mode, 27); + QCOMPARE(QString(prefs.dive_computer.product), QString("t2 product")); + QCOMPARE(QString(prefs.dive_computer.vendor), QString("t2 vendor")); +} + +void TestQPrefDiveComputer::test_set_load_struct() +{ + // test set func -> load -> struct pref + + auto tst = qPrefDiveComputer::instance(); + + tst->set_device("t3 device"); + tst->set_device_name("t3 device name"); + tst->set_download_mode(37); + tst->set_product("t3 product"); + tst->set_vendor("t3 vendor"); + + prefs.dive_computer.device = copy_qstring("error1"); + prefs.dive_computer.device_name = copy_qstring("error2"); + prefs.dive_computer.download_mode = 38; + prefs.dive_computer.product = copy_qstring("error3"); + prefs.dive_computer.vendor = copy_qstring("error4"); + + tst->load(); + QCOMPARE(QString(prefs.dive_computer.device), QString("t3 device")); + QCOMPARE(QString(prefs.dive_computer.device_name), QString("t3 device name")); + QCOMPARE(prefs.dive_computer.download_mode, 37); + QCOMPARE(QString(prefs.dive_computer.product), QString("t3 product")); + QCOMPARE(QString(prefs.dive_computer.vendor), QString("t3 vendor")); +} + +void TestQPrefDiveComputer::test_struct_disk() +{ + // test struct prefs -> disk + + auto tst = qPrefDiveComputer::instance(); + + prefs.dive_computer.device = copy_qstring("t4 device"); + prefs.dive_computer.device_name = copy_qstring("t4 device name"); + prefs.dive_computer.download_mode = 47; + prefs.dive_computer.product = copy_qstring("t4 product"); + prefs.dive_computer.vendor = copy_qstring("t4 vendor"); + + tst->sync(); + + prefs.dive_computer.device = copy_qstring("error"); + prefs.dive_computer.device_name = copy_qstring("error"); + prefs.dive_computer.download_mode = 48; + prefs.dive_computer.product = copy_qstring("error"); + prefs.dive_computer.vendor = copy_qstring("error"); + + tst->load(); + + QCOMPARE(QString(prefs.dive_computer.device), QString("t4 device")); + QCOMPARE(QString(prefs.dive_computer.device_name), QString("t4 device name")); + QCOMPARE(prefs.dive_computer.download_mode, 47); + QCOMPARE(QString(prefs.dive_computer.product), QString("t4 product")); + QCOMPARE(QString(prefs.dive_computer.vendor), QString("t4 vendor")); +} + +void TestQPrefDiveComputer::test_multiple() +{ + // test multiple instances have the same information + prefs.dive_computer.download_mode = 57; + + auto tst_direct = new qPrefDiveComputer; + + prefs.dive_computer.download_mode = 25; + auto tst = qPrefDiveComputer::instance(); + + QCOMPARE(tst->download_mode(), tst_direct->download_mode()); +} + +QTEST_MAIN(TestQPrefDiveComputer) + diff --git a/tests/testqPrefDiveComputer.h b/tests/testqPrefDiveComputer.h new file mode 100644 index 000000000..df0e2cfef --- /dev/null +++ b/tests/testqPrefDiveComputer.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFDIVECOMPUTER_H +#define TESTQPREFDIVECOMPUTER_H + +#include <QObject> + +class TestQPrefDiveComputer : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void test_struct_get(); + void test_set_struct(); + void test_set_load_struct(); + void test_struct_disk(); + void test_multiple(); +}; + +#endif // TESTQPREFDIVECOMPUTER_H |