Preferences tests: fix Update Manager date loading

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

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2016-11-01 11:57:28 +01:00 committed by Dirk Hohndel
parent 3966f3e7dd
commit 92272311bf
2 changed files with 24 additions and 3 deletions

View file

@ -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");

View file

@ -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)