2017-04-27 18:21:27 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-02-22 01:23:19 +00:00
|
|
|
#include "testmerge.h"
|
2020-10-17 10:32:22 +00:00
|
|
|
#include "core/device.h"
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "core/dive.h" // for save_dives()
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#include "core/divelog.h"
|
2019-03-04 22:20:29 +00:00
|
|
|
#include "core/divesite.h"
|
2018-07-25 19:39:04 +00:00
|
|
|
#include "core/file.h"
|
2019-05-31 14:09:14 +00:00
|
|
|
#include "core/trip.h"
|
2021-04-16 13:47:51 +00:00
|
|
|
#include "core/pref.h"
|
2017-02-22 01:23:19 +00:00
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
|
void TestMerge::initTestCase()
|
|
|
|
{
|
|
|
|
/* we need to manually tell that the resource exists, because we are using it as library. */
|
|
|
|
Q_INIT_RESOURCE(subsurface);
|
2021-07-21 20:32:28 +00:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2017-02-22 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
2017-03-03 06:33:25 +00:00
|
|
|
void TestMerge::cleanup()
|
|
|
|
{
|
|
|
|
clear_dive_file_data();
|
|
|
|
}
|
|
|
|
|
2017-02-22 01:23:19 +00:00
|
|
|
void TestMerge::testMergeEmpty()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* check that we correctly merge mixed cylinder dives
|
|
|
|
*/
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog log;
|
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
|
|
|
|
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
|
|
|
|
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
2017-02-22 01:23:19 +00:00
|
|
|
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
|
2017-02-24 06:52:07 +00:00
|
|
|
QFile org(SUBSURFACE_TEST_DATA "/dives/test47+48.xml");
|
2017-02-22 01:23:19 +00:00
|
|
|
org.open(QFile::ReadOnly);
|
|
|
|
QFile out("./testmerge47+48.ssrf");
|
|
|
|
out.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QStringList readin = orgS.readAll().split("\n");
|
|
|
|
QStringList written = outS.readAll().split("\n");
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
while (readin.size() && written.size())
|
2017-03-03 06:22:22 +00:00
|
|
|
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
|
2017-02-22 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestMerge::testMergeBackwards()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* check that we correctly merge mixed cylinder dives
|
|
|
|
*/
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog log;
|
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &log), 0);
|
|
|
|
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &log), 0);
|
|
|
|
add_imported_dives(&log, IMPORT_MERGE_ALL_TRIPS);
|
2017-02-22 01:23:19 +00:00
|
|
|
QCOMPARE(save_dives("./testmerge47+48.ssrf"), 0);
|
2019-04-05 19:56:20 +00:00
|
|
|
QFile org(SUBSURFACE_TEST_DATA "/dives/test48+47.xml");
|
2017-02-22 01:23:19 +00:00
|
|
|
org.open(QFile::ReadOnly);
|
|
|
|
QFile out("./testmerge47+48.ssrf");
|
|
|
|
out.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QStringList readin = orgS.readAll().split("\n");
|
|
|
|
QStringList written = outS.readAll().split("\n");
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
while (readin.size() && written.size())
|
2017-03-03 06:22:22 +00:00
|
|
|
QCOMPARE(written.takeFirst().trimmed(), readin.takeFirst().trimmed());
|
2017-02-22 01:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestMerge)
|