2018-07-05 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "testqPrefDisplay.h"
|
|
|
|
|
2018-07-06 13:10:22 +00:00
|
|
|
#include "core/pref.h"
|
|
|
|
#include "core/qthelper.h"
|
2018-07-25 19:39:04 +00:00
|
|
|
#include "core/settings/qPref.h"
|
2018-07-05 20:34:04 +00:00
|
|
|
|
|
|
|
#include <QDate>
|
2018-07-17 14:19:56 +00:00
|
|
|
#include <QTest>
|
2018-07-05 20:34:04 +00:00
|
|
|
|
|
|
|
void TestQPrefDisplay::initTestCase()
|
|
|
|
{
|
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
|
|
|
QCoreApplication::setApplicationName("SubsurfaceTestQPrefDisplay");
|
|
|
|
}
|
|
|
|
|
2018-07-06 13:10:22 +00:00
|
|
|
void TestQPrefDisplay::test_struct_get()
|
2018-07-05 20:34:04 +00:00
|
|
|
{
|
2018-07-06 13:10:22 +00:00
|
|
|
// Test struct pref -> get func.
|
|
|
|
|
2018-07-05 20:34:04 +00:00
|
|
|
auto display = qPrefDisplay::instance();
|
2018-07-06 13:10:22 +00:00
|
|
|
|
|
|
|
prefs.display_invalid_dives = true;
|
|
|
|
prefs.divelist_font = copy_qstring("comic");
|
|
|
|
prefs.font_size = 12.0;
|
|
|
|
prefs.show_developer = false;
|
2018-07-25 19:39:04 +00:00
|
|
|
prefs.theme = copy_qstring("myTheme");
|
2018-07-06 13:10:22 +00:00
|
|
|
|
|
|
|
QCOMPARE(display->display_invalid_dives(), prefs.display_invalid_dives);
|
|
|
|
QCOMPARE(display->divelist_font(), QString(prefs.divelist_font));
|
|
|
|
QCOMPARE(display->font_size(), prefs.font_size);
|
|
|
|
QCOMPARE(display->show_developer(), prefs.show_developer);
|
|
|
|
QCOMPARE(display->theme(), QString(prefs.theme));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestQPrefDisplay::test_set_struct()
|
|
|
|
{
|
|
|
|
// Test set func -> struct pref
|
|
|
|
|
|
|
|
auto display = qPrefDisplay::instance();
|
|
|
|
|
2018-07-05 20:34:04 +00:00
|
|
|
display->set_display_invalid_dives(true);
|
2018-07-17 14:19:56 +00:00
|
|
|
display->set_divelist_font("doNotCareAtAll");
|
2018-07-06 13:10:22 +00:00
|
|
|
display->set_font_size(12.0);
|
|
|
|
display->set_show_developer(false);
|
2018-07-25 19:39:04 +00:00
|
|
|
display->set_theme("myTheme");
|
2018-07-06 13:10:22 +00:00
|
|
|
|
|
|
|
QCOMPARE(prefs.display_invalid_dives, true);
|
2018-07-17 14:19:56 +00:00
|
|
|
QCOMPARE(prefs.divelist_font, "doNotCareAtAll");
|
2018-07-06 13:10:22 +00:00
|
|
|
QCOMPARE(prefs.font_size, 12.0);
|
|
|
|
QCOMPARE(prefs.show_developer, false);
|
|
|
|
QCOMPARE(prefs.theme, "myTheme");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestQPrefDisplay::test_set_load_struct()
|
|
|
|
{
|
2018-07-25 19:39:04 +00:00
|
|
|
// test set func -> load -> struct pref
|
2018-07-05 20:34:04 +00:00
|
|
|
|
2018-07-06 13:10:22 +00:00
|
|
|
auto display = qPrefDisplay::instance();
|
2018-07-05 20:34:04 +00:00
|
|
|
|
|
|
|
display->set_display_invalid_dives(false);
|
2018-07-17 14:19:56 +00:00
|
|
|
display->set_divelist_font("doNotCareString");
|
2018-07-06 13:10:22 +00:00
|
|
|
display->set_font_size(15.0);
|
|
|
|
display->set_show_developer(true);
|
2018-07-25 19:39:04 +00:00
|
|
|
display->set_theme("myTheme2");
|
2018-07-06 13:10:22 +00:00
|
|
|
|
|
|
|
prefs.display_invalid_dives = true;
|
2018-07-17 14:19:56 +00:00
|
|
|
prefs.divelist_font = copy_qstring("doNotCareAtAll");
|
2018-07-06 13:10:22 +00:00
|
|
|
prefs.font_size = 12.0;
|
|
|
|
prefs.show_developer = false;
|
2018-07-25 19:39:04 +00:00
|
|
|
prefs.theme = copy_qstring("myTheme");
|
2018-07-06 13:10:22 +00:00
|
|
|
|
|
|
|
display->load();
|
|
|
|
QCOMPARE(prefs.display_invalid_dives, false);
|
2018-07-17 14:19:56 +00:00
|
|
|
QCOMPARE(prefs.divelist_font, "doNotCareString");
|
2018-07-06 13:10:22 +00:00
|
|
|
QCOMPARE(prefs.font_size, 15.0);
|
|
|
|
QCOMPARE(prefs.show_developer, true);
|
|
|
|
QCOMPARE(prefs.theme, "myTheme2");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestQPrefDisplay::test_struct_disk()
|
|
|
|
{
|
|
|
|
// test struct prefs -> disk
|
|
|
|
|
|
|
|
auto display = qPrefDisplay::instance();
|
|
|
|
|
|
|
|
prefs.display_invalid_dives = true;
|
2018-07-17 14:19:56 +00:00
|
|
|
prefs.divelist_font = copy_qstring("doNotCareAtAll");
|
2018-07-06 13:10:22 +00:00
|
|
|
prefs.font_size = 17.0;
|
|
|
|
prefs.show_developer = false;
|
2018-07-25 19:39:04 +00:00
|
|
|
prefs.theme = copy_qstring("myTheme3");
|
2018-07-06 13:10:22 +00:00
|
|
|
|
|
|
|
display->sync();
|
|
|
|
prefs.display_invalid_dives = false;
|
2018-07-17 14:19:56 +00:00
|
|
|
prefs.divelist_font = copy_qstring("noString");
|
2018-07-06 13:10:22 +00:00
|
|
|
prefs.font_size = 11.0;
|
|
|
|
prefs.show_developer = true;
|
2018-07-25 19:39:04 +00:00
|
|
|
prefs.theme = copy_qstring("myTheme");
|
2018-07-06 13:10:22 +00:00
|
|
|
|
|
|
|
display->load();
|
|
|
|
QCOMPARE(prefs.display_invalid_dives, true);
|
2018-07-17 14:19:56 +00:00
|
|
|
QCOMPARE(prefs.divelist_font, "doNotCareAtAll");
|
2018-07-06 13:10:22 +00:00
|
|
|
QCOMPARE(prefs.font_size, 17.0);
|
|
|
|
QCOMPARE(prefs.show_developer, false);
|
|
|
|
QCOMPARE(prefs.theme, "myTheme3");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestQPrefDisplay::test_multiple()
|
|
|
|
{
|
|
|
|
// test multiple instances have the same information
|
|
|
|
|
|
|
|
prefs.display_invalid_dives = false;
|
|
|
|
prefs.divelist_font = copy_qstring("comic");
|
|
|
|
prefs.font_size = 11.0;
|
|
|
|
prefs.show_developer = true;
|
2018-07-25 19:39:04 +00:00
|
|
|
prefs.theme = copy_qstring("myTheme");
|
2018-07-06 13:10:22 +00:00
|
|
|
auto display_direct = new qPrefDisplay;
|
|
|
|
|
|
|
|
prefs.display_invalid_dives = true;
|
2018-07-17 14:19:56 +00:00
|
|
|
prefs.divelist_font = copy_qstring("multipleCharsInString");
|
2018-07-06 13:10:22 +00:00
|
|
|
prefs.font_size = 15.0;
|
|
|
|
prefs.show_developer = false;
|
2018-07-25 19:39:04 +00:00
|
|
|
prefs.theme = copy_qstring("myTheme8");
|
2018-07-06 13:10:22 +00:00
|
|
|
auto display = qPrefDisplay::instance();
|
2018-07-05 20:34:04 +00:00
|
|
|
|
2018-07-06 13:10:22 +00:00
|
|
|
QCOMPARE(display->display_invalid_dives(), display_direct->display_invalid_dives());
|
|
|
|
QCOMPARE(display->divelist_font(), display_direct->divelist_font());
|
|
|
|
QCOMPARE(display->font_size(), display_direct->font_size());
|
|
|
|
QCOMPARE(display->show_developer(), display_direct->show_developer());
|
|
|
|
QCOMPARE(display->theme(), display_direct->theme());
|
2018-07-05 20:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(TestQPrefDisplay)
|