core: introduce divelog structure

The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.

Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).

The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.

To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.

The whole commit is large, but was mostly an automatic
conversion.

One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-08 21:31:08 +01:00 committed by bstoeger
parent eebb47ec22
commit 9c253ee6c5
81 changed files with 661 additions and 698 deletions

View file

@ -2,6 +2,7 @@
#include "testAirPressure.h"
#include "core/device.h"
#include "core/dive.h"
#include "core/divelog.h"
#include "core/divesite.h"
#include "core/trip.h"
#include "core/file.h"
@ -21,8 +22,7 @@ void TestAirPressure::get_dives()
struct dive *dive;
verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &divelog), 0);
dive = get_dive(0);
dive->selected = true;
QVERIFY(dive != NULL);
@ -57,8 +57,7 @@ void TestAirPressure::testWriteReadBackAirPressure()
dive->surface_pressure.mbar = ap;
QCOMPARE(save_dives("./testout.ssrf"), 0);
clear_dive_file_data();
QCOMPARE(parse_file("./testout.ssrf", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table), 0);
QCOMPARE(parse_file("./testout.ssrf", &divelog), 0);
dive = get_dive(0);
QVERIFY(dive != NULL);
dive->selected = true;

View file

@ -1,18 +1,15 @@
// SPDX-License-Identifier: GPL-2.0
#include "testdivesiteduplication.h"
#include "core/device.h"
#include "core/dive.h"
#include "core/divelog.h"
#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);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &divelog), 0);
QCOMPARE(divelog.sites->nr, 2);
}
QTEST_GUILESS_MAIN(TestDiveSiteDuplication)

View file

@ -4,13 +4,13 @@
#include "core/device.h"
#include "core/dive.h"
#include "core/divesite.h"
#include "core/divelist.h"
#include "core/divelog.h"
#include "core/file.h"
#include "core/qthelper.h"
#include "core/subsurfacestartup.h"
#include "core/settings/qPrefProxy.h"
#include "core/settings/qPrefCloudStorage.h"
#include "core/trip.h"
#include "core/git-access.h"
#include <QDir>
@ -152,8 +152,7 @@ void TestGitStorage::initTestCase()
// cleanup local and remote branches
localRemoteCleanup();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
}
void TestGitStorage::cleanupTestCase()
@ -185,8 +184,7 @@ void TestGitStorage::testGitStorageLocal()
{
// test writing and reading back from local git storage
git_repository *repo;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &divelog), 0);
QFETCH(QString, testDirName);
QFETCH(QString, prefixRead);
QFETCH(QString, prefixWrite);
@ -199,8 +197,7 @@ void TestGitStorage::testGitStorageLocal()
QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0);
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &divelog), 0);
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@ -218,12 +215,10 @@ void TestGitStorage::testGitStorageCloud()
// test writing and reading back from cloud storage
// connect to the ssrftest repository on the cloud server
// and repeat the same test as before with the local git storage
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &divelog), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly);
@ -241,10 +236,8 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
// make a change to local cache repo (pretending that we did some offline changes)
// and then open the remote one again and check that things were propagated correctly
// read the local repo from the previous test and add dive 10
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &divelog), 0);
// calling process_loaded_dives() sorts the table, but calling add_imported_dives()
// causes it to try to update the window title... let's not do that
process_loaded_dives();
@ -255,8 +248,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
clear_dive_file_data();
// now pretend that we are online again and open the cloud storage and compare
git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
QFile org("./SampleDivesV3plus10local.ssrf");
org.open(QFile::ReadOnly);
@ -271,8 +263,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
moveDir(localCacheDir, localCacheDir + "save");
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
org.close();
org.open(QFile::ReadOnly);
@ -301,10 +292,8 @@ void TestGitStorage::testGitStorageCloudMerge()
// (1) open the repo, add dive test11 and save to the cloud
git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &divelog), 0);
process_loaded_dives();
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
@ -315,34 +304,27 @@ void TestGitStorage::testGitStorageCloudMerge()
// (3) open the repo from the old cache and add dive test12 while offline
git_local_only = true;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &divelog), 0);
process_loaded_dives();
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data();
// (4) now take things back online
git_local_only = false;
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
clear_dive_file_data();
// (5) now we should have all the dives in our repo on the second client
// first create the reference data from the xml files:
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &divelog), 0);
process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0);
// then load from the cloud
clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
// finally compare what we have
@ -359,8 +341,7 @@ void TestGitStorage::testGitStorageCloudMerge()
// (6) move ourselves back to the first client and compare data there
moveDir(localCacheDir + "client1", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
process_loaded_dives();
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged-client1.ssrf"), 0);
QFile client1("./SampleDivesV3plus10-11-12-merged-client1.ssrf");
@ -376,8 +357,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
// edit the same dive in the cloud repo
// merge
// (1) open repo, delete second dive, save offline
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
process_loaded_dives();
struct dive *dive = get_dive(1);
delete_single_dive(1);
@ -391,8 +371,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
moveDir(localCacheDir, localCacheDir + "save");
// (3) now we open the cloud storage repo and modify that second dive
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
process_loaded_dives();
dive = get_dive(1);
QVERIFY(dive != NULL);
@ -404,8 +383,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
// (4) move the saved local cache backinto place and try to open the cloud repo
// -> this forces a merge
moveDir(localCacheDir + "save", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
QFile org("./SampleDivesMinus1-merged.ssrf");
@ -428,8 +406,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (1) open repo, edit notes of first three dives
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
process_loaded_dives();
struct dive *dive;
QVERIFY((dive = get_dive(0)) != 0);
@ -445,8 +422,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
clear_dive_file_data();
// (2) make different edits offline
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
process_loaded_dives();
QVERIFY((dive = get_dive(0)) != 0);
free(dive->notes);
@ -465,8 +441,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (3) simulate a second system by moving the cache away and open the cloud storage repo and modify
// those first dive notes differently while online
moveDir(localCacheDir, localCacheDir + "save");
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
process_loaded_dives();
QVERIFY((dive = get_dive(0)) != 0);
free(dive->notes);
@ -482,8 +457,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
// (4) move the saved local cache back into place and open the cloud repo -> this forces a merge
moveDir(localCacheDir + "save", localCacheDir);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &divelog), 0);
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
// we are not trying to compare this to a pre-determined result... what this test
// checks is that there are no parsing errors with the merge

