This will save us tons of time later, so here are the first ones, and it already helped me find two bugs. :)
(three days sending code in a row, tomaz is back? )
From 4269db4498618ccbb15c7200b30e063d973d7758 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 28 Aug 2016 20:20:53 -0300 Subject: [PATCH 5/5] Fix git_local_only loading Thanks to the unittesting. Signed-off-by: Tomaz Canabrava <[email protected]> --- core/subsurface-qt/SettingsObjectWrapper.cpp | 3 +++ tests/testpreferences.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 55670eb..a329e04 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -1111,6 +1111,9 @@ void CloudStorageSettings::setGitLocalOnly(bool value) { if (value == prefs.git_local_only) return; + QSettings s; + s.beginGroup("CloudStorage"); + s.setValue("git_local_only", value); prefs.git_local_only = value; emit gitLocalOnlyChanged(value); } diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index 652cf6f..3148bff 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -30,6 +30,16 @@ void TestPreferences::testPreferences() TEST(pref->cloud_storage->baseUrl(), QStringLiteral("test_one")); pref->cloud_storage->setBaseUrl("test_two"); TEST(pref->cloud_storage->baseUrl(), QStringLiteral("test_two")); + + pref->cloud_storage->setEmail("[email protected]"); + TEST(pref->cloud_storage->email(), QStringLiteral("[email protected]")); + pref->cloud_storage->setEmail("[email protected]"); + TEST(pref->cloud_storage->email(), QStringLiteral("[email protected]")); + + pref->cloud_storage->setGitLocalOnly(true); + TEST(pref->cloud_storage->gitLocalOnly(), true); + pref->cloud_storage->setGitLocalOnly(false); + TEST(pref->cloud_storage->gitLocalOnly(), false); } QTEST_MAIN(TestPreferences) -- 2.9.3
From 7693c1a2af0a32389046a247af893fa53bfb4a8d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 28 Aug 2016 20:11:29 -0300 Subject: [PATCH 4/5] Added the beginning of the Preferences test And it actually helped me to find a bug. yey. Signed-off-by: Tomaz Canabrava <[email protected]> --- tests/CMakeLists.txt | 2 ++ tests/testpreferences.cpp | 35 +++++++++++++++++++++++++++++++++++ tests/testpreferences.h | 14 ++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/testpreferences.cpp create mode 100644 tests/testpreferences.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d6b2ffc..03f550a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,7 @@ TEST(TestPlan testplan.cpp) TEST(TestDiveSiteDuplication testdivesiteduplication.cpp) TEST(TestRenumber testrenumber.cpp) TEST(TestGitStorage testgitstorage.cpp) +TEST(TestPreferences testpreferences.cpp) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS @@ -29,5 +30,6 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestGitStorage TestPlan TestDiveSiteDuplication + TestPreferences TestRenumber ) diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp new file mode 100644 index 0000000..652cf6f --- /dev/null +++ b/tests/testpreferences.cpp @@ -0,0 +1,35 @@ +#include "testpreferences.h" + +#include "core/subsurface-qt/SettingsObjectWrapper.h" + +#include <QtTest> + +#define TEST(METHOD, VALUE) \ +QCOMPARE(METHOD, VALUE); \ +pref->sync(); \ +pref->load(); \ +QCOMPARE(METHOD, VALUE); + + +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); + + pref->cloud_storage->setBackgroundSync(true); + TEST(pref->cloud_storage->backgroundSync(), true); + pref->cloud_storage->setBackgroundSync(false); + TEST(pref->cloud_storage->backgroundSync(), false); + + pref->cloud_storage->setBaseUrl("test_one"); + TEST(pref->cloud_storage->baseUrl(), QStringLiteral("test_one")); + pref->cloud_storage->setBaseUrl("test_two"); + TEST(pref->cloud_storage->baseUrl(), QStringLiteral("test_two")); +} + +QTEST_MAIN(TestPreferences) diff --git a/tests/testpreferences.h b/tests/testpreferences.h new file mode 100644 index 0000000..9b2c44a --- /dev/null +++ b/tests/testpreferences.h @@ -0,0 +1,14 @@ +#ifndef TESTDIVESITEDUPLICATION_H +#define TESTDIVESITEDUPLICATION_H + +#include <QTest> +#include <functional> + +class TestPreferences : public QObject +{ + Q_OBJECT +private slots: + void testPreferences(); +}; + +#endif // TESTDIVESITEDUPLICATION_H -- 2.9.3
From cbdb91bfac71ac9a61aba13021a39ca768580dac Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 28 Aug 2016 20:10:17 -0300 Subject: [PATCH 3/5] Fix cloud_git_url I was freeing data segment, sigh. Signed-off-by: Tomaz Canabrava <[email protected]> --- core/subsurface-qt/SettingsObjectWrapper.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index edb5ad8..55670eb 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -1089,9 +1089,15 @@ void CloudStorageSettings::setBaseUrl(const QString& value) { if (value == prefs.cloud_base_url) return; - qDebug() << prefs.cloud_base_url << prefs.cloud_git_url; - free((void*)prefs.cloud_base_url); - free((void*)prefs.cloud_git_url); + + // dont free data segment. + if (prefs.cloud_base_url != default_prefs.cloud_base_url) { + free((void*)prefs.cloud_base_url); + free((void*)prefs.cloud_git_url); + } + QSettings s; + s.beginGroup(group); + s.setValue("cloud_base_url", value); prefs.cloud_base_url = copy_string(qPrintable(value)); prefs.cloud_git_url = copy_string(qPrintable(QString(prefs.cloud_base_url) + "/git")); } -- 2.9.3
From 96f7a10036996087142bf69576057b85b67b918b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 28 Aug 2016 19:26:42 -0300 Subject: [PATCH 2/5] Added renumber test as a dependency for running the tests Signed-off-by: Tomaz Canabrava <[email protected]> --- tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d516bb6..d6b2ffc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,4 +29,5 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestGitStorage TestPlan TestDiveSiteDuplication -) \ No newline at end of file + TestRenumber +) -- 2.9.3
From 3986a45f416c7bc0a933c646420e13b3cb88712c Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sun, 28 Aug 2016 19:24:44 -0300 Subject: [PATCH 1/5] Fix loading show pictures in profile tests. Signed-off-by: Tomaz Canabrava <[email protected]> --- core/subsurface-qt/SettingsObjectWrapper.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 64d4e27..edb5ad8 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -2107,6 +2107,7 @@ void SettingsObjectWrapper::load() GET_BOOL("show_sac", show_sac); GET_BOOL("display_unused_tanks", display_unused_tanks); GET_BOOL("show_average_depth", show_average_depth); + GET_BOOL("show_pictures_in_profile", show_pictures_in_profile); s.endGroup(); s.beginGroup("GeneralSettings"); -- 2.9.3
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
