mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
eebb47ec22
commit
9c253ee6c5
81 changed files with 661 additions and 698 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue