mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: turn C dive-table into an owning table
This is a humongous commit, because it touches all parts of the code. It removes the last user of our horrible TABLE macros, which simulate std::vector<> in a very clumsy way. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
f00c30ad4a
commit
b95ac3f79c
73 changed files with 1030 additions and 1230 deletions
|
@ -363,7 +363,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
|
|||
QCOMPARE(parse_file(cloudTestRepo.c_str(), &divelog), 0);
|
||||
process_loaded_dives();
|
||||
struct dive *dive = get_dive(1);
|
||||
divelog.delete_single_dive(1);
|
||||
divelog.delete_multiple_dives(std::vector<struct dive *>{ dive });
|
||||
QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0);
|
||||
git_local_only = true;
|
||||
QCOMPARE(save_dives(localCacheRepo.c_str()), 0);
|
||||
|
|
|
@ -28,9 +28,9 @@ void TestMerge::testMergeEmpty()
|
|||
*/
|
||||
struct divelog log;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
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);
|
||||
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);
|
||||
|
@ -51,9 +51,9 @@ void TestMerge::testMergeBackwards()
|
|||
*/
|
||||
struct divelog log;
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
|
||||
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
||||
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);
|
||||
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);
|
||||
|
|
|
@ -118,19 +118,21 @@ int TestParse::parseV3()
|
|||
|
||||
void TestParse::testParse()
|
||||
{
|
||||
// On some platforms (Windows) size_t has a different format string.
|
||||
// Let's just cast to int.
|
||||
QCOMPARE(parseCSV(0, SUBSURFACE_TEST_DATA "/dives/test41.csv"), 0);
|
||||
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
|
||||
fprintf(stderr, "number of dives %d \n", static_cast<int>(divelog.dives.size()));
|
||||
|
||||
QCOMPARE(parseDivingLog(), 0);
|
||||
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
|
||||
fprintf(stderr, "number of dives %d \n", static_cast<int>(divelog.dives.size()));
|
||||
|
||||
QCOMPARE(parseV2NoQuestion(), 0);
|
||||
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
|
||||
fprintf(stderr, "number of dives %d \n", static_cast<int>(divelog.dives.size()));
|
||||
|
||||
QCOMPARE(parseV3(), 0);
|
||||
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
|
||||
fprintf(stderr, "number of dives %d \n", static_cast<int>(divelog.dives.size()));
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
QCOMPARE(save_dives("./testout.ssrf"), 0);
|
||||
FILE_COMPARE("./testout.ssrf",
|
||||
|
@ -142,7 +144,7 @@ void TestParse::testParseDM4()
|
|||
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM4.db", &_sqlite3_handle), 0);
|
||||
QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &divelog), 0);
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
QCOMPARE(save_dives("./testdm4out.ssrf"), 0);
|
||||
FILE_COMPARE("./testdm4out.ssrf",
|
||||
|
@ -154,7 +156,7 @@ void TestParse::testParseDM5()
|
|||
QCOMPARE(sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDiveDM5.db", &_sqlite3_handle), 0);
|
||||
QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &divelog), 0);
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
QCOMPARE(save_dives("./testdm5out.ssrf"), 0);
|
||||
FILE_COMPARE("./testdm5out.ssrf",
|
||||
|
@ -186,19 +188,19 @@ void TestParse::testParseHUDC()
|
|||
¶ms, "csv", &divelog),
|
||||
0);
|
||||
|
||||
QCOMPARE(divelog.dives->nr, 1);
|
||||
QCOMPARE(divelog.dives.size(), 1);
|
||||
|
||||
/*
|
||||
* CSV import uses time and date stamps relative to current
|
||||
* time, thus we need to use a static (random) timestamp
|
||||
*/
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
dive->when = 1255152761;
|
||||
dive->dcs[0].when = 1255152761;
|
||||
if (!divelog.dives.empty()) {
|
||||
struct dive &dive = *divelog.dives.back();
|
||||
dive.when = 1255152761;
|
||||
dive.dcs[0].when = 1255152761;
|
||||
}
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
QCOMPARE(save_dives("./testhudcout.ssrf"), 0);
|
||||
FILE_COMPARE("./testhudcout.ssrf",
|
||||
|
@ -232,12 +234,12 @@ void TestParse::testParseNewFormat()
|
|||
.toLatin1()
|
||||
.data(), &divelog),
|
||||
0);
|
||||
QCOMPARE(divelog.dives->nr, i + 1);
|
||||
QCOMPARE(divelog.dives.size(), i + 1);
|
||||
}
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
fprintf(stderr, "number of dives %d \n", divelog.dives->nr);
|
||||
fprintf(stderr, "number of dives %d \n", static_cast<int>(divelog.dives.size()));
|
||||
QCOMPARE(save_dives("./testsbnewout.ssrf"), 0);
|
||||
|
||||
// Currently the CSV parse fails
|
||||
|
@ -253,9 +255,9 @@ void TestParse::testParseDLD()
|
|||
QVERIFY(err > 0);
|
||||
QVERIFY(try_to_open_zip(filename.toLatin1().data(), &divelog) > 0);
|
||||
|
||||
fprintf(stderr, "number of dives from DLD: %d \n", divelog.dives->nr);
|
||||
fprintf(stderr, "number of dives from DLD: %d \n", static_cast<int>(divelog.dives.size()));
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
// Compare output
|
||||
QCOMPARE(save_dives("./testdldout.ssrf"), 0);
|
||||
|
@ -271,7 +273,7 @@ void TestParse::testParseMerge()
|
|||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &divelog), 0);
|
||||
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &divelog), 0);
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
QCOMPARE(save_dives("./testmerge.ssrf"), 0);
|
||||
FILE_COMPARE("./testmerge.ssrf",
|
||||
|
@ -324,21 +326,16 @@ void TestParse::exportCSVDiveDetails()
|
|||
export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false);
|
||||
export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false);
|
||||
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
saved_sac = dive->sac;
|
||||
}
|
||||
if (!divelog.dives.empty())
|
||||
saved_sac = divelog.dives.back()->sac;
|
||||
clear_dive_file_data();
|
||||
|
||||
parseCSVmanual(1, "testcsvexportmanualimperial.csv");
|
||||
|
||||
// We do not currently support reading SAC, thus faking it
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
dive->sac = saved_sac;
|
||||
}
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
if (!divelog.dives.empty())
|
||||
divelog.dives.back()->sac = saved_sac;
|
||||
divelog.dives.sort();
|
||||
|
||||
export_dives_xslt("testcsvexportmanual2.csv", 0, 0, "xml2manualcsv.xslt", false);
|
||||
FILE_COMPARE("testcsvexportmanual2.csv",
|
||||
|
@ -358,10 +355,8 @@ void TestParse::exportSubsurfaceCSV()
|
|||
export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false);
|
||||
export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false);
|
||||
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
saved_sac = dive->sac;
|
||||
}
|
||||
if (!divelog.dives.empty())
|
||||
saved_sac = divelog.dives.back()->sac;
|
||||
|
||||
clear_dive_file_data();
|
||||
|
||||
|
@ -370,12 +365,10 @@ void TestParse::exportSubsurfaceCSV()
|
|||
parse_csv_file("testcsvexportmanualimperial-cyl.csv", ¶ms, "SubsurfaceCSV", &divelog);
|
||||
|
||||
// We do not currently support reading SAC, thus faking it
|
||||
if (divelog.dives->nr > 0) {
|
||||
struct dive *dive = divelog.dives->dives[divelog.dives->nr - 1];
|
||||
dive->sac = saved_sac;
|
||||
}
|
||||
if (!divelog.dives.empty())
|
||||
divelog.dives.back()->sac = saved_sac;
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
export_dives_xslt("testcsvexportmanual2-cyl.csv", 0, 0, "xml2manualcsv.xslt", false);
|
||||
FILE_COMPARE("testcsvexportmanual2-cyl.csv",
|
||||
|
@ -414,7 +407,7 @@ void TestParse::exportCSVDiveProfile()
|
|||
clear_dive_file_data();
|
||||
|
||||
parseCSVprofile(1, "testcsvexportprofileimperial.csv");
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
export_dives_xslt("testcsvexportprofile2.csv", 0, 0, "xml2csv.xslt", false);
|
||||
FILE_COMPARE("testcsvexportprofile2.csv",
|
||||
|
@ -432,7 +425,7 @@ void TestParse::exportUDDF()
|
|||
clear_dive_file_data();
|
||||
|
||||
parse_file("testuddfexport.uddf", &divelog);
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false);
|
||||
FILE_COMPARE("testuddfexport.uddf",
|
||||
|
@ -478,9 +471,9 @@ void TestParse::parseDL7()
|
|||
QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu",
|
||||
¶ms, "DL7", &divelog),
|
||||
0);
|
||||
QCOMPARE(divelog.dives->nr, 3);
|
||||
QCOMPARE(divelog.dives.size(), 3);
|
||||
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
|
||||
QCOMPARE(save_dives("./testdl7out.ssrf"), 0);
|
||||
FILE_COMPARE("./testdl7out.ssrf",
|
||||
|
|
|
@ -487,7 +487,7 @@ void TestPlan::testMetric()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -527,7 +527,7 @@ void TestPlan::testImperial()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -566,7 +566,7 @@ void TestPlan::testVpmbMetric45m30minTx()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -595,7 +595,7 @@ void TestPlan::testVpmbMetric60m10minTx()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -624,7 +624,7 @@ void TestPlan::testVpmbMetric60m30minAir()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -653,7 +653,7 @@ void TestPlan::testVpmbMetric60m30minEan50()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -688,7 +688,7 @@ void TestPlan::testVpmbMetric60m30minTx()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -723,7 +723,7 @@ void TestPlan::testVpmbMetric100m60min()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -765,7 +765,7 @@ void TestPlan::testMultipleGases()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
gasmix gas;
|
||||
|
@ -789,7 +789,7 @@ void TestPlan::testVpmbMetricMultiLevelAir()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -818,7 +818,7 @@ void TestPlan::testVpmbMetric100m10min()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -864,7 +864,7 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -884,7 +884,7 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -921,7 +921,7 @@ void TestPlan::testVpmbMetricRepeat()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check minimum gas result
|
||||
|
@ -959,7 +959,7 @@ void TestPlan::testCcrBailoutGasSelection()
|
|||
|
||||
#if DEBUG
|
||||
dive.notes.clear();
|
||||
save_dive(stdout, &dive, false);
|
||||
save_dive(stdout, dive, false);
|
||||
#endif
|
||||
|
||||
// check diluent used
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "testprofile.h"
|
||||
#include "core/device.h"
|
||||
#include "core/dive.h"
|
||||
#include "core/divelog.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/trip.h"
|
||||
|
@ -34,7 +35,7 @@ void TestProfile::testProfileExport()
|
|||
{
|
||||
prefs.planner_deco_mode = BUEHLMANN;
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
save_profiledata("exportprofile.csv", false);
|
||||
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv");
|
||||
QCOMPARE(org.open(QFile::ReadOnly), true);
|
||||
|
@ -51,7 +52,7 @@ void TestProfile::testProfileExportVPMB()
|
|||
{
|
||||
prefs.planner_deco_mode = VPMB;
|
||||
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
|
||||
sort_dive_table(divelog.dives);
|
||||
divelog.dives.sort();
|
||||
save_profiledata("exportprofileVPMB.csv", false);
|
||||
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv");
|
||||
QCOMPARE(org.open(QFile::ReadOnly), true);
|
||||
|
|
|
@ -20,16 +20,16 @@ void TestRenumber::testMerge()
|
|||
{
|
||||
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);
|
||||
add_imported_dives(log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(divelog.dives.size(), 1);
|
||||
}
|
||||
|
||||
void TestRenumber::testMergeAndAppend()
|
||||
{
|
||||
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);
|
||||
add_imported_dives(log, IMPORT_MERGE_ALL_TRIPS);
|
||||
QCOMPARE(divelog.dives.size(), 2);
|
||||
struct dive *d = get_dive(1);
|
||||
QVERIFY(d != NULL);
|
||||
if (d)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue