From 33949735f2965a2249b2915b7c38e30202520bf4 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Thu, 12 Jul 2018 12:36:19 +0200 Subject: tests: add qPrefAnimations testcases add test cases to secure struct preferences and qPrefAnimations work together remove animation tests from testpreferences Signed-off-by: Jan Iversen --- tests/CMakeLists.txt | 1 + tests/testpreferences.cpp | 5 --- tests/testqPrefAnimations.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ tests/testqPrefAnimations.h | 19 ++++++++++ 4 files changed, 101 insertions(+), 5 deletions(-) create mode 100644 tests/testqPrefAnimations.cpp create mode 100644 tests/testqPrefAnimations.h (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 771504794..0f30bfecb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -98,6 +98,7 @@ TEST(TestRenumber testrenumber.cpp) TEST(TestGitStorage testgitstorage.cpp) TEST(TestPreferences testpreferences.cpp) TEST(TestQPrefDisplay testqPrefDisplay.cpp) +TEST(TestQPrefAnimations testqPrefAnimations.cpp) TEST(TestPicture testpicture.cpp) TEST(TestMerge testmerge.cpp) TEST(TestTagList testtaglist.cpp) diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index 7a0fa64fd..d950c49f9 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -482,11 +482,6 @@ void TestPreferences::testPreferences() TEST(language->dateFormatOverride(),true); TEST(language->useSystemLanguage(), true); - pref->animation_settings->setAnimationSpeed(20); - TEST(pref->animation_settings->animationSpeed(), 20); - pref->animation_settings->setAnimationSpeed(30); - TEST(pref->animation_settings->animationSpeed(), 30); - auto location = pref->location_settings; location->setTimeThreshold(10); location->setDistanceThreshold(20); diff --git a/tests/testqPrefAnimations.cpp b/tests/testqPrefAnimations.cpp new file mode 100644 index 000000000..db0e31218 --- /dev/null +++ b/tests/testqPrefAnimations.cpp @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefAnimations.h" + +#include "core/settings/qPrefAnimations.h" +#include "core/pref.h" +#include "core/qthelper.h" + +#include + +void TestQPrefAnimations::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefAnimations"); +} + +void TestQPrefAnimations::test_struct_get() +{ + // Test struct pref -> get func. + + auto tst = qPrefAnimations::instance(); + + prefs.animation_speed = 17; + + QCOMPARE(tst->animation_speed(), prefs.animation_speed); +} + +void TestQPrefAnimations::test_set_struct() +{ + // Test set func -> struct pref + + auto tst = qPrefAnimations::instance(); + + tst->set_animation_speed(27); + + QCOMPARE(prefs.animation_speed, 27); +} + +void TestQPrefAnimations::test_set_load_struct() +{ + // test set func -> load -> struct pref + + auto tst = qPrefAnimations::instance(); + + tst->set_animation_speed(33); + + prefs.animation_speed = 17; + + tst->load(); + QCOMPARE(prefs.animation_speed, 33); +} + +void TestQPrefAnimations::test_struct_disk() +{ + // test struct prefs -> disk + + auto tst = qPrefAnimations::instance(); + + prefs.animation_speed = 27; + + tst->sync(); + prefs.animation_speed = 35; + + tst->load(); + QCOMPARE(prefs.animation_speed, 27); +} + +void TestQPrefAnimations::test_multiple() +{ + // test multiple instances have the same information + + prefs.animation_speed = 37; + auto tst_direct = new qPrefAnimations; + + prefs.animation_speed = 25; + auto tst = qPrefAnimations::instance(); + + QCOMPARE(tst->animation_speed(), tst_direct->animation_speed()); +} + +QTEST_MAIN(TestQPrefAnimations) diff --git a/tests/testqPrefAnimations.h b/tests/testqPrefAnimations.h new file mode 100644 index 000000000..162baf8fd --- /dev/null +++ b/tests/testqPrefAnimations.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFANIMATIONS_H +#define TESTQPREFANIMATIONS_H + +#include + +class TestQPrefAnimations : 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 // TESTQPREFANIMATIONS_H -- cgit v1.2.3-70-g09d2