From 3174c7156371f64efedcf19281ea0dc565f23bf8 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Mon, 6 Aug 2018 17:50:08 +0200 Subject: tests: add qPrefLocationService testcases add test cases to secure struct preferences and qPrefLocationService work together Signed-off-by: Jan Iversen --- tests/CMakeLists.txt | 2 + tests/testqPrefLocationService.cpp | 94 ++++++++++++++++++++++++++++++++++++++ tests/testqPrefLocationService.h | 19 ++++++++ 3 files changed, 115 insertions(+) create mode 100644 tests/testqPrefLocationService.cpp create mode 100644 tests/testqPrefLocationService.h (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 882f0e03a..ecbcd4fc4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -107,6 +107,7 @@ TEST(TestQPrefDisplay testqPrefDisplay.cpp) TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp) TEST(TestQPrefDivePlanner testqPrefDivePlanner.cpp) TEST(TestQPrefFacebook testqPrefFacebook.cpp) +TEST(TestQPrefLocationService testqPrefLocationService.cpp) TEST(TestQPrefProxy testqPrefProxy.cpp) TEST(TestQPrefTechnicalDetails testqPrefTechnicalDetails.cpp) TEST(TestQPrefUnits testqPrefUnits.cpp) @@ -135,6 +136,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestQPrefDiveComputer TestQPrefDivePlanner TestQPrefFacebook + TestQPrefLocationService TestQPrefProxy TestQPrefTechnicalDetails TestQPrefUnits diff --git a/tests/testqPrefLocationService.cpp b/tests/testqPrefLocationService.cpp new file mode 100644 index 000000000..0bd02e560 --- /dev/null +++ b/tests/testqPrefLocationService.cpp @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefLocationService.h" + +#include "core/pref.h" +#include "core/qthelper.h" +#include "core/settings/qPref.h" + +#include + +void TestQPrefLocationService::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefLocationService"); +} + +void TestQPrefLocationService::test_struct_get() +{ + // Test struct pref -> get func. + + auto tst = qPrefLocationService::instance(); + + prefs.distance_threshold = 1000; + prefs.time_threshold = 60; + + QCOMPARE(tst->distance_threshold(), prefs.distance_threshold); + QCOMPARE(tst->time_threshold(), prefs.time_threshold); +} + +void TestQPrefLocationService::test_set_struct() +{ + // Test set func -> struct pref + + auto tst = qPrefLocationService::instance(); + + tst->set_distance_threshold(2000); + tst->set_time_threshold(90); + + QCOMPARE(prefs.distance_threshold, 2000); + QCOMPARE(prefs.time_threshold, 90); +} + +void TestQPrefLocationService::test_set_load_struct() +{ + // test set func -> load -> struct pref + + auto tst = qPrefLocationService::instance(); + + tst->set_distance_threshold(2001); + tst->set_time_threshold(91); + + prefs.distance_threshold = 1000; + prefs.time_threshold = 60; + + tst->load(); + QCOMPARE(tst->distance_threshold(), 2001); + QCOMPARE(tst->time_threshold(), 91); +} + +void TestQPrefLocationService::test_struct_disk() +{ + // test struct prefs -> disk + + auto tst = qPrefLocationService::instance(); + + prefs.distance_threshold = 1002; + prefs.time_threshold = 62; + + tst->sync(); + prefs.distance_threshold = 12; + prefs.time_threshold = 2; + + tst->load(); + QCOMPARE(tst->distance_threshold(), 1002); + QCOMPARE(tst->time_threshold(), 62); +} + +void TestQPrefLocationService::test_multiple() +{ + // test multiple instances have the same information + + prefs.distance_threshold = 52; + auto tst_direct = new qPrefLocationService; + + prefs.time_threshold = 62; + auto tst = qPrefLocationService::instance(); + + QCOMPARE(tst->distance_threshold(), tst_direct->distance_threshold()); + QCOMPARE(tst->time_threshold(), tst_direct->time_threshold()); + QCOMPARE(tst_direct->distance_threshold(), 52); + QCOMPARE(tst_direct->time_threshold(), 62); +} + +QTEST_MAIN(TestQPrefLocationService) diff --git a/tests/testqPrefLocationService.h b/tests/testqPrefLocationService.h new file mode 100644 index 000000000..a3a134003 --- /dev/null +++ b/tests/testqPrefLocationService.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFLOCATIONSERVICE_H +#define TESTQPREFLOCATIONSERVICE_H + +#include + +class TestQPrefLocationService : 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 // TESTQPREFLOCATIONSERVICE_H -- cgit v1.2.3-70-g09d2