summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar willemferguson <willemferguson@zoology.up.ac.za>2019-12-08 12:03:10 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-25 02:57:42 +0900
commitf63f3eb4ae0cd3621cf5748dfd76749b40b6d886 (patch)
tree04255e67905b1e90c084e56edb3fe6d2e8b01323 /tests
parent2ac279d12953ad840ade1c08d0eff5c2f4adb0b9 (diff)
downloadsubsurface-f63f3eb4ae0cd3621cf5748dfd76749b40b6d886.tar.gz
Preferences: Create a test program for qPrefMedia
This is a companion for the new Media tab in the Preferences UI Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/testqPrefMedia.cpp130
-rw-r--r--tests/testqPrefMedia.h19
3 files changed, 151 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 07452f7a1..fd8bc80a6 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -111,6 +111,7 @@ TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp)
TEST(TestQPrefDivePlanner testqPrefDivePlanner.cpp)
TEST(TestQPrefGeneral testqPrefGeneral.cpp)
TEST(TestQPrefEquipment testqPrefEquipment.cpp)
+TEST(TestQPrefMedia testqPrefMedia.cpp)
TEST(TestQPrefGeocoding testqPrefGeocoding.cpp)
TEST(TestQPrefLanguage testqPrefLanguage.cpp)
TEST(TestQPrefLocationService testqPrefLocationService.cpp)
@@ -143,6 +144,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestQPrefDivePlanner
TestQPrefGeneral
TestQPrefEquipment
+ TestQPrefMedia
TestQPrefGeocoding
TestQPrefLanguage
TestQPrefLocationService
diff --git a/tests/testqPrefMedia.cpp b/tests/testqPrefMedia.cpp
new file mode 100644
index 000000000..f0c864408
--- /dev/null
+++ b/tests/testqPrefMedia.cpp
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "testqPrefMedia.h"
+
+#include "core/pref.h"
+#include "core/qthelper.h"
+#include "core/settings/qPrefMedia.h"
+#include "core/settings/qPref.h"
+
+#include <QTest>
+#include <QSignalSpy>
+
+void TestQPrefMedia::initTestCase()
+{
+ QCoreApplication::setOrganizationName("Subsurface");
+ QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
+ QCoreApplication::setApplicationName("SubsurfaceTestQPrefMedia");
+ qPref::registerQML(NULL);
+}
+
+void TestQPrefMedia::test_struct_get()
+{
+ // Test struct pref -> get func.
+
+ auto tst = qPrefMedia::instance();
+
+ prefs.auto_recalculate_thumbnails = true;
+ prefs.extract_video_thumbnails = true;
+ prefs.extract_video_thumbnails_position = 15;
+ prefs.ffmpeg_executable = copy_qstring("new base16");
+
+ QCOMPARE(tst->auto_recalculate_thumbnails(), prefs.auto_recalculate_thumbnails);
+ QCOMPARE(tst->extract_video_thumbnails(), prefs.extract_video_thumbnails);
+ QCOMPARE(tst->extract_video_thumbnails_position(), prefs.extract_video_thumbnails_position);
+ QCOMPARE(tst->ffmpeg_executable(), QString(prefs.ffmpeg_executable));
+}
+
+void TestQPrefMedia::test_set_struct()
+{
+ // Test set func -> struct pref
+
+ auto tst = qPrefMedia::instance();
+
+ tst->set_auto_recalculate_thumbnails(false);
+ tst->set_extract_video_thumbnails(false);
+ tst->set_extract_video_thumbnails_position(25);
+ tst->set_ffmpeg_executable("new base26");
+
+ QCOMPARE(prefs.auto_recalculate_thumbnails, false);
+ QCOMPARE(prefs.extract_video_thumbnails, false);
+ QCOMPARE(prefs.extract_video_thumbnails_position, 25);
+ QCOMPARE(QString(prefs.ffmpeg_executable), QString("new base26"));
+}
+
+void TestQPrefMedia::test_set_load_struct()
+{
+ // test set func -> load -> struct pref
+
+ auto tst = qPrefMedia::instance();
+
+ tst->set_auto_recalculate_thumbnails(true);
+ tst->set_extract_video_thumbnails(true);
+ tst->set_extract_video_thumbnails_position(35);
+ tst->set_ffmpeg_executable("new base36");
+
+ prefs.auto_recalculate_thumbnails = false;
+ prefs.extract_video_thumbnails = false;
+ prefs.extract_video_thumbnails_position = 15;
+ prefs.ffmpeg_executable = copy_qstring("error");
+
+ tst->load();
+ QCOMPARE(prefs.auto_recalculate_thumbnails, true);
+ QCOMPARE(prefs.extract_video_thumbnails, true);
+ QCOMPARE(prefs.extract_video_thumbnails_position, 35);
+ QCOMPARE(QString(prefs.ffmpeg_executable), QString("new base36"));
+}
+
+void TestQPrefMedia::test_struct_disk()
+{
+ // test struct prefs -> disk
+
+ auto tst = qPrefMedia::instance();
+
+ prefs.auto_recalculate_thumbnails = true;
+ prefs.extract_video_thumbnails = true;
+ prefs.extract_video_thumbnails_position = 45;
+ prefs.ffmpeg_executable = copy_qstring("base46");
+
+ tst->sync();
+ prefs.auto_recalculate_thumbnails = false;
+ prefs.extract_video_thumbnails = false;
+ prefs.extract_video_thumbnails_position = 15;
+ prefs.ffmpeg_executable = copy_qstring("error");
+
+ tst->load();
+ QCOMPARE(prefs.auto_recalculate_thumbnails, true);
+ QCOMPARE(prefs.extract_video_thumbnails, true);
+ QCOMPARE(prefs.extract_video_thumbnails_position, 45);
+ QCOMPARE(QString(prefs.ffmpeg_executable), QString("base46"));
+}
+
+#define TEST(METHOD, VALUE) \
+ QCOMPARE(METHOD, VALUE); \
+ media->sync(); \
+ media->load(); \
+ QCOMPARE(METHOD, VALUE);
+
+void TestQPrefMedia::test_signals()
+{
+ QSignalSpy spy1(qPrefMedia::instance(), &qPrefMedia::auto_recalculate_thumbnailsChanged);
+ QSignalSpy spy6(qPrefMedia::instance(), &qPrefMedia::extract_video_thumbnailsChanged);
+ QSignalSpy spy7(qPrefMedia::instance(), &qPrefMedia::extract_video_thumbnails_positionChanged);
+ QSignalSpy spy8(qPrefMedia::instance(), &qPrefMedia::ffmpeg_executableChanged);
+
+ prefs.auto_recalculate_thumbnails = true;
+ qPrefMedia::set_auto_recalculate_thumbnails(false);
+
+ qPrefMedia::set_extract_video_thumbnails(false);
+ qPrefMedia::set_extract_video_thumbnails_position(25);
+ qPrefMedia::set_ffmpeg_executable("new base26");
+
+ QCOMPARE(spy1.count(), 1);
+
+ QVERIFY(spy1.takeFirst().at(0).toBool() == false);
+
+ qPrefMedia::set_extract_video_thumbnails(false);
+ qPrefMedia::set_extract_video_thumbnails_position(25);
+ qPrefMedia::set_ffmpeg_executable("new base26");
+}
+
+QTEST_MAIN(TestQPrefMedia)
diff --git a/tests/testqPrefMedia.h b/tests/testqPrefMedia.h
new file mode 100644
index 000000000..a1bb51058
--- /dev/null
+++ b/tests/testqPrefMedia.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQPREFMEDIA_H
+#define TESTQPREFMEDIA_H
+
+#include <QObject>
+
+class TestQPrefMedia : 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_signals();
+};
+
+#endif // TESTQPREFMEDIA_H