diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-08-30 13:00:32 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-08-30 13:00:32 -0700 |
commit | 6d7faa106faa37b887d24fb18b538a34521f1710 (patch) | |
tree | f2f06963237c7ce03871d80171ab916b2d683184 /tests | |
parent | 1b37e0f1a4e4225026e7c5b2c15f178a9c75b2ad (diff) | |
download | subsurface-6d7faa106faa37b887d24fb18b538a34521f1710.tar.gz |
Add test case for multi line dive notes merging
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testgitstorage.cpp | 66 | ||||
-rw-r--r-- | tests/testgitstorage.h | 1 |
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index f5846bbd2..99ee8d8c4 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -256,6 +256,72 @@ void TestGitStorage::testGitStorageCloudMerge2() QString readin = orgS.readAll(); QString written = outS.readAll(); QCOMPARE(readin, written); + clear_dive_file_data(); +} + +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]"; + QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); + process_dives(false, false); + struct dive *dive = get_dive(0); + 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"); + QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); + clear_dive_file_data(); + + QCOMPARE(parse_file(qPrintable(localCacheRepo)), 0); + 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"); + QCOMPARE(save_dives(qPrintable(localCacheRepo)), 0); + 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 + QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); + 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"); + QCOMPARE(save_dives(qPrintable(cloudTestRepo)), 0); + 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); + + QCOMPARE(parse_file(qPrintable(cloudTestRepo)), 0); + 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 + clear_dive_file_data(); } QTEST_MAIN(TestGitStorage) diff --git a/tests/testgitstorage.h b/tests/testgitstorage.h index d5f69fc65..ef1dacd9e 100644 --- a/tests/testgitstorage.h +++ b/tests/testgitstorage.h @@ -13,6 +13,7 @@ private slots: void testGitStorageCloudOfflineSync(); void testGitStorageCloudMerge(); void testGitStorageCloudMerge2(); + void testGitStorageCloudMerge3(); }; #endif // TESTGITSTORAGE_H |