mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
parser: add device_table to parser state
If we want to avoid the parsers to directly modify global data, we have to provide a device_table to parse into. This adds such a state and the corresponding function parameters. However, for now this is unused. Adding new parameters is very painful and this commit shows that we urgently need a "struct divelog" collecting all those tables! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
41975435a2
commit
a261466594
25 changed files with 242 additions and 139 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "testgitstorage.h"
|
||||
#include "git2.h"
|
||||
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/file.h"
|
||||
|
@ -153,7 +154,8 @@ void TestGitStorage::initTestCase()
|
|||
|
||||
// cleanup local and remote branches
|
||||
localRemoteCleanup();
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
}
|
||||
|
||||
void TestGitStorage::cleanupTestCase()
|
||||
|
@ -185,7 +187,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QFETCH(QString, testDirName);
|
||||
QFETCH(QString, prefixRead);
|
||||
QFETCH(QString, prefixWrite);
|
||||
|
@ -198,7 +201,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
|
||||
QFile org("./SampleDivesV3.ssrf");
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -216,10 +220,12 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
clear_dive_file_data();
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
|
||||
QFile org("./SampleDivesV3.ssrf");
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -237,8 +243,10 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
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);
|
||||
// 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();
|
||||
|
@ -249,7 +257,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
|
||||
QFile org("./SampleDivesV3plus10local.ssrf");
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -264,7 +273,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
|
||||
org.close();
|
||||
org.open(QFile::ReadOnly);
|
||||
|
@ -293,8 +303,10 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
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);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
clear_dive_file_data();
|
||||
|
@ -305,27 +317,34 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
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);
|
||||
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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
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);
|
||||
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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
|
||||
// finally compare what we have
|
||||
|
@ -342,7 +361,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
process_loaded_dives();
|
||||
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged-client1.ssrf"), 0);
|
||||
QFile client1("./SampleDivesV3plus10-11-12-merged-client1.ssrf");
|
||||
|
@ -358,7 +378,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
process_loaded_dives();
|
||||
struct dive *dive = get_dive(1);
|
||||
delete_single_dive(1);
|
||||
|
@ -372,7 +393,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
process_loaded_dives();
|
||||
dive = get_dive(1);
|
||||
QVERIFY(dive != NULL);
|
||||
|
@ -384,7 +406,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
|
||||
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
|
||||
QFile org("./SampleDivesMinus1-merged.ssrf");
|
||||
|
@ -407,7 +430,8 @@ void TestGitStorage::testGitStorageCloudMerge3()
|
|||
|
||||
|
||||
// (1) open repo, edit notes of first three dives
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
process_loaded_dives();
|
||||
struct dive *dive;
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
|
@ -423,7 +447,8 @@ void TestGitStorage::testGitStorageCloudMerge3()
|
|||
clear_dive_file_data();
|
||||
|
||||
// (2) make different edits offline
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
process_loaded_dives();
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
free(dive->notes);
|
||||
|
@ -442,7 +467,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 0);
|
||||
process_loaded_dives();
|
||||
QVERIFY((dive = get_dive(0)) != 0);
|
||||
free(dive->notes);
|
||||
|
@ -458,7 +484,8 @@ 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, &filter_preset_table), 0);
|
||||
QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table, &trip_table,
|
||||
&dive_site_table, &device_table, &filter_preset_table), 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