diff options
author | jan Iversen <jani@apache.org> | 2018-08-08 17:13:31 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-08-13 11:49:32 -0700 |
commit | dfa3f5e0e7d2e7e0f043ad60ef5ea832319504f5 (patch) | |
tree | 44beca8471a969a06a91496a6eaab58eaafca37f /tests | |
parent | 72d87364c018c61f2127b7293fff11b83e97b82c (diff) | |
download | subsurface-dfa3f5e0e7d2e7e0f043ad60ef5ea832319504f5.tar.gz |
tests: add qPrefLanguage testcases
add test cases to secure struct preferences and qPrefLanguage 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/testqPrefLanguage.cpp | 154 | ||||
-rw-r--r-- | tests/testqPrefLanguage.h | 19 |
3 files changed, 175 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ecbcd4fc4..96d789158 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(TestQPrefLanguage testqPrefLanguage.cpp) TEST(TestQPrefLocationService testqPrefLocationService.cpp) TEST(TestQPrefProxy testqPrefProxy.cpp) TEST(TestQPrefTechnicalDetails testqPrefTechnicalDetails.cpp) @@ -136,6 +137,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestQPrefDiveComputer TestQPrefDivePlanner TestQPrefFacebook + TestQPrefLanguage TestQPrefLocationService TestQPrefProxy TestQPrefTechnicalDetails diff --git a/tests/testqPrefLanguage.cpp b/tests/testqPrefLanguage.cpp new file mode 100644 index 000000000..d2cea59e8 --- /dev/null +++ b/tests/testqPrefLanguage.cpp @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefLanguage.h" + +#include "core/pref.h" +#include "core/qthelper.h" +#include "core/settings/qPref.h" + +#include <QTest> + +void TestQPrefLanguage::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefLanguage"); +} + +void TestQPrefLanguage::test_struct_get() +{ + // Test struct pref -> get func. + + auto tst = qPrefLanguage::instance(); + + prefs.date_format = copy_qstring("new date format"); + prefs.date_format_override = true; + prefs.date_format_short = copy_qstring("new short format"); + prefs.locale.language = copy_qstring("new lang format"); + prefs.locale.lang_locale = copy_qstring("new loc lang format"); + prefs.time_format = copy_qstring("new time format"); + prefs.time_format_override = true; + prefs.locale.use_system_language = true; + + QCOMPARE(tst->date_format(), QString(prefs.date_format)); + QCOMPARE(tst->date_format_override(), prefs.date_format_override); + QCOMPARE(tst->date_format_short(), QString(prefs.date_format_short)); + QCOMPARE(tst->language(), QString(prefs.locale.language)); + QCOMPARE(tst->lang_locale(), QString(prefs.locale.lang_locale)); + QCOMPARE(tst->time_format(), QString(prefs.time_format)); + QCOMPARE(tst->time_format_override(), prefs.time_format_override); + QCOMPARE(tst->use_system_language(), prefs.locale.use_system_language); +} + +void TestQPrefLanguage::test_set_struct() +{ + // Test set func -> struct pref + + auto tst = qPrefLanguage::instance(); + + tst->set_date_format("new date2"); + tst->set_date_format_override(false); + tst->set_date_format_short("new short2"); + tst->set_language("new lang format"); + tst->set_lang_locale("new loc lang2"); + tst->set_time_format("new time2"); + tst->set_time_format_override(false); + tst->set_use_system_language(false); + + QCOMPARE(tst->date_format(), QString("new date2")); + QCOMPARE(tst->date_format_override(), false); + QCOMPARE(tst->date_format_short(), QString("new short2")); + QCOMPARE(tst->language(), QString("new lang format")); + QCOMPARE(tst->lang_locale(), QString("new loc lang2")); + QCOMPARE(tst->time_format(), QString("new time2")); + QCOMPARE(tst->time_format_override(), false); + QCOMPARE(tst->use_system_language(), false); +} + +void TestQPrefLanguage::test_set_load_struct() +{ + // test set func -> load -> struct pref + + auto tst = qPrefLanguage::instance(); + + tst->set_date_format("new date3"); + tst->set_date_format_override(true); + tst->set_date_format_short("new short3"); + tst->set_language("new lang format3"); + tst->set_lang_locale("new loc lang3"); + tst->set_time_format("new time3"); + tst->set_time_format_override(true); + tst->set_use_system_language(true); + + prefs.date_format = copy_qstring("error3"); + prefs.date_format_override = false; + prefs.date_format_short = copy_qstring("error3"); + prefs.locale.language = copy_qstring("error3"); + prefs.locale.lang_locale = copy_qstring("error3"); + prefs.time_format = copy_qstring("error3"); + prefs.time_format_override = false; + prefs.locale.use_system_language = false; + + tst->load(); + QCOMPARE(QString(prefs.date_format), QString("new date3")); + QCOMPARE(prefs.date_format_override, true); + QCOMPARE(QString(prefs.date_format_short), QString("new short3")); + QCOMPARE(QString(prefs.locale.language), QString("new lang format3")); + QCOMPARE(QString(prefs.locale.lang_locale), QString("new loc lang3")); + QCOMPARE(QString(prefs.time_format), QString("new time3")); + QCOMPARE(prefs.time_format_override, true); + QCOMPARE(prefs.locale.use_system_language, true); +} + +void TestQPrefLanguage::test_struct_disk() +{ + // test struct prefs -> disk + + auto tst = qPrefLanguage::instance(); + + prefs.date_format = copy_qstring("new date format"); + prefs.date_format_override = true; + prefs.date_format_short = copy_qstring("new short format"); + prefs.locale.language = copy_qstring("new lang format"); + prefs.locale.lang_locale = copy_qstring("new loc lang format"); + prefs.time_format = copy_qstring("new time format"); + prefs.time_format_override = true; + prefs.locale.use_system_language = true; + + tst->sync(); + prefs.date_format = copy_qstring("error3"); + prefs.date_format_override = false; + prefs.date_format_short = copy_qstring("error3"); + prefs.locale.language = copy_qstring("error3"); + prefs.locale.lang_locale = copy_qstring("error3"); + prefs.time_format = copy_qstring("error3"); + prefs.time_format_override = false; + prefs.locale.use_system_language = false; + + tst->load(); + QCOMPARE(QString(prefs.date_format), QString("new date format")); + QCOMPARE(prefs.date_format_override, true); + QCOMPARE(QString(prefs.date_format_short), QString("new short format")); + QCOMPARE(QString(prefs.locale.language), QString("new lang format")); + QCOMPARE(QString(prefs.locale.lang_locale), QString("new loc lang format")); + QCOMPARE(QString(prefs.time_format), QString("new time format")); + QCOMPARE(prefs.time_format_override, true); + QCOMPARE(prefs.locale.use_system_language, true); +} + +void TestQPrefLanguage::test_multiple() +{ + // test multiple instances have the same information + + prefs.locale.use_system_language = false; + auto tst_direct = new qPrefLanguage; + + prefs.time_format_override = true; + auto tst = qPrefLanguage::instance(); + + QCOMPARE(tst->use_system_language(), tst_direct->use_system_language()); + QCOMPARE(tst->time_format_override(), tst_direct->time_format_override()); + QCOMPARE(tst_direct->use_system_language(), false); + QCOMPARE(tst_direct->time_format_override(), true); +} + +QTEST_MAIN(TestQPrefLanguage) diff --git a/tests/testqPrefLanguage.h b/tests/testqPrefLanguage.h new file mode 100644 index 000000000..b7afe9e1a --- /dev/null +++ b/tests/testqPrefLanguage.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFLANGUAGE_H +#define TESTQPREFLANGUAGE_H + +#include <QObject> + +class TestQPrefLanguage : 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 // TESTQPREFLANGUAGE_H |