summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/testqPrefEquipment.cpp109
-rw-r--r--tests/testqPrefEquipment.h20
-rw-r--r--tests/testqPrefGeneral.cpp18
-rw-r--r--tests/testqPrefTechnicalDetails.cpp19
5 files changed, 131 insertions, 37 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 887e1b34d..07452f7a1 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -110,6 +110,7 @@ TEST(TestQPrefDisplay testqPrefDisplay.cpp)
TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp)
TEST(TestQPrefDivePlanner testqPrefDivePlanner.cpp)
TEST(TestQPrefGeneral testqPrefGeneral.cpp)
+TEST(TestQPrefEquipment testqPrefEquipment.cpp)
TEST(TestQPrefGeocoding testqPrefGeocoding.cpp)
TEST(TestQPrefLanguage testqPrefLanguage.cpp)
TEST(TestQPrefLocationService testqPrefLocationService.cpp)
@@ -141,6 +142,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestQPrefDiveComputer
TestQPrefDivePlanner
TestQPrefGeneral
+ TestQPrefEquipment
TestQPrefGeocoding
TestQPrefLanguage
TestQPrefLocationService
diff --git a/tests/testqPrefEquipment.cpp b/tests/testqPrefEquipment.cpp
new file mode 100644
index 000000000..29d1baccb
--- /dev/null
+++ b/tests/testqPrefEquipment.cpp
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "testqPrefEquipment.h"
+
+#include "core/pref.h"
+#include "core/qthelper.h"
+#include "core/settings/qPrefEquipment.h"
+#include "core/settings/qPref.h"
+
+#include <QTest>
+#include <QSignalSpy>
+
+void TestQPrefEquipment::initTestCase()
+{
+ QCoreApplication::setOrganizationName("Subsurface");
+ QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
+ QCoreApplication::setApplicationName("SubsurfaceTestQPrefEquipment");
+ qPref::registerQML(NULL);
+}
+
+void TestQPrefEquipment::test_struct_get()
+{
+ // Test struct pref -> get func.
+
+ auto tst = qPrefEquipment::instance();
+ prefs.default_cylinder = copy_qstring("new base11");
+ QCOMPARE(tst->default_cylinder(), QString(prefs.default_cylinder));
+ prefs.display_unused_tanks = true;
+ QCOMPARE(tst->display_unused_tanks(), prefs.display_unused_tanks);
+}
+
+void TestQPrefEquipment::test_set_struct()
+{
+ // Test set func -> struct pref
+
+ auto tst = qPrefEquipment::instance();
+ tst->set_default_cylinder("new base21");
+ QCOMPARE(QString(prefs.default_cylinder), QString("new base21"));
+ tst->set_display_unused_tanks(false);
+ QCOMPARE(prefs.display_unused_tanks, false);
+}
+
+void TestQPrefEquipment::test_set_load_struct()
+{
+ // test set func -> load -> struct pref
+
+ auto tst = qPrefEquipment::instance();
+
+ tst->set_default_cylinder("new base31");
+ prefs.default_cylinder = copy_qstring("error");
+ tst->set_display_unused_tanks(false);
+ prefs.display_unused_tanks = true;
+ tst->load();
+ QCOMPARE(QString(prefs.default_cylinder), QString("new base31"));
+ QCOMPARE(prefs.display_unused_tanks, false);
+}
+
+void TestQPrefEquipment::test_struct_disk()
+{
+ // test struct prefs -> disk
+
+ auto tst = qPrefEquipment::instance();
+ prefs.default_cylinder = copy_qstring("base41");
+ prefs.display_unused_tanks = true;
+
+ tst->sync();
+ prefs.default_cylinder = copy_qstring("error");
+ prefs.display_unused_tanks = false;
+
+ tst->load();
+ QCOMPARE(QString(prefs.default_cylinder), QString("base41"));
+ QCOMPARE(prefs.display_unused_tanks, true);
+
+}
+
+#define TEST(METHOD, VALUE) \
+ QCOMPARE(METHOD, VALUE); \
+ equipment->sync(); \
+ equipment->load(); \
+ QCOMPARE(METHOD, VALUE);
+
+void TestQPrefEquipment::test_oldPreferences()
+{
+ auto equipment = qPrefEquipment::instance();
+ equipment->set_default_cylinder("cylinder_2");
+ TEST(equipment->default_cylinder(), QStringLiteral("cylinder_2"));
+ equipment->set_default_cylinder("cylinder_1");
+ TEST(equipment->default_cylinder(), QStringLiteral("cylinder_1"));
+ equipment->set_display_unused_tanks(true);
+ TEST(equipment->display_unused_tanks(), true);
+ equipment->set_display_unused_tanks(false);
+ TEST(equipment->display_unused_tanks(), false);
+}
+
+void TestQPrefEquipment::test_signals()
+{
+ QSignalSpy spy1(qPrefEquipment::instance(), &qPrefEquipment::default_cylinderChanged);
+ QSignalSpy spy2(qPrefEquipment::instance(), &qPrefEquipment::display_unused_tanksChanged);
+
+ qPrefEquipment::set_default_cylinder("new base21");
+ QCOMPARE(spy1.count(), 1);
+ QVERIFY(spy1.takeFirst().at(0).toBool() == false);
+
+ prefs.display_unused_tanks = true;
+ qPrefEquipment::set_display_unused_tanks(false);
+ QCOMPARE(spy2.count(), 1);
+ QVERIFY(spy2.takeFirst().at(0).toBool() == false);
+}
+
+QTEST_MAIN(TestQPrefEquipment)
diff --git a/tests/testqPrefEquipment.h b/tests/testqPrefEquipment.h
new file mode 100644
index 000000000..b9a4bcee2
--- /dev/null
+++ b/tests/testqPrefEquipment.h
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQPREFEQUIPMENT_H
+#define TESTQPREFEQUIPMENT_H
+
+#include <QObject>
+
+class TestQPrefEquipment : 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_oldPreferences();
+ void test_signals();
+};
+
+#endif // TESTQPREFEQUIPMENT_H
diff --git a/tests/testqPrefGeneral.cpp b/tests/testqPrefGeneral.cpp
index 29ff6a811..1463b914b 100644
--- a/tests/testqPrefGeneral.cpp
+++ b/tests/testqPrefGeneral.cpp
@@ -24,7 +24,6 @@ void TestQPrefGeneral::test_struct_get()
auto tst = qPrefGeneral::instance();
prefs.auto_recalculate_thumbnails = true;
- prefs.default_cylinder = copy_qstring("new base11");
prefs.default_filename = copy_qstring("new base12");
prefs.default_file_behavior = UNDEFINED_DEFAULT_FILE;
prefs.defaultsetpoint = 14;
@@ -36,7 +35,6 @@ void TestQPrefGeneral::test_struct_get()
prefs.use_default_file = true;
QCOMPARE(tst->auto_recalculate_thumbnails(), prefs.auto_recalculate_thumbnails);
- QCOMPARE(tst->default_cylinder(), QString(prefs.default_cylinder));
QCOMPARE(tst->default_filename(), QString(prefs.default_filename));
QCOMPARE(tst->default_file_behavior(), prefs.default_file_behavior);
QCOMPARE(tst->defaultsetpoint(), prefs.defaultsetpoint);
@@ -55,7 +53,6 @@ void TestQPrefGeneral::test_set_struct()
auto tst = qPrefGeneral::instance();
tst->set_auto_recalculate_thumbnails(false);
- tst->set_default_cylinder("new base21");
tst->set_default_filename("new base22");
tst->set_default_file_behavior(LOCAL_DEFAULT_FILE);
tst->set_defaultsetpoint(24);
@@ -69,7 +66,6 @@ void TestQPrefGeneral::test_set_struct()
tst->set_diveshareExport_private(false);
QCOMPARE(prefs.auto_recalculate_thumbnails, false);
- QCOMPARE(QString(prefs.default_cylinder), QString("new base21"));
QCOMPARE(QString(prefs.default_filename), QString("new base22"));
QCOMPARE(prefs.default_file_behavior, LOCAL_DEFAULT_FILE);
QCOMPARE(prefs.defaultsetpoint, 24);
@@ -90,7 +86,6 @@ void TestQPrefGeneral::test_set_load_struct()
auto tst = qPrefGeneral::instance();
tst->set_auto_recalculate_thumbnails(true);
- tst->set_default_cylinder("new base31");
tst->set_default_filename("new base32");
tst->set_default_file_behavior(NO_DEFAULT_FILE);
tst->set_defaultsetpoint(34);
@@ -104,7 +99,6 @@ void TestQPrefGeneral::test_set_load_struct()
tst->set_diveshareExport_private(true);
prefs.auto_recalculate_thumbnails = false;
- prefs.default_cylinder = copy_qstring("error");
prefs.default_filename = copy_qstring("error");
prefs.default_file_behavior = UNDEFINED_DEFAULT_FILE;
prefs.defaultsetpoint = 14;
@@ -117,7 +111,6 @@ void TestQPrefGeneral::test_set_load_struct()
tst->load();
QCOMPARE(prefs.auto_recalculate_thumbnails, true);
- QCOMPARE(QString(prefs.default_cylinder), QString("new base31"));
QCOMPARE(QString(prefs.default_filename), QString("new base32"));
QCOMPARE(prefs.default_file_behavior, NO_DEFAULT_FILE);
QCOMPARE(prefs.defaultsetpoint, 34);
@@ -138,7 +131,6 @@ void TestQPrefGeneral::test_struct_disk()
auto tst = qPrefGeneral::instance();
prefs.auto_recalculate_thumbnails = true;
- prefs.default_cylinder = copy_qstring("base41");
prefs.default_filename = copy_qstring("base42");
prefs.default_file_behavior = CLOUD_DEFAULT_FILE;
prefs.defaultsetpoint = 44;
@@ -151,7 +143,6 @@ void TestQPrefGeneral::test_struct_disk()
tst->sync();
prefs.auto_recalculate_thumbnails = false;
- prefs.default_cylinder = copy_qstring("error");
prefs.default_filename = copy_qstring("error");
prefs.default_file_behavior = UNDEFINED_DEFAULT_FILE;
prefs.defaultsetpoint = 14;
@@ -164,7 +155,6 @@ void TestQPrefGeneral::test_struct_disk()
tst->load();
QCOMPARE(prefs.auto_recalculate_thumbnails, true);
- QCOMPARE(QString(prefs.default_cylinder), QString("base41"));
QCOMPARE(QString(prefs.default_filename), QString("base42"));
QCOMPARE(prefs.default_file_behavior, CLOUD_DEFAULT_FILE);
QCOMPARE(prefs.defaultsetpoint, 44);
@@ -201,7 +191,6 @@ void TestQPrefGeneral::test_oldPreferences()
auto general = qPrefGeneral::instance();
general->set_default_filename("filename");
- general->set_default_cylinder("cylinder_2");
general->set_default_file_behavior(LOCAL_DEFAULT_FILE);
general->set_defaultsetpoint(0);
general->set_o2consumption(0);
@@ -209,7 +198,6 @@ void TestQPrefGeneral::test_oldPreferences()
general->set_use_default_file(true);
TEST(general->default_filename(), QStringLiteral("filename"));
- TEST(general->default_cylinder(), QStringLiteral("cylinder_2"));
TEST(general->default_file_behavior(), LOCAL_DEFAULT_FILE); // since we have a default file, here it returns
TEST(general->defaultsetpoint(), 0);
TEST(general->o2consumption(), 0);
@@ -217,7 +205,6 @@ void TestQPrefGeneral::test_oldPreferences()
TEST(general->use_default_file(), true);
general->set_default_filename("no_file_name");
- general->set_default_cylinder("cylinder_1");
//TODOl: Change this to a enum.
general->set_default_file_behavior(CLOUD_DEFAULT_FILE);
@@ -227,7 +214,6 @@ void TestQPrefGeneral::test_oldPreferences()
general->set_use_default_file(false);
TEST(general->default_filename(), QStringLiteral("no_file_name"));
- TEST(general->default_cylinder(), QStringLiteral("cylinder_1"));
TEST(general->default_file_behavior(), CLOUD_DEFAULT_FILE);
TEST(general->defaultsetpoint(), 1);
TEST(general->o2consumption(), 1);
@@ -238,7 +224,6 @@ void TestQPrefGeneral::test_oldPreferences()
void TestQPrefGeneral::test_signals()
{
QSignalSpy spy1(qPrefGeneral::instance(), &qPrefGeneral::auto_recalculate_thumbnailsChanged);
- QSignalSpy spy2(qPrefGeneral::instance(), &qPrefGeneral::default_cylinderChanged);
QSignalSpy spy3(qPrefGeneral::instance(), &qPrefGeneral::default_filenameChanged);
QSignalSpy spy4(qPrefGeneral::instance(), &qPrefGeneral::default_file_behaviorChanged);
QSignalSpy spy5(qPrefGeneral::instance(), &qPrefGeneral::defaultsetpointChanged);
@@ -254,7 +239,6 @@ void TestQPrefGeneral::test_signals()
prefs.auto_recalculate_thumbnails = true;
qPrefGeneral::set_auto_recalculate_thumbnails(false);
- qPrefGeneral::set_default_cylinder("new base21");
qPrefGeneral::set_default_filename("new base22");
qPrefGeneral::set_default_file_behavior(LOCAL_DEFAULT_FILE);
qPrefGeneral::set_defaultsetpoint(24);
@@ -271,7 +255,6 @@ void TestQPrefGeneral::test_signals()
QVERIFY(spy1.takeFirst().at(0).toBool() == false);
- qPrefGeneral::set_default_cylinder("new base21");
qPrefGeneral::set_default_filename("new base22");
qPrefGeneral::set_default_file_behavior(LOCAL_DEFAULT_FILE);
qPrefGeneral::set_defaultsetpoint(24);
@@ -285,5 +268,4 @@ void TestQPrefGeneral::test_signals()
qPrefGeneral::set_diveshareExport_private(false);
}
-
QTEST_MAIN(TestQPrefGeneral)
diff --git a/tests/testqPrefTechnicalDetails.cpp b/tests/testqPrefTechnicalDetails.cpp
index 9b6d88a45..b6272dbff 100644
--- a/tests/testqPrefTechnicalDetails.cpp
+++ b/tests/testqPrefTechnicalDetails.cpp
@@ -29,7 +29,6 @@ void TestQPrefTechnicalDetails::test_struct_get()
prefs.calcndltts = true;
prefs.dcceiling = true;
prefs.display_deco_mode = BUEHLMANN;
- prefs.display_unused_tanks = true;
prefs.ead = true;
prefs.gfhigh = 27;
prefs.gflow = 25;
@@ -56,7 +55,6 @@ void TestQPrefTechnicalDetails::test_struct_get()
QCOMPARE(tst->calcndltts(), prefs.calcndltts);
QCOMPARE(tst->dcceiling(), prefs.dcceiling);
QCOMPARE(tst->display_deco_mode(), prefs.display_deco_mode);
- QCOMPARE(tst->display_unused_tanks(), prefs.display_unused_tanks);
QCOMPARE(tst->ead(), prefs.ead);
QCOMPARE(tst->gfhigh(), prefs.gfhigh);
QCOMPARE(tst->gflow(), prefs.gflow);
@@ -91,7 +89,6 @@ void TestQPrefTechnicalDetails::test_set_struct()
tst->set_calcndltts(false);
tst->set_dcceiling(false);
tst->set_display_deco_mode(RECREATIONAL);
- tst->set_display_unused_tanks(false);
tst->set_ead(false);
tst->set_gfhigh(29);
tst->set_gflow(24);
@@ -118,7 +115,6 @@ void TestQPrefTechnicalDetails::test_set_struct()
QCOMPARE(prefs.calcndltts, false);
QCOMPARE(prefs.dcceiling, false);
QCOMPARE(prefs.display_deco_mode, RECREATIONAL);
- QCOMPARE(prefs.display_unused_tanks, false);
QCOMPARE(prefs.ead, false);
QCOMPARE(prefs.gfhigh, 29);
QCOMPARE(prefs.gflow, 24);
@@ -153,7 +149,6 @@ void TestQPrefTechnicalDetails::test_set_load_struct()
tst->set_calcndltts(false);
tst->set_dcceiling(true);
tst->set_display_deco_mode(RECREATIONAL);
- tst->set_display_unused_tanks(false);
tst->set_ead(false);
tst->set_gfhigh(29);
tst->set_gflow(24);
@@ -181,7 +176,6 @@ void TestQPrefTechnicalDetails::test_set_load_struct()
prefs.calcndltts = true;
prefs.dcceiling = false;
prefs.display_deco_mode = BUEHLMANN;
- prefs.display_unused_tanks = true;
prefs.ead = true;
prefs.gfhigh = 27;
prefs.gflow = 25;
@@ -209,7 +203,6 @@ void TestQPrefTechnicalDetails::test_set_load_struct()
QCOMPARE(prefs.calcndltts, false);
QCOMPARE(prefs.dcceiling, true);
QCOMPARE(prefs.display_deco_mode, RECREATIONAL);
- QCOMPARE(prefs.display_unused_tanks, false);
QCOMPARE(prefs.ead, false);
QCOMPARE((int)prefs.gfhigh, 29);
QCOMPARE((int)prefs.gflow, 24);
@@ -244,7 +237,6 @@ void TestQPrefTechnicalDetails::test_struct_disk()
prefs.calcndltts = true;
prefs.dcceiling = true;
prefs.display_deco_mode = BUEHLMANN;
- prefs.display_unused_tanks = true;
prefs.ead = true;
prefs.gfhigh = 11;
prefs.gflow = 12;
@@ -273,7 +265,6 @@ void TestQPrefTechnicalDetails::test_struct_disk()
prefs.calcndltts = false;
prefs.dcceiling = false;
prefs.display_deco_mode = RECREATIONAL;
- prefs.display_unused_tanks = false;
prefs.ead = false;
prefs.gfhigh = 27;
prefs.gflow = 25;
@@ -301,7 +292,6 @@ void TestQPrefTechnicalDetails::test_struct_disk()
QCOMPARE(prefs.calcndltts, true);
QCOMPARE(prefs.dcceiling, true);
QCOMPARE(prefs.display_deco_mode, BUEHLMANN);
- QCOMPARE(prefs.display_unused_tanks, true);
QCOMPARE(prefs.ead, true);
QCOMPARE(prefs.gfhigh, 11);
QCOMPARE(prefs.gflow, 12);
@@ -399,8 +389,6 @@ void TestQPrefTechnicalDetails::test_oldPreferences()
TEST(tecDetails->zoomed_plot(), true);
tecDetails->set_show_sac(true);
TEST(tecDetails->show_sac(), true);
- tecDetails->set_display_unused_tanks(true);
- TEST(tecDetails->display_unused_tanks(), true);
tecDetails->set_show_average_depth(true);
TEST(tecDetails->show_average_depth(), true);
tecDetails->set_show_pictures_in_profile(true);
@@ -438,8 +426,6 @@ void TestQPrefTechnicalDetails::test_oldPreferences()
TEST(tecDetails->zoomed_plot(), false);
tecDetails->set_show_sac(false);
TEST(tecDetails->show_sac(), false);
- tecDetails->set_display_unused_tanks(false);
- TEST(tecDetails->display_unused_tanks(), false);
tecDetails->set_show_average_depth(false);
TEST(tecDetails->show_average_depth(), false);
tecDetails->set_show_pictures_in_profile(false);
@@ -454,7 +440,6 @@ void TestQPrefTechnicalDetails::test_signals()
QSignalSpy spy4(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::calcndlttsChanged);
QSignalSpy spy5(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::dcceilingChanged);
QSignalSpy spy6(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::display_deco_modeChanged);
- QSignalSpy spy7(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::display_unused_tanksChanged);
QSignalSpy spy8(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::eadChanged);
QSignalSpy spy9(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::gfhighChanged);
QSignalSpy spy10(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::gflowChanged);
@@ -487,8 +472,6 @@ void TestQPrefTechnicalDetails::test_signals()
prefs.dcceiling = true;
qPrefTechnicalDetails::set_dcceiling(false);
qPrefTechnicalDetails::set_display_deco_mode(VPMB);
- prefs.display_unused_tanks = true;
- qPrefTechnicalDetails::set_display_unused_tanks(false);
prefs.ead = true;
qPrefTechnicalDetails::set_ead(false);
qPrefTechnicalDetails::set_gfhigh(-29);
@@ -532,7 +515,6 @@ void TestQPrefTechnicalDetails::test_signals()
QCOMPARE(spy4.count(), 1);
QCOMPARE(spy5.count(), 1);
QCOMPARE(spy6.count(), 1);
- QCOMPARE(spy7.count(), 1);
QCOMPARE(spy8.count(), 1);
QCOMPARE(spy9.count(), 1);
QCOMPARE(spy10.count(), 1);
@@ -560,7 +542,6 @@ void TestQPrefTechnicalDetails::test_signals()
QVERIFY(spy4.takeFirst().at(0).toBool() == false);
QVERIFY(spy5.takeFirst().at(0).toBool() == false);
QVERIFY(spy6.takeFirst().at(0).toInt() == VPMB);
- QVERIFY(spy7.takeFirst().at(0).toBool() == false);
QVERIFY(spy8.takeFirst().at(0).toBool() == false);
QVERIFY(spy9.takeFirst().at(0).toInt() == -29);
QVERIFY(spy10.takeFirst().at(0).toInt() == -24);