From be8e93d28a78b4d58b35eca9e0f097b824a84fa9 Mon Sep 17 00:00:00 2001
From: jan Iversen <jani@apache.org>
Date: Sun, 15 Jul 2018 13:53:03 +0200
Subject: tests: move CloudStorage test from testpreferences

Remove CloudStorage test in testpreferences
add the same CloudStorage tests to testqPrefCloudStorage

Signed-off-by: Jan Iversen <jani@apache.org>
---
 tests/testpreferences.cpp       | 48 ----------------------------------
 tests/testqPrefCloudStorage.cpp | 57 +++++++++++++++++++++++++++++++++++++++++
 tests/testqPrefCloudStorage.h   |  1 +
 3 files changed, 58 insertions(+), 48 deletions(-)

(limited to 'tests')

diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index b0f543a45..3f51f0ea0 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -24,54 +24,6 @@ void TestPreferences::testPreferences()
 	auto pref = SettingsObjectWrapper::instance();
 	pref->load();
 
-	auto cloud = pref->cloud_storage;
-
-	cloud->set_cloud_base_url("test_one");
-	TEST(cloud->cloud_base_url(), QStringLiteral("test_one"));
-	cloud->set_cloud_base_url("test_two");
-	TEST(cloud->cloud_base_url(), QStringLiteral("test_two"));
-
-	cloud->set_cloud_storage_email("tomaz@subsurface.com");
-	TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@subsurface.com"));
-	cloud->set_cloud_storage_email("tomaz@gmail.com");
-	TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@gmail.com"));
-
-	cloud->set_git_local_only(true);
-	TEST(cloud->git_local_only(), true);
-	cloud->set_git_local_only(false);
-	TEST(cloud->git_local_only(), false);
-
-	// Why there's new password and password on the prefs?
-	cloud->set_cloud_storage_newpassword("ABCD");
-	TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCD"));
-	cloud->set_cloud_storage_newpassword("ABCDE");
-	TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCDE"));
-
-	cloud->set_cloud_storage_password("ABCDE");
-	TEST(cloud->cloud_storage_password(), QStringLiteral("ABCDE"));
-	cloud->set_cloud_storage_password("ABCABC");
-	TEST(cloud->cloud_storage_password(), QStringLiteral("ABCABC"));
-
-	cloud->set_save_password_local(true);
-	TEST(cloud->save_password_local(), true);
-	cloud->set_save_password_local(false);
-	TEST(cloud->save_password_local(), false);
-
-	cloud->set_save_userid_local(1);
-	TEST(cloud->save_userid_local(), true);
-	cloud->set_save_userid_local(0);
-	TEST(cloud->save_userid_local(), false);
-
-	cloud->set_userid("Tomaz");
-	TEST(cloud->userid(), QStringLiteral("Tomaz"));
-	cloud->set_userid("Zamot");
-	TEST(cloud->userid(), QStringLiteral("Zamot"));
-
-	cloud->set_cloud_verification_status(0);
-	TEST(cloud->cloud_verification_status(), (short)0);
-	cloud->set_cloud_verification_status(1);
-	TEST(cloud->cloud_verification_status(), (short)1);
-
 	auto tecDetails = pref->techDetails;
 	tecDetails->setModpO2(0.2);
 	TEST(tecDetails->modpO2(), 0.2);
diff --git a/tests/testqPrefCloudStorage.cpp b/tests/testqPrefCloudStorage.cpp
index 26397c194..1165987d3 100644
--- a/tests/testqPrefCloudStorage.cpp
+++ b/tests/testqPrefCloudStorage.cpp
@@ -206,4 +206,61 @@ void TestQPrefCloudStorage::test_multiple()
 	QCOMPARE(tst->cloud_timeout(), tst_direct->cloud_timeout());
 }
 
+#define TEST(METHOD, VALUE) \
+QCOMPARE(METHOD, VALUE); \
+cloud->sync(); \
+cloud->load(); \
+QCOMPARE(METHOD, VALUE);
+
+void TestQPrefCloudStorage::test_oldPreferences()
+{
+	auto cloud = qPrefCloudStorage::instance();
+
+	cloud->set_cloud_base_url("test_one");
+	TEST(cloud->cloud_base_url(), QStringLiteral("test_one"));
+	cloud->set_cloud_base_url("test_two");
+	TEST(cloud->cloud_base_url(), QStringLiteral("test_two"));
+
+	cloud->set_cloud_storage_email("tomaz@subsurface.com");
+	TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@subsurface.com"));
+	cloud->set_cloud_storage_email("tomaz@gmail.com");
+	TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@gmail.com"));
+
+	cloud->set_git_local_only(true);
+	TEST(cloud->git_local_only(), true);
+	cloud->set_git_local_only(false);
+	TEST(cloud->git_local_only(), false);
+
+	// Why there's new password and password on the prefs?
+	cloud->set_cloud_storage_newpassword("ABCD");
+	TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCD"));
+	cloud->set_cloud_storage_newpassword("ABCDE");
+	TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCDE"));
+
+	cloud->set_cloud_storage_password("ABCDE");
+	TEST(cloud->cloud_storage_password(), QStringLiteral("ABCDE"));
+	cloud->set_cloud_storage_password("ABCABC");
+	TEST(cloud->cloud_storage_password(), QStringLiteral("ABCABC"));
+
+	cloud->set_save_password_local(true);
+	TEST(cloud->save_password_local(), true);
+	cloud->set_save_password_local(false);
+	TEST(cloud->save_password_local(), false);
+
+	cloud->set_save_userid_local(1);
+	TEST(cloud->save_userid_local(), true);
+	cloud->set_save_userid_local(0);
+	TEST(cloud->save_userid_local(), false);
+
+	cloud->set_userid("Tomaz");
+	TEST(cloud->userid(), QStringLiteral("Tomaz"));
+	cloud->set_userid("Zamot");
+	TEST(cloud->userid(), QStringLiteral("Zamot"));
+
+	cloud->set_cloud_verification_status(0);
+	TEST(cloud->cloud_verification_status(), 0);
+	cloud->set_cloud_verification_status(1);
+	TEST(cloud->cloud_verification_status(), 1);
+}
+
 QTEST_MAIN(TestQPrefCloudStorage)
diff --git a/tests/testqPrefCloudStorage.h b/tests/testqPrefCloudStorage.h
index 5caa0e18e..e7aefef46 100644
--- a/tests/testqPrefCloudStorage.h
+++ b/tests/testqPrefCloudStorage.h
@@ -15,6 +15,7 @@ private slots:
 	void test_set_load_struct();
 	void test_struct_disk();
 	void test_multiple();
+	void test_oldPreferences();
 };
 
 #endif // TESTQPREFCLOUDSTORAGE_H
-- 
cgit v1.2.3-70-g09d2