2017-04-27 18:21:27 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-04-17 15:21:39 +00:00
|
|
|
#include "testprofile.h"
|
2020-10-17 10:32:22 +00:00
|
|
|
#include "core/device.h"
|
2024-06-07 08:25:09 +00:00
|
|
|
#include "core/dive.h"
|
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"
|
2019-05-31 14:09:14 +00:00
|
|
|
#include "core/trip.h"
|
2019-03-03 21:29:40 +00:00
|
|
|
#include "core/file.h"
|
2020-05-02 19:38:55 +00:00
|
|
|
#include "core/save-profiledata.h"
|
2021-02-26 13:03:31 +00:00
|
|
|
#include "core/pref.h"
|
2022-02-10 01:14:22 +00:00
|
|
|
#include "QTextCodec"
|
2014-04-17 15:21:39 +00:00
|
|
|
|
2020-05-05 12:39:44 +00:00
|
|
|
// This test compares the content of struct profile against a known reference version for a list
|
|
|
|
// of dives to prevent accidental regressions. Thus is you change anything in the profile this
|
|
|
|
// test will fail. If this change was intentional, run the test manually. Make sure only the
|
|
|
|
// indended fields change (for example by computing a diff between exportprofile.csv and
|
|
|
|
// ..dives/exportprofilereference.csv) and copy the former over the later and commit that change
|
|
|
|
// as well.
|
|
|
|
|
2021-04-16 13:47:51 +00:00
|
|
|
void TestProfile::init()
|
|
|
|
{
|
2024-06-02 10:49:11 +00:00
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
|
2021-04-16 13:47:51 +00:00
|
|
|
// Set UTF8 text codec as in real applications
|
|
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
|
|
|
|
|
2024-06-16 10:24:36 +00:00
|
|
|
// first, setup the preferences
|
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2021-04-16 13:47:51 +00:00
|
|
|
|
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
|
|
|
QCoreApplication::setApplicationName("Subsurface");
|
|
|
|
}
|
2020-05-02 19:38:55 +00:00
|
|
|
void TestProfile::testProfileExport()
|
2014-04-17 15:21:39 +00:00
|
|
|
{
|
2021-02-26 13:03:31 +00:00
|
|
|
prefs.planner_deco_mode = BUEHLMANN;
|
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
|
|
|
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
|
2024-06-07 08:25:09 +00:00
|
|
|
divelog.dives.sort();
|
2020-05-02 19:38:55 +00:00
|
|
|
save_profiledata("exportprofile.csv", false);
|
2021-03-24 18:47:48 +00:00
|
|
|
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv");
|
2021-02-26 13:03:31 +00:00
|
|
|
QCOMPARE(org.open(QFile::ReadOnly), true);
|
2020-05-02 19:38:55 +00:00
|
|
|
QFile out("exportprofile.csv");
|
2021-02-26 13:03:31 +00:00
|
|
|
QCOMPARE(out.open(QFile::ReadOnly), true);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QString readin = orgS.readAll();
|
|
|
|
QString written = outS.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
|
|
|
|
|
|
|
}
|
|
|
|
void TestProfile::testProfileExportVPMB()
|
|
|
|
{
|
|
|
|
prefs.planner_deco_mode = VPMB;
|
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
|
|
|
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
|
2024-06-07 08:25:09 +00:00
|
|
|
divelog.dives.sort();
|
2021-02-26 13:03:31 +00:00
|
|
|
save_profiledata("exportprofileVPMB.csv", false);
|
2021-03-24 18:47:48 +00:00
|
|
|
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv");
|
2021-02-26 13:03:31 +00:00
|
|
|
QCOMPARE(org.open(QFile::ReadOnly), true);
|
|
|
|
QFile out("exportprofileVPMB.csv");
|
|
|
|
QCOMPARE(out.open(QFile::ReadOnly), true);
|
2020-05-02 19:38:55 +00:00
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QString readin = orgS.readAll();
|
|
|
|
QString written = outS.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
|
|
|
|
2014-04-17 15:21:39 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 22:26:51 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestProfile)
|