Parse: pass dive_table argument to parse_file()

To enable undo of divelog-importing it is crucial that parse_file()
can parse into arbitrary dive tables.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-08-18 15:06:15 +02:00 committed by Dirk Hohndel
parent ecb64d7e3e
commit d815e0c947
15 changed files with 77 additions and 77 deletions

View file

@ -499,9 +499,9 @@ extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, i
extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table); extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
extern int parse_dlf_buffer(unsigned char *buffer, size_t size); extern int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table);
extern int parse_file(const char *filename); extern int parse_file(const char *filename, struct dive_table *table);
extern int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate); extern int parse_csv_file(const char *filename, char **params, int pnr, const char *csvtemplate);
extern int parse_seabear_log(const char *filename); extern int parse_seabear_log(const char *filename);
extern int parse_txt_file(const char *filename, const char *csv); extern int parse_txt_file(const char *filename, const char *csv);

View file

@ -75,7 +75,7 @@ out:
} }
static void zip_read(struct zip_file *file, const char *filename) static void zip_read(struct zip_file *file, const char *filename, struct dive_table *table)
{ {
int size = 1024, n, read = 0; int size = 1024, n, read = 0;
char *mem = malloc(size); char *mem = malloc(size);
@ -86,11 +86,11 @@ static void zip_read(struct zip_file *file, const char *filename)
mem = realloc(mem, size); mem = realloc(mem, size);
} }
mem[read] = 0; mem[read] = 0;
(void) parse_xml_buffer(filename, mem, read, &dive_table, NULL); (void) parse_xml_buffer(filename, mem, read, table, NULL);
free(mem); free(mem);
} }
int try_to_open_zip(const char *filename) int try_to_open_zip(const char *filename, struct dive_table *table)
{ {
int success = 0; int success = 0;
/* Grr. libzip needs to re-open the file, it can't take a buffer */ /* Grr. libzip needs to re-open the file, it can't take a buffer */
@ -105,7 +105,7 @@ int try_to_open_zip(const char *filename)
/* skip parsing the divelogs.de pictures */ /* skip parsing the divelogs.de pictures */
if (strstr(zip_get_name(zip, index, 0), "pictures/")) if (strstr(zip_get_name(zip, index, 0), "pictures/"))
continue; continue;
zip_read(file, filename); zip_read(file, filename, table);
zip_fclose(file); zip_fclose(file);
success++; success++;
} }
@ -126,7 +126,7 @@ static int db_test_func(void *param, int columns, char **data, char **column)
} }
static int try_to_open_db(const char *filename, struct memblock *mem) static int try_to_open_db(const char *filename, struct memblock *mem, struct dive_table *table)
{ {
sqlite3 *handle; sqlite3 *handle;
char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'"; char dm4_test[] = "select count(*) from sqlite_master where type='table' and name='Dive' and sql like '%ProfileBlob%'";
@ -146,7 +146,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* Testing if DB schema resembles Suunto DM5 database format */ /* Testing if DB schema resembles Suunto DM5 database format */
retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, dm5_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, &dive_table); retval = parse_dm5_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -154,7 +154,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* Testing if DB schema resembles Suunto DM4 database format */ /* Testing if DB schema resembles Suunto DM4 database format */
retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, dm4_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, &dive_table); retval = parse_dm4_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -162,7 +162,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* Testing if DB schema resembles Shearwater database format */ /* Testing if DB schema resembles Shearwater database format */
retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, shearwater_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, &dive_table); retval = parse_shearwater_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -170,7 +170,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* Testing if DB schema resembles Atomic Cobalt database format */ /* Testing if DB schema resembles Atomic Cobalt database format */
retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, cobalt_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, &dive_table); retval = parse_cobalt_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -178,7 +178,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
/* Testing if DB schema resembles Divinglog database format */ /* Testing if DB schema resembles Divinglog database format */
retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL); retval = sqlite3_exec(handle, divinglog_test, &db_test_func, 0, NULL);
if (!retval) { if (!retval) {
retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, &dive_table); retval = parse_divinglog_buffer(handle, filename, mem->buffer, mem->size, table);
sqlite3_close(handle); sqlite3_close(handle);
return retval; return retval;
} }
@ -204,7 +204,7 @@ static int try_to_open_db(const char *filename, struct memblock *mem)
* *
* Followed by the data values (all comma-separated, all one long line). * Followed by the data values (all comma-separated, all one long line).
*/ */
static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem) static int open_by_filename(const char *filename, const char *fmt, struct memblock *mem, struct dive_table *table)
{ {
// hack to be able to provide a comment for the translated string // hack to be able to provide a comment for the translated string
static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC", static char *csv_warning = QT_TRANSLATE_NOOP3("gettextFromC",
@ -213,7 +213,7 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
/* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */ /* Suunto Dive Manager files: SDE, ZIP; divelogs.de files: DLD */
if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD")) if (!strcasecmp(fmt, "SDE") || !strcasecmp(fmt, "ZIP") || !strcasecmp(fmt, "DLD"))
return try_to_open_zip(filename); return try_to_open_zip(filename, table);
/* CSV files */ /* CSV files */
if (!strcasecmp(fmt, "CSV")) if (!strcasecmp(fmt, "CSV"))
@ -234,17 +234,17 @@ static int open_by_filename(const char *filename, const char *fmt, struct memblo
return 0; return 0;
} }
static int parse_file_buffer(const char *filename, struct memblock *mem) static int parse_file_buffer(const char *filename, struct memblock *mem, struct dive_table *table)
{ {
int ret; int ret;
char *fmt = strrchr(filename, '.'); char *fmt = strrchr(filename, '.');
if (fmt && (ret = open_by_filename(filename, fmt + 1, mem)) != 0) if (fmt && (ret = open_by_filename(filename, fmt + 1, mem, table)) != 0)
return ret; return ret;
if (!mem->size || !mem->buffer) if (!mem->size || !mem->buffer)
return report_error("Out of memory parsing file %s\n", filename); return report_error("Out of memory parsing file %s\n", filename);
return parse_xml_buffer(filename, mem->buffer, mem->size, &dive_table, NULL); return parse_xml_buffer(filename, mem->buffer, mem->size, table, NULL);
} }
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p) int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
@ -281,7 +281,7 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha
return 1; return 1;
} }
int parse_file(const char *filename) int parse_file(const char *filename, struct dive_table *table)
{ {
struct git_repository *git; struct git_repository *git;
const char *branch = NULL; const char *branch = NULL;
@ -327,7 +327,7 @@ int parse_file(const char *filename)
fmt = strrchr(filename, '.'); fmt = strrchr(filename, '.');
if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) { if (fmt && (!strcasecmp(fmt + 1, "DB") || !strcasecmp(fmt + 1, "BAK") || !strcasecmp(fmt + 1, "SQL"))) {
if (!try_to_open_db(filename, &mem)) { if (!try_to_open_db(filename, &mem, table)) {
free(mem.buffer); free(mem.buffer);
return 0; return 0;
} }
@ -335,14 +335,14 @@ int parse_file(const char *filename)
/* Divesoft Freedom */ /* Divesoft Freedom */
if (fmt && (!strcasecmp(fmt + 1, "DLF"))) { if (fmt && (!strcasecmp(fmt + 1, "DLF"))) {
ret = parse_dlf_buffer(mem.buffer, mem.size); ret = parse_dlf_buffer(mem.buffer, mem.size, table);
free(mem.buffer); free(mem.buffer);
return ret; return ret;
} }
/* DataTrak/Wlog */ /* DataTrak/Wlog */
if (fmt && !strcasecmp(fmt + 1, "LOG")) { if (fmt && !strcasecmp(fmt + 1, "LOG")) {
ret = datatrak_import(&mem, &dive_table); ret = datatrak_import(&mem, table);
free(mem.buffer); free(mem.buffer);
return ret; return ret;
} }
@ -350,11 +350,11 @@ int parse_file(const char *filename)
/* OSTCtools */ /* OSTCtools */
if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) { if (fmt && (!strcasecmp(fmt + 1, "DIVE"))) {
free(mem.buffer); free(mem.buffer);
ostctools_import(filename, &dive_table); ostctools_import(filename, table);
return 0; return 0;
} }
ret = parse_file_buffer(filename, &mem); ret = parse_file_buffer(filename, &mem, table);
free(mem.buffer); free(mem.buffer);
return ret; return ret;
} }

View file

@ -16,7 +16,7 @@ extern void ostctools_import(const char *file, struct dive_table *table);
extern "C" { extern "C" {
#endif #endif
extern int readfile(const char *filename, struct memblock *mem); extern int readfile(const char *filename, struct memblock *mem);
extern int try_to_open_zip(const char *filename); extern int try_to_open_zip(const char *filename, struct dive_table *table);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -1654,7 +1654,7 @@ static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
return offset + 946684800; return offset + 946684800;
} }
int parse_dlf_buffer(unsigned char *buffer, size_t size) int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *table)
{ {
unsigned char *ptr = buffer; unsigned char *ptr = buffer;
unsigned char event; unsigned char event;
@ -1663,7 +1663,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size)
int i; int i;
char serial[6]; char serial[6];
target_table = &dive_table; target_table = table;
// Check for the correct file magic // Check for the correct file magic
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E') if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')

View file

@ -620,7 +620,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
showProgressBar(); showProgressBar();
QByteArray fileNamePtr = QFile::encodeName(filename); QByteArray fileNamePtr = QFile::encodeName(filename);
if (!parse_file(fileNamePtr.data())) if (!parse_file(fileNamePtr.data(), &dive_table))
setCurrentFile(fileNamePtr.data()); setCurrentFile(fileNamePtr.data());
process_dives(false, false); process_dives(false, false);
hideProgressBar(); hideProgressBar();
@ -1776,7 +1776,7 @@ void MainWindow::importFiles(const QStringList fileNames)
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i)); fileNamePtr = QFile::encodeName(fileNames.at(i));
parse_file(fileNamePtr.data()); parse_file(fileNamePtr.data(), &dive_table);
} }
process_dives(true, false); process_dives(true, false);
refreshDisplay(); refreshDisplay();
@ -1823,7 +1823,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
showProgressBar(); showProgressBar();
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i)); fileNamePtr = QFile::encodeName(fileNames.at(i));
if (!parse_file(fileNamePtr.data())) { if (!parse_file(fileNamePtr.data(), &dive_table)) {
setCurrentFile(fileNamePtr.data()); setCurrentFile(fileNamePtr.data());
addRecentFile(fileNamePtr, false); addRecentFile(fileNamePtr, false);
} }

