FINALLY
this finishes the unittests - sorry for all delays.

I'll now look for misbehaving preferences, like the one willan complained.

Tomaz
From 7437265091fb221578a09b26199e1eea18a523e0 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 1 Nov 2016 11:16:50 +0100
Subject: [PATCH 1/4] Move animation_settings to the bottom of the test file

This is made just to make the tests appear in the same
order of the SettingsObjectWrapper order of initialization

Since the SettingsObjectWrapper is huge, this helps
checking if everything is correct.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 tests/testpreferences.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index 862ba61..9ad3ee0 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -16,11 +16,6 @@ void TestPreferences::testPreferences()
 	auto pref = SettingsObjectWrapper::instance();
 	pref->load();
 
-	pref->animation_settings->setAnimationSpeed(20);
-	TEST(pref->animation_settings->animationSpeed(), 20);
-	pref->animation_settings->setAnimationSpeed(30);
-	TEST(pref->animation_settings->animationSpeed(), 30);
-
 	auto cloud = pref->cloud_storage;
 	cloud->setBackgroundSync(true);
 	TEST(cloud->backgroundSync(), true);
@@ -537,6 +532,11 @@ void TestPreferences::testPreferences()
 	TEST(language->timeFormatOverride(),true);
 	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);
 }
 
 QTEST_MAIN(TestPreferences)
-- 
2.10.2

From b0ec91686a7ef719e4bfe67dc8c22997cd9fa172 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 1 Nov 2016 11:28:08 +0100
Subject: [PATCH 2/4] Location updates & bug fix

Fixed loading the location preferences.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 core/subsurface-qt/SettingsObjectWrapper.cpp |  7 -------
 core/subsurface-qt/SettingsObjectWrapper.h   |  2 +-
 tests/testpreferences.cpp                    | 13 +++++++++++++
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index 0cd0568..d692c4b 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -2229,13 +2229,6 @@ void SettingsObjectWrapper::load()
 	// Subsurface webservice id is stored outside of the groups
 	GET_TXT("subsurface_webservice_uid", userid);
 
-	// but the related time / distance threshold (only used in the mobile app)
-	// are in their own group
-	s.beginGroup("locationService");
-	GET_INT("distance_threshold", distance_threshold);
-	GET_INT("time_threshold", time_threshold);
-	s.endGroup();
-
 	// GeoManagement
 	s.beginGroup("geocoding");
 
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index d9b8196..bd12da5 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -668,7 +668,7 @@ signals:
 	void timeThresholdChanged(int value);
 	void distanceThresholdChanged(int value);
 private:
-	const QString group = QStringLiteral("locationService");
+	const QString group = QStringLiteral("LocationService");
 };
 
 class SettingsObjectWrapper : public QObject {
diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index 9ad3ee0..c1ef2a8 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -537,6 +537,19 @@ void TestPreferences::testPreferences()
 	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);
+
+	TEST(location->timeThreshold(), 10);
+	TEST(location->distanceThreshold(), 20);
+
+	location->setTimeThreshold(30);
+	location->setDistanceThreshold(40);
+
+	TEST(location->timeThreshold(), 30);
+	TEST(location->distanceThreshold(), 40);
 }
 
 QTEST_MAIN(TestPreferences)
-- 
2.10.2

From 7de9581d3ce7be438512f2da7a4fa6c6b95960fe Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 1 Nov 2016 11:57:28 +0100
Subject: [PATCH 3/4] Fix Update Manager date loading

Date loading was incorrect, this unittest + fix deals with that.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 core/subsurface-qt/SettingsObjectWrapper.cpp |  6 +++---
 tests/testpreferences.cpp                    | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index d692c4b..81f6237 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -102,7 +102,7 @@ QString UpdateManagerSettings::lastVersionUsed() const
 
 QDate UpdateManagerSettings::nextCheck() const
 {
-	return QDate::fromString(QString(prefs.update_manager.next_check));
+	return QDate::fromString(QString(prefs.update_manager.next_check), "dd/MM/yyyy");
 }
 
 void UpdateManagerSettings::setDontCheckForUpdates(bool value)
@@ -140,7 +140,7 @@ void UpdateManagerSettings::setNextCheck(const QDate& date)
 	s.beginGroup(group);
 	s.setValue("NextCheck", date);
 	free (prefs.update_manager.next_check);
-	prefs.update_manager.next_check = copy_string(qPrintable(date.toString()));
+	prefs.update_manager.next_check = copy_string(qPrintable(date.toString("dd/MM/yyyy")));
 	emit nextCheckChanged(date);
 }
 
@@ -2283,7 +2283,7 @@ void SettingsObjectWrapper::load()
 	prefs.update_manager.dont_check_exists = s.contains("DontCheckForUpdates");
 	prefs.update_manager.dont_check_for_updates = s.value("DontCheckForUpdates").toBool();
 	prefs.update_manager.last_version_used = copy_string(qPrintable(s.value("LastVersionUsed").toString()));
