2017-04-27 18:21:27 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-08-24 16:32:27 +00:00
|
|
|
#include "testgitstorage.h"
|
|
|
|
#include "git2.h"
|
2016-04-05 17:22:00 +00:00
|
|
|
|
|
|
|
#include "core/dive.h"
|
|
|
|
#include "core/divelist.h"
|
|
|
|
#include "core/file.h"
|
|
|
|
#include "core/prefs-macros.h"
|
|
|
|
#include "core/subsurfacestartup.h"
|
|
|
|
|
2015-08-24 16:32:27 +00:00
|
|
|
#include <QDir>
|
|
|
|
#include <QTextStream>
|
2015-08-24 19:15:45 +00:00
|
|
|
#include <QNetworkProxy>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QDebug>
|
2015-08-24 16:32:27 +00:00
|
|
|
|
2015-08-24 23:23:21 +00:00
|
|
|
// this is a local helper function in git-access.c
|
|
|
|
extern "C" char *get_local_dir(const char *remote, const char *branch);
|
2015-08-24 16:32:27 +00:00
|
|
|
|
2017-03-03 06:25:23 +00:00
|
|
|
void TestGitStorage::initTestCase()
|
2015-08-24 19:15:45 +00:00
|
|
|
{
|
|
|
|
// first, setup the preferences an proxy information
|
2015-10-06 09:15:38 +00:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2015-08-24 19:15:45 +00:00
|
|
|
QCoreApplication::setOrganizationName("Subsurface");
|
|
|
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
|
|
|
QCoreApplication::setApplicationName("Subsurface");
|
|
|
|
QSettings s;
|
|
|
|
QVariant v;
|
|
|
|
s.beginGroup("Network");
|
|
|
|
GET_INT_DEF("proxy_type", proxy_type, QNetworkProxy::DefaultProxy);
|
|
|
|
GET_TXT("proxy_host", proxy_host);
|
|
|
|
GET_INT("proxy_port", proxy_port);
|
|
|
|
GET_BOOL("proxy_auth", proxy_auth);
|
|
|
|
GET_TXT("proxy_user", proxy_user);
|
|
|
|
GET_TXT("proxy_pass", proxy_pass);
|
|
|
|
s.endGroup();
|
|
|
|
s.beginGroup("CloudStorage");
|
|
|
|
GET_TXT("cloud_base_url", cloud_base_url);
|
|
|
|
QString gitUrl(prefs.cloud_base_url);
|
|
|
|
if (gitUrl.right(1) != "/")
|
|
|
|
gitUrl += "/";
|
2017-02-24 06:56:31 +00:00
|
|
|
prefs.cloud_git_url = strdup(qUtf8Printable(gitUrl + "git"));
|
2015-08-24 19:15:45 +00:00
|
|
|
s.endGroup();
|
|
|
|
prefs.cloud_storage_email_encoded = strdup("ssrftest@hohndel.org");
|
|
|
|
prefs.cloud_storage_password = strdup("geheim");
|
|
|
|
prefs.cloud_background_sync = true;
|
|
|
|
QNetworkProxy proxy;
|
|
|
|
proxy.setType(QNetworkProxy::ProxyType(prefs.proxy_type));
|
|
|
|
proxy.setHostName(prefs.proxy_host);
|
|
|
|
proxy.setPort(prefs.proxy_port);
|
|
|
|
if (prefs.proxy_auth) {
|
|
|
|
proxy.setUser(prefs.proxy_user);
|
|
|
|
proxy.setPassword(prefs.proxy_pass);
|
|
|
|
}
|
|
|
|
QNetworkProxy::setApplicationProxy(proxy);
|
|
|
|
|
2015-08-24 23:23:21 +00:00
|
|
|
// now cleanup the cache dir in case there's something weird from previous runs
|
|
|
|
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
|
|
|
|
QDir localCacheDirectory(localCacheDir);
|
|
|
|
QCOMPARE(localCacheDirectory.removeRecursively(), true);
|
|
|
|
}
|
|
|
|
|
2017-03-03 06:33:25 +00:00
|
|
|
void TestGitStorage::cleanup()
|
|
|
|
{
|
|
|
|
clear_dive_file_data();
|
|
|
|
}
|
|
|
|
|
2017-02-24 07:02:32 +00:00
|
|
|
void TestGitStorage::testGitStorageLocal_data()
|
|
|
|
{
|
2017-12-02 19:13:59 +00:00
|
|
|
// Test different paths we may encounter (since storage depends on user name)
|
|
|
|
// as well as with and without "file://" URL prefix.
|
2017-02-24 07:02:32 +00:00
|
|
|
QTest::addColumn<QString>("testDirName");
|
2017-12-02 19:13:59 +00:00
|
|
|
QTest::addColumn<QString>("prefixRead");
|
|
|
|
QTest::addColumn<QString>("prefixWrite");
|
|
|
|
QTest::newRow("ASCII path") << "./gittest" << "" << "";
|
|
|
|
QTest::newRow("Non ASCII path") << "./gittest_éèêôàüäößíñóúäåöø" << "" << "";
|
|
|
|
QTest::newRow("ASCII path with file:// prefix on read") << "./gittest2" << "file://" << "";
|
|
|
|
QTest::newRow("Non ASCII path with file:// prefix on read") << "./gittest2_éèêôàüäößíñóúäåöø" << "" << "file://";
|
|
|
|
QTest::newRow("ASCII path with file:// prefix on write") << "./gittest3" << "file://" << "";
|
|
|
|
QTest::newRow("Non ASCII path with file:// prefix on write") << "./gittest3_éèêôàüäößíñóúäåöø" << "" << "file://";
|
2017-02-24 07:02:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 23:23:21 +00:00
|
|
|
void TestGitStorage::testGitStorageLocal()
|
|
|
|
{
|
|
|
|
// test writing and reading back from local git storage
|
|
|
|
git_repository *repo;
|
|
|
|
git_libgit2_init();
|
2017-02-24 06:52:07 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf"), 0);
|
2017-02-24 07:02:32 +00:00
|
|
|
QFETCH(QString, testDirName);
|
2017-12-02 19:13:59 +00:00
|
|
|
QFETCH(QString, prefixRead);
|
|
|
|
QFETCH(QString, prefixWrite);
|
2015-08-24 23:23:21 +00:00
|
|
|
QDir testDir(testDirName);
|
|
|
|
QCOMPARE(testDir.removeRecursively(), true);
|
|
|
|
QCOMPARE(QDir().mkdir(testDirName), true);
|
2017-12-02 19:13:59 +00:00
|
|
|
QString repoNameRead = prefixRead + testDirName;
|
|
|
|
QString repoNameWrite = prefixWrite + testDirName;
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(git_repository_init(&repo, qUtf8Printable(testDirName), false), 0);
|
2017-12-02 19:13:59 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(repoNameWrite + "[test]")), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3.ssrf"), 0);
|
|
|
|
clear_dive_file_data();
|
2017-12-02 19:13:59 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(repoNameRead + "[test]")), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3viagit.ssrf"), 0);
|
|
|
|
QFile org("./SampleDivesV3.ssrf");
|
|
|
|
org.open(QFile::ReadOnly);
|
|
|
|
QFile out("./SampleDivesV3viagit.ssrf");
|
|
|
|
out.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QString readin = orgS.readAll();
|
|
|
|
QString written = outS.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestGitStorage::testGitStorageCloud()
|
|
|
|
{
|
|
|
|
// test writing and reading back from cloud storage
|
|
|
|
// connect to the ssrftest repository on the cloud server
|
2015-08-24 19:15:45 +00:00
|
|
|
// and repeat the same test as before with the local git storage
|
|
|
|
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
|
2017-02-24 06:52:07 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/SampleDivesV2.ssrf"), 0);
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 19:15:45 +00:00
|
|
|
clear_dive_file_data();
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 19:15:45 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3viacloud.ssrf"), 0);
|
|
|
|
QFile org("./SampleDivesV3.ssrf");
|
|
|
|
org.open(QFile::ReadOnly);
|
|
|
|
QFile out("./SampleDivesV3viacloud.ssrf");
|
|
|
|
out.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QString readin = orgS.readAll();
|
|
|
|
QString written = outS.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
|
|
|
}
|
|
|
|
|
2015-08-24 20:59:20 +00:00
|
|
|
void TestGitStorage::testGitStorageCloudOfflineSync()
|
|
|
|
{
|
|
|
|
// make a change to local cache repo (pretending that we did some offline changes)
|
|
|
|
// and then open the remote one again and check that things were propagated correctly
|
|
|
|
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
|
|
|
|
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
|
|
|
|
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
|
|
|
|
// read the local repo from the previous test and add dive 10
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(localCacheRepo)), 0);
|
2017-02-24 06:52:07 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test10.xml"), 0);
|
2015-08-24 20:59:20 +00:00
|
|
|
// calling process_dive() sorts the table, but calling it with
|
|
|
|
// is_imported == true causes it to try to update the window title... let's not do that
|
|
|
|
process_dives(false, false);
|
|
|
|
// now save only to the local cache but not to the remote server
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(localCacheRepo)), 0);
|
2015-08-24 20:59:20 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3plus10local.ssrf"), 0);
|
|
|
|
clear_dive_file_data();
|
|
|
|
// open the cloud storage and compare
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 20:59:20 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3plus10viacloud.ssrf"), 0);
|
|
|
|
QFile org("./SampleDivesV3plus10local.ssrf");
|
|
|
|
org.open(QFile::ReadOnly);
|
|
|
|
QFile out("./SampleDivesV3plus10viacloud.ssrf");
|
|
|
|
out.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QString readin = orgS.readAll();
|
|
|
|
QString written = outS.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
|
|
|
// write back out to cloud storage, move away the local cache, open again and compare
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 20:59:20 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
QDir localCacheDirectory(localCacheDir);
|
|
|
|
QDir localCacheDirectorySave(localCacheDir + "save");
|
|
|
|
QCOMPARE(localCacheDirectorySave.removeRecursively(), true);
|
|
|
|
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 20:59:20 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3plus10fromcloud.ssrf"), 0);
|
|
|
|
org.close();
|
|
|
|
org.open(QFile::ReadOnly);
|
|
|
|
QFile out2("./SampleDivesV3plus10fromcloud.ssrf");
|
|
|
|
out2.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS2(&org);
|
|
|
|
QTextStream outS2(&out2);
|
|
|
|
readin = orgS2.readAll();
|
|
|
|
written = outS2.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
|
|
|
}
|
|
|
|
|
2015-08-24 21:00:42 +00:00
|
|
|
void TestGitStorage::testGitStorageCloudMerge()
|
|
|
|
{
|
|
|
|
// now we need to mess with the local git repo to get an actual merge
|
|
|
|
// first we add another dive to the "moved away" repository, pretending we did
|
|
|
|
// another offline change there
|
|
|
|
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
|
|
|
|
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
|
|
|
|
QString localCacheRepoSave = localCacheDir + "save[ssrftest@hohndel.org]";
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(localCacheRepoSave)), 0);
|
2017-02-24 06:52:07 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml"), 0);
|
2015-08-24 21:00:42 +00:00
|
|
|
process_dives(false, false);
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(localCacheRepoSave)), 0);
|
2015-08-24 21:00:42 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
|
|
|
|
// now we open the cloud storage repo and add a different dive to it
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2017-02-24 06:52:07 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml"), 0);
|
2015-08-24 21:00:42 +00:00
|
|
|
process_dives(false, false);
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 21:00:42 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
|
|
|
|
// now we move the saved local cache into place and try to open the cloud repo
|
|
|
|
// -> this forces a merge
|
|
|
|
QDir localCacheDirectory(localCacheDir);
|
|
|
|
QCOMPARE(localCacheDirectory.removeRecursively(), true);
|
|
|
|
QDir localCacheDirectorySave(localCacheDir + "save");
|
|
|
|
QCOMPARE(localCacheDirectory.rename(localCacheDir + "save", localCacheDir), true);
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2017-12-03 23:17:50 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12-merged.ssrf"), 0);
|
2015-08-24 21:00:42 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
QCOMPARE(parse_file("./SampleDivesV3plus10local.ssrf"), 0);
|
2017-02-24 06:52:07 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test11.xml"), 0);
|
2015-08-24 21:00:42 +00:00
|
|
|
process_dives(false, false);
|
2017-02-24 06:52:07 +00:00
|
|
|
QCOMPARE(parse_file(SUBSURFACE_TEST_DATA "/dives/test12.xml"), 0);
|
2015-08-24 21:00:42 +00:00
|
|
|
process_dives(false, false);
|
2017-12-03 23:17:50 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesV3plus10-11-12.ssrf"), 0);
|
|
|
|
QFile org("./SampleDivesV3plus10-11-12-merged.ssrf");
|
2015-08-24 21:00:42 +00:00
|
|
|
org.open(QFile::ReadOnly);
|
2017-12-03 23:17:50 +00:00
|
|
|
QFile out("./SampleDivesV3plus10-11-12.ssrf");
|
2015-08-24 21:00:42 +00:00
|
|
|
out.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QString readin = orgS.readAll();
|
|
|
|
QString written = outS.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
2015-08-24 23:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGitStorage::testGitStorageCloudMerge2()
|
|
|
|
{
|
|
|
|
// delete a dive offline
|
|
|
|
// edit the same dive in the cloud repo
|
|
|
|
// merge
|
|
|
|
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
|
|
|
|
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
|
|
|
|
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(localCacheRepo)), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
process_dives(false, false);
|
|
|
|
struct dive *dive = get_dive(1);
|
|
|
|
delete_single_dive(1);
|
|
|
|
QCOMPARE(save_dives("./SampleDivesMinus1.ssrf"), 0);
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(localCacheRepo)), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
|
|
|
|
// move the local cache away
|
|
|
|
{ // scope for variables
|
|
|
|
QDir localCacheDirectory(localCacheDir);
|
|
|
|
QDir localCacheDirectorySave(localCacheDir + "save");
|
|
|
|
QCOMPARE(localCacheDirectorySave.removeRecursively(), true);
|
|
|
|
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
|
|
|
|
}
|
|
|
|
// now we open the cloud storage repo and modify that first dive
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
process_dives(false, false);
|
|
|
|
dive = get_dive(1);
|
2016-03-23 19:12:11 +00:00
|
|
|
QVERIFY(dive != NULL);
|
2015-08-24 23:23:21 +00:00
|
|
|
free(dive->notes);
|
|
|
|
dive->notes = strdup("These notes have been modified by TestGitStorage");
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
|
|
|
|
// now we move the saved local cache into place and try to open the cloud repo
|
|
|
|
// -> this forces a merge
|
|
|
|
QDir localCacheDirectory(localCacheDir);
|
|
|
|
QDir localCacheDirectorySave(localCacheDir + "save");
|
|
|
|
QCOMPARE(localCacheDirectory.removeRecursively(), true);
|
|
|
|
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
|
|
|
|
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesMinus1-merged.ssrf"), 0);
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-24 23:23:21 +00:00
|
|
|
QFile org("./SampleDivesMinus1-merged.ssrf");
|
|
|
|
org.open(QFile::ReadOnly);
|
|
|
|
QFile out("./SampleDivesMinus1.ssrf");
|
|
|
|
out.open(QFile::ReadOnly);
|
|
|
|
QTextStream orgS(&org);
|
|
|
|
QTextStream outS(&out);
|
|
|
|
QString readin = orgS.readAll();
|
|
|
|
QString written = outS.readAll();
|
|
|
|
QCOMPARE(readin, written);
|
2015-08-30 20:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestGitStorage::testGitStorageCloudMerge3()
|
|
|
|
{
|
|
|
|
// create multi line notes and store them to the cloud repo and local cache
|
|
|
|
// edit dive notes offline
|
|
|
|
// edit the same dive notes in the cloud repo
|
|
|
|
// merge
|
|
|
|
clear_dive_file_data();
|
|
|
|
QString cloudTestRepo("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org[ssrftest@hohndel.org]");
|
|
|
|
QString localCacheDir(get_local_dir("https://cloud.subsurface-divelog.org/git/ssrftest@hohndel.org", "ssrftest@hohndel.org"));
|
|
|
|
QString localCacheRepo = localCacheDir + "[ssrftest@hohndel.org]";
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
process_dives(false, false);
|
|
|
|
struct dive *dive = get_dive(0);
|
2015-09-02 15:31:13 +00:00
|
|
|
QVERIFY(dive != 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
dive->notes = strdup("Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough");
|
|
|
|
dive = get_dive(1);
|
|
|
|
dive->notes = strdup("Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough");
|
|
|
|
dive = get_dive(2);
|
|
|
|
dive->notes = strdup("Create multi line dive notes\nLine 2\nLine 3\nLine 4\nLine 5\nThat should be enough");
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(localCacheRepo)), 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
process_dives(false, false);
|
|
|
|
dive = get_dive(0);
|
|
|
|
dive->notes = strdup("Create multi line dive notes\nDifferent line 2 and removed 3-5\n\nThat should be enough");
|
|
|
|
dive = get_dive(1);
|
|
|
|
dive->notes = strdup("Line 2\nLine 3\nLine 4\nLine 5"); // keep the middle, remove first and last");
|
|
|
|
dive = get_dive(2);
|
|
|
|
dive->notes = strdup("single line dive notes");
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(localCacheRepo)), 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
|
|
|
|
// move the local cache away
|
|
|
|
{ // scope for variables
|
|
|
|
QDir localCacheDirectory(localCacheDir);
|
|
|
|
QDir localCacheDirectorySave(localCacheDir + "save");
|
|
|
|
QCOMPARE(localCacheDirectorySave.removeRecursively(), true);
|
|
|
|
QCOMPARE(localCacheDirectory.rename(localCacheDir, localCacheDir + "save"), true);
|
|
|
|
}
|
|
|
|
// now we open the cloud storage repo and modify those first dive notes differently
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
process_dives(false, false);
|
|
|
|
dive = get_dive(0);
|
|
|
|
dive->notes = strdup("Completely different dive notes\nBut also multi line");
|
|
|
|
dive = get_dive(1);
|
|
|
|
dive->notes = strdup("single line dive notes");
|
|
|
|
dive = get_dive(2);
|
|
|
|
dive->notes = strdup("Line 2\nLine 3\nLine 4\nLine 5"); // keep the middle, remove first and last");
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(save_dives(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
clear_dive_file_data();
|
|
|
|
|
|
|
|
// now we move the saved local cache into place and try to open the cloud repo
|
|
|
|
// -> this forces a merge
|
|
|
|
QDir localCacheDirectory(localCacheDir);
|
|
|
|
QDir localCacheDirectorySave(localCacheDir + "save");
|
|
|
|
QCOMPARE(localCacheDirectory.removeRecursively(), true);
|
|
|
|
QCOMPARE(localCacheDirectorySave.rename(localCacheDir + "save", localCacheDir), true);
|
|
|
|
|
2017-02-24 06:56:31 +00:00
|
|
|
QCOMPARE(parse_file(qUtf8Printable(cloudTestRepo)), 0);
|
2015-08-30 20:00:32 +00:00
|
|
|
QCOMPARE(save_dives("./SampleDivesMerge3.ssrf"), 0);
|
|
|
|
// we are not trying to compare this to a pre-determined result... what this test
|
|
|
|
// checks is that there are no parsing errors with the merge
|
2015-08-24 21:00:42 +00:00
|
|
|
}
|
|
|
|
|
2017-02-05 22:26:51 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestGitStorage)
|