View file

@ -986,7 +986,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button)
break; break;
} }
/* parse file and import dives */ /* parse file and import dives */
parse_file(QFile::encodeName(zipFile.fileName())); parse_file(QFile::encodeName(zipFile.fileName()), &dive_table);
process_dives(true, false); process_dives(true, false);
MainWindow::instance()->refreshDisplay(); MainWindow::instance()->refreshDisplay();

View file

@ -41,7 +41,7 @@ int main(int argc, char **argv)
qDebug() << "need --source and --output"; qDebug() << "need --source and --output";
exit(1); exit(1);
} }
int ret = parse_file(qPrintable(source)); int ret = parse_file(qPrintable(source, &dive_table));
if (ret) { if (ret) {
fprintf(stderr, "parse_file returned %d\n", ret); fprintf(stderr, "parse_file returned %d\n", ret);
exit(1); exit(1);

View file

@ -255,7 +255,7 @@ void QMLManager::openLocalThenRemote(QString url)
QByteArray fileNamePrt = QFile::encodeName(url); QByteArray fileNamePrt = QFile::encodeName(url);
bool glo = qPrefCloudStorage::git_local_only(); bool glo = qPrefCloudStorage::git_local_only();
prefs.git_local_only = true; prefs.git_local_only = true;
int error = parse_file(fileNamePrt.data()); int error = parse_file(fileNamePrt.data(), &dive_table);
qPrefCloudStorage::set_git_local_only(glo); qPrefCloudStorage::set_git_local_only(glo);
if (error) { if (error) {
appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error)); appendTextToLog(QStringLiteral("loading dives from cache failed %1").arg(error));
@ -324,7 +324,7 @@ void QMLManager::updateAllGlobalLists()
void QMLManager::mergeLocalRepo() void QMLManager::mergeLocalRepo()
{ {
char *filename = NOCLOUD_LOCALSTORAGE; char *filename = NOCLOUD_LOCALSTORAGE;
parse_file(filename); parse_file(filename, &dive_table);
process_dives(true, false); process_dives(true, false);
} }
@ -389,7 +389,7 @@ void QMLManager::finishSetup()
QMLPrefs::instance()->setCredentialStatus(qPref::CS_NOCLOUD); QMLPrefs::instance()->setCredentialStatus(qPref::CS_NOCLOUD);
saveCloudCredentials(); saveCloudCredentials();
appendTextToLog(tr("working in no-cloud mode")); appendTextToLog(tr("working in no-cloud mode"));
int error = parse_file(existing_filename); int error = parse_file(existing_filename, &dive_table);
if (error) { if (error) {
// we got an error loading the local file // we got an error loading the local file
setNotificationText(tr("Error parsing local storage, giving up")); setNotificationText(tr("Error parsing local storage, giving up"));
@ -678,7 +678,7 @@ void QMLManager::loadDivesWithValidCredentials()
error = git_load_dives(git, branch); error = git_load_dives(git, branch);
} else { } else {
appendTextToLog(QString("didn't receive valid git repo, try again")); appendTextToLog(QString("didn't receive valid git repo, try again"));
error = parse_file(fileNamePrt.data()); error = parse_file(fileNamePrt.data(), &dive_table);
} }
if (!error) { if (!error) {
report_error("filename is now %s", fileNamePrt.data()); report_error("filename is now %s", fileNamePrt.data());

View file

@ -5,7 +5,7 @@
void TestDiveSiteDuplication::testReadV2() void TestDiveSiteDuplication::testReadV2()
{ {
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/TwoTimesTwo.ssrf", &dive_table), 0);
QCOMPARE(dive_site_table.nr, 2); QCOMPARE(dive_site_table.nr, 2);
} }

View file

@ -88,7 +88,7 @@ void TestGitStorage::testGitStorageLocal()
// test writing and reading back from local git storage // test writing and reading back from local git storage
git_repository *repo; git_repository *repo;
git_libgit2_init(); git_libgit2_init();
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table), 0);
QFETCH(QString, testDirName); QFETCH(QString, testDirName);
QFETCH(QString, prefixRead); QFETCH(QString, prefixRead);
QFETCH(QString, prefixWrite); QFETCH(QString, prefixWrite);
@ -101,7 +101,7 @@ void TestGitStorage::testGitStorageLocal()
QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0); QCOMPARE(save_dives(qPrintable(repoNameWrite + "[test]")), 0);
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]")), 0); QCOMPARE(parse_file(qPrintable(repoNameRead + "[test]"), &dive_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf"); QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -120,10 +120,10 @@ void TestGitStorage::testGitStorageCloud()
// connect to the ssrftest repository on the cloud server // connect to the ssrftest repository on the cloud server
// and repeat the same test as before with the local git storage // and repeat the same test as before with the local git storage
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf", &dive_table), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
QFile org("./SampleDivesV3.ssrf"); QFile org("./SampleDivesV3.ssrf");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -144,8 +144,8 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
// read the local repo from the previous test and add dive 10 // read the local repo from the previous test and add dive 10
QCOMPARE(parse_file(qPrintable(localCacheRepo)), 0); QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml", &dive_table), 0);
// calling process_dive() sorts the table, but calling it with // calling process_dive() sorts the table, but calling it with
// is_imported == true causes it to try to update the window title... let's not do that // is_imported == true causes it to try to update the window title... let's not do that
process_dives(false, false); process_dives(false, false);
@ -154,7 +154,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QCOMPARE(save_dives("./SampleDivesV3plus10local.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10local.ssrf"), 0);
clear_dive_file_data(); clear_dive_file_data();
// open the cloud storage and compare // open the cloud storage and compare
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
QFile org("./SampleDivesV3plus10local.ssrf"); QFile org("./SampleDivesV3plus10local.ssrf");
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -172,7 +172,7 @@ void TestGitStorage::testGitStorageCloudOfflineSync()
QDir localCacheDirectorySave(localCacheDir + "save"); QDir localCacheDirectorySave(localCacheDir + "save");
QCOMPARE(localCacheDirectorySave.removeRecursively(), true); QCOMPARE(localCacheDirectorySave.removeRecursively(), true);
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true); QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
org.close(); org.close();
org.open(QFile::ReadOnly); org.open(QFile::ReadOnly);
@ -193,15 +193,15 @@ void TestGitStorage::testGitStorageCloudMerge()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]"; QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]";
QCOMPARE(parse_file(qPrintable(localCacheRepoSave)), 0); QCOMPARE(parse_file(qPrintable(localCacheRepoSave), &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table), 0);
process_dives(false, false); process_dives(false, false);
QCOMPARE(save_dives(qPrintable(localCacheRepoSave)), 0); QCOMPARE(save_dives(qPrintable(localCacheRepoSave)), 0);
clear_dive_file_data(); clear_dive_file_data();
// now we open the cloud storage repo and add a different dive to it // now we open the cloud storage repo and add a different dive to it
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table), 0);
process_dives(false, false); process_dives(false, false);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data(); clear_dive_file_data();
@ -212,13 +212,13 @@ void TestGitStorage::testGitStorageCloudMerge()
QCOMPARE(localCacheDirectory.removeRecursively(), true); QCOMPARE(localCacheDirectory.removeRecursively(), true);
QDir localCacheDirectorySave(localCacheDir + "save"); QDir localCacheDirectorySave(localCacheDir + "save");
QCOMPARE(localCacheDirectory.rename(localCacheDir + "save", localCacheDir), true); QCOMPARE(localCacheDirectory.rename(localCacheDir + "save", localCacheDir), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf"), 0); QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml", &dive_table), 0);
process_dives(false, false); process_dives(false, false);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml", &dive_table), 0);
process_dives(false, false); process_dives(false, false);
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0);
QFile org("./SampleDivesV3plus10-11-12-merged.ssrf"); QFile org("./SampleDivesV3plus10-11-12-merged.ssrf");
@ -240,7 +240,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
QCOMPARE(parse_file(qPrintable(localCacheRepo)), 0); QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0);
process_dives(false, false); process_dives(false, false);
struct dive *dive = get_dive(1); struct dive *dive = get_dive(1);
delete_single_dive(1); delete_single_dive(1);
@ -256,7 +256,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true); QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
} }
// now we open the cloud storage repo and modify that first dive // now we open the cloud storage repo and modify that first dive
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
process_dives(false, false); process_dives(false, false);
dive = get_dive(1); dive = get_dive(1);
QVERIFY(dive != NULL); QVERIFY(dive != NULL);
@ -272,7 +272,7 @@ void TestGitStorage::testGitStorageCloudMerge2()
QCOMPARE(localCacheDirectory.removeRecursively(), true); QCOMPARE(localCacheDirectory.removeRecursively(), true);
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true); QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
QFile org("./SampleDivesMinus1-merged.ssrf"); QFile org("./SampleDivesMinus1-merged.ssrf");
@ -296,7 +296,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]"); QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org")); QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]"; QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
process_dives(false, false); process_dives(false, false);
struct dive *dive = get_dive(0); struct dive *dive = get_dive(0);
QVERIFY(dive != 0); QVERIFY(dive != 0);
@ -308,7 +308,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0);
clear_dive_file_data(); clear_dive_file_data();
QCOMPARE(parse_file(qPrintable(localCacheRepo)), 0); QCOMPARE(parse_file(qPrintable(localCacheRepo), &dive_table), 0);
process_dives(false, false); process_dives(false, false);
dive = get_dive(0); dive = get_dive(0);
dive->notes = strdup("Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough"); dive->notes = strdup("Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough");
@ -327,7 +327,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true); QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
} }
// now we open the cloud storage repo and modify those first dive notes differently // now we open the cloud storage repo and modify those first dive notes differently
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
process_dives(false, false); process_dives(false, false);
dive = get_dive(0); dive = get_dive(0);
dive->notes = strdup("Completely different dive notes\nBut also multi line"); dive->notes = strdup("Completely different dive notes\nBut also multi line");
@ -345,7 +345,7 @@ void TestGitStorage::testGitStorageCloudMerge3()
QCOMPARE(localCacheDirectory.removeRecursively(), true); QCOMPARE(localCacheDirectory.removeRecursively(), true);
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true); QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); QCOMPARE(parse_file(qPrintable(cloudTestRepo), &dive_table), 0);
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0); QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
// we are not trying to compare this to a pre-determined result... what this test // 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 // checks is that there are no parsing errors with the merge