-	prefs.update_manager.next_check = copy_string(qPrintable(s.value("NextCheck").toString()));
+	prefs.update_manager.next_check = copy_string(qPrintable(s.value("NextCheck").toDate().toString("dd/MM/yyyy")));
 	s.endGroup();
 
 	s.beginGroup("Language");
diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index c1ef2a8..33dfb55 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -3,6 +3,7 @@
 #include "core/subsurface-qt/SettingsObjectWrapper.h"
 
 #include <QtTest>
+#include <QDate>
 
 #define TEST(METHOD, VALUE) \
 QCOMPARE(METHOD, VALUE); \
@@ -550,6 +551,26 @@ void TestPreferences::testPreferences()
 
 	TEST(location->timeThreshold(), 30);
 	TEST(location->distanceThreshold(), 40);
+
+	auto update = pref->update_manager_settings;
+	QDate date = QDate::currentDate();
+
+	update->setDontCheckForUpdates(true);
+	update->setLastVersionUsed("tomaz-1");
+	update->setNextCheck(date);
+
+	TEST(update->dontCheckForUpdates(), true);
+	TEST(update->lastVersionUsed(), QStringLiteral("tomaz-1"));
+	TEST(update->nextCheck(), date);
+
+	date.addDays(3);
+	update->setDontCheckForUpdates(false);
+	update->setLastVersionUsed("tomaz-2");
+	update->setNextCheck(date);
+
+	//TEST(update->dontCheckForUpdates(), false);
+	//TEST(update->lastVersionUsed(), QStringLiteral("tomaz-2"));
+	//TEST(update->nextCheck(), date);
 }
 
 QTEST_MAIN(TestPreferences)
-- 
2.10.2

From 09eb63fd4f28ddc9b19362a32246050d5d818abb Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <tcanabr...@kde.org>
Date: Tue, 1 Nov 2016 12:02:36 +0100
Subject: [PATCH 4/4] Remove comments, move code.

This finishes the final round of Unittests for the Preferences
now it's time to look for things to fix.

Signed-off-by: Tomaz Canabrava <tcanabr...@kde.org>
---
 tests/testpreferences.cpp | 48 +++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index 33dfb55..c3de709 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -70,27 +70,6 @@ void TestPreferences::testPreferences()
 	cloud->setVerificationStatus(1);
 	TEST(cloud->verificationStatus(), (short)1);
 
-	auto dc = pref->dive_computer_settings;
-	dc->setDevice("TomazComputer");
-	TEST(dc->dc_device(), QStringLiteral("TomazComputer"));
-	dc->setDevice("Deepwater");
-	TEST(dc->dc_device(), QStringLiteral("Deepwater"));
-
-	dc->setDownloadMode(0);
-	TEST(dc->downloadMode(), 0);
-	dc->setDownloadMode(1);
-	TEST(dc->downloadMode(), 1);
-
-	dc->setProduct("Thingy1");
-	TEST(dc->dc_product(), QStringLiteral("Thingy1"));
-	dc->setProduct("Thingy2");
-	TEST(dc->dc_product(), QStringLiteral("Thingy2"));
-
-	dc->setVendor("Sharewater");
-	TEST(dc->dc_vendor(), QStringLiteral("Sharewater"));
-	dc->setVendor("OSTS");
-	TEST(dc->dc_vendor(), QStringLiteral("OSTS"));
-
 	auto tecDetails = pref->techDetails;
 	tecDetails->setModp02(0.2);
 	TEST(tecDetails->modp02(), 0.2);
@@ -568,9 +547,30 @@ void TestPreferences::testPreferences()
 	update->setLastVersionUsed("tomaz-2");
 	update->setNextCheck(date);
 
-	//TEST(update->dontCheckForUpdates(), false);
-	//TEST(update->lastVersionUsed(), QStringLiteral("tomaz-2"));
-	//TEST(update->nextCheck(), date);
+	TEST(update->dontCheckForUpdates(), false);
+	TEST(update->lastVersionUsed(), QStringLiteral("tomaz-2"));
+	TEST(update->nextCheck(), date);
+
+	auto dc = pref->dive_computer_settings;
+	dc->setDevice("TomazComputer");
+	TEST(dc->dc_device(), QStringLiteral("TomazComputer"));
+	dc->setDevice("Deepwater");
+	TEST(dc->dc_device(), QStringLiteral("Deepwater"));
+
+	dc->setDownloadMode(0);
+	TEST(dc->downloadMode(), 0);
+	dc->setDownloadMode(1);
+	TEST(dc->downloadMode(), 1);
+
+	dc->setProduct("Thingy1");
+	TEST(dc->dc_product(), QStringLiteral("Thingy1"));
+	dc->setProduct("Thingy2");
+	TEST(dc->dc_product(), QStringLiteral("Thingy2"));
+
+	dc->setVendor("Sharewater");
+	TEST(dc->dc_vendor(), QStringLiteral("Sharewater"));
+	dc->setVendor("OSTS");
+	TEST(dc->dc_vendor(), QStringLiteral("OSTS"));
 }
 
 QTEST_MAIN(TestPreferences)
-- 
2.10.2

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to