aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-16 06:47:51 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-04-19 12:51:01 -0700
commitfe074ccad153791b32c2f62af530091cb025cdee (patch)
treec40ecb5394edba602cfac732732dd14de7e0b3a4 /tests
parentcfe20ee5f4f77a3a42ba301bdd69f5585c46184c (diff)
downloadsubsurface-fe074ccad153791b32c2f62af530091cb025cdee.tar.gz
cloudstorage: adapt tests
The code assumes that prefs.cloud_base_url is non NULL. Allowing that to be NULL makes no sense during normal operation of the app. Yet, most of the tests don't initialize the prefs at all. Making things worse, if we do correctly initialize the prefs (so as to reasonably approximate the behavior when running the app), things break because some of the reference outputs assume that the prefs are unset. This deserves fixing. For now, simply make sure that cloud_base_url is set for all the tests that try to parse files. Additionally, the semantics how cloud_base_url is saved to disk have changed, so adjust the test for those prefs accordingly. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/testAirPressure.cpp1
-rw-r--r--tests/testdivesiteduplication.cpp2
-rw-r--r--tests/testmerge.cpp2
-rw-r--r--tests/testparse.cpp1
-rw-r--r--tests/testpicture.cpp2
-rw-r--r--tests/testprofile.cpp17
-rw-r--r--tests/testprofile.h1
-rw-r--r--tests/testqPrefCloudStorage.cpp4
-rw-r--r--tests/testrenumber.cpp2
9 files changed, 32 insertions, 0 deletions
diff --git a/tests/testAirPressure.cpp b/tests/testAirPressure.cpp
index 5bc8c5369..2a29fe813 100644
--- a/tests/testAirPressure.cpp
+++ b/tests/testAirPressure.cpp
@@ -13,6 +13,7 @@ void TestAirPressure::initTestCase()
{
/* we need to manually tell that the resource exists, because we are using it as library. */
Q_INIT_RESOURCE(subsurface);
+ prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
}
void TestAirPressure::get_dives()
diff --git a/tests/testdivesiteduplication.cpp b/tests/testdivesiteduplication.cpp
index d626e23ed..d2b29a0f6 100644
--- a/tests/testdivesiteduplication.cpp
+++ b/tests/testdivesiteduplication.cpp
@@ -5,9 +5,11 @@
#include "core/divesite.h"
#include "core/trip.h"
#include "core/file.h"
+#include "core/pref.h"
void TestDiveSiteDuplication::testReadV2()
{
+ prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(dive_site_table.nr, 2);
diff --git a/tests/testmerge.cpp b/tests/testmerge.cpp
index e710de66e..238044739 100644
--- a/tests/testmerge.cpp
+++ b/tests/testmerge.cpp
@@ -5,12 +5,14 @@
#include "core/divesite.h"
#include "core/file.h"
#include "core/trip.h"
+#include "core/pref.h"
#include <QTextStream>
void TestMerge::initTestCase()
{
/* we need to manually tell that the resource exists, because we are using it as library. */
Q_INIT_RESOURCE(subsurface);
+ prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
}
void TestMerge::cleanup()
diff --git a/tests/testparse.cpp b/tests/testparse.cpp
index 1a655f4e4..06eddaa8a 100644
--- a/tests/testparse.cpp
+++ b/tests/testparse.cpp
@@ -35,6 +35,7 @@ void TestParse::initTestCase()
{
/* we need to manually tell that the resource exists, because we are using it as library. */
Q_INIT_RESOURCE(subsurface);
+ prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
}
void TestParse::init()
diff --git a/tests/testpicture.cpp b/tests/testpicture.cpp
index 2833a8144..0bf72b0ff 100644
--- a/tests/testpicture.cpp
+++ b/tests/testpicture.cpp
@@ -7,6 +7,7 @@
#include "core/picture.h"
#include "core/trip.h"
#include "core/file.h"
+#include "core/pref.h"
#include <QString>
#include <core/qthelper.h>
@@ -14,6 +15,7 @@ void TestPicture::initTestCase()
{
/* we need to manually tell that the resource exists, because we are using it as library. */
Q_INIT_RESOURCE(subsurface);
+ prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
}
#define PIC1_NAME "/dives/images/wreck.jpg"
diff --git a/tests/testprofile.cpp b/tests/testprofile.cpp
index cd9d51f0c..66f6eea5c 100644
--- a/tests/testprofile.cpp
+++ b/tests/testprofile.cpp
@@ -14,6 +14,23 @@
// ..dives/exportprofilereference.csv) and copy the former over the later and commit that change
// as well.
+void TestProfile::init()
+{
+ // Set UTF8 text codec as in real applications
+ QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
+
+ // first, setup the preferences
+
+ // normally we should be able to do this - but it makes this test fail because the reference data
+ // assume that the prefs are all 0 / false
+ // copy_prefs(&default_prefs, &prefs);
+ // instead we just set up the cloud_base_url to prevent parse_file() from crashing
+ prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
+
+ QCoreApplication::setOrganizationName("Subsurface");
+ QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
+ QCoreApplication::setApplicationName("Subsurface");
+}
void TestProfile::testProfileExport()
{
prefs.planner_deco_mode = BUEHLMANN;
diff --git a/tests/testprofile.h b/tests/testprofile.h
index 18311dc77..2ae832190 100644
--- a/tests/testprofile.h
+++ b/tests/testprofile.h
@@ -8,6 +8,7 @@
class TestProfile : public QObject {
Q_OBJECT
private slots:
+ void init();
void testProfileExport();
void testProfileExportVPMB();
};
diff --git a/tests/testqPrefCloudStorage.cpp b/tests/testqPrefCloudStorage.cpp
index a4e58ed82..8f6cebfa1 100644
--- a/tests/testqPrefCloudStorage.cpp
+++ b/tests/testqPrefCloudStorage.cpp
@@ -76,6 +76,7 @@ void TestQPrefCloudStorage::test_set_load_struct()
auto tst = qPrefCloudStorage::instance();
tst->set_cloud_base_url("t3 base");
+ tst->store_cloud_base_url("t3 base"); // the base URL is no longer automatically saved to disk
tst->set_cloud_storage_email("t3 email");
tst->set_cloud_storage_email_encoded("t3 email2");
tst->set_save_password_local(true);
@@ -114,6 +115,7 @@ void TestQPrefCloudStorage::test_struct_disk()
auto tst = qPrefCloudStorage::instance();
prefs.cloud_base_url = copy_qstring("t4 base");
+ tst->store_cloud_base_url("t4 base"); // the base URL is no longer automatically saved to disk
prefs.cloud_storage_email = copy_qstring("t4 email");
prefs.cloud_storage_email_encoded = copy_qstring("t4 email2");
prefs.save_password_local = true;
@@ -170,8 +172,10 @@ void TestQPrefCloudStorage::test_oldPreferences()
auto cloud = qPrefCloudStorage::instance();
cloud->set_cloud_base_url("test_one");
+ cloud->store_cloud_base_url("test_one");
TEST(cloud->cloud_base_url(), QStringLiteral("test_one"));
cloud->set_cloud_base_url("test_two");
+ cloud->store_cloud_base_url("test_two");
TEST(cloud->cloud_base_url(), QStringLiteral("test_two"));
cloud->set_cloud_storage_email("tomaz@subsurface.com");
diff --git a/tests/testrenumber.cpp b/tests/testrenumber.cpp
index 2c4921461..1796928cb 100644
--- a/tests/testrenumber.cpp
+++ b/tests/testrenumber.cpp
@@ -5,10 +5,12 @@
#include "core/divesite.h"
#include "core/trip.h"
#include "core/file.h"
+#include "core/pref.h"
#include <QTextStream>
void TestRenumber::setup()
{
+ prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), 0);
process_loaded_dives();
}