View file

@ -21,9 +21,9 @@ void TestMerge::testMergeEmpty()
/* /*
* check that we correctly merge mixed cylinder dives * check that we correctly merge mixed cylinder dives
*/ */
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table), 0);
process_dives(true, false); process_dives(true, false);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &dive_table), 0);
process_dives(true, false); process_dives(true, false);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
@ -44,9 +44,9 @@ void TestMerge::testMergeBackwards()
/* /*
* check that we correctly merge mixed cylinder dives * check that we correctly merge mixed cylinder dives
*/ */
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &dive_table), 0);
process_dives(true, false); process_dives(true, false);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table), 0);
process_dives(true, false); process_dives(true, false);
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0); QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml"); QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");

View file

@ -127,13 +127,13 @@ int TestParse::parseDivingLog()
int TestParse::parseV2NoQuestion() int TestParse::parseV2NoQuestion()
{ {
// parsing of a V2 file should work // parsing of a V2 file should work
return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml"); return parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
} }
int TestParse::parseV3() int TestParse::parseV3()
{ {
// parsing of a V3 files should succeed // parsing of a V3 files should succeed
return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml"); return parse_file(SUBSURFACE_TEST_DATA "/dives/test42.xml", &dive_table);
} }
void TestParse::testParse() void TestParse::testParse()
@ -279,7 +279,7 @@ void TestParse::testParseDLD()
QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD"; QString filename = SUBSURFACE_TEST_DATA "/dives/TestDiveDivelogsDE.DLD";
QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0); QVERIFY(readfile(filename.toLatin1().data(), &mem) > 0);
QVERIFY(try_to_open_zip(filename.toLatin1().data()) > 0); QVERIFY(try_to_open_zip(filename.toLatin1().data(), &dive_table) > 0);
fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr); fprintf(stderr, "number of dives from DLD: %d \n", dive_table.nr);
@ -299,8 +299,8 @@ void TestParse::testParseMerge()
/* /*
* check that we correctly merge mixed cylinder dives * check that we correctly merge mixed cylinder dives
*/ */
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/ostc.xml", &dive_table), 0);
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/vyper.xml", &dive_table), 0);
QCOMPARE(save_dives("./testmerge.ssrf"), 0); QCOMPARE(save_dives("./testmerge.ssrf"), 0);
FILE_COMPARE("./testmerge.ssrf", FILE_COMPARE("./testmerge.ssrf",
SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml"); SUBSURFACE_TEST_DATA "/dives/mergedVyperOstc.xml");
@ -371,7 +371,7 @@ int TestParse::parseCSVmanual(int units, std::string file)
void TestParse::exportCSVDiveDetails() void TestParse::exportCSVDiveDetails()
{ {
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml"); parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt"); export_dives_xslt("testcsvexportmanual.csv", 0, 0, "xml2manualcsv.xslt");
export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt"); export_dives_xslt("testcsvexportmanualimperial.csv", 0, 1, "xml2manualcsv.xslt");
@ -420,7 +420,7 @@ int TestParse::parseCSVprofile(int units, std::string file)
void TestParse::exportCSVDiveProfile() void TestParse::exportCSVDiveProfile()
{ {
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml"); parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt"); export_dives_xslt("testcsvexportprofile.csv", 0, 0, "xml2csv.xslt");
export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt"); export_dives_xslt("testcsvexportprofileimperial.csv", 0, 1, "xml2csv.xslt");
@ -438,13 +438,13 @@ void TestParse::exportCSVDiveProfile()
void TestParse::exportUDDF() void TestParse::exportUDDF()
{ {
parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml"); parse_file(SUBSURFACE_TEST_DATA "/dives/test40.xml", &dive_table);
export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt"); export_dives_xslt("testuddfexport.uddf", 0, 1, "uddf-export.xslt");
clear_dive_file_data(); clear_dive_file_data();
parse_file("testuddfexport.uddf"); parse_file("testuddfexport.uddf", &dive_table);
export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt"); export_dives_xslt("testuddfexport2.uddf", 0, 1, "uddf-export.xslt");
FILE_COMPARE("testuddfexport.uddf", FILE_COMPARE("testuddfexport.uddf",

View file

@ -23,7 +23,7 @@ void TestPicture::addPicture()
struct picture *pic1, *pic2; struct picture *pic1, *pic2;
verbose = 1; verbose = 1;
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test44.xml", &dive_table), 0);
dive = get_dive(0); dive = get_dive(0);
QVERIFY(dive != NULL); QVERIFY(dive != NULL);
pic1 = dive->picture_list; pic1 = dive->picture_list;

View file

@ -4,7 +4,7 @@
void TestProfile::testRedCeiling() void TestProfile::testRedCeiling()
{ {
parse_file("../dives/deep.xml"); parse_file("../dives/deep.xml", &dive_table);
} }
QTEST_GUILESS_MAIN(TestProfile) QTEST_GUILESS_MAIN(TestProfile)

View file

@ -7,14 +7,14 @@
void TestRenumber::setup() void TestRenumber::setup()
{ {
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &dive_table), 0);
process_dives(false, false); process_dives(false, false);
dive_table.preexisting = dive_table.nr; dive_table.preexisting = dive_table.nr;
} }
void TestRenumber::testMerge() void TestRenumber::testMerge()
{ {
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47b.xml", &dive_table), 0);
process_dives(true, false); process_dives(true, false);
QCOMPARE(dive_table.nr, 1); QCOMPARE(dive_table.nr, 1);
QCOMPARE(unsaved_changes(), 1); QCOMPARE(unsaved_changes(), 1);
@ -24,7 +24,7 @@ void TestRenumber::testMerge()
void TestRenumber::testMergeAndAppend() void TestRenumber::testMergeAndAppend()
{ {
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml"), 0); QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47c.xml", &dive_table), 0);
process_dives(true, false); process_dives(true, false);
QCOMPARE(dive_table.nr, 2); QCOMPARE(dive_table.nr, 2);
QCOMPARE(unsaved_changes(), 1); QCOMPARE(unsaved_changes(), 1);