summaryrefslogtreecommitdiffstats
path: root/tests/testqPrefDisplay.cpp
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-07-06 15:10:22 +0200
committerGravatar jan Iversen <jani@apache.org>2018-07-12 19:01:21 +0200
commit1ef3f61cc9ce312e6a8649d7946e1b06b4febc9e (patch)
treebd5731c5e801d80263ac1d5b815c8f98330c1cf1 /tests/testqPrefDisplay.cpp
parent8f7f1cacd60f150f5d2520d3c9c47d31322fd4c1 (diff)
downloadsubsurface-1ef3f61cc9ce312e6a8649d7946e1b06b4febc9e.tar.gz
tests: add qPrefDisplay testcases
remove test macro, split in functions and add test cases the existing test macro does not work because sync() does not save these variables to disk (set* does) Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'tests/testqPrefDisplay.cpp')
-rw-r--r--tests/testqPrefDisplay.cpp127
1 files changed, 109 insertions, 18 deletions
diff --git a/tests/testqPrefDisplay.cpp b/tests/testqPrefDisplay.cpp
index bfd5b5eae..5d510fe21 100644
--- a/tests/testqPrefDisplay.cpp
+++ b/tests/testqPrefDisplay.cpp
@@ -2,16 +2,11 @@
#include "testqPrefDisplay.h"
#include "core/settings/qPrefDisplay.h"
+#include "core/pref.h"
+#include "core/qthelper.h"
-#include <QtTest>
#include <QDate>
-#define TEST(METHOD, VALUE) \
-QCOMPARE(METHOD, VALUE); \
-display->sync(); \
-display->load(); \
-QCOMPARE(METHOD, VALUE);
-
void TestQPrefDisplay::initTestCase()
{
QCoreApplication::setOrganizationName("Subsurface");
@@ -19,24 +14,120 @@ void TestQPrefDisplay::initTestCase()
QCoreApplication::setApplicationName("SubsurfaceTestQPrefDisplay");
}
-void TestQPrefDisplay::test1()
+void TestQPrefDisplay::test_struct_get()
{
+ // Test struct pref -> get func.
+
auto display = qPrefDisplay::instance();
- display->set_divelist_font("comic");
- display->set_font_size(10.0);
+
+ prefs.display_invalid_dives = true;
+ prefs.divelist_font = copy_qstring("comic");
+ prefs.font_size = 12.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme");
+
+ 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();
+
display->set_display_invalid_dives(true);
+ display->set_divelist_font("comic");
+ display->set_font_size(12.0);
+ display->set_show_developer(false);
+ display->set_theme("myTheme");
+
+ QCOMPARE(prefs.display_invalid_dives, true);
+ QCOMPARE(prefs.divelist_font, "comic");
+ QCOMPARE(prefs.font_size, 12.0);
+ QCOMPARE(prefs.show_developer, false);
+ QCOMPARE(prefs.theme, "myTheme");
+}
+
+void TestQPrefDisplay::test_set_load_struct()
+{
+ // test set func -> load -> struct pref
- TEST(display->divelist_font(),QStringLiteral("comic"));
- TEST(display->font_size(), 10.0);
- TEST(display->display_invalid_dives(), true);
+ auto display = qPrefDisplay::instance();
- display->set_divelist_font("helvetica");
- display->set_font_size(14.0);
display->set_display_invalid_dives(false);
+ display->set_divelist_font("helvitica");
+ display->set_font_size(15.0);
+ display->set_show_developer(true);
+ display->set_theme("myTheme2");
+
+ prefs.display_invalid_dives = true;
+ prefs.divelist_font = copy_qstring("comic");
+ prefs.font_size = 12.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme");
+
+ display->load();
+ QCOMPARE(prefs.display_invalid_dives, false);
+ QCOMPARE(prefs.divelist_font, "helvitica");
+ 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;
+ prefs.divelist_font = copy_qstring("helvitica");
+ prefs.font_size = 17.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme3");
+
+ display->sync();
+ prefs.display_invalid_dives = false;
+ prefs.divelist_font = copy_qstring("comic");
+ prefs.font_size = 11.0;
+ prefs.show_developer = true;
+ prefs.theme = copy_qstring("myTheme");
+
+ display->load();
+ QCOMPARE(prefs.display_invalid_dives, true);
+ QCOMPARE(prefs.divelist_font, "helvitica");
+ 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;
+ prefs.theme = copy_qstring("myTheme");
+ auto display_direct = new qPrefDisplay;
+
+ prefs.display_invalid_dives = true;
+ prefs.divelist_font = copy_qstring("helvetica");
+ prefs.font_size = 15.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme8");
+ auto display = qPrefDisplay::instance();
- TEST(display->divelist_font(),QStringLiteral("helvetica"));
- TEST(display->font_size(), 14.0);
- TEST(display->display_invalid_dives(), false);
+ 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());
}
QTEST_MAIN(TestQPrefDisplay)