diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-17 12:32:22 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-24 09:51:37 -0700 |
commit | a2614665942959b95eef8453730cd3ac66ac42a3 (patch) | |
tree | e8491231112634e6fa188a605ddab47910cfe8c2 /tests/testparse.cpp | |
parent | 41975435a2a93733a0e46a7e594ffba193be6e87 (diff) | |
download | subsurface-a2614665942959b95eef8453730cd3ac66ac42a3.tar.gz |
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>
Diffstat (limited to 'tests/testparse.cpp')
-rw-r--r-- | tests/testparse.cpp | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/tests/testparse.cpp b/tests/testparse.cpp index 58bb6a153..c0ffaeb36 100644 --- a/tests/testparse.cpp +++ b/tests/testparse.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testparse.h" +#include "core/device.h" #include "core/divesite.h" #include "core/errorhelper.h" #include "core/trip.h" @@ -82,7 +83,8 @@ int TestParse::parseCSV(int units, std::string file) xml_params_add_int(¶ms, "airtempField", -1); xml_params_add_int(¶ms, "watertempField", -1); - return parse_manual_file(file.c_str(), ¶ms, &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + return parse_manual_file(file.c_str(), ¶ms, &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); } int TestParse::parseDivingLog() @@ -93,7 +95,7 @@ int TestParse::parseDivingLog() 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); + ret = parse_divinglog_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table); else fprintf(stderr, "Can't open sqlite3 db: " SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql"); @@ -103,13 +105,15 @@ 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, &filter_preset_table); + return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); } 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, &filter_preset_table); + return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); } void TestParse::testParse() @@ -134,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), 0); + QCOMPARE(parse_dm4_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table), 0); QCOMPARE(save_dives("./testdm4out.ssrf"), 0); FILE_COMPARE("./testdm4out.ssrf", @@ -144,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), 0); + QCOMPARE(parse_dm5_buffer(_sqlite3_handle, 0, 0, 0, &dive_table, &trip_table, &dive_site_table, &device_table), 0); QCOMPARE(save_dives("./testdm5out.ssrf"), 0); FILE_COMPARE("./testdm5out.ssrf", @@ -173,7 +177,8 @@ void TestParse::testParseHUDC() xml_params_add(¶ms, "hw", "\"DC text\""); QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/TestDiveSeabearHUDC.csv", - ¶ms, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), + ¶ms, "csv", &dive_table, &trip_table, &dive_site_table, + &device_table, &filter_preset_table), 0); QCOMPARE(dive_table.nr, 1); @@ -218,7 +223,8 @@ void TestParse::testParseNewFormat() "/dives/") .append(files.at(i)) .toLatin1() - .data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table), + .data(), &dive_table, &trip_table, &dive_site_table, + &device_table, &filter_preset_table), 0); QCOMPARE(dive_table.nr, i + 1); } @@ -237,7 +243,7 @@ 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, &filter_preset_table) > 0); + QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table) > 0); fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr); @@ -252,8 +258,10 @@ 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, &filter_preset_table), 0); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0); + 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(save_dives("./testmerge.ssrf"), 0); FILE_COMPARE("./testmerge.ssrf", SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml"); @@ -293,15 +301,16 @@ int TestParse::parseCSVmanual(int units, std::string file) xml_params_add_int(¶ms, "datefmt", 2); xml_params_add_int(¶ms, "durationfmt", 2); xml_params_add_int(¶ms, "units", units); - - return parse_manual_file(file.c_str(), ¶ms, &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + return parse_manual_file(file.c_str(), ¶ms, &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); } void TestParse::exportCSVDiveDetails() { int saved_sac = 0; - parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/test25.xml", &dive_table, &trip_table, &dive_site_table, + &device_table, &filter_preset_table); export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt", false); @@ -336,7 +345,8 @@ 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, &filter_preset_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); export_dives_xslt("testcsvexportmanual-cyl.csv", 0, 0, "xml2manualcsv.xslt", false); export_dives_xslt("testcsvexportmanualimperial-cyl.csv", 0, 1, "xml2manualcsv.xslt", false); @@ -350,7 +360,8 @@ void TestParse::exportSubsurfaceCSV() xml_params_add_int(¶ms, "separatorIndex", 0); xml_params_add_int(¶ms, "units", 1); - parse_csv_file("testcsvexportmanualimperial-cyl.csv", ¶ms, "SubsurfaceCSV", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + parse_csv_file("testcsvexportmanualimperial-cyl.csv", ¶ms, "SubsurfaceCSV", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); // We do not currently support reading SAC, thus faking it if (dive_table.nr > 0) { @@ -383,12 +394,14 @@ int TestParse::parseCSVprofile(int units, std::string file) xml_params_add_int(¶ms, "datefmt", 2); xml_params_add_int(¶ms, "units", units); - return parse_csv_file(file.c_str(), ¶ms, "csv", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + return parse_csv_file(file.c_str(), ¶ms, "csv", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); } void TestParse::exportCSVDiveProfile() { - parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt", false); export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt", false); @@ -406,13 +419,14 @@ void TestParse::exportCSVDiveProfile() void TestParse::exportUDDF() { - parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); 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, &filter_preset_table); + parse_file("testuddfexport.uddf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt", false); FILE_COMPARE("testuddfexport.uddf", @@ -456,7 +470,7 @@ void TestParse::parseDL7() clear_dive_file_data(); QCOMPARE(parse_csv_file(SUBSURFACE_TEST_DATA "/dives/DL7.zxu", - ¶ms, "DL7", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), + ¶ms, "DL7", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), 0); QCOMPARE(dive_table.nr, 3); |