View file

@ -2,6 +2,7 @@
#include "testmerge.h"
#include "core/device.h"
#include "core/dive.h" // for save_dives()
#include "core/divelog.h"
#include "core/divesite.h"
#include "core/file.h"
#include "core/trip.h"
@ -25,15 +26,11 @@ void TestMerge::testMergeEmpty()
/*
* check that we correctly merge mixed cylinder dives
*/
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
struct device_table devices;
struct filter_preset_table filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
struct divelog log;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
org.open(QFile::ReadOnly);
@ -43,9 +40,8 @@ void TestMerge::testMergeEmpty()
QTextStream outS(&out);
QStringList readin = orgS.readAll().split("\n");
QStringList written = outS.readAll().split("\n");
while (readin.size() && written.size()) {
while (readin.size() && written.size())
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
}
}
void TestMerge::testMergeBackwards()
@ -53,15 +49,11 @@ void TestMerge::testMergeBackwards()
/*
* check that we correctly merge mixed cylinder dives
*/
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
struct device_table devices;
struct filter_preset_table filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
struct divelog log;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test48+47.xml");
org.open(QFile::ReadOnly);
@ -71,9 +63,8 @@ void TestMerge::testMergeBackwards()
QTextStream outS(&out);
QStringList readin = orgS.readAll().split("\n");
QStringList written = outS.readAll().split("\n");
while (readin.size() && written.size()) {
while (readin.size() && written.size())
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
}
}
QTEST_GUILESS_MAIN(TestMerge)

View file

