Commit graph

33 commits

Author SHA1 Message Date
Berthold Stoeger
7f4d9db962 Cleanup: move trip-related functions into own translation unit
These functions were spread out over dive.c and divelist.c.
Move them into their own file to make all this a bit less monolithic.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19 13:11:10 -07:00
Berthold Stoeger
c22fd9f4fd Dive sites: prepare for dive site ref-counting
Add a dive site table to each dive site to keep track of dives
that have been added to a dive site. Add two functions to add
dives to / remove dives from dive sites.

Since dive sites now contain a dive table, the order of includes
had to be changed: "divesite.h" now includes "dive.h" and not
vice-versa. This caused some include churn.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
37146c5742 Parser: parse into custom dive site table
To extend the undo system to dive sites, the importers and downloaders
must not parse directly into the global dive site table. Instead,
pass a dive_site_table argument to parse into.

For now, always pass the global dive_site_table so that this commit
should not cause any functional change.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00
Berthold Stoeger
0249e12589 Import: split process_imported_dives() function
Split the process_imported_dives() function in two:
1) process_imported_dives() processes the dives and generates
   a list of dives and trips to be added and removed.
2) add_imported_dives() calls process_imported_dives() and
   does the actual removal / addition of dives and trips.

The goal is to split preparation and actual work, to
make dive import undo-able.

The code adds extra checks to never merge into the same
dive twice, as this would lead to a double-free() bug.
This should in principle never happen, as dives that
compare equal according to is_same_dive() are merged
in the imported-dives list, but perhaps in some pathologival
corner-cases is_same_dive() turns out to be non-transitive.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09 20:58:04 -08:00
Berthold Stoeger
7e33369dc8 Parser: add trip_table parameter to parsing functions
To allow parsing into arbitrary trip_tables, add the corresponding
parameter to the parsing functions and the parser state. Currently,
all callers pass the global trip_table so there should be no change
in functionality. These arguments will be replaced in subsequent commits.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09 20:58:04 -08:00
Berthold Stoeger
35b8a4f404 Core: split process_dives() in post-import and post-load versions
process_dives() is used to post-process the dive table after loading
or importing. The first parameter states whether this was after
load or import.

Especially in the light of undo, load and import are fundamentally
different things. Notably, that latter should be undo-able, whereas
the former is not. Therefore, as a first step to make import undo-able,
split the function in two versions and remove the first parameter.

It turns out the the load-version is very light. It only sets the
DC nicknames and sorts the dive-table. There seems to be no reason
to merge dives.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-23 11:50:53 -07:00
jan Iversen
5dd0981961 core/tests: remove QSettings from testgitstorage
update testgitstorage.cpp to use qPrefProxy and qPrefCloudStorage
remove core/prefs-macros.h since it is unused

Signed-off-by: Jan Iversen <jani@apache.org>
2018-08-25 11:49:47 -07:00
Berthold Stoeger
d815e0c947 Parse: pass dive_table argument to parse_file()
To enable undo of divelog-importing it is crucial that parse_file()
can parse into arbitrary dive tables.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 10:17:12 -07:00
Berthold Stoeger
d1572a8d95 Cleanup: introduce copy_qstring() function
strdup(qPrintable(s)) and copy_string(qPrintable(s)) were such common
occurrences that they seem worthy of a short helper-function.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Berthold Stoeger
b72cc1f317 Cleanup: consistently use qPrintable()
Replace constructs of the kind
  s.toUtf8().data(),
  s.toUtf8().constData(),
  s.toLocal8Bit().data(),
  s.toLocal8Bit.constData() or
  qUtf8Printable(s)
by
  qPrintable(s).

This is concise, consistent and - in principle - more performant than
the .data() versions.

Sadly, owing to a suboptimal implementation, qPrintable(s) currently
is a pessimization compared to s.toUtf8().data(). A fix is scheduled for
new Qt versions: https://codereview.qt-project.org/#/c/221331/

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-14 13:55:36 +02:00
Berthold Stoeger
59526e948a Remove cloud_background_sync preferences option
The preferences flag cloud_background_sync used to be used heavily in
the mobile code, but is not used there anymore. Now, it is accessed
only in one place, but does not do what it actually says: If it is off,
the remote storage is not synced on save (but will be synced on next
load).

Syncing on save can also be prevented by unchecking the "Cloud online"
menu checkbox. Since the latter seems more logical and general
(support for non-cloud remote git repositories), remove the cloud_background_sync
option.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06 10:46:07 -08:00
Berthold Stoeger
cab0699d4c Fix typo in TestGitStorage: SapleDives -> SampleDives
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-03 19:07:03 -08:00
Berthold Stoeger
d775adfb29 Add tests to read/write "file://..." style local git repositories
Requested-by: Dirk Hohndel <dirk@hohndel.org>

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-03 08:26:43 -08:00
Dirk Hohndel
ee1bf18189 Add SPDX header to tests
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Jeremie Guichard
5caa9b23fe Use QTest cleanup method for proper test shutdown
In case of QCOMPARE failure, code following the comparison
is not executed, this results in application state not being
properly resorted and often gives several test failures,
when only one test really fails.
Using QTest cleanup method allows restoring proper state,
before next test is executed.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-04 12:03:33 -08:00
Jeremie Guichard
16a321d43b Use proper QTest initialization method in TestGitStorage
Method originally called testSetup is more a precondition
to test execution rather than an actual test.
QTest recommends to use initTestCase for that purpose.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-04 12:03:33 -08:00
Jeremie Guichard
5ed93a9d9e Fix "Load/Save to cloudstorage" for non-ASCII user names
On Windows that would fail because stat() doesn't deal well with our
utf8 strings.

Added new subsurface_stat() portability function to replace stat().
Added Windows implementation of subsurface_stat() using wstat(),
with conversion to ut16 of the inputed path.
Other platform implementations (linux, android) make use of the normal stat().

Added non ASCII test case in TestGitStorage::testGitStorageLocal()

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-02-24 01:10:22 -08:00
Jeremie Guichard
5640a6a839 Make TestGitStorage::testGitStorageLocal parametrizable
Make use of QTest "Data Driven Testing",
allowing to test multiple repo base path values.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-02-24 01:10:22 -08:00
Jeremie Guichard
56d31c9c1b Replace pPrintable with qUtf8Printable in TestGitStorage
Update TestGitStorage to use qUtf8Printable instead of pPrintable.
This ensures that non-ASCII chars are utf8 encoded before calling internal functions.
In windows case pPrintable returns other codepoint that depends on system settings.

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-02-24 01:10:22 -08:00
Jeremie Guichard
1e2580c3fd Use SUBSURFACE_TEST_DATA definition to point to test data dir
Update tests with a (compile time) option SUBSURFACE_TEST_DATA,
pointing to test data base path. It is needed for cross compilation cases.
SUBSURFACE_TEST_DATA is set to SUBSURFACE_SOURCE by default,
or configurable via cmake option -DSUBSURFACE_TEST_DATA="...".

Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-02-24 01:10:22 -08:00
Anton Lundin
c2ea3c2616 Our tests are actually GUILESS
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-02-05 14:45:25 -08:00
Tomaz Canabrava
21e8b1e363 Fix compilation with the new folder architecture
A few more fixes for things that broke in commit 7be962bfc2 ("Move
subsurface-core to core and qt-mobile to mobile-widgets").

[Dirk Hohndel: slightly edited and overlap with Linus' patch removed]

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05 12:32:36 -07:00
Dirk Hohndel
aef6364921 Prevent possible SIGSEGV in test
If the load fails the get_dive(1) could return NULL. Let's catch that as
an error instead of having the test crash.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-03-23 12:12:11 -07:00
Dirk Hohndel
787b12cff4 Remove unnecessary call from tests
Now that the WindowTitleUpdater is fixed we don't need to create an
instance in the tests, either.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-11-07 09:56:41 -08:00
Dirk Hohndel
9d8b0addf9 Correctly copy preferences
When just assigning one structure to the other we copy the string
pointers. If we then modify those strings in the copy, we happily free
the strings of the original. And then resetting the preferences equally
happily reused those strings, pointing to long since freed memory.

I think what I did now is excessive for the current use case in that it
copies a ton of strings that are unset in the default_prefs. But I figured
this is a rarely used function and I might as well do it correctly.

Also, once we implement multi user support with per user preferences we
will be copying completely populated preferences around (at least that's
my guess).

Fixes #940

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-06 10:19:43 +01:00
Dirk Hohndel
ade2067155 Git storage test: need to instantiate the window title updater class
Otherwise calling the static function can cause a crash in
mark_divelist_changed()

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-18 12:05:07 -07:00
Robert C. Helling
40122e4233 Prevent tests from hanging when offline
From 31e324797c06d366f49db453a67a119819ca8012 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <helling@atdotde.de>
Date: Wed, 2 Sep 2015 17:28:12 +0200
Subject: [PATCH] Test that there is a dive

so that the TestGitStorage does not hang when offline.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-02 09:11:20 -07:00
Dirk Hohndel
6d7faa106f Add test case for multi line dive notes merging
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-30 13:00:32 -07:00
Dirk Hohndel
72817ff47f Cloud storage: second merge test, delete dive on one side, modify on other
Delete a dive while offline, modify it from a different system while
online. Then resync.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:44:30 -07:00
Dirk Hohndel
9f5a944107 Cloud storage: first test case for a very simple merge
- We add a dive while offline.
- On a different computer (here simulated by a different local cache) we
  add a different file.
- Now we go back to the previous local cache (the one where we added a
  different dive in the first step) and take that online (i.e., connect to
  cloud storage). Now both of the new dives should have been added to our
  data file.

This is a rather trivial test with no conflict and a straight forward
merge. We need to add a lot more test cases to make sure this works as
expected and doesn't leave the user with a corrupt state.

Ideally whatever happens, the user should never see an error...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:44:15 -07:00
Dirk Hohndel
449ba2876f Cloud storage: test offline operation
All this really does is make sure that the fast forward works if the local
cache has received updates that haven't made it to the server, yet.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:44:10 -07:00
Dirk Hohndel
092abe9b39 Cloud storage: add test for simple save / load from our test account
This will fail if the proxy settings of the user running the test are
incorrect.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:57 -07:00
Dirk Hohndel
6eed3155e6 Add simple test for git storage
This just makes sure that writing data to git storage and reading it back
gives you the same result. Without the fixed generation of initial dive
site UUIDs this fails.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-25 10:43:41 -07:00