Introduce synchronize merge method

* Create history-based merging that keeps older data in history instead of discarding or deleting it
* Extract merge logic into the Merger class
* Allows special merge behavior
* Improve handling of deletion and changes on groups
* Enable basic change tracking while merging
* Prevent unintended timestamp changes while merging
* Handle differences in timestamp precision
* Introduce comparison operators to allow for more sophisticated comparisons (ignore special properties, ...)
* Introduce Clock class to handle datetime across the app

Merge Strategies:
* Default (use inherited/fallback method)
* Duplicate (duplicate conflicting nodes, apply all deletions)
* KeepLocal (use local values, but apply all deletions)
* KeepRemote (use remote values, but apply all deletions)
* KeepNewer (merge history only)
* Synchronize (merge history, newest value stays on top, apply all deletions)
This commit is contained in:
Jonathan White
2018-09-30 08:45:06 -04:00
committed by Jonathan White
parent b40e5686dc
commit c1e9f45df9
43 changed files with 2777 additions and 585 deletions

View File

@@ -19,20 +19,33 @@
#define KEEPASSX_TESTMERGE_H
#include "core/Database.h"
#include <QDateTime>
#include <QMap>
#include <QObject>
#include <functional>
class TestMerge : public QObject
{
Q_OBJECT
private slots:
void initTestCase();
void init();
void cleanup();
void testMergeIntoNew();
void testMergeNoChanges();
void testResolveConflictNewer();
void testResolveConflictOlder();
void testResolveConflictExisting();
void testResolveGroupConflictOlder();
void testResolveConflictKeepBoth();
void testResolveConflictDuplicate();
void testResolveConflictEntry_Synchronize();
void testResolveConflictEntry_KeepLocal();
void testResolveConflictEntry_KeepRemote();
void testResolveConflictEntry_KeepNewer();
void testDeletionConflictEntry_Duplicate();
void testDeletionConflictEntry_Synchronized();
void testDeletionConflictEntry_KeepLocal();
void testDeletionConflictEntry_KeepRemote();
void testDeletionConflictEntry_KeepNewer();
void testMoveEntry();
void testMoveEntryPreserveChanges();
void testMoveEntryIntoNewGroup();
@@ -42,9 +55,24 @@ private slots:
void testUpdateGroupLocation();
void testMergeAndSync();
void testMergeCustomIcons();
void testMetadata();
void testDeletedEntry();
void testDeletedGroup();
void testDeletedRevertedEntry();
void testDeletedRevertedGroup();
private:
Database* createTestDatabase();
Database* createTestDatabaseStructureClone(Database* source, int entryFlags, int groupFlags);
void testResolveConflictTemplate(int mergeMode, std::function<void(Database*, const QMap<const char*, QDateTime>&)> verification);
void testDeletionConflictTemplate(int mergeMode, std::function<void(Database*, const QMap<QString, QUuid>&)> verification);
static void assertDeletionNewerOnly(Database *db, const QMap<QString, QUuid> &identifiers);
static void assertDeletionLocalOnly(Database *db, const QMap<QString, QUuid> &identifiers);
static void assertUpdateMergedEntry1(Entry *entry, const QMap<const char*, QDateTime> &timestamps);
static void assertUpdateReappliedEntry2(Entry *entry, const QMap<const char*, QDateTime> &timestamps);
static void assertUpdateReappliedEntry1(Entry *entry, const QMap<const char*, QDateTime> &timestamps);
static void assertUpdateMergedEntry2(Entry *entry, const QMap<const char *, QDateTime> &timestamps);
};
#endif // KEEPASSX_TESTMERGE_H