@ -2,6 +2,7 @@
#include "testparse.h"
#include "core/device.h"
#include "core/dive.h"
#include "core/divelog.h"
#include "core/divesite.h"
#include "core/errorhelper.h"
#include "core/trip.h"
@ -85,19 +86,18 @@ int TestParse::parseCSV(int units, std::string file)
xml_params_add_int(&params, "airtempField", -1);
xml_params_add_int(&params, "watertempField", -1);
return parse_manual_file(file.c_str(), &params, &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
return parse_manual_file(file.c_str(), &params, &divelog);
}
int TestParse::parseDivingLog()
{
// Parsing of DivingLog import from SQLite database
struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef, &dive_site_table);
struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef, divelog.sites);
ds->name = copy_string("Suomi - - Hälvälä");
int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle);
if (ret == 0)
ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table);
ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &divelog);
else
fprintf(stderr, "Can't open sqlite3 db: " SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql");
@ -107,30 +107,28 @@ int TestParse::parseDivingLog()
int TestParse::parseV2NoQuestion()
{
// parsing of a V2 file should work
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
}
int TestParse::parseV3()
{
// parsing of a V3 files should succeed
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &divelog);
}
void TestParse::testParse()
{
QCOMPARE(parseCSV(0, SUBSURFACE_TEST_DATA "/dives/test41.csv"), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr);
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(parseDivingLog(), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr);
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(parseV2NoQuestion(), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr);
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(parseV3(), 0);
fprintf(stderr, "number of dives %d \n", dive_table.nr);
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(save_dives("./testout.ssrf"), 0);
FILE_COMPARE("./testout.ssrf",
@ -140,7 +138,7 @@ void TestParse::testParse()
void TestParse::testParseDM4()
{
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM4.db", &_sqlite3_handle), 0);
QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table), 0);
QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &divelog), 0);
QCOMPARE(save_dives("./testdm4out.ssrf"), 0);
FILE_COMPARE("./testdm4out.ssrf",
@ -150,7 +148,7 @@ void TestParse::testParseDM4()
void TestParse::testParseDM5()
{
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM5.db", &_sqlite3_handle), 0);
QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table), 0);
QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &divelog), 0);
QCOMPARE(save_dives("./testdm5out.ssrf"), 0);
FILE_COMPARE("./testdm5out.ssrf",
@ -179,18 +177,17 @@ void TestParse::testParseHUDC()
xml_params_add(&params, "hw", "\"DC text\"");
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv",
&params, "csv", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table),
&params, "csv", &divelog),
0);
QCOMPARE(dive_table.nr, 1);
QCOMPARE(divelog.dives->nr, 1);
/*
* CSV import uses time and date stamps relative to current
* time, thus we need to use a static (random) timestamp
*/
if (dive_table.nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1];
if (divelog.dives->nr > 0) {
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
dive->when = 1255152761;
dive->dc.when = 1255152761;
}
@ -225,13 +222,12 @@ void TestParse::testParseNewFormat()
"/dives/")
.append(files.at(i))
.toLatin1()
.data(), &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table),
.data(), &divelog),
0);
QCOMPARE(dive_table.nr, i + 1);
QCOMPARE(divelog.dives->nr, i + 1);
}
fprintf(stderr, "number of dives %d \n", dive_table.nr);
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
QCOMPARE(save_dives("./testsbnewout.ssrf"), 0);
// Currently the CSV parse fails
@ -245,9 +241,9 @@ void TestParse::testParseDLD()
QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD";
QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &divelog) > 0);
fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr);
fprintf(stderr, "number of dives from DLD: %d \n", divelog.dives->nr);
// Compare output
QCOMPARE(save_dives("./testdldout.ssrf"), 0);
@ -260,10 +256,8 @@ void TestParse::testParseMerge()
/*
* check that we correctly merge mixed cylinder dives
*/
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &divelog), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &divelog), 0);
QCOMPARE(save_dives("./testmerge.ssrf"), 0);
FILE_COMPARE("./testmerge.ssrf",
SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml");
@ -303,22 +297,20 @@ int TestParse::parseCSVmanual(int units, std::string file)
xml_params_add_int(&params, "datefmt", 2);
xml_params_add_int(&params, "durationfmt", 2);
xml_params_add_int(&params, "units", units);
return parse_manual_file(file.c_str(), &params, &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
return parse_manual_file(file.c_str(), &params, &divelog);
}
void TestParse::exportCSVDiveDetails()
{
int saved_sac = 0;
parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &divelog);
export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false);
export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false);
if (dive_table.nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1];
if (divelog.dives->nr > 0) {
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
saved_sac = dive->sac;
}
clear_dive_file_data();
@ -326,8 +318,8 @@ void TestParse::exportCSVDiveDetails()
parseCSVmanual(1, "testcsvexportmanualimperial.csv");
// We do not currently support reading SAC, thus faking it
if (dive_table.nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1];
if (divelog.dives->nr > 0) {
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
dive->sac = saved_sac;
}
@ -347,14 +339,13 @@ void TestParse::exportSubsurfaceCSV()
xml_params params;
/* Test SubsurfaceCSV with multiple cylinders */
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false);
export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false);
if (dive_table.nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1];
if (divelog.dives->nr > 0) {
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
saved_sac = dive->sac;
}
@ -362,12 +353,11 @@ void TestParse::exportSubsurfaceCSV()
xml_params_add_int(&params, "separatorIndex", 0);
xml_params_add_int(&params, "units", 1);
parse_csv_file("testcsvexportmanualimperial-cyl.csv", &params, "SubsurfaceCSV", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
parse_csv_file("testcsvexportmanualimperial-cyl.csv", &params, "SubsurfaceCSV", &divelog);
// We do not currently support reading SAC, thus faking it
if (dive_table.nr > 0) {
struct dive *dive = dive_table.dives[dive_table.nr - 1];
if (divelog.dives->nr > 0) {
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
dive->sac = saved_sac;
}
@ -396,14 +386,12 @@ int TestParse::parseCSVprofile(int units, std::string file)
xml_params_add_int(&params, "datefmt", 2);
xml_params_add_int(&params, "units", units);
return parse_csv_file(file.c_str(), &params, "csv", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
return parse_csv_file(file.c_str(), &params, "csv", &divelog);
}
void TestParse::exportCSVDiveProfile()
{
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false);
export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false);
@ -421,14 +409,13 @@ void TestParse::exportCSVDiveProfile()
void TestParse::exportUDDF()
{
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &divelog);
export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt", false);
clear_dive_file_data();
parse_file("testuddfexport.uddf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table);
parse_file("testuddfexport.uddf", &divelog);
export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false);
FILE_COMPARE("testuddfexport.uddf",
@ -472,9 +459,9 @@ void TestParse::parseDL7()
clear_dive_file_data();
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu",
&params, "DL7", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table),
&params, "DL7", &divelog),
0);
QCOMPARE(dive_table.nr, 3);
QCOMPARE(divelog.dives->nr, 3);
QCOMPARE(save_dives("./testdl7out.ssrf"), 0);
FILE_COMPARE("./testdl7out.ssrf",

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "testparseperformance.h"
#include "core/device.h"
#include "core/divelog.h"
#include "core/divesite.h"
#include "core/trip.h"
#include "core/file.h"
@ -65,8 +66,7 @@ void TestParsePerformance::parseSsrf()
return;
}
QBENCHMARK {
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table,
&dive_site_table, &device_table, &filter_preset_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &divelog);
}
}
@ -77,14 +77,12 @@ void TestParsePerformance::parseGit()
// first parse this once to populate the local cache - this way network
// effects don't dominate the parse time
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table);
parse_file(LARGE_TEST_REPO "[git]", &divelog);
cleanup();
QBENCHMARK {
parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table,
&device_table, &filter_preset_table);
parse_file(LARGE_TEST_REPO "[git]", &divelog);
}
}

View file

@ -2,10 +2,9 @@
#include "testpicture.h"
#include "core/device.h"
#include "core/dive.h"
#include "core/divesite.h"
#include "core/divelog.h"
#include "core/errorhelper.h"
#include "core/picture.h"
#include "core/trip.h"
#include "core/file.h"
#include "core/pref.h"
#include <QString>
@ -29,7 +28,7 @@ void TestPicture::addPicture()
struct picture *pic1, *pic2;
verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &divelog), 0);
dive = get_dive(0);
// Pictures will be added to selected dives
dive->selected = true;

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "testprofile.h"
#include "core/device.h"
#include "core/divelog.h"
#include "core/divesite.h"
#include "core/trip.h"
#include "core/file.h"
@ -34,7 +35,7 @@ void TestProfile::init()
void TestProfile::testProfileExport()
{
prefs.planner_deco_mode = BUEHLMANN;
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
save_profiledata("exportprofile.csv", false);
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv");
QCOMPARE(org.open(QFile::ReadOnly), true);
@ -50,7 +51,7 @@ void TestProfile::testProfileExport()
void TestProfile::testProfileExportVPMB()
{
prefs.planner_deco_mode = VPMB;
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table);
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
save_profiledata("exportprofileVPMB.csv", false);
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv");
QCOMPARE(org.open(QFile::ReadOnly), true);

View file

@ -2,6 +2,7 @@
#include "testrenumber.h"
#include "core/device.h"
#include "core/dive.h"
#include "core/divelog.h"
#include "core/divesite.h"
#include "core/trip.h"
#include "core/file.h"
@ -11,32 +12,24 @@
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);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &divelog), 0);
process_loaded_dives();
}
void TestRenumber::testMerge()
{
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
struct device_table devices;
struct filter_preset_table filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(dive_table.nr, 1);
struct divelog log;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &log), 0);
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(divelog.dives->nr, 1);
}
void TestRenumber::testMergeAndAppend()
{
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
struct device_table devices;
struct filter_preset_table filter_presets;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(dive_table.nr, 2);
struct divelog log;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &log), 0);
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
QCOMPARE(divelog.dives->nr, 2);
struct dive *d = get_dive(1);
QVERIFY(d != NULL);
if (d)