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()
|
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
|
|
|
|
*/
|
2020-01-09 05:25:02 +00:00
|
|
|
struct dive_table table = empty_dive_table;
|
|
|
|
struct trip_table trips = empty_trip_table;
|
|
|
|
struct dive_site_table sites = empty_dive_site_table;
|
2020-10-17 10:32:22 +00:00
|
|
|
struct device_table devices;
|
2020-10-17 07:58:23 +00:00
|
|
|
struct filter_preset_table filter_presets;
|
2020-10-17 10:32:22 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
|
2020-10-17 14:07:39 +00:00
|
|
|
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
|
2020-10-17 10:32:22 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
|
2020-10-17 14:07:39 +00:00
|
|
|
add_imported_dives(&table, &trips, &sites, &devices, 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");
|
2018-07-25 19:39:04 +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
|
|
|
|
*/
|
2020-01-09 05:25:02 +00:00
|
|
|
struct dive_table table = empty_dive_table;
|
|
|
|
struct trip_table trips = empty_trip_table;
|
|
|
|
struct dive_site_table sites = empty_dive_site_table;
|
2020-10-17 10:32:22 +00:00
|
|
|
struct device_table devices;
|
2020-10-17 07:58:23 +00:00
|
|
|
struct filter_preset_table filter_presets;
|
2020-10-17 10:32:22 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test48.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
|
2020-10-17 14:07:39 +00:00
|
|
|
add_imported_dives(&table, &trips, &sites, &devices, IMPORT_MERGE_ALL_TRIPS);
|
2020-10-17 10:32:22 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test47.xml", &table, &trips, &sites, &devices, &filter_presets), 0);
|
2020-10-17 14:07:39 +00:00
|
|
|
add_imported_dives(&table, &trips, &sites, &devices, 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");
|
2018-07-25 19:39:04 +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)
|