diff options
author | jan Iversen <jani@apache.org> | 2018-08-13 17:40:17 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-08-14 09:09:06 -0700 |
commit | 4ba458318c48ff80017d8c5fe74e928b8b7df449 (patch) | |
tree | 73e3677235c5ceb496ac6e664eb8a2eccecdc1c3 /tests | |
parent | 691025fa2440d76e1b208a3ecd280a4aec646890 (diff) | |
download | subsurface-4ba458318c48ff80017d8c5fe74e928b8b7df449.tar.gz |
tests: add qPrefGeneral testcases
add test cases to secure struct preferences and qPrefGeneral work together
Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/testqPrefGeneral.cpp | 184 | ||||
-rw-r--r-- | tests/testqPrefGeneral.h | 19 |
3 files changed, 205 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9b7e557d1..12bd1ee56 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(TestQPrefGeneral testqPrefGeneral.cpp) TEST(TestQPrefGeocoding testqPrefGeocoding.cpp) TEST(TestQPrefLanguage testqPrefLanguage.cpp) TEST(TestQPrefLocationService testqPrefLocationService.cpp) @@ -139,6 +140,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestQPrefDiveComputer TestQPrefDivePlanner TestQPrefFacebook + TestQPrefGeneral TestQPrefGeocoding TestQPrefLanguage TestQPrefLocationService diff --git a/tests/testqPrefGeneral.cpp b/tests/testqPrefGeneral.cpp new file mode 100644 index 000000000..6a8e1f242 --- /dev/null +++ b/tests/testqPrefGeneral.cpp @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefGeneral.h" + +#include "core/pref.h" +#include "core/qthelper.h" +#include "core/settings/qPref.h" + +#include <QTest> + +void TestQPrefGeneral::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefGeneral"); +} + +void TestQPrefGeneral::test_struct_get() +{ + // Test struct pref -> get func. + + 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; + prefs.extract_video_thumbnails = true; + prefs.extract_video_thumbnails_position = 15; + prefs.ffmpeg_executable = copy_qstring("new base16"); + prefs.o2consumption = 17; + prefs.pscr_ratio = 18; + 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); + QCOMPARE(tst->extract_video_thumbnails(), prefs.extract_video_thumbnails); + QCOMPARE(tst->extract_video_thumbnails_position(), prefs.extract_video_thumbnails_position); + QCOMPARE(tst->ffmpeg_executable(), QString(prefs.ffmpeg_executable)); + QCOMPARE(tst->o2consumption(), prefs.o2consumption); + QCOMPARE(tst->pscr_ratio(), prefs.pscr_ratio); + QCOMPARE(tst->use_default_file(), prefs.use_default_file); +} + +void TestQPrefGeneral::test_set_struct() +{ + // Test set func -> struct pref + + 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); + tst->set_extract_video_thumbnails(false); + tst->set_extract_video_thumbnails_position(25); + tst->set_ffmpeg_executable("new base26"); + tst->set_o2consumption(27); + tst->set_pscr_ratio(28); + tst->set_use_default_file(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); + QCOMPARE(prefs.extract_video_thumbnails, false); + QCOMPARE(prefs.extract_video_thumbnails_position, 25); + QCOMPARE(QString(prefs.ffmpeg_executable), QString("new base26")); + QCOMPARE(prefs.o2consumption, 27); + QCOMPARE(prefs.pscr_ratio, 28); + QCOMPARE(prefs.use_default_file, false); +} + +void TestQPrefGeneral::test_set_load_struct() +{ + // test set func -> load -> struct pref + + 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); + tst->set_extract_video_thumbnails(true); + tst->set_extract_video_thumbnails_position(35); + tst->set_ffmpeg_executable("new base36"); + tst->set_o2consumption(37); + tst->set_pscr_ratio(38); + tst->set_use_default_file(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; + prefs.extract_video_thumbnails = false; + prefs.extract_video_thumbnails_position = 15; + prefs.ffmpeg_executable = copy_qstring("error"); + prefs.o2consumption = 17; + prefs.pscr_ratio = 18; + prefs.use_default_file = false; + + 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); + QCOMPARE(prefs.extract_video_thumbnails, true); + QCOMPARE(prefs.extract_video_thumbnails_position, 35); + QCOMPARE(QString(prefs.ffmpeg_executable), QString("new base36")); + QCOMPARE(prefs.o2consumption, 37); + QCOMPARE(prefs.pscr_ratio, 38); + QCOMPARE(prefs.use_default_file, true); +} + +void TestQPrefGeneral::test_struct_disk() +{ + // test struct prefs -> 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; + prefs.extract_video_thumbnails = true; + prefs.extract_video_thumbnails_position = 45; + prefs.ffmpeg_executable = copy_qstring("base46"); + prefs.o2consumption = 47; + prefs.pscr_ratio = 48; + prefs.use_default_file = true; + + 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; + prefs.extract_video_thumbnails = false; + prefs.extract_video_thumbnails_position = 15; + prefs.ffmpeg_executable = copy_qstring("error"); + prefs.o2consumption = 17; + prefs.pscr_ratio = 18; + prefs.use_default_file = false; + + 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); + QCOMPARE(prefs.extract_video_thumbnails, true); + QCOMPARE(prefs.extract_video_thumbnails_position, 45); + QCOMPARE(QString(prefs.ffmpeg_executable), QString("base46")); + QCOMPARE(prefs.o2consumption, 47); + QCOMPARE(prefs.pscr_ratio, 48); + QCOMPARE(prefs.use_default_file, true); +} + +void TestQPrefGeneral::test_multiple() +{ + // test multiple instances have the same information + + prefs.o2consumption = 17; + auto tst_direct = new qPrefGeneral; + + prefs.pscr_ratio = 18; + auto tst = qPrefGeneral::instance(); + + QCOMPARE(tst->o2consumption(), tst_direct->o2consumption()); + QCOMPARE(tst->pscr_ratio(), tst_direct->pscr_ratio()); + QCOMPARE(tst_direct->o2consumption(), 17); + QCOMPARE(tst_direct->pscr_ratio(), 18); +} + +QTEST_MAIN(TestQPrefGeneral) diff --git a/tests/testqPrefGeneral.h b/tests/testqPrefGeneral.h new file mode 100644 index 000000000..c96fa09fb --- /dev/null +++ b/tests/testqPrefGeneral.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFGENERAL_H +#define TESTQPREFGENERAL_H + +#include <QObject> + +class TestQPrefGeneral : 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 // TESTQPREFGENERAL_H |