summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-08-15 17:19:29 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-23 05:19:16 -0700
commit62672276d0457e8890aed57e4ca114e9daac16f2 (patch)
treef9abfdab852b8f67fb8ed15926c88c452c62e104
parentfa62ffdbf018f32758e2828179f8f7f243a874a5 (diff)
downloadsubsurface-62672276d0457e8890aed57e4ca114e9daac16f2.tar.gz
core: correct error in qPrefUpdateManager
make next_check (in qPrefUpdateManager) long instead of string Correct test cases (compare time_t not strings) Add test case to check time_t works as expected Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r--core/pref.h2
-rw-r--r--core/settings/qPrefUpdateManager.cpp15
-rw-r--r--core/settings/qPrefUpdateManager.h2
-rw-r--r--tests/testqPrefUpdateManager.cpp26
-rw-r--r--tests/testqPrefUpdateManager.h1
5 files changed, 31 insertions, 15 deletions
diff --git a/core/pref.h b/core/pref.h
index d7a7432a4..a27c7d6c4 100644
--- a/core/pref.h
+++ b/core/pref.h
@@ -55,7 +55,7 @@ typedef struct {
bool dont_check_for_updates;
bool dont_check_exists;
const char *last_version_used;
- const char *next_check;
+ int next_check;
} update_manager_prefs_t;
typedef struct {
diff --git a/core/settings/qPrefUpdateManager.cpp b/core/settings/qPrefUpdateManager.cpp
index 2b2bb373d..23952f700 100644
--- a/core/settings/qPrefUpdateManager.cpp
+++ b/core/settings/qPrefUpdateManager.cpp
@@ -41,12 +41,17 @@ HANDLE_PREFERENCE_TXT_EXT(UpdateManager, "/LastVersionUsed", last_version_used,
void qPrefUpdateManager::set_next_check(const QDate& value)
{
- QString valueString = value.toString("dd/MM/yyyy");
- if (valueString != prefs.update_manager.next_check) {
- qPrefPrivate::copy_txt(&prefs.update_manager.next_check, valueString);
+ long time_value = value.toJulianDay();
+ if (time_value != prefs.update_manager.next_check) {
+ prefs.update_manager.next_check = time_value;
disk_next_check(true);
emit instance()->next_check_changed(value);
}
}
-DISK_LOADSYNC_TXT_EXT(UpdateManager, "/NextCheck", next_check, update_manager.);
-
+void qPrefUpdateManager::disk_next_check(bool doSync)
+{
+ if (doSync)
+ qPrefPrivate::instance()->setting.setValue(group + "/NextCheck", prefs.update_manager.next_check);
+ else
+ prefs.update_manager.next_check = qPrefPrivate::instance()->setting.value(group + "/NextCheck", 0).toInt();
+}
diff --git a/core/settings/qPrefUpdateManager.h b/core/settings/qPrefUpdateManager.h
index 773ca3b4b..a1ed468ba 100644
--- a/core/settings/qPrefUpdateManager.h
+++ b/core/settings/qPrefUpdateManager.h
@@ -26,7 +26,7 @@ public:
static bool dont_check_for_updates() { return prefs.update_manager.dont_check_for_updates; }
static bool dont_check_exists() { return prefs.update_manager.dont_check_exists; }
static const QString last_version_used() { return prefs.update_manager.last_version_used; }
- static const QDate next_check() { return QDate::fromString(QString(prefs.update_manager.next_check), "dd/MM/yyyy"); }
+ static const QDate next_check() { return QDate::fromJulianDay(prefs.update_manager.next_check); }
public slots:
static void set_dont_check_for_updates(bool value);
diff --git a/tests/testqPrefUpdateManager.cpp b/tests/testqPrefUpdateManager.cpp
index 166fea032..1d2e5d98d 100644
--- a/tests/testqPrefUpdateManager.cpp
+++ b/tests/testqPrefUpdateManager.cpp
@@ -23,7 +23,7 @@ void TestQPrefUpdateManager::test_struct_get()
prefs.update_manager.dont_check_for_updates = true;
prefs.update_manager.dont_check_exists = true;
prefs.update_manager.last_version_used = copy_qstring("last_version");
- prefs.update_manager.next_check = copy_qstring(QString("11/09/1957"));
+ prefs.update_manager.next_check = QDate::fromString("11/09/1957", "dd/MM/yyyy").toJulianDay();
QCOMPARE(tst->dont_check_for_updates(), true);
QCOMPARE(tst->dont_check_exists(), true);
@@ -40,12 +40,12 @@ void TestQPrefUpdateManager::test_set_struct()
tst->set_dont_check_for_updates(false);
tst->set_dont_check_exists(false);
tst->set_last_version_used("last_version2");
- prefs.update_manager.next_check = copy_qstring(QString("11/09/1957"));
+ tst->set_next_check(QDate::fromString("11/09/1957", "dd/MM/yyyy"));
QCOMPARE(prefs.update_manager.dont_check_for_updates, false);
QCOMPARE(prefs.update_manager.dont_check_exists, false);
QCOMPARE(QString(prefs.update_manager.last_version_used), QString("last_version2"));
- QCOMPARE(QDate::fromString(QString(prefs.update_manager.next_check), "dd/MM/yyyy"), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
+ QCOMPARE(QDate::fromJulianDay(prefs.update_manager.next_check), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
}
void TestQPrefUpdateManager::test_set_load_struct()
@@ -57,7 +57,7 @@ void TestQPrefUpdateManager::test_set_load_struct()
// secure set_ stores on disk
prefs.update_manager.dont_check_for_updates = true;
prefs.update_manager.dont_check_exists = true;
- prefs.update_manager.next_check = copy_qstring(QString("value1"));
+ prefs.update_manager.next_check = 100;
tst->set_dont_check_for_updates(false);
tst->set_dont_check_exists(false);
@@ -67,12 +67,12 @@ void TestQPrefUpdateManager::test_set_load_struct()
prefs.update_manager.dont_check_for_updates = true;
prefs.update_manager.dont_check_exists = true;
prefs.update_manager.last_version_used = copy_qstring("last_version");
- prefs.update_manager.next_check = copy_qstring(QString("01/01/2018"));
+ prefs.update_manager.next_check = 1000;
tst->load();
QCOMPARE(prefs.update_manager.dont_check_for_updates, false);
QCOMPARE(QString(prefs.update_manager.last_version_used), QString("last_version2"));
- QCOMPARE(QDate::fromString(QString(prefs.update_manager.next_check),"dd/MM/yyyy"), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
+ QCOMPARE(QDate::fromJulianDay(prefs.update_manager.next_check), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
// dont_check_exists is NOT stored on disk
QCOMPARE(prefs.update_manager.dont_check_exists, true);
@@ -87,13 +87,13 @@ void TestQPrefUpdateManager::test_struct_disk()
prefs.update_manager.dont_check_for_updates = true;
prefs.update_manager.dont_check_exists = true;
prefs.update_manager.last_version_used = copy_qstring("last_version");
- prefs.update_manager.next_check = copy_qstring("11/09/1957");
+ prefs.update_manager.next_check = QDate::fromString("11/09/1957", "dd/MM/yyyy").toJulianDay();
tst->sync();
prefs.update_manager.dont_check_for_updates = false;
prefs.update_manager.dont_check_exists = false;
prefs.update_manager.last_version_used = copy_qstring("");
- prefs.update_manager.next_check = copy_qstring("01/09/2057");
+ prefs.update_manager.next_check = 1000;
tst->load();
QCOMPARE(tst->dont_check_for_updates(), true);
@@ -120,6 +120,16 @@ void TestQPrefUpdateManager::test_multiple()
QCOMPARE(tst_direct->dont_check_exists(), false);
}
+void TestQPrefUpdateManager::test_next_check()
+{
+ auto tst = qPrefUpdateManager::instance();
+
+ prefs.update_manager.next_check = QDate::fromString("11/09/1957", "dd/MM/yyyy").toJulianDay();
+ prefs.update_manager.next_check++;
+
+ QCOMPARE(tst->next_check(), QDate::fromString("12/09/1957", "dd/MM/yyyy"));
+}
+
#define TEST(METHOD, VALUE) \
QCOMPARE(METHOD, VALUE); \
update->sync(); \
diff --git a/tests/testqPrefUpdateManager.h b/tests/testqPrefUpdateManager.h
index 5dc58e0d2..baa8d3489 100644
--- a/tests/testqPrefUpdateManager.h
+++ b/tests/testqPrefUpdateManager.h
@@ -15,6 +15,7 @@ private slots:
void test_struct_disk();
void test_multiple();
void test_oldPreferences();
+ void test_next_check();
};
#endif // TESTQPREFUPDATEMANAGER_H