Commit graph

399 commits

Author SHA1 Message Date
Berthold Stoeger
aa4b48f440 core: move floating point functions to own header file
This were in subsurface-string.h for unknown reasons.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-30 22:34:38 +02:00
Berthold Stoeger
61701509b0 core: replace IS_FP_SAME macro by inline function
No reason to keep this as a macro - a function is easier to
read, type safe and easier to debug. Moreover, give it the
more appropriate name "nearly_equal()". After all, it precisely
does NOT check floating points for equality.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-08-30 22:34:38 +02:00
Linus Torvalds
e33680c336 git access: add proper cleanup function for git_info
We had various random "free parts of the git info" left-overs from when
we passed down the git repo data ad-hoc.  Get rid of it, and replace it
with just doing a 'cleanup_git_info()' that does the final cleanup of it
all.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-04-22 08:28:17 -07:00
Linus Torvalds
7e632173e0 Collect and convert git repo data to 'struct git_info'
We have this nasty habit of randomly passing down all the different
things that we use to look up the local and remote git repository, and
the information associated with it.

Start collecting the data into a 'struct git_info' instead, so that it
is easier to manage, and easier and more logical to just look up
different parts of the puzzle.

This is a fairly mechanical conversion, but has moved all the basic
information collection to the 'is_git_repository()' function.  That
function no longer actually opens the repository (so the 'dry_run'
argument is gone, and instead a successful 'is_git_repository()' is
followed by 'opn_git_repository()' if you actually want the old
non-dry_run semantics.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-04-17 22:14:34 -07:00
Dirk Hohndel
8b463ca158 Qt6: add missing includes
This class is only available via Qt5 compatibility and for that we need the
explicit include.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-03-12 08:28:32 -08:00
Dirk Hohndel
ce254bee57 build-system: update cmake to allow Qt5 and Qt6
Qt6 builds of course still fail, but now they are at least possible.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-03-12 08:28:32 -08:00
Dirk Hohndel
4fdbb116ef tests: fix integer constants
In TestUnitConversion we used casts instead of the more common suffix
designations to indicate the type of those integer constants.
Worse, in commit efab955d85 ("cleanup: make feet_to_mm signed") the
return type of feet_to_mm() changed, but the value it is compared to
wasn't adjusted in the test which caused some builds with more
aggressive compiler flags to fail.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-01-04 19:48:35 +01:00
Berthold Stoeger
0e9eee0a7f core: return floating point from to_PSI() functions
Dive data are stored internally using integral types using
appropriately fine units (mm, mbar, mkelvin, etc.). These
are converted with functions defined in units.h for display
(m, bar, C, etc.). Usually floating points are returned by
these functions, to retain the necessary precision. There
is one exception: the to_PSI() and mbar_to_PSI() functions.

For consistency, make these functions likewise return floats.
This will be needed for the rework of the profile-axes.
The plan is to use the conversion functions to make the
axes aware of the displayed values. This in turn will be
necessary to place the ticks at sensible distances. However,
the conversions need to be precise, which is not the
case for the current to_PSI() functions.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Dirk Hohndel
2a0d14b100 core: remove location service preferences
Including the related tests.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-09-13 11:21:34 -07:00
Dirk Hohndel
72bdd506f0 tests: initialize our prefs to the default values
Otherwise we end up with nonsensical values which lead to a division by zero,
which in return leads to different results, depending on platform.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-07-23 11:30:17 -07:00
Robert C. Helling
09bbd846da The planner should not always ascent from the depth of
the last manually entered waypoint but consider the
possibility that it should first top where we are
before the next stop depth has cleared.

Reported-by: David Carron

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-05-07 08:16:41 -07:00
Dirk Hohndel
fe074ccad1 cloudstorage: adapt tests
The code assumes that prefs.cloud_base_url is non NULL. Allowing that to
be NULL makes no sense during normal operation of the app. Yet, most of
the tests don't initialize the prefs at all.

Making things worse, if we do correctly initialize the prefs (so as to
reasonably approximate the behavior when running the app), things break
because some of the reference outputs assume that the prefs are unset.
This deserves fixing.

For now, simply make sure that cloud_base_url is set for all the tests
that try to parse files.

Additionally, the semantics how cloud_base_url is saved to disk have
changed, so adjust the test for those prefs accordingly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-04-19 12:51:01 -07:00
Dirk Hohndel
c5eb806adb cloudstorage: some cleanup of cloud url handling
We know the preference is never empty, so stop testing for this. But
don't maintain two different preferences with basically the same
content. Instead add the '/git' suffix where needed and keep this all in
one place.

Simplify the extraction of the branch name from the cloud URL.

Also a typo fix and a new comment.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-04-19 12:51:01 -07:00
Dirk Hohndel
01fb69e198 tests: fix incorrect relative path names
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-03-24 11:47:48 -07:00
Robert C. Helling
1c8c6f9551 Add test for profile in VPMB mode
For some reason, this test seems not to run effectively, at least
locally, I had to update the reference file.

Added a check that indeed the file to be compared was
successfully opened.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2021-03-24 10:30:22 -07:00
Berthold Stoeger
80c92acc33 cleanup: remove setAppState from TestPlan
This is not needed anymore, since the planner passes down the
in_planner flag to the appropriate functions. The planner state
is not queried via a global anymore.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Dirk Hohndel
76136010bf preferences: remove pointless member
This could never have worked the way it was used.

Some whitespace fixes snuck into this commit.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2021-01-06 10:18:23 -08:00
Dirk Hohndel
695950b15a build-system: fix tests in mobile builds
We can no longer build TestPictures in mobile builds.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-11-19 17:18:33 -08:00
Dirk Hohndel
2a876be844 tests: don't fail if TestGitStorage can reach the server
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-26 19:27:03 -07:00
Berthold Stoeger
0e196310f9 cleanup: split out divecomputer functions from dive.c
Since dive.c is so huge, split out divecomputer-related functions
into divecomputer.[c|h], sample.[c|h] and extradata.[c|h].

This does not give huge compile time improvements, since
struct dive contains a struct divecomputer and therefore
dive.h has to include divecomputer.h. However, it make things
distinctly more clear.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
8212acc992 cleanup: break out event-related code into event.[c|h]
In an effort to reduce the size of dive.h and dive.c, break out
the event related functions. Moreover event-names were handled
by the profile-code, collect that also in the new source files.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:52 -07:00
Berthold Stoeger
d403532a86 cleanup: remove unsaved_changes() test in testrenumber.cpp
Unsaved changes are now kept track by the undo-system. No need
to test for this function when directly modifying the core
data structures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25 13:59:04 -07:00
Dirk Hohndel
a58eee9aa3 tests: move TestGitStorage to its own test config
This way 'make check' doesn't execute TestGitStorage anymore.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-24 15:22:37 -07:00
Berthold Stoeger
39a4090c0a devices: add devices in Command::importTable()
Add a device_table parameters to Command::importTable() and
add_imported_dives(). The content of this table will be added
to the global device list (respectively removed on undo).

This is currently a no-op, as the parser doesn't yet fill
out the device table, but adds devices directly to the global
device table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
a261466594 parser: add device_table to parser state
If we want to avoid the parsers to directly modify global data,
we have to provide a device_table to parse into. This adds such
a state and the corresponding function parameters. However,
for now this is unused.

Adding new parameters is very painful and this commit shows that
we urgently need a "struct divelog" collecting all those tables!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24 09:51:37 -07:00
Berthold Stoeger
d508a16aca parser: replace params[] code by new xml_params struct
This fixes a load of memory holes, and makes the code
(hopefully) more readable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23 18:17:02 -07:00
Berthold Stoeger
a7bbb6c1cc filter: remove filter_preset_table_t
We used a typedef "filter_preset_table_t" for the filter preset table,
because it is a "std::vector<filter_preset>". However, that is in
contrast to all the other global tables (dives, trips, sites) that we
have.

Therefore, turn this into a standard struct, which simply inherits
from "std::vector<filter_preset>". Note that while inheriting from
std::vector<> is generally not recommended, it is not a problem
here, because we don't modify it in any shape or form.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17 09:04:20 -07:00
Berthold Stoeger
41cf83583d filter: load filter presets from XML files
This is a bit painful: since we don't want to modify the filter
presets when the user imports (as opposed to opens) a log,
we have to provide a table where the parser stores the presets.
Calling the parser is getting quite unwieldy, since many tables
are passed. We probably should introduce a structure representing
a full log-book at one point, which collects all the things that
are saved to the log.

Apart from that, this is simply the counterpart to saving to XML.
The interpretation of the string data is performed by core
functions, not the parser itself to avoid code duplication with
the git parser.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-09-29 16:13:03 -07:00
Miika Turkia
75f3cb2027 Test case for multicylinder support on CSV import
Test for importing Subsurface generated CSV dive details, with multiple
cylinders support.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-26 11:33:10 -07:00
Miika Turkia
5a7e11b0bc Use single cylinder dive for tests
Now that CSV export supports multiple cylinders and import doesn't, we
need a test dive with single cylinder in it. (Multi-cylinder import from
CSV will be supported for Subsurface style CSV export only, and not
generic exports that are used here.)

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-26 11:33:10 -07:00
Miika Turkia
cef10454aa Initialize variable to silence compiler warning
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-26 11:33:10 -07:00
Miika Turkia
dbd1ee306a Use stored SAC for validation
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-18 09:32:58 -07:00
Miika Turkia
86f003b21c TestParse to support SAC
Take into account the added SAC field in dive detail CSV export.

Note that we do a test of:
- export to CSV file
- import the written CSV file
- export the newly read data to second file
- compare these two exported files

As SAC information is not currently read from any import, this adds the
SAC value to the imported data before exporting again.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-18 09:32:58 -07:00
Berthold Stoeger
74f03e3537 media: move addition of pictures out of create_picture()
If we want to make addition of pictures undoable, then create_picture()
must not add directly to the dive. Instead, return the dive to which the
picture should be added and let the caller perform the addition.

This means that the picture-test has to be adapted.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Berthold Stoeger
989d6a3f96 media: use table instead of linked list for media
For consistency with equipment, use our table macros for pictures.
Generally tables (arrays) are preferred over linked lists, because
they allow random access.

This is mostly copy & paste of the equipment code.

Sadly, our table macros are quite messy and need some revamping.
Therefore, the resulting code is likewise somewhat messy.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06 13:58:09 -07:00
Robert C. Helling
f55925db60 Explanatory comment in testprofile.cpp
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-05-05 08:56:33 -07:00
Robert C. Helling
b3270222fd Add test for profile data
There was a TestProfile but that was a stub that did not test anything.

We have an export function that serialises the profile data
(including lots of derived data like deco information and
cylinder pressure interpolation). So here is now a simple
tests that can detect regressions in the profle.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-05-04 13:39:18 -07:00
Miika Turkia
435778b162 CSV import/export test: Add support for dive mode
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-05-04 10:43:40 +02:00
Berthold Stoeger
95284c026e cleanup: move dive_table from dive.h to divelist.h
This allows us to decouple dive.h and divelist.h, a small step in
include disentangling.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01 09:42:31 -07:00
Dirk Hohndel
da953fa18a move GitHub url to the Subsurface org
Instead of using the Subsurface-divelog user on GitHub, we now use an org that
was generously donated to us.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-26 16:36:30 -07:00
Berthold Stoeger
17526ded58 cleanup: move clearing of device nodes to clear_dive_file_data()
It makes no sense to keep the device nodes if all the other data
is cleared. Let's do this automatically and not explicitly.
This ensures that the function is also called on mobile.
Currently it was only called on desktop.

Weirdly, the parser-tests were expecting that the device nodes
were not reset by clear_dive_file_data() and therefore divecomputers
were accumulating in the test results. Thus, the additional
computers had to be removed from the expected test results.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-24 10:40:12 -07:00
Dirk Hohndel
ad66297cfd desktop: remove user survey
We have never made good use of the results. Let's just remove it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-19 14:27:54 -07:00
Dirk Hohndel
af753a52e3 testing: re-enable TestGitStorage
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15 07:58:10 -07:00
Dirk Hohndel
935b28c119 testing/git-storage: alternative random number generation for Qt 5.9
We still need to support Qt 5.9 for Ubuntu 18.04 / Bionic. This uses
deprecated calls to qrand() - but then qrand() wasn't deprecated in 5.9.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15 07:58:10 -07:00
Dirk Hohndel
20f0a82b4e testing/git-storage: fairly fundamental rewrite of the storage test
The old test was broken in many ways and kept failing for a number of
reasons. Some of them were addressed in the previous commits (the
missing HEAD ref being the main one), the other one was that the tests
kept stepping on top of each other - as were potentially random users or
reviewers using the 'universal' test account.

This uses a random one of ten dedicated test accounts, and on top of
that uses a random branch name (instead of the fixed email address
associated with the account).

This also rewrites several of the tests dealing with offline changes to
correctly model going offline (but keeps one that directly writes to the
local cache).

Finally this change also tries to do a much better job cleaning up after
itself and not leaving data behind the the next run could stumble over.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-04-15 07:58:10 -07:00
Berthold Stoeger
3f3869ff65 media: move picture function from dive.c to picture.c
Currently, move only those functions that do not access dive
structures.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-10 10:53:03 -07:00
Berthold Stoeger
6dbc9ca4b0 cleanup: don't compile subsurface-helper.cpp for tests
It is unclear why the subsurface-helper.cpp file was linked with the
tests. In any case, it led to comlicated ifdef-ery, so let's remove
that for now and readd later if the need arises.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-03-31 08:49:12 -07:00
Robert C. Helling
285fa8acbc Grammar: replaces 'indexes' by 'indices'
Grammar-nazi ran

git grep -l 'indexes' | xargs sed -i '' -e 's/indexes/indices/g'

to prevent future wincing when reading the source code.

Unfortunatly, Qt itself is infected as in
QModelIndexList QItemSelection::indexes() const

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-03-11 08:26:30 -07:00
Dirk Hohndel
5601104ba5 tests: don't build PlannerShared
Once we start using the commands on mobile, the dependencies for this test
break. And since we have disabled the failed attempt to create a planner for
mobile, there's no point running these tests right now.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-03-09 12:41:11 -07:00
Berthold Stoeger
d27b6805f3 Cleanup: rename plannerShared to PlannerShared
Usually, we use PascalCase (i.e. camelCase with a capital
letter at the start) for class names. For consistency, let's
do it here as well.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-02-04 02:17:52 +01:00