mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 13:10:19 +00:00
9c253ee6c5
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>
68 lines
2.5 KiB
C++
68 lines
2.5 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "testprofile.h"
|
|
#include "core/device.h"
|
|
#include "core/divelog.h"
|
|
#include "core/divesite.h"
|
|
#include "core/trip.h"
|
|
#include "core/file.h"
|
|
#include "core/save-profiledata.h"
|
|
#include "core/pref.h"
|
|
#include "QTextCodec"
|
|
|
|
// 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.
|
|
|
|
void TestProfile::init()
|
|
{
|
|
// Set UTF8 text codec as in real applications
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForMib(106));
|
|
// first, setup the preferences
|
|
|
|
// normally we should be able to do this - but it makes this test fail because the reference data
|
|
// assume that the prefs are all 0 / false
|
|
// copy_prefs(&default_prefs, &prefs);
|
|
// instead we just set up the cloud_base_url to prevent parse_file() from crashing
|
|
prefs.cloud_base_url = strdup(default_prefs.cloud_base_url);
|
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
|
QCoreApplication::setApplicationName("Subsurface");
|
|
}
|
|
void TestProfile::testProfileExport()
|
|
{
|
|
prefs.planner_deco_mode = BUEHLMANN;
|
|
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
|
|
save_profiledata("exportprofile.csv", false);
|
|
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereference.csv");
|
|
QCOMPARE(org.open(QFile::ReadOnly), true);
|
|
QFile out("exportprofile.csv");
|
|
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;
|
|
parse_file(SUBSURFACE_TEST_DATA "/dives/abitofeverything.ssrf", &divelog);
|
|
save_profiledata("exportprofileVPMB.csv", false);
|
|
QFile org(SUBSURFACE_TEST_DATA "/dives/exportprofilereferenceVPMB.csv");
|
|
QCOMPARE(org.open(QFile::ReadOnly), true);
|
|
QFile out("exportprofileVPMB.csv");
|
|
QCOMPARE(out.open(QFile::ReadOnly), true);
|
|
QTextStream orgS(&org);
|
|
QTextStream outS(&out);
|
|
QString readin = orgS.readAll();
|
|
QString written = outS.readAll();
|
|
QCOMPARE(readin, written);
|
|
|
|
}
|
|
|
|
QTEST_GUILESS_MAIN(TestProfile)
|