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 | |
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>
-rw-r--r-- | core/file.c | 45 | ||||
-rw-r--r-- | core/file.h | 7 | ||||
-rw-r--r-- | core/import-cobalt.c | 4 | ||||
-rw-r--r-- | core/import-csv.c | 31 | ||||
-rw-r--r-- | core/import-csv.h | 10 | ||||
-rw-r--r-- | core/import-divinglog.c | 4 | ||||
-rw-r--r-- | core/import-seac.c | 6 | ||||
-rw-r--r-- | core/import-shearwater.c | 8 | ||||
-rw-r--r-- | core/import-suunto.c | 8 | ||||
-rw-r--r-- | core/parse-xml.c | 8 | ||||
-rw-r--r-- | core/parse.h | 27 | ||||
-rw-r--r-- | desktop-widgets/divelogimportdialog.cpp | 12 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 4 | ||||
-rw-r--r-- | export-html.cpp | 3 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 11 | ||||
-rw-r--r-- | tests/testAirPressure.cpp | 7 | ||||
-rw-r--r-- | tests/testdivesiteduplication.cpp | 4 | ||||
-rw-r--r-- | tests/testgitstorage.cpp | 79 | ||||
-rw-r--r-- | tests/testmerge.cpp | 11 | ||||
-rw-r--r-- | tests/testparse.cpp | 56 | ||||
-rw-r--r-- | tests/testparseperformance.cpp | 10 | ||||
-rw-r--r-- | tests/testpicture.cpp | 3 | ||||
-rw-r--r-- | tests/testprofile.cpp | 4 | ||||
-rw-r--r-- | tests/testrenumber.cpp | 9 |
25 files changed, 242 insertions, 139 deletions
diff --git a/core/file.c b/core/file.c index d8f9d48a9..e6fe28df6 100644 --- a/core/file.c +++ b/core/file.c @@ -77,7 +77,7 @@ out: static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table, struct trip_table *trips, - struct dive_site_table *sites, struct filter_preset_table *filter_presets) + struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets) { int size = 1024, n, read = 0; char *mem = malloc(size); @@ -88,12 +88,12 @@ static void zip_read(struct zip_file *file, const char *filename, struct dive_ta mem = realloc(mem, size); } mem[read] = 0; - (void) parse_xml_buffer(filename, mem, read, table, trips, sites, filter_presets, NULL); + (void) parse_xml_buffer(filename, mem, read, table, trips, sites, devices, filter_presets, NULL); free(mem); } int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - struct filter_preset_table *filter_presets) + struct device_table *devices, struct filter_preset_table *filter_presets) { int success = 0; /* Grr. libzip needs to re-open the file, it can't take a buffer */ @@ -108,7 +108,7 @@ int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_ /* skip parsing the divelogs.de pictures */ if (strstr(zip_get_name(zip, index, 0), "pictures/")) continue; - zip_read(file, filename, table, trips, sites, filter_presets); + zip_read(file, filename, table, trips, sites, devices, filter_presets); zip_fclose(file); success++; } @@ -128,7 +128,8 @@ static int db_test_func(void *param, int columns, char **data, char **column) return *data[0] == '0'; } -static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) +static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices) { sqlite3 *handle; char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'"; @@ -150,7 +151,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div /* Testing if DB schema resembles Suunto DM5 database format */ retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL); if (!retval) { - retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); + retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); sqlite3_close(handle); return retval; } @@ -158,7 +159,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div /* Testing if DB schema resembles Suunto DM4 database format */ retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL); if (!retval) { - retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); + retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); sqlite3_close(handle); return retval; } @@ -166,7 +167,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div /* Testing if DB schema resembles Shearwater database format */ retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL); if (!retval) { - retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); + retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); sqlite3_close(handle); return retval; } @@ -174,7 +175,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div /* Testing if DB schema resembles Shearwater cloud database format */ retval = sqlite3_exec(handle, shearwater_cloud_test, &db_test_func, 0, NULL); if (!retval) { - retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); + retval = parse_shearwater_cloud_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); sqlite3_close(handle); return retval; } @@ -182,7 +183,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div /* Testing if DB schema resembles Atomic Cobalt database format */ retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL); if (!retval) { - retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); + retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); sqlite3_close(handle); return retval; } @@ -190,7 +191,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div /* Testing if DB schema resembles Divinglog database format */ retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL); if (!retval) { - retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); + retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); sqlite3_close(handle); return retval; } @@ -198,7 +199,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div /* Testing if DB schema resembles Seac database format */ retval = sqlite3_exec(handle, seacsync_test, &db_test_func, 0, NULL); if (!retval) { - retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites); + retval = parse_seac_buffer(handle, filename, mem->buffer, mem->size, table, trips, sites, devices); sqlite3_close(handle); return retval; } @@ -227,7 +228,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem, struct div */ static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - struct filter_preset_table *filter_presets) + struct device_table *devices, struct filter_preset_table *filter_presets) { // hack to be able to provide a comment for the translated string static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC", @@ -236,7 +237,7 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo /* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */ if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD")) - return try_to_open_zip(filename, table, trips, sites, filter_presets); + return try_to_open_zip(filename, table, trips, sites, devices, filter_presets); /* CSV files */ if (!strcasecmp(fmt, "CSV")) @@ -258,17 +259,18 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo } static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table, - struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets) + struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices, struct filter_preset_table *filter_presets) { int ret; char *fmt = strrchr(filename, '.'); - if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites, filter_presets)) != 0) + if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table, trips, sites, devices, filter_presets)) != 0) return ret; if (!mem->size || !mem->buffer) return report_error("Out of memory parsing file %s\n", filename); - return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, filter_presets, NULL); + return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, devices, filter_presets, NULL); } int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p) @@ -305,7 +307,8 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha return 1; } -int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets) +int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices, struct filter_preset_table *filter_presets) { struct git_repository *git; const char *branch = NULL; @@ -336,7 +339,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table fmt = strrchr(filename, '.'); if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) { - if (!try_to_open_db(filename, &mem, table, trips, sites)) { + if (!try_to_open_db(filename, &mem, table, trips, sites, devices)) { free(mem.buffer); return 0; } @@ -344,7 +347,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table /* Divesoft Freedom */ if (fmt && (!strcasecmp(fmt + 1, "DLF"))) { - ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites); + ret = parse_dlf_buffer(mem.buffer, mem.size, table, trips, sites, devices); free(mem.buffer); return ret; } @@ -375,7 +378,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table return 0; } - ret = parse_file_buffer(filename, &mem, table, trips, sites, filter_presets); + ret = parse_file_buffer(filename, &mem, table, trips, sites, devices, filter_presets); free(mem.buffer); return ret; } diff --git a/core/file.h b/core/file.h index 00b1dcbde..e479cdaac 100644 --- a/core/file.h +++ b/core/file.h @@ -13,6 +13,7 @@ struct memblock { }; struct trip_table; +struct device_table; struct dive_site_table; struct dive_table; struct zip; @@ -26,8 +27,10 @@ extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); extern int readfile(const char *filename, struct memblock *mem); -extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets); -extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets); +extern int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices, struct filter_preset_table *filter_presets); +extern int try_to_open_zip(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices, struct filter_preset_table *filter_presets); // Platform specific functions extern int subsurface_rename(const char *path, const char *newpath); diff --git a/core/import-cobalt.c b/core/import-cobalt.c index 28f6968a3..22bf14dbb 100644 --- a/core/import-cobalt.c +++ b/core/import-cobalt.c @@ -217,7 +217,8 @@ static int cobalt_dive(void *param, int columns, char **data, char **column) int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices) { UNUSED(buffer); UNUSED(size); @@ -229,6 +230,7 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buffer, in state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.sql_handle = handle; char get_dives[] = "select Id,strftime('%s',DiveStartTime),LocationId,'buddy','notes',Units,(MaxDepthPressure*10000/SurfacePressure)-10000,DiveMinutes,SurfacePressure,SerialNumber,'model' from Dive where IsViewDeleted = 0"; diff --git a/core/import-csv.c b/core/import-csv.c index 9748ce5ef..a815408a8 100644 --- a/core/import-csv.c +++ b/core/import-csv.c @@ -105,7 +105,7 @@ static char *parse_dan_new_line(char *buf, const char *NL) static int try_to_xslt_open_csv(const char *filename, struct memblock *mem, const char *tag); static int parse_dan_format(const char *filename, struct xml_params *params, struct dive_table *table, - struct trip_table *trips, struct dive_site_table *sites, + struct trip_table *trips, struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets) { int ret = 0, i; @@ -210,7 +210,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str xml_params_add(params, "waterTemp", tmpbuf); } } - ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, filter_presets, params); + ret |= parse_xml_buffer(filename, "<csv></csv>", 11, table, trips, sites, devices, filter_presets, params); continue; } @@ -265,7 +265,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str if (try_to_xslt_open_csv(filename, &mem_csv, "csv")) return -1; - ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, filter_presets, params); + ret |= parse_xml_buffer(filename, mem_csv.buffer, mem_csv.size, table, trips, sites, devices, filter_presets, params); end_ptr += ptr - (char *)mem_csv.buffer; free(mem_csv.buffer); } @@ -277,7 +277,7 @@ static int parse_dan_format(const char *filename, struct xml_params *params, str int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - struct filter_preset_table *filter_presets) + struct device_table *devices, struct filter_preset_table *filter_presets) { int ret, i; struct memblock mem; @@ -297,7 +297,7 @@ int parse_csv_file(const char *filename, struct xml_params *params, const char * mem.size = 0; if (!strcmp("DL7", csvtemplate)) { - return parse_dan_format(filename, params, table, trips, sites, filter_presets); + return parse_dan_format(filename, params, table, trips, sites, devices, filter_presets); } else if (strcmp(xml_params_get_key(params, 0), "date")) { time(&now); timep = localtime(&now); @@ -329,7 +329,7 @@ int parse_csv_file(const char *filename, struct xml_params *params, const char * fprintf(stderr, "%s/xslt/%s -\n", SUBSURFACE_SOURCE, csvtemplate); } #endif - ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, params); + ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params); free(mem.buffer); @@ -499,7 +499,8 @@ static char *next_mkvi_key(const char *haystack) return ret; } -int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) +int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices) { UNUSED(sites); struct memblock memtxt, memcsv; @@ -794,14 +795,16 @@ int parse_txt_file(const char *filename, const char *csv, struct dive_table *tab #define SBPARAMS 40 static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets); -int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices, struct filter_preset_table *filter_presets); +int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices, struct filter_preset_table *filter_presets) { struct xml_params *params = alloc_xml_params(); int ret; parse_seabear_header(filename, params); - ret = parse_seabear_csv_file(filename, params, "csv", table, trips, sites, filter_presets) < 0 ? -1 : 0; + ret = parse_seabear_csv_file(filename, params, "csv", table, trips, sites, devices, filter_presets) < 0 ? -1 : 0; free_xml_params(params); @@ -811,7 +814,7 @@ int parse_seabear_log(const char *filename, struct dive_table *table, struct tri static int parse_seabear_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - struct filter_preset_table *filter_presets) + struct device_table *devices, struct filter_preset_table *filter_presets) { int ret, i; struct memblock mem; @@ -929,14 +932,14 @@ static int parse_seabear_csv_file(const char *filename, struct xml_params *param fprintf(stderr, "xslt/csv2xml.xslt\n"); } - ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, params); + ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params); free(mem.buffer); return ret; } int parse_manual_file(const char *filename, struct xml_params *params, struct dive_table *table, struct trip_table *trips, - struct dive_site_table *sites, struct filter_preset_table *filter_presets) + struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets) { struct memblock mem; time_t now; @@ -972,7 +975,7 @@ int parse_manual_file(const char *filename, struct xml_params *params, struct di fprintf(stderr, "%s/xslt/manualcsv2xml.xslt -\n", SUBSURFACE_SOURCE); } #endif - ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, filter_presets, params); + ret = parse_xml_buffer(filename, mem.buffer, mem.size, table, trips, sites, devices, filter_presets, params); free(mem.buffer); return ret; diff --git a/core/import-csv.h b/core/import-csv.h index 1ef4ee46b..d73b0fe04 100644 --- a/core/import-csv.h +++ b/core/import-csv.h @@ -26,14 +26,16 @@ extern "C" { #endif int parse_csv_file(const char *filename, struct xml_params *params, const char *csvtemplate, struct dive_table *table, - struct trip_table *trips, struct dive_site_table *sites, struct filter_preset_table *filter_presets); + struct trip_table *trips, struct dive_site_table *sites, struct device_table *devices, + struct filter_preset_table *filter_presets); int try_to_open_csv(struct memblock *mem, enum csv_format type, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); +int parse_txt_file(const char *filename, const char *csv, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); int parse_seabear_log(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - struct filter_preset_table *filter_presets); + struct device_table *devices, struct filter_preset_table *filter_presets); int parse_manual_file(const char *filename, struct xml_params *params, struct dive_table *table, struct trip_table *trips, - struct dive_site_table *sites, struct filter_preset_table *filter_presets); + struct dive_site_table *sites, struct device_table *devices, struct filter_preset_table *filter_presets); #ifdef __cplusplus } diff --git a/core/import-divinglog.c b/core/import-divinglog.c index f3a62eaff..24ab5c548 100644 --- a/core/import-divinglog.c +++ b/core/import-divinglog.c @@ -389,7 +389,8 @@ static int divinglog_dive(void *param, int columns, char **data, char **column) int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices) { UNUSED(buffer); UNUSED(size); @@ -401,6 +402,7 @@ int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buffer, state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.sql_handle = handle; char get_dives[] = "select Number,strftime('%s',Divedate || ' ' || ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer,ID,Visibility,SupplyType from Logbook where UUID not in (select UUID from DeletedRecords)"; diff --git a/core/import-seac.c b/core/import-seac.c index 4b34cbe99..38c7978af 100644 --- a/core/import-seac.c +++ b/core/import-seac.c @@ -260,7 +260,8 @@ static int seac_dive(void *param, int columns, char **data, char **column) * table, to read in the sample values. */ int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices) { UNUSED(buffer); UNUSED(size); @@ -273,6 +274,7 @@ int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.sql_handle = handle; const char *get_dives = "SELECT dive_number, device_sn, date, timezone, time, elapsed_surface_time, dive_type, start_mode, water_type, comment, total_dive_time, max_depth, firmware_version FROM headers_dive"; @@ -300,4 +302,4 @@ int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buffer, int } return 0; -}
\ No newline at end of file +} diff --git a/core/import-shearwater.c b/core/import-shearwater.c index 0b0fa8799..4dd67de2b 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -485,7 +485,8 @@ static int shearwater_cloud_dive(void *param, int columns, char **data, char **c } int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices) { UNUSED(buffer); UNUSED(size); @@ -497,6 +498,7 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.sql_handle = handle; // So far have not seen any sample rate in Shearwater Desktop @@ -516,7 +518,8 @@ int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buffer } int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices) { UNUSED(buffer); UNUSED(size); @@ -528,6 +531,7 @@ int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char * state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.sql_handle = handle; char get_dives[] = "select l.number,strftime('%s', DiveDate),location||' / '||site,buddy,notes,imperialUnits,maxDepth,DiveLengthTime,startSurfacePressure,computerSerial,computerModel,d.diveId,l.sampleRateMs / 1000 FROM dive_details AS d JOIN dive_logs AS l ON d.diveId=l.diveId"; diff --git a/core/import-suunto.c b/core/import-suunto.c index d34c01442..27d5680be 100644 --- a/core/import-suunto.c +++ b/core/import-suunto.c @@ -290,7 +290,8 @@ static int dm4_dive(void *param, int columns, char **data, char **column) } int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices) { UNUSED(buffer); UNUSED(size); @@ -303,6 +304,7 @@ int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buffer, int s state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.sql_handle = handle; /* StartTime is converted from Suunto's nano seconds to standard @@ -560,7 +562,8 @@ static int dm5_dive(void *param, int columns, char **data, char **column) } int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int size, - struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) + struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, + struct device_table *devices) { UNUSED(buffer); UNUSED(size); @@ -573,6 +576,7 @@ int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buffer, int s state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.sql_handle = handle; /* StartTime is converted from Suunto's nano seconds to standard diff --git a/core/parse-xml.c b/core/parse-xml.c index d5bbf7ae0..b5b66c181 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1722,7 +1722,8 @@ static const char *preprocess_divelog_de(const char *buffer) int parse_xml_buffer(const char *url, const char *buffer, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - struct filter_preset_table *filter_presets, const struct xml_params *params) + struct device_table *devices, struct filter_preset_table *filter_presets, + const const struct xml_params *params) { UNUSED(size); xmlDoc *doc; @@ -1734,6 +1735,7 @@ int parse_xml_buffer(const char *url, const char *buffer, int size, state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; state.filter_presets = filter_presets; doc = xmlReadMemory(res, strlen(res), url, NULL, 0); if (!doc) @@ -1776,7 +1778,8 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer) return offset + 946684800; } -int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites) +int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices) { unsigned char *ptr = buffer; unsigned char event; @@ -1800,6 +1803,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl state.target_table = table; state.trips = trips; state.sites = sites; + state.devices = devices; // Check for the correct file magic if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E') diff --git a/core/parse.h b/core/parse.h index 3b4efe1d8..7c4529739 100644 --- a/core/parse.h +++ b/core/parse.h @@ -78,6 +78,7 @@ struct parser_state { struct dive_table *target_table; /* non-owning */ struct trip_table *trips; /* non-owning */ struct dive_site_table *sites; /* non-owning */ + struct device_table *devices; /* non-owning */ struct filter_preset_table *filter_presets; /* non-owning */ sqlite3 *sql_handle; /* for SQL based parsers */ @@ -142,16 +143,24 @@ int atoi_n(char *ptr, unsigned int len); void parse_xml_init(void); int parse_xml_buffer(const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - struct filter_preset_table *filter_presets, const struct xml_params *params); + struct device_table *devices, struct filter_preset_table *filter_presets, const struct xml_params *params); void parse_xml_exit(void); -int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); -int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites); +int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); +int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); +int parse_seac_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); +int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); +int parse_shearwater_cloud_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); +int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); +int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); +int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table, struct trip_table *trips, + struct dive_site_table *sites, struct device_table *devices); #ifdef __cplusplus } #endif diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index eccdd2264..e6243e98d 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -13,6 +13,7 @@ #include "core/filterpreset.h" #include "core/qthelper.h" #include "core/divesite.h" +#include "core/device.h" #include "core/trip.h" #include "core/import-csv.h" #include "core/xmlparams.h" @@ -880,15 +881,16 @@ void DiveLogImportDialog::on_buttonBox_accepted() 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; QStringList r = resultModel->result(); if (ui->knownImports->currentText() != "Manual import") { for (int i = 0; i < fileNames.size(); ++i) { if (ui->knownImports->currentText() == "Seabear CSV") { - parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &sites, &filter_presets); + parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &sites, &devices, &filter_presets); } else if (ui->knownImports->currentText() == "Poseidon MkVI") { QPair<QString, QString> pair = poseidonFileNames(fileNames[i]); - parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &sites); + parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &sites, &devices); } else { xml_params params; @@ -902,7 +904,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() setup_csv_params(r, params); parse_csv_file(qPrintable(fileNames[i]), ¶ms, specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", - &table, &trips, &sites, &filter_presets); + &table, &trips, &sites, &devices, &filter_presets); } } } else { @@ -938,7 +940,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() xml_params_add_int(¶ms, "visibilityField", r.indexOf(tr("Visibility"))); xml_params_add_int(¶ms, "ratingField", r.indexOf(tr("Rating"))); - parse_manual_file(qPrintable(fileNames[i]), ¶ms, &table, &trips, &sites, &filter_presets); + parse_manual_file(qPrintable(fileNames[i]), ¶ms, &table, &trips, &sites, &devices, &filter_presets); } else { xml_params params; @@ -952,7 +954,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() setup_csv_params(r, params); parse_csv_file(qPrintable(fileNames[i]), ¶ms, specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", - &table, &trips, &sites, &filter_presets); + &table, &trips, &sites, &devices, &filter_presets); } } } diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 14619abae..327eb0578 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -530,7 +530,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() showProgressBar(); QByteArray fileNamePtr = QFile::encodeName(filename); - if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table)) + if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table)) setCurrentFile(fileNamePtr.data()); process_loaded_dives(); hideProgressBar(); @@ -1549,11 +1549,12 @@ void MainWindow::importFiles(const QStringList fileNames) 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; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); - parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_presets); + parse_file(fileNamePtr.data(), &table, &trips, &sites, &devices, &filter_presets); } QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); Command::importDives(&table, &trips, &sites, &filter_presets, IMPORT_MERGE_ALL_TRIPS, source); @@ -1570,7 +1571,7 @@ void MainWindow::loadFiles(const QStringList fileNames) showProgressBar(); for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); - if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table)) { + if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table)) { setCurrentFile(fileNamePtr.data()); addRecentFile(fileNamePtr, false); } @@ -1644,11 +1645,12 @@ void MainWindow::on_actionImportDiveSites_triggered() 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; for (const QString &s: fileNames) { QByteArray fileNamePtr = QFile::encodeName(s); - parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_presets); + parse_file(fileNamePtr.data(), &table, &trips, &sites, &devices, &filter_presets); } // The imported dive sites still have pointers to imported dives - remove them for (int i = 0; i < sites.nr; ++i) diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index bc4c4745d..c5a5cad48 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -5,6 +5,7 @@ #include "core/settings/qPrefCloudStorage.h" #include "desktop-widgets/mainwindow.h" #include "commands/command.h" +#include "core/device.h" #include "core/divesite.h" #include "core/trip.h" #include "core/errorhelper.h" @@ -456,8 +457,9 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) 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; - parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites, &filter_presets); + parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites, &devices, &filter_presets); Command::importDives(&table, &trips, &sites, nullptr, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de")); /* store last entered user/pass in config */ diff --git a/export-html.cpp b/export-html.cpp index e93d116d4..81ebbde75 100644 --- a/export-html.cpp +++ b/export-html.cpp @@ -9,6 +9,7 @@ #include "core/qt-gui.h" #include "core/qthelper.h" #include "core/file.h" +#include "core/device.h" #include "core/divesite.h" #include "core/trip.h" #include "core/save-html.h" @@ -44,7 +45,7 @@ int main(int argc, char **argv) qDebug() << "need --source and --output"; exit(1); } - int ret = parse_file(qPrintable(source), &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + int ret = parse_file(qPrintable(source), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); if (ret) { fprintf(stderr, "parse_file returned %d\n", ret); exit(1); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index e901d2ef1..f56e31551 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -353,7 +353,7 @@ void QMLManager::openLocalThenRemote(QString url) * we try to open this), parse_file (which is called by openAndMaybeSync) will ALWAYS connect * to the remote and populate the cache. * Otherwise parse_file will respect the git_local_only flag and only update if that isn't set */ - int error = parse_file(encodedFilename.constData(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + int error = parse_file(encodedFilename.constData(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); if (error) { /* there can be 2 reasons for this: * 1) we have cloud credentials, but there is no local repo (yet). @@ -452,7 +452,7 @@ void QMLManager::mergeLocalRepo() struct trip_table trips = empty_trip_table; struct dive_site_table sites = empty_dive_site_table; struct filter_preset_table filter_presets; - parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites, &filter_presets); + parse_file(qPrintable(nocloud_localstorage()), &table, &trips, &sites, &device_table, &filter_presets); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); } @@ -526,7 +526,7 @@ void QMLManager::finishSetup() qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_NOCLOUD); saveCloudCredentials(qPrefCloudStorage::cloud_storage_email(), qPrefCloudStorage::cloud_storage_password(), qPrefCloudStorage::cloud_storage_pin()); appendTextToLog(tr("working in no-cloud mode")); - int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); if (error) { // we got an error loading the local file setNotificationText(tr("Error parsing local storage, giving up")); @@ -710,7 +710,7 @@ void QMLManager::loadDivesWithValidCredentials() error = git_load_dives(git, branch, &dive_table, &trip_table, &dive_site_table, &filter_preset_table); } else { appendTextToLog(QString("didn't receive valid git repo, try again")); - error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); } setDiveListProcessing(false); if (!error) { @@ -2236,10 +2236,11 @@ void QMLManager::importCacheRepo(QString repo) 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; QString repoPath = QString("%1/cloudstorage/%2").arg(system_default_directory()).arg(repo); appendTextToLog(QString("importing %1").arg(repoPath)); - parse_file(qPrintable(repoPath), &table, &trips, &sites, &filter_presets); + parse_file(qPrintable(repoPath), &table, &trips, &sites, &devices, &filter_presets); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); changesNeedSaving(); } diff --git a/tests/testAirPressure.cpp b/tests/testAirPressure.cpp index 73088df68..5bc8c5369 100644 --- a/tests/testAirPressure.cpp +++ b/tests/testAirPressure.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testAirPressure.h" +#include "core/device.h" #include "core/dive.h" #include "core/divesite.h" #include "core/trip.h" @@ -19,7 +20,8 @@ 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, &filter_preset_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TestAtmPress.xml", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table), 0); dive = get_dive(0); dive->selected = true; QVERIFY(dive != NULL); @@ -54,7 +56,8 @@ 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, &filter_preset_table), 0); + QCOMPARE(parse_file("./testout.ssrf", &dive_table, &trip_table, &dive_site_table, + &device_table, &filter_preset_table), 0); dive = get_dive(0); QVERIFY(dive != NULL); dive->selected = true; diff --git a/tests/testdivesiteduplication.cpp b/tests/testdivesiteduplication.cpp index ca706b618..d626e23ed 100644 --- a/tests/testdivesiteduplication.cpp +++ b/tests/testdivesiteduplication.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testdivesiteduplication.h" +#include "core/device.h" #include "core/dive.h" #include "core/divesite.h" #include "core/trip.h" @@ -7,7 +8,8 @@ void TestDiveSiteDuplication::testReadV2() { - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0); + 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); } diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index fb864f2a8..9aa9a97ee 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -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 diff --git a/tests/testmerge.cpp b/tests/testmerge.cpp index 6055cfacd..b71bb0955 100644 --- a/tests/testmerge.cpp +++ b/tests/testmerge.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testmerge.h" +#include "core/device.h" #include "core/dive.h" // for save_dives() #include "core/divesite.h" #include "core/file.h" @@ -25,10 +26,11 @@ void TestMerge::testMergeEmpty() 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, &filter_presets), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &filter_presets), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); @@ -52,10 +54,11 @@ void TestMerge::testMergeBackwards() 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, &filter_presets), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &filter_presets), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QFile org(SUBSURFACE_TEST_DATA "/dives/test48+47.xml"); 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); diff --git a/tests/testparseperformance.cpp b/tests/testparseperformance.cpp index 8ca850918..32ca27a6d 100644 --- a/tests/testparseperformance.cpp +++ b/tests/testparseperformance.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testparseperformance.h" +#include "core/device.h" #include "core/divesite.h" #include "core/trip.h" #include "core/file.h" @@ -63,7 +64,8 @@ void TestParsePerformance::parseSsrf() return; } QBENCHMARK { - parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + parse_file(SUBSURFACE_TEST_DATA "/dives/large-anon.ssrf", &dive_table, &trip_table, + &dive_site_table, &device_table, &filter_preset_table); } } @@ -74,12 +76,14 @@ 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, &filter_preset_table); + parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table, + &device_table, &filter_preset_table); cleanup(); QBENCHMARK { - parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + parse_file(LARGE_TEST_REPO "[git]", &dive_table, &trip_table, &dive_site_table, + &device_table, &filter_preset_table); } } diff --git a/tests/testpicture.cpp b/tests/testpicture.cpp index c8215a09e..2833a8144 100644 --- a/tests/testpicture.cpp +++ b/tests/testpicture.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testpicture.h" +#include "core/device.h" #include "core/dive.h" #include "core/divesite.h" #include "core/errorhelper.h" @@ -26,7 +27,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, &filter_preset_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), 0); dive = get_dive(0); // Pictures will be added to selected dives dive->selected = true; diff --git a/tests/testprofile.cpp b/tests/testprofile.cpp index 22edb24de..c40c3083a 100644 --- a/tests/testprofile.cpp +++ b/tests/testprofile.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testprofile.h" +#include "core/device.h" #include "core/divesite.h" #include "core/trip.h" #include "core/file.h" @@ -12,10 +13,9 @@ // ..dives/exportprofilereference.csv) and copy the former over the later and commit that change // as well. - void TestProfile::testProfileExport() { - parse_file("../dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &filter_preset_table); + parse_file("../dives/abitofeverything.ssrf", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table); save_profiledata("exportprofile.csv", false); QFile org("../dives/exportprofilereference.csv"); org.open(QFile::ReadOnly); diff --git a/tests/testrenumber.cpp b/tests/testrenumber.cpp index 36c9f36cd..af5bd0203 100644 --- a/tests/testrenumber.cpp +++ b/tests/testrenumber.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "testrenumber.h" +#include "core/device.h" #include "core/dive.h" #include "core/divesite.h" #include "core/trip.h" @@ -8,7 +9,7 @@ void TestRenumber::setup() { - QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table, &dive_site_table, &filter_preset_table), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table), 0); process_loaded_dives(); } @@ -17,8 +18,9 @@ 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, &filter_presets), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &table, &trips, &sites, &devices, &filter_presets), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(dive_table.nr, 1); QCOMPARE(unsaved_changes(), 1); @@ -30,8 +32,9 @@ 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, &filter_presets), 0); + QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &table, &trips, &sites, &devices, &filter_presets), 0); add_imported_dives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS); QCOMPARE(dive_table.nr, 2); QCOMPARE(unsaved_changes(), 1); |