tests: add qPrefLanguage testcases

add test cases to secure struct preferences and qPrefLanguage work together

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2018-08-08 17:13:31 +02:00 committed by Dirk Hohndel
parent 72d87364c0
commit dfa3f5e0e7
3 changed files with 175 additions and 0 deletions

View file

@ -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

154
tests/testqPrefLanguage.cpp Normal file
View file

@ -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)

19
tests/testqPrefLanguage.h Normal file
View file

@ -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