Compare commits

...

8 Commits

Author SHA1 Message Date
louib
bcb547a072 fix: formatting 2022-12-27 12:48:46 -05:00
louib
be94f97e05 fix: most extensions need the gui sources still
Thanks to @yan12125 for the patch.
2022-12-27 11:17:41 -05:00
Jonathan White
f23b07f609 Fix test cases
* Disable quick unlock when running TestGuiBrowser
* Use QString and auto pointers in TestMerge. This test was failing under Visual Studio.
2022-12-21 22:16:30 -05:00
Jonathan White
48715c6bda Further cleanup of naming conventions and organization
* Rename all variables to use keepassxc instead of keepassx
* Move some definitions to their proper locations in CMakeLists.txt
2022-12-21 22:16:30 -05:00
louib
e5308d61ca refactor: move mac clipboard utils to gui/ 2022-12-21 22:16:30 -05:00
louib
709ea1101c fix: add MacPasteboard back to compilation
fix provided by yan12125
2022-12-21 22:16:30 -05:00
louib
b42fb1cce1 fix: link to corefoundation from thirdparty dir
fix provided by yan12125
2022-12-21 22:16:30 -05:00
louib
a7ffd28e26 Separate GUI sources from core sources.
This PR splits the GUI source files from the core
source files. The immediate goal is to allow the
CLI to require only a minimum number of dynamic
libraries. The long term goal is to create an
architectural boundary around the core module,
in preparation of libkdbx.
2022-12-21 22:16:30 -05:00
30 changed files with 249 additions and 247 deletions

View File

@@ -117,6 +117,17 @@ if(UNIX AND NOT APPLE AND NOT WITH_XC_X11)
set(WITH_XC_AUTOTYPE OFF)
endif()
add_feature_info(Auto-Type WITH_XC_AUTOTYPE "Automatic password typing")
add_feature_info(Networking WITH_XC_NETWORKING "Compile KeePassXC with network access code (e.g. for downloading website icons)")
add_feature_info(KeePassXC-Browser WITH_XC_BROWSER "Browser integration with KeePassXC-Browser")
add_feature_info(SSHAgent WITH_XC_SSHAGENT "SSH agent integration compatible with KeeAgent")
add_feature_info(KeeShare WITH_XC_KEESHARE "Sharing integration with KeeShare")
add_feature_info(YubiKey WITH_XC_YUBIKEY "YubiKey HMAC-SHA1 challenge-response")
add_feature_info(UpdateCheck WITH_XC_UPDATECHECK "Automatic update checking")
if(UNIX AND NOT APPLE)
add_feature_info(FdoSecrets WITH_XC_FDOSECRETS "Implement freedesktop.org Secret Storage Spec server side API.")
endif()
set(KEEPASSXC_VERSION_MAJOR "2")
set(KEEPASSXC_VERSION_MINOR "8")
set(KEEPASSXC_VERSION_PATCH "0")

View File

@@ -30,7 +30,7 @@ if(NOT ZXCVBN_LIBRARIES)
set(ZXCVBN_LIBRARIES zxcvbn)
endif(NOT ZXCVBN_LIBRARIES)
set(keepassx_SOURCES
set(core_SOURCES
core/Alloc.cpp
core/AutoTypeAssociations.cpp
core/Base32.cpp
@@ -89,6 +89,19 @@ set(keepassx_SOURCES
format/OpVaultReaderAttachments.cpp
format/OpVaultReaderBandEntry.cpp
format/OpVaultReaderSections.cpp
keys/CompositeKey.cpp
keys/FileKey.cpp
keys/PasswordKey.cpp
keys/ChallengeResponseKey.cpp
streams/HashedBlockStream.cpp
streams/HmacBlockStream.cpp
streams/LayeredStream.cpp
streams/qtiocompressor.cpp
streams/StoreDataStream.cpp
streams/SymmetricCipherStream.cpp
totp/totp.cpp)
set(gui_SOURCES
gui/styles/styles.qrc
gui/styles/StateColorPalette.cpp
gui/styles/base/phantomcolor.cpp
@@ -183,82 +196,61 @@ set(keepassx_SOURCES
gui/wizard/NewDatabaseWizardPageMetaData.cpp
gui/wizard/NewDatabaseWizardPageEncryption.cpp
gui/wizard/NewDatabaseWizardPageDatabaseKey.cpp
keys/CompositeKey.cpp
keys/FileKey.cpp
keys/PasswordKey.cpp
keys/ChallengeResponseKey.cpp
streams/HashedBlockStream.cpp
streams/HmacBlockStream.cpp
streams/LayeredStream.cpp
streams/qtiocompressor.cpp
streams/StoreDataStream.cpp
streams/SymmetricCipherStream.cpp
totp/totp.cpp)
../share/icons/icons.qrc
../share/wizard/wizard.qrc)
if(APPLE)
set(keepassx_SOURCES
${keepassx_SOURCES}
core/MacPasteboard.cpp
list(APPEND gui_SOURCES
gui/osutils/macutils/MacPasteboard.cpp
gui/osutils/macutils/MacUtils.cpp
gui/osutils/macutils/ScreenLockListenerMac.cpp
gui/osutils/macutils/AppKitImpl.mm
gui/osutils/macutils/AppKit.h)
endif()
if(UNIX AND NOT APPLE)
set(keepassx_SOURCES
${keepassx_SOURCES}
list(APPEND gui_SOURCES
gui/osutils/nixutils/ScreenLockListenerDBus.cpp
gui/osutils/nixutils/NixUtils.cpp)
if(WITH_XC_X11)
list(APPEND keepassx_SOURCES
list(APPEND gui_SOURCES
gui/osutils/nixutils/X11Funcs.cpp)
endif()
qt5_add_dbus_adaptor(keepassx_SOURCES
qt5_add_dbus_adaptor(gui_SOURCES
gui/org.keepassxc.KeePassXC.MainWindow.xml
gui/MainWindow.h
MainWindow)
endif()
if(WIN32)
set(keepassx_SOURCES
${keepassx_SOURCES}
list(APPEND gui_SOURCES
gui/osutils/winutils/ScreenLockListenerWin.cpp
gui/osutils/winutils/WinUtils.cpp)
if (MSVC)
list(APPEND keepassx_SOURCES winhello/WindowsHello.cpp)
list(APPEND gui_SOURCES winhello/WindowsHello.cpp)
endif()
endif()
set(keepassx_SOURCES ${keepassx_SOURCES}
../share/icons/icons.qrc
../share/wizard/wizard.qrc)
set(keepassx_SOURCES_MAINEXE main.cpp)
add_feature_info(Auto-Type WITH_XC_AUTOTYPE "Automatic password typing")
add_feature_info(Networking WITH_XC_NETWORKING "Compile KeePassXC with network access code (e.g. for downloading website icons)")
add_feature_info(KeePassXC-Browser WITH_XC_BROWSER "Browser integration with KeePassXC-Browser")
add_feature_info(SSHAgent WITH_XC_SSHAGENT "SSH agent integration compatible with KeeAgent")
add_feature_info(KeeShare WITH_XC_KEESHARE "Sharing integration with KeeShare")
add_feature_info(YubiKey WITH_XC_YUBIKEY "YubiKey HMAC-SHA1 challenge-response")
add_feature_info(UpdateCheck WITH_XC_UPDATECHECK "Automatic update checking")
if(UNIX AND NOT APPLE)
add_feature_info(FdoSecrets WITH_XC_FDOSECRETS "Implement freedesktop.org Secret Storage Spec server side API.")
endif()
add_subdirectory(browser)
add_subdirectory(proxy)
if(WITH_XC_BROWSER)
set(keepassxcbrowser_LIB keepassxcbrowser)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/entry/EntryURLModel.cpp)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/reports/ReportsWidgetBrowserStatistics.cpp)
set(keepassx_SOURCES ${keepassx_SOURCES} gui/reports/ReportsPageBrowserStatistics.cpp)
list(APPEND gui_SOURCES
gui/dbsettings/DatabaseSettingsWidgetBrowser.cpp
gui/entry/EntryURLModel.cpp
gui/reports/ReportsWidgetBrowserStatistics.cpp
gui/reports/ReportsPageBrowserStatistics.cpp)
endif()
add_subdirectory(autotype)
add_subdirectory(thirdparty)
add_subdirectory(cli)
add_subdirectory(qrcode)
set(qrcode_LIB qrcode)
add_subdirectory(autotype)
if(WITH_XC_AUTOTYPE)
set(autotype_LIB autotype)
endif()
add_subdirectory(keeshare)
if(WITH_XC_KEESHARE)
set(keeshare_LIB keeshare)
@@ -274,48 +266,31 @@ if(WITH_XC_FDOSECRETS)
set(fdosecrets_LIB fdosecrets)
endif()
add_subdirectory(thirdparty)
set(autotype_SOURCES
core/Tools.cpp
autotype/AutoType.cpp
autotype/AutoTypeAction.cpp
autotype/AutoTypeMatchModel.cpp
autotype/AutoTypeMatchView.cpp
autotype/AutoTypeSelectDialog.cpp
autotype/PickcharsDialog.cpp
autotype/ShortcutWidget.cpp
autotype/WindowSelectComboBox.cpp)
if(WIN32)
set(keepassx_SOURCES_MAINEXE ${keepassx_SOURCES_MAINEXE} ${CMAKE_SOURCE_DIR}/share/windows/icon.rc)
endif()
if(WITH_XC_YUBIKEY)
list(APPEND keepassx_SOURCES
list(APPEND core_SOURCES
keys/drivers/YubiKey.h
keys/drivers/YubiKey.cpp
keys/drivers/YubiKeyInterface.cpp
keys/drivers/YubiKeyInterfaceUSB.cpp
keys/drivers/YubiKeyInterfacePCSC.cpp)
else()
list(APPEND keepassx_SOURCES
list(APPEND core_SOURCES
keys/drivers/YubiKey.h
keys/drivers/YubiKeyStub.cpp)
endif()
if(WITH_XC_NETWORKING)
list(APPEND keepassx_SOURCES
core/HibpDownloader.cpp
core/NetworkManager.cpp
list(APPEND gui_SOURCES
networking/HibpDownloader.cpp
networking/NetworkManager.cpp
networking/UpdateChecker.cpp
gui/UpdateCheckDialog.cpp
gui/IconDownloader.cpp
gui/IconDownloaderDialog.cpp
updatecheck/UpdateChecker.cpp)
gui/IconDownloaderDialog.cpp)
endif()
if(APPLE)
list(APPEND keepassx_SOURCES touchid/TouchID.mm)
list(APPEND core_SOURCES touchid/TouchID.mm)
# TODO: Remove -Wno-error once deprecation warnings have been resolved.
set_source_files_properties(touchid/TouchID.mm PROPERTY COMPILE_FLAGS "-Wno-old-style-cast")
endif()
@@ -323,56 +298,50 @@ endif()
configure_file(config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepassx.h)
configure_file(git-info.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/git-info.h)
add_library(autotype STATIC ${autotype_SOURCES})
target_link_libraries(autotype Qt5::Core Qt5::Widgets)
add_library(keepassx_core STATIC ${keepassx_SOURCES})
set_target_properties(keepassx_core PROPERTIES COMPILE_DEFINITIONS KEEPASSX_BUILDING_CORE)
target_link_libraries(keepassx_core
autotype
${keepassxcbrowser_LIB}
add_library(keepassxc_core STATIC ${core_SOURCES})
set_target_properties(keepassxc_core PROPERTIES COMPILE_DEFINITIONS KEEPASSXC_BUILDING_CORE)
target_link_libraries(keepassxc_core
${qrcode_LIB}
${fdosecrets_LIB}
Qt5::Core
Qt5::Concurrent
Qt5::Network
Qt5::Widgets
${BOTAN2_LIBRARIES}
${PCSC_LIBRARIES}
${ZXCVBN_LIBRARIES}
${ZLIB_LIBRARIES}
${ARGON2_LIBRARIES}
${thirdparty_LIBRARIES}
)
${thirdparty_LIBRARIES})
if(WITH_XC_SSHAGENT)
target_link_libraries(keepassx_core sshagent)
endif()
if(WITH_XC_KEESHARE)
target_link_libraries(keepassx_core keeshare)
endif()
add_library(keepassxc_gui STATIC ${gui_SOURCES})
target_link_libraries(keepassxc_gui
keepassxc_core
Qt5::Network
Qt5::Widgets
${autotype_LIB}
${keepassxcbrowser_LIB}
${fdosecrets_LIB}
${sshagent_LIB}
${keeshare_LIB})
if(APPLE)
target_link_libraries(keepassx_core "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication")
target_link_libraries(keepassxc_gui "-framework Foundation -framework AppKit -framework Carbon -framework Security -framework LocalAuthentication")
if(Qt5MacExtras_FOUND)
target_link_libraries(keepassx_core Qt5::MacExtras)
target_link_libraries(keepassxc_gui Qt5::MacExtras)
endif()
endif()
if(HAIKU)
target_link_libraries(keepassx_core network)
target_link_libraries(keepassxc_gui network)
endif()
if(UNIX AND NOT APPLE)
target_link_libraries(keepassx_core Qt5::DBus)
target_link_libraries(keepassxc_gui Qt5::DBus)
if(WITH_XC_X11)
target_link_libraries(keepassx_core Qt5::X11Extras X11)
target_link_libraries(keepassxc_gui Qt5::X11Extras X11)
endif()
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
endif()
if(WIN32)
target_link_libraries(keepassx_core Wtsapi32.lib Ws2_32.lib)
target_link_libraries(keepassxc_gui Wtsapi32.lib Ws2_32.lib)
if (MSVC)
target_link_libraries(keepassx_core WindowsApp.lib)
target_link_libraries(keepassxc_gui WindowsApp.lib)
endif()
endif()
@@ -388,8 +357,13 @@ if(WIN32)
)
endif()
add_executable(${PROGNAME} WIN32 ${keepassx_SOURCES_MAINEXE} ${WIN32_ProductVersionFiles})
target_link_libraries(${PROGNAME} keepassx_core)
set(mainexe_SOURCES main.cpp)
if(WIN32)
list(APPEND mainexe_SOURCES ${CMAKE_SOURCE_DIR}/share/windows/icon.rc)
endif()
add_executable(${PROGNAME} WIN32 ${mainexe_SOURCES} ${WIN32_ProductVersionFiles})
target_link_libraries(${PROGNAME} keepassxc_gui)
set_target_properties(${PROGNAME} PROPERTIES ENABLE_EXPORTS ON)
@@ -532,5 +506,5 @@ if(WIN32)
endif()
# The install commands in this subdirectory will be executed after all the install commands in the
# current scope are ran. It is required for correct functtioning of macdeployqt.
# current scope are ran. It is required for correct functioning of macdeployqt.
add_subdirectory(post_install)

View File

@@ -18,4 +18,17 @@ if(WITH_XC_AUTOTYPE)
if(WITH_TESTS)
add_subdirectory(test)
endif()
set(autotype_SOURCES
AutoType.cpp
AutoTypeAction.cpp
AutoTypeMatchModel.cpp
AutoTypeMatchView.cpp
AutoTypeSelectDialog.cpp
PickcharsDialog.cpp
ShortcutWidget.cpp
WindowSelectComboBox.cpp)
add_library(autotype STATIC ${autotype_SOURCES})
target_link_libraries(autotype Qt5::Core Qt5::Widgets)
endif()

View File

@@ -1,4 +1,4 @@
set(autotype_test_SOURCES AutoTypeTest.cpp)
add_library(keepassxc-autotype-test MODULE ${autotype_test_SOURCES})
target_link_libraries(keepassxc-autotype-test keepassx_core ${autotype_LIB} Qt5::Core Qt5::Widgets)
target_link_libraries(keepassxc-autotype-test keepassxc_gui ${autotype_LIB} Qt5::Core Qt5::Widgets)

View File

@@ -1,7 +1,7 @@
set(autotype_win_SOURCES AutoTypeWindows.cpp)
add_library(keepassxc-autotype-windows MODULE ${autotype_win_SOURCES})
target_link_libraries(keepassxc-autotype-windows keepassx_core ${autotype_LIB} Qt5::Core Qt5::Widgets)
target_link_libraries(keepassxc-autotype-windows keepassxc_gui ${autotype_LIB} Qt5::Core Qt5::Widgets)
install(TARGETS keepassxc-autotype-windows
BUNDLE DESTINATION . COMPONENT Runtime
LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime)

View File

@@ -3,7 +3,7 @@ include_directories(SYSTEM ${X11_X11_INCLUDE_PATH})
set(autotype_XCB_SOURCES AutoTypeXCB.cpp)
add_library(keepassxc-autotype-xcb MODULE ${autotype_XCB_SOURCES})
target_link_libraries(keepassxc-autotype-xcb keepassx_core Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB})
target_link_libraries(keepassxc-autotype-xcb keepassxc_gui Qt5::Core Qt5::Widgets Qt5::X11Extras ${X11_X11_LIB} ${X11_Xi_LIB} ${X11_XTest_LIB})
install(TARGETS keepassxc-autotype-xcb
BUNDLE DESTINATION . COMPONENT Runtime
LIBRARY DESTINATION ${PLUGIN_INSTALL_DIR} COMPONENT Runtime)

View File

@@ -33,5 +33,5 @@ if(WITH_XC_BROWSER)
)
add_library(keepassxcbrowser STATIC ${keepassxcbrowser_SOURCES})
target_link_libraries(keepassxcbrowser Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network ${BOTAN2_LIBRARIES})
target_link_libraries(keepassxcbrowser keepassxc_gui Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network ${BOTAN2_LIBRARIES})
endif()

View File

@@ -58,7 +58,7 @@ add_executable(keepassxc-cli keepassxc-cli.cpp)
target_link_libraries(keepassxc-cli
${GPGERROR_LIBRARIES}
cli
keepassx_core)
keepassxc_core)
install(TARGETS keepassxc-cli
BUNDLE DESTINATION . COMPONENT Runtime

View File

@@ -17,13 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_GLOBAL_H
#define KEEPASSX_GLOBAL_H
#ifndef KEEPASSXC_GLOBAL_H
#define KEEPASSXC_GLOBAL_H
#include <QString>
#if defined(Q_OS_WIN)
#if defined(KEEPASSX_BUILDING_CORE)
#if defined(KEEPASSXC_BUILDING_CORE)
#define KEEPASSXC_EXPORT Q_DECL_IMPORT
#else
#define KEEPASSXC_EXPORT Q_DECL_EXPORT
@@ -67,4 +67,4 @@ template <typename T> constexpr typename AddConst<T>::Type& asConst(T& t) noexce
// prevent rvalue arguments:
template <typename T> void asConst(const T&&) = delete;
#endif // KEEPASSX_GLOBAL_H
#endif // KEEPASSXC_GLOBAL_H

View File

@@ -31,5 +31,5 @@ if(WITH_XC_FDOSECRETS)
objects/Prompt.cpp
dbus/DBusTypes.cpp
)
target_link_libraries(fdosecrets Qt5::Core Qt5::Widgets Qt5::DBus ${BOTAN2_LIBRARIES})
target_link_libraries(fdosecrets keepassxc_gui Qt5::Core Qt5::Widgets Qt5::DBus ${BOTAN2_LIBRARIES})
endif()

View File

@@ -22,7 +22,7 @@
#include <QElapsedTimer>
#include <QObject>
#ifdef Q_OS_MACOS
#include "core/MacPasteboard.h"
#include "gui/osutils/macutils/MacPasteboard.h"
#include <QPointer>
#endif

View File

@@ -17,7 +17,7 @@
#include "IconDownloader.h"
#include "core/Config.h"
#include "core/NetworkManager.h"
#include "networking/NetworkManager.h"
#include <QBuffer>
#include <QHostInfo>

View File

@@ -48,7 +48,7 @@
#ifdef WITH_XC_UPDATECHECK
#include "gui/UpdateCheckDialog.h"
#include "updatecheck/UpdateChecker.h"
#include "networking/UpdateChecker.h"
#endif
#ifdef WITH_XC_SSHAGENT

View File

@@ -22,7 +22,7 @@
#include "config-keepassx.h"
#include "gui/Icons.h"
#include "updatecheck/UpdateChecker.h"
#include "networking/UpdateChecker.h"
UpdateCheckDialog::UpdateCheckDialog(QWidget* parent)
: QDialog(parent)

View File

@@ -24,7 +24,7 @@
#include <QWidget>
#ifdef WITH_XC_NETWORKING
#include "core/HibpDownloader.h"
#include "networking/HibpDownloader.h"
#endif
class Database;

View File

@@ -16,7 +16,7 @@
*/
#include "HibpDownloader.h"
#include "core/NetworkManager.h"
#include "NetworkManager.h"
#include <QCryptographicHash>
#include <QNetworkReply>

View File

@@ -17,10 +17,10 @@
#include "UpdateChecker.h"
#include "NetworkManager.h"
#include "config-keepassx.h"
#include "core/Clock.h"
#include "core/Config.h"
#include "core/NetworkManager.h"
#include <QJsonArray>
#include <QJsonDocument>

View File

@@ -12,5 +12,5 @@ if(WITH_XC_SSHAGENT)
)
add_library(sshagent STATIC ${sshagent_SOURCES})
target_link_libraries(sshagent Qt5::Core Qt5::Widgets Qt5::Network)
target_link_libraries(sshagent keepassxc_gui Qt5::Core Qt5::Widgets Qt5::Network)
endif()

View File

@@ -40,5 +40,5 @@ elseif(UNIX AND NOT APPLE)
target_compile_definitions(ykcore PRIVATE _GNU_SOURCE)
elseif(APPLE)
target_sources(ykcore PRIVATE ykcore_osx.c)
target_link_libraries(ykcore PUBLIC "-framework IOKit")
target_link_libraries(ykcore PUBLIC "-framework IOKit -framework Foundation")
endif()

View File

@@ -90,7 +90,7 @@ macro(add_unit_test)
endif()
endmacro(add_unit_test)
set(TEST_LIBRARIES keepassx_core Qt5::Test)
set(TEST_LIBRARIES keepassxc_gui Qt5::Test)
set(testsupport_SOURCES
modeltest.cpp

View File

@@ -119,15 +119,15 @@ void TestMerge::testResolveConflictNewer()
createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries));
// sanity check
QPointer<Group> groupSourceInitial = dbSource->rootGroup()->findChildByName("group1");
auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group1");
QVERIFY(groupSourceInitial != nullptr);
QCOMPARE(groupSourceInitial->entries().size(), 2);
QPointer<Group> groupDestinationInitial = dbSource->rootGroup()->findChildByName("group1");
auto groupDestinationInitial = dbSource->rootGroup()->findChildByName("group1");
QVERIFY(groupDestinationInitial != nullptr);
QCOMPARE(groupDestinationInitial->entries().size(), 2);
QPointer<Entry> entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entrySourceInitial != nullptr);
QVERIFY(entrySourceInitial->group() == groupSourceInitial);
@@ -156,12 +156,12 @@ void TestMerge::testResolveConflictNewer()
merger.merge();
// sanity check
QPointer<Group> groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
QVERIFY(groupDestinationMerged != nullptr);
QCOMPARE(groupDestinationMerged->entries().size(), 2);
QCOMPARE(groupDestinationMerged->timeInfo(), groupDestinationInitialTimeInfo);
QPointer<Entry> entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationMerged != nullptr);
QVERIFY(entryDestinationMerged->group() != nullptr);
QCOMPARE(entryDestinationMerged->password(), QString("password"));
@@ -186,15 +186,15 @@ void TestMerge::testResolveConflictExisting()
createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries));
// sanity check
QPointer<Group> groupSourceInitial = dbSource->rootGroup()->findChildByName("group1");
auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group1");
QVERIFY(groupSourceInitial != nullptr);
QCOMPARE(groupSourceInitial->entries().size(), 2);
QPointer<Group> groupDestinationInitial = dbDestination->rootGroup()->findChildByName("group1");
auto groupDestinationInitial = dbDestination->rootGroup()->findChildByName("group1");
QVERIFY(groupDestinationInitial != nullptr);
QCOMPARE(groupSourceInitial->entries().size(), 2);
QPointer<Entry> entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entrySourceInitial != nullptr);
QVERIFY(entrySourceInitial->group() == groupSourceInitial);
@@ -212,10 +212,10 @@ void TestMerge::testResolveConflictExisting()
const TimeInfo entrySourceUpdatedOlderTimeInfo = entrySourceInitial->timeInfo();
const TimeInfo groupSourceUpdatedOlderTimeInfo = groupSourceInitial->timeInfo();
QPointer<Group> groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1");
auto groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1");
QVERIFY(groupDestinationUpdated != nullptr);
QCOMPARE(groupDestinationUpdated->entries().size(), 2);
QPointer<Entry> entryDestinationUpdated = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationUpdated = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationUpdated != nullptr);
QVERIFY(entryDestinationUpdated->group() == groupDestinationUpdated);
@@ -241,12 +241,12 @@ void TestMerge::testResolveConflictExisting()
merger.merge();
// sanity check
QPointer<Group> groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
QVERIFY(groupDestinationMerged != nullptr);
QCOMPARE(groupDestinationMerged->entries().size(), 2);
QCOMPARE(groupDestinationMerged->timeInfo(), groupDestinationUpdatedNewerTimeInfo);
QPointer<Entry> entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationMerged != nullptr);
QCOMPARE(entryDestinationMerged->password(), QString("password2"));
QCOMPARE(entryDestinationMerged->timeInfo(), entryDestinationUpdatedNewerTimeInfo);
@@ -271,7 +271,7 @@ void TestMerge::testResolveConflictDuplicate()
QCOMPARE(dbDestination->rootGroup()->children().at(0)->entries().size(), 2);
// make this entry newer than in original db
QPointer<Entry> updatedDestinationEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0);
auto updatedDestinationEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0);
const TimeInfo initialEntryTimeInfo = updatedDestinationEntry->timeInfo();
const TimeInfo updatedEntryTimeInfo = modificationTime(initialEntryTimeInfo, 1, 0, 0);
@@ -289,8 +289,8 @@ void TestMerge::testResolveConflictDuplicate()
QCOMPARE(dbDestination->rootGroup()->children().at(0)->entries().size(), 3);
QCOMPARE(dbDestination->rootGroup()->children().at(0)->entries().at(0)->historyItems().isEmpty(), false);
// the older entry was merged from the other db as last in the group
QPointer<Entry> newerEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0);
QPointer<Entry> olderEntry = dbDestination->rootGroup()->children().at(0)->entries().at(2);
auto newerEntry = dbDestination->rootGroup()->children().at(0)->entries().at(0);
auto olderEntry = dbDestination->rootGroup()->children().at(0)->entries().at(2);
QVERIFY(newerEntry->title() == olderEntry->title());
QVERIFY2(!newerEntry->attributes()->hasKey("merged"), "newer entry is not marked with an attribute \"merged\"");
QVERIFY2(olderEntry->attributes()->hasKey("merged"), "older entry is marked with an attribute \"merged\"");
@@ -304,9 +304,9 @@ void TestMerge::testResolveConflictDuplicate()
void TestMerge::testResolveConflictTemplate(
int mergeMode,
std::function<void(Database*, const QMap<const char*, QDateTime>&)> verification)
std::function<void(Database*, const QMap<QString, QDateTime>&)> verification)
{
QMap<const char*, QDateTime> timestamps;
QMap<QString, QDateTime> timestamps;
timestamps["initialTime"] = m_clock->currentDateTimeUtc();
QScopedPointer<Database> dbDestination(createTestDatabase());
@@ -340,10 +340,10 @@ void TestMerge::testResolveConflictTemplate(
QCOMPARE(dbSource->rootGroup()->children().at(0)->entries().at(1)->historyItems().count(), 1);
// simulate some work in the dbs (manipulate the history)
QPointer<Entry> destinationEntry1 = dbDestination->rootGroup()->children().at(0)->entries().at(0);
QPointer<Entry> destinationEntry2 = dbDestination->rootGroup()->children().at(0)->entries().at(1);
QPointer<Entry> sourceEntry1 = dbSource->rootGroup()->children().at(0)->entries().at(0);
QPointer<Entry> sourceEntry2 = dbSource->rootGroup()->children().at(0)->entries().at(1);
auto destinationEntry1 = dbDestination->rootGroup()->children().at(0)->entries().at(0);
auto destinationEntry2 = dbDestination->rootGroup()->children().at(0)->entries().at(1);
auto sourceEntry1 = dbSource->rootGroup()->children().at(0)->entries().at(0);
auto sourceEntry2 = dbSource->rootGroup()->children().at(0)->entries().at(1);
timestamps["newestCommonHistoryTime"] = m_clock->advanceMinute(1);
@@ -386,9 +386,9 @@ void TestMerge::testResolveConflictTemplate(
m_clock->advanceMinute(1);
QPointer<Entry> deletedEntryDestination = dbDestination->rootGroup()->findEntryByPath("deletedDestination");
auto deletedEntryDestination = dbDestination->rootGroup()->findEntryByPath("deletedDestination");
dbDestination->recycleEntry(deletedEntryDestination);
QPointer<Entry> deletedEntrySource = dbSource->rootGroup()->findEntryByPath("deletedSource");
auto deletedEntrySource = dbSource->rootGroup()->findEntryByPath("deletedSource");
dbSource->recycleEntry(deletedEntrySource);
m_clock->advanceMinute(1);
@@ -417,13 +417,13 @@ void TestMerge::testResolveConflictTemplate(
Merger merger(dbSource.data(), dbDestination.data());
merger.merge();
QPointer<Group> mergedRootGroup = dbDestination->rootGroup();
auto mergedRootGroup = dbDestination->rootGroup();
QCOMPARE(mergedRootGroup->entries().size(), 0);
// Both databases contain their own generated recycleBin - just one is considered a real recycleBin, the other
// exists as normal group, therefore only one entry is considered deleted
QCOMPARE(dbDestination->metadata()->recycleBin()->entries().size(), 1);
QPointer<Group> mergedGroup1 = mergedRootGroup->children().at(0);
QPointer<Group> mergedGroup2 = mergedRootGroup->children().at(1);
auto mergedGroup1 = mergedRootGroup->children().at(0);
auto mergedGroup2 = mergedRootGroup->children().at(1);
QVERIFY(mergedGroup1);
QVERIFY(mergedGroup2);
QCOMPARE(mergedGroup2->entries().size(), 2);
@@ -454,7 +454,7 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode,
// entry indirectly deleted in target before updated in source
// entry indirectly deleted in target after updated in source
auto createGroup = [&](const char* name, Group* parent) {
auto createGroup = [&](QString name, Group* parent) {
auto group = new Group();
group->setUuid(QUuid::createUuid());
group->setName(name);
@@ -462,7 +462,7 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode,
identifiers[group->name()] = group->uuid();
return group;
};
auto createEntry = [&](const char* title, Group* parent) {
auto createEntry = [&](QString title, Group* parent) {
auto entry = new Entry();
entry->setUuid(QUuid::createUuid());
entry->setTitle(title);
@@ -501,70 +501,70 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode,
QScopedPointer<Database> dbSource(
createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneIncludeHistory, Group::CloneIncludeEntries));
QPointer<Entry> sourceEntryDeletedInSourceBeforeChangedInTarget =
auto sourceEntryDeletedInSourceBeforeChangedInTarget =
dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]);
QPointer<Entry> targetEntryDeletedInSourceBeforeChangedInTarget =
auto targetEntryDeletedInSourceBeforeChangedInTarget =
dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]);
QPointer<Entry> sourceEntryDeletedInSourceAfterChangedInTarget =
auto sourceEntryDeletedInSourceAfterChangedInTarget =
dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceAfterChangedInTarget"]);
QPointer<Entry> targetEntryDeletedInSourceAfterChangedInTarget =
auto targetEntryDeletedInSourceAfterChangedInTarget =
dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceAfterChangedInTarget"]);
QPointer<Entry> sourceEntryDeletedInTargetBeforeChangedInSource =
auto sourceEntryDeletedInTargetBeforeChangedInSource =
dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetBeforeChangedInSource"]);
QPointer<Entry> targetEntryDeletedInTargetBeforeChangedInSource =
auto targetEntryDeletedInTargetBeforeChangedInSource =
dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetBeforeChangedInSource"]);
QPointer<Entry> sourceEntryDeletedInTargetAfterChangedInSource =
auto sourceEntryDeletedInTargetAfterChangedInSource =
dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetAfterChangedInSource"]);
QPointer<Entry> targetEntryDeletedInTargetAfterChangedInSource =
auto targetEntryDeletedInTargetAfterChangedInSource =
dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetAfterChangedInSource"]);
QPointer<Group> sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget =
auto sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget =
dbSource->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInSourceBeforeEntryUpdatedInTarget"]);
QPointer<Entry> targetEntryDeletedInSourceBeforeEntryUpdatedInTarget =
auto targetEntryDeletedInSourceBeforeEntryUpdatedInTarget =
dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeEntryUpdatedInTarget"]);
QPointer<Group> sourceGroupDeletedInSourceAfterEntryUpdatedInTarget =
auto sourceGroupDeletedInSourceAfterEntryUpdatedInTarget =
dbSource->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInSourceAfterEntryUpdatedInTarget"]);
QPointer<Entry> targetEntryDeletedInSourceAfterEntryUpdatedInTarget =
auto targetEntryDeletedInSourceAfterEntryUpdatedInTarget =
dbDestination->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInSourceAfterEntryUpdatedInTarget"]);
QPointer<Group> targetGroupDeletedInTargetBeforeEntryUpdatedInSource =
auto targetGroupDeletedInTargetBeforeEntryUpdatedInSource =
dbDestination->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInTargetBeforeEntryUpdatedInSource"]);
QPointer<Entry> sourceEntryDeletedInTargetBeforeEntryUpdatedInSource =
auto sourceEntryDeletedInTargetBeforeEntryUpdatedInSource =
dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetBeforeEntryUpdatedInSource"]);
QPointer<Group> targetGroupDeletedInTargetAfterEntryUpdatedInSource =
auto targetGroupDeletedInTargetAfterEntryUpdatedInSource =
dbDestination->rootGroup()->findGroupByUuid(identifiers["GroupDeletedInTargetAfterEntryUpdatedInSource"]);
QPointer<Entry> sourceEntryDeletedInTargetAfterEntryUpdatedInSoruce =
auto sourceEntryDeletedInTargetAfterEntryUpdatedInSoruce =
dbSource->rootGroup()->findEntryByUuid(identifiers["EntryDeletedInTargetAfterEntryUpdatedInSource"]);
// simulate some work in the dbs (manipulate the history)
m_clock->advanceMinute(1);
delete sourceEntryDeletedInSourceBeforeChangedInTarget.data();
delete sourceEntryDeletedInSourceBeforeChangedInTarget;
changeEntry(targetEntryDeletedInSourceAfterChangedInTarget);
delete targetEntryDeletedInTargetBeforeChangedInSource.data();
delete targetEntryDeletedInTargetBeforeChangedInSource;
changeEntry(sourceEntryDeletedInTargetAfterChangedInSource);
delete sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget.data();
delete sourceGroupDeletedInSourceBeforeEntryUpdatedInTarget;
changeEntry(targetEntryDeletedInSourceAfterEntryUpdatedInTarget);
delete targetGroupDeletedInTargetBeforeEntryUpdatedInSource.data();
delete targetGroupDeletedInTargetBeforeEntryUpdatedInSource;
changeEntry(sourceEntryDeletedInTargetAfterEntryUpdatedInSoruce);
m_clock->advanceMinute(1);
changeEntry(targetEntryDeletedInSourceBeforeChangedInTarget);
delete sourceEntryDeletedInSourceAfterChangedInTarget.data();
delete sourceEntryDeletedInSourceAfterChangedInTarget;
changeEntry(sourceEntryDeletedInTargetBeforeChangedInSource);
delete targetEntryDeletedInTargetAfterChangedInSource.data();
delete targetEntryDeletedInTargetAfterChangedInSource;
changeEntry(targetEntryDeletedInSourceBeforeEntryUpdatedInTarget);
delete sourceGroupDeletedInSourceAfterEntryUpdatedInTarget.data();
delete sourceGroupDeletedInSourceAfterEntryUpdatedInTarget;
changeEntry(sourceEntryDeletedInTargetBeforeEntryUpdatedInSource);
delete targetGroupDeletedInTargetAfterEntryUpdatedInSource.data();
delete targetGroupDeletedInTargetAfterEntryUpdatedInSource;
m_clock->advanceMinute(1);
dbDestination->rootGroup()->setMergeMode(static_cast<Group::MergeMode>(mergeMode));
@@ -577,7 +577,7 @@ void TestMerge::testDeletionConflictTemplate(int mergeMode,
void TestMerge::assertDeletionNewerOnly(Database* db, const QMap<QString, QUuid>& identifiers)
{
QPointer<Group> mergedRootGroup = db->rootGroup();
auto mergedRootGroup = db->rootGroup();
// newer change in target prevents deletion
QVERIFY(mergedRootGroup->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]));
QVERIFY(!db->containsDeletedObject(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]));
@@ -614,7 +614,7 @@ void TestMerge::assertDeletionNewerOnly(Database* db, const QMap<QString, QUuid>
void TestMerge::assertDeletionLocalOnly(Database* db, const QMap<QString, QUuid>& identifiers)
{
QPointer<Group> mergedRootGroup = db->rootGroup();
auto mergedRootGroup = db->rootGroup();
QVERIFY(mergedRootGroup->findEntryByUuid(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]));
QVERIFY(!db->containsDeletedObject(identifiers["EntryDeletedInSourceBeforeChangedInTarget"]));
@@ -650,8 +650,9 @@ void TestMerge::assertDeletionLocalOnly(Database* db, const QMap<QString, QUuid>
QVERIFY(db->containsDeletedObject(identifiers["EntryDeletedInTargetAfterEntryUpdatedInSource"]));
}
void TestMerge::assertUpdateMergedEntry1(Entry* mergedEntry1, const QMap<const char*, QDateTime>& timestamps)
void TestMerge::assertUpdateMergedEntry1(Entry* mergedEntry1, const QMap<QString, QDateTime>& timestamps)
{
auto initial = timestamps.keys();
QCOMPARE(mergedEntry1->historyItems().count(), 4);
QCOMPARE(mergedEntry1->historyItems().at(0)->notes(), QString(""));
QCOMPARE(mergedEntry1->historyItems().at(0)->timeInfo().lastModificationTime(), timestamps["initialTime"]);
@@ -668,7 +669,7 @@ void TestMerge::assertUpdateMergedEntry1(Entry* mergedEntry1, const QMap<const c
QCOMPARE(mergedEntry1->timeInfo().lastModificationTime(), timestamps["newestDivergingHistoryTime"]);
}
void TestMerge::assertUpdateReappliedEntry2(Entry* mergedEntry2, const QMap<const char*, QDateTime>& timestamps)
void TestMerge::assertUpdateReappliedEntry2(Entry* mergedEntry2, const QMap<QString, QDateTime>& timestamps)
{
QCOMPARE(mergedEntry2->historyItems().count(), 5);
QCOMPARE(mergedEntry2->historyItems().at(0)->notes(), QString(""));
@@ -689,7 +690,7 @@ void TestMerge::assertUpdateReappliedEntry2(Entry* mergedEntry2, const QMap<cons
QCOMPARE(mergedEntry2->timeInfo().lastModificationTime(), timestamps["mergeTime"]);
}
void TestMerge::assertUpdateReappliedEntry1(Entry* mergedEntry1, const QMap<const char*, QDateTime>& timestamps)
void TestMerge::assertUpdateReappliedEntry1(Entry* mergedEntry1, const QMap<QString, QDateTime>& timestamps)
{
QCOMPARE(mergedEntry1->historyItems().count(), 5);
QCOMPARE(mergedEntry1->historyItems().at(0)->notes(), QString(""));
@@ -710,7 +711,7 @@ void TestMerge::assertUpdateReappliedEntry1(Entry* mergedEntry1, const QMap<cons
QCOMPARE(mergedEntry1->timeInfo().lastModificationTime(), timestamps["mergeTime"]);
}
void TestMerge::assertUpdateMergedEntry2(Entry* mergedEntry2, const QMap<const char*, QDateTime>& timestamps)
void TestMerge::assertUpdateMergedEntry2(Entry* mergedEntry2, const QMap<QString, QDateTime>& timestamps)
{
QCOMPARE(mergedEntry2->historyItems().count(), 4);
QCOMPARE(mergedEntry2->historyItems().at(0)->notes(), QString(""));
@@ -758,9 +759,9 @@ void TestMerge::testDeletionConflictEntry_Duplicate()
*/
void TestMerge::testResolveConflictEntry_Synchronize()
{
testResolveConflictTemplate(Group::Synchronize, [](Database* db, const QMap<const char*, QDateTime>& timestamps) {
QPointer<Group> mergedRootGroup = db->rootGroup();
QPointer<Group> mergedGroup1 = mergedRootGroup->children().at(0);
testResolveConflictTemplate(Group::Synchronize, [](Database* db, const QMap<QString, QDateTime>& timestamps) {
auto mergedRootGroup = db->rootGroup();
auto mergedGroup1 = mergedRootGroup->children().at(0);
TestMerge::assertUpdateMergedEntry1(mergedGroup1->entries().at(0), timestamps);
TestMerge::assertUpdateMergedEntry2(mergedGroup1->entries().at(1), timestamps);
});
@@ -771,9 +772,9 @@ void TestMerge::testResolveConflictEntry_Synchronize()
*/
void TestMerge::testResolveConflictEntry_KeepLocal()
{
testResolveConflictTemplate(Group::KeepLocal, [](Database* db, const QMap<const char*, QDateTime>& timestamps) {
QPointer<Group> mergedRootGroup = db->rootGroup();
QPointer<Group> mergedGroup1 = mergedRootGroup->children().at(0);
testResolveConflictTemplate(Group::KeepLocal, [](Database* db, const QMap<QString, QDateTime>& timestamps) {
auto mergedRootGroup = db->rootGroup();
auto mergedGroup1 = mergedRootGroup->children().at(0);
TestMerge::assertUpdateMergedEntry1(mergedGroup1->entries().at(0), timestamps);
TestMerge::assertUpdateReappliedEntry2(mergedGroup1->entries().at(1), timestamps);
});
@@ -781,9 +782,9 @@ void TestMerge::testResolveConflictEntry_KeepLocal()
void TestMerge::testResolveConflictEntry_KeepRemote()
{
testResolveConflictTemplate(Group::KeepRemote, [](Database* db, const QMap<const char*, QDateTime>& timestamps) {
QPointer<Group> mergedRootGroup = db->rootGroup();
QPointer<Group> mergedGroup1 = mergedRootGroup->children().at(0);
testResolveConflictTemplate(Group::KeepRemote, [](Database* db, const QMap<QString, QDateTime>& timestamps) {
auto mergedRootGroup = db->rootGroup();
auto mergedGroup1 = mergedRootGroup->children().at(0);
TestMerge::assertUpdateReappliedEntry1(mergedGroup1->entries().at(0), timestamps);
TestMerge::assertUpdateMergedEntry2(mergedGroup1->entries().at(1), timestamps);
});
@@ -791,9 +792,9 @@ void TestMerge::testResolveConflictEntry_KeepRemote()
void TestMerge::testResolveConflictEntry_KeepNewer()
{
testResolveConflictTemplate(Group::KeepNewer, [](Database* db, const QMap<const char*, QDateTime>& timestamps) {
QPointer<Group> mergedRootGroup = db->rootGroup();
QPointer<Group> mergedGroup1 = mergedRootGroup->children().at(0);
testResolveConflictTemplate(Group::KeepNewer, [](Database* db, const QMap<QString, QDateTime>& timestamps) {
auto mergedRootGroup = db->rootGroup();
auto mergedGroup1 = mergedRootGroup->children().at(0);
TestMerge::assertUpdateMergedEntry1(mergedGroup1->entries().at(0), timestamps);
TestMerge::assertUpdateMergedEntry2(mergedGroup1->entries().at(1), timestamps);
});
@@ -809,10 +810,10 @@ void TestMerge::testMoveEntry()
QScopedPointer<Database> dbSource(
createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries));
QPointer<Entry> entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entrySourceInitial != nullptr);
QPointer<Group> groupSourceInitial = dbSource->rootGroup()->findChildByName("group2");
auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group2");
QVERIFY(groupSourceInitial != nullptr);
// Make sure the two changes have a different timestamp.
@@ -826,7 +827,7 @@ void TestMerge::testMoveEntry()
Merger merger(dbSource.data(), dbDestination.data());
merger.merge();
QPointer<Entry> entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationMerged != nullptr);
QCOMPARE(entryDestinationMerged->group()->name(), QString("group2"));
QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2);
@@ -843,10 +844,10 @@ void TestMerge::testMoveEntryPreserveChanges()
QScopedPointer<Database> dbSource(
createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries));
QPointer<Entry> entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entrySourceInitial != nullptr);
QPointer<Group> group2Source = dbSource->rootGroup()->findChildByName("group2");
auto group2Source = dbSource->rootGroup()->findChildByName("group2");
QVERIFY(group2Source != nullptr);
m_clock->advanceSecond(1);
@@ -854,7 +855,7 @@ void TestMerge::testMoveEntryPreserveChanges()
entrySourceInitial->setGroup(group2Source);
QCOMPARE(entrySourceInitial->group()->name(), QString("group2"));
QPointer<Entry> entryDestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationInitial != nullptr);
m_clock->advanceSecond(1);
@@ -868,7 +869,7 @@ void TestMerge::testMoveEntryPreserveChanges()
Merger merger(dbSource.data(), dbDestination.data());
merger.merge();
QPointer<Entry> entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationMerged != nullptr);
QCOMPARE(entryDestinationMerged->group()->name(), QString("group2"));
QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2);
@@ -893,7 +894,7 @@ void TestMerge::testCreateNewGroups()
Merger merger(dbSource.data(), dbDestination.data());
merger.merge();
QPointer<Group> groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3");
auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3");
QVERIFY(groupDestinationMerged != nullptr);
QCOMPARE(groupDestinationMerged->name(), QString("group3"));
}
@@ -911,7 +912,7 @@ void TestMerge::testMoveEntryIntoNewGroup()
groupSourceCreated->setUuid(QUuid::createUuid());
groupSourceCreated->setParent(dbSource->rootGroup());
QPointer<Entry> entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1");
auto entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1");
entrySourceMoved->setGroup(groupSourceCreated);
m_clock->advanceSecond(1);
@@ -921,12 +922,12 @@ void TestMerge::testMoveEntryIntoNewGroup()
QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2);
QPointer<Group> groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3");
auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group3");
QVERIFY(groupDestinationMerged != nullptr);
QCOMPARE(groupDestinationMerged->name(), QString("group3"));
QCOMPARE(groupDestinationMerged->entries().size(), 1);
QPointer<Entry> entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationMerged != nullptr);
QCOMPARE(entryDestinationMerged->group()->name(), QString("group3"));
}
@@ -948,7 +949,7 @@ void TestMerge::testUpdateEntryDifferentLocation()
m_clock->advanceSecond(1);
QPointer<Entry> entryDestinationMoved = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationMoved = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationMoved != nullptr);
entryDestinationMoved->setGroup(groupDestinationCreated);
QUuid uuidBeforeSyncing = entryDestinationMoved->uuid();
@@ -957,7 +958,7 @@ void TestMerge::testUpdateEntryDifferentLocation()
// Change the entry in the source db.
m_clock->advanceSecond(1);
QPointer<Entry> entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1");
auto entrySourceMoved = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entrySourceMoved != nullptr);
entrySourceMoved->beginUpdate();
entrySourceMoved->setUsername("username");
@@ -973,7 +974,7 @@ void TestMerge::testUpdateEntryDifferentLocation()
QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2);
QPointer<Entry> entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entryDestinationMerged != nullptr);
QVERIFY(entryDestinationMerged->group() != nullptr);
QCOMPARE(entryDestinationMerged->username(), QString("username"));
@@ -994,14 +995,14 @@ void TestMerge::testUpdateGroup()
m_clock->advanceSecond(1);
QPointer<Group> groupSourceInitial = dbSource->rootGroup()->findChildByName("group2");
auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group2");
groupSourceInitial->setName("group2 renamed");
groupSourceInitial->setNotes("updated notes");
QUuid customIconId = QUuid::createUuid();
dbSource->metadata()->addCustomIcon(customIconId, QString("custom icon").toLocal8Bit());
groupSourceInitial->setIcon(customIconId);
QPointer<Entry> entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entrySourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entrySourceInitial != nullptr);
entrySourceInitial->setGroup(groupSourceInitial);
entrySourceInitial->setTitle("entry1 renamed");
@@ -1014,13 +1015,13 @@ void TestMerge::testUpdateGroup()
QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 2);
QPointer<Entry> entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1 renamed");
auto entryDestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1 renamed");
QVERIFY(entryDestinationMerged != nullptr);
QVERIFY(entryDestinationMerged->group() != nullptr);
QCOMPARE(entryDestinationMerged->group()->name(), QString("group2 renamed"));
QCOMPARE(uuidBeforeSyncing, entryDestinationMerged->uuid());
QPointer<Group> groupMerged = dbDestination->rootGroup()->findChildByName("group2 renamed");
auto groupMerged = dbDestination->rootGroup()->findChildByName("group2 renamed");
QCOMPARE(groupMerged->notes(), QString("updated notes"));
QCOMPARE(groupMerged->iconUuid(), customIconId);
}
@@ -1038,14 +1039,14 @@ void TestMerge::testUpdateGroupLocation()
createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries));
// Sanity check
QPointer<Group> group3SourceInitial = dbSource->rootGroup()->findGroupByUuid(group3Uuid);
auto group3SourceInitial = dbSource->rootGroup()->findGroupByUuid(group3Uuid);
QVERIFY(group3DestinationCreated != nullptr);
QDateTime initialLocationChanged = group3SourceInitial->timeInfo().locationChanged();
m_clock->advanceSecond(1);
QPointer<Group> group3SourceMoved = dbSource->rootGroup()->findGroupByUuid(group3Uuid);
auto group3SourceMoved = dbSource->rootGroup()->findGroupByUuid(group3Uuid);
QVERIFY(group3SourceMoved != nullptr);
group3SourceMoved->setParent(dbSource->rootGroup()->findChildByName("group2"));
@@ -1057,7 +1058,7 @@ void TestMerge::testUpdateGroupLocation()
Merger merger1(dbSource.data(), dbDestination.data());
merger1.merge();
QPointer<Group> group3DestinationMerged1 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid);
auto group3DestinationMerged1 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid);
QVERIFY(group3DestinationMerged1 != nullptr);
QCOMPARE(group3DestinationMerged1->parent(), dbDestination->rootGroup()->findChildByName("group2"));
QCOMPARE(group3DestinationMerged1->timeInfo().locationChanged(), movedLocaltionChanged);
@@ -1067,7 +1068,7 @@ void TestMerge::testUpdateGroupLocation()
Merger merger2(dbSource.data(), dbDestination.data());
merger2.merge();
QPointer<Group> group3DestinationMerged2 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid);
auto group3DestinationMerged2 = dbDestination->rootGroup()->findGroupByUuid(group3Uuid);
QVERIFY(group3DestinationMerged2 != nullptr);
QCOMPARE(group3DestinationMerged2->parent(), dbDestination->rootGroup()->findChildByName("group2"));
QCOMPARE(group3DestinationMerged1->timeInfo().locationChanged(), movedLocaltionChanged);
@@ -1244,7 +1245,7 @@ void TestMerge::testDeletedEntry()
m_clock->advanceSecond(1);
QPointer<Entry> entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entry1SourceInitial != nullptr);
QUuid entry1Uuid = entry1SourceInitial->uuid();
delete entry1SourceInitial;
@@ -1252,7 +1253,7 @@ void TestMerge::testDeletedEntry()
m_clock->advanceSecond(1);
QPointer<Entry> entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2");
auto entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2");
QVERIFY(entry2DestinationInitial != nullptr);
QUuid entry2Uuid = entry2DestinationInitial->uuid();
delete entry2DestinationInitial;
@@ -1263,10 +1264,10 @@ void TestMerge::testDeletedEntry()
Merger merger(dbSource.data(), dbDestination.data());
merger.merge();
QPointer<Entry> entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entry1DestinationMerged);
QVERIFY(!dbDestination->containsDeletedObject(entry1Uuid));
QPointer<Entry> entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2");
auto entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2");
QVERIFY(entry2DestinationMerged);
// Uuid in db and deletedObjects is intended according to KeePass #1752
QVERIFY(dbDestination->containsDeletedObject(entry2Uuid));
@@ -1282,7 +1283,7 @@ void TestMerge::testDeletedGroup()
m_clock->advanceSecond(1);
QPointer<Group> group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2");
auto group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2");
QVERIFY(group2DestinationInitial != nullptr);
auto entry3DestinationCreated = new Entry();
entry3DestinationCreated->beginUpdate();
@@ -1293,11 +1294,11 @@ void TestMerge::testDeletedGroup()
m_clock->advanceSecond(1);
QPointer<Group> group1SourceInitial = dbSource->rootGroup()->findChildByName("group1");
auto group1SourceInitial = dbSource->rootGroup()->findChildByName("group1");
QVERIFY(group1SourceInitial != nullptr);
QPointer<Entry> entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entry1SourceInitial != nullptr);
QPointer<Entry> entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2");
auto entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2");
QVERIFY(entry2SourceInitial != nullptr);
QUuid group1Uuid = group1SourceInitial->uuid();
QUuid entry1Uuid = entry1SourceInitial->uuid();
@@ -1309,7 +1310,7 @@ void TestMerge::testDeletedGroup()
m_clock->advanceSecond(1);
QPointer<Group> group2SourceInitial = dbSource->rootGroup()->findChildByName("group2");
auto group2SourceInitial = dbSource->rootGroup()->findChildByName("group2");
QVERIFY(group2SourceInitial != nullptr);
QUuid group2Uuid = group2SourceInitial->uuid();
delete group2SourceInitial;
@@ -1325,15 +1326,15 @@ void TestMerge::testDeletedGroup()
QVERIFY(!dbDestination->containsDeletedObject(entry2Uuid));
QVERIFY(!dbDestination->containsDeletedObject(group2Uuid));
QPointer<Entry> entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entry1DestinationMerged);
QPointer<Entry> entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2");
auto entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2");
QVERIFY(entry2DestinationMerged);
QPointer<Entry> entry3DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry3");
auto entry3DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry3");
QVERIFY(entry3DestinationMerged);
QPointer<Group> group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
auto group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
QVERIFY(group1DestinationMerged);
QPointer<Group> group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2");
auto group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2");
QVERIFY(group2DestinationMerged);
QCOMPARE(dbDestination->rootGroup()->entriesRecursive().size(), 3);
@@ -1347,7 +1348,7 @@ void TestMerge::testDeletedRevertedEntry()
m_clock->advanceSecond(1);
QPointer<Entry> entry1DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entry1DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entry1DestinationInitial != nullptr);
QUuid entry1Uuid = entry1DestinationInitial->uuid();
delete entry1DestinationInitial;
@@ -1355,7 +1356,7 @@ void TestMerge::testDeletedRevertedEntry()
m_clock->advanceSecond(1);
QPointer<Entry> entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2");
auto entry2SourceInitial = dbSource->rootGroup()->findEntryByPath("entry2");
QVERIFY(entry2SourceInitial != nullptr);
QUuid entry2Uuid = entry2SourceInitial->uuid();
delete entry2SourceInitial;
@@ -1363,11 +1364,11 @@ void TestMerge::testDeletedRevertedEntry()
m_clock->advanceSecond(1);
QPointer<Entry> entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
auto entry1SourceInitial = dbSource->rootGroup()->findEntryByPath("entry1");
QVERIFY(entry1SourceInitial != nullptr);
entry1SourceInitial->setNotes("Updated");
QPointer<Entry> entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2");
auto entry2DestinationInitial = dbDestination->rootGroup()->findEntryByPath("entry2");
QVERIFY(entry2DestinationInitial != nullptr);
entry2DestinationInitial->setNotes("Updated");
@@ -1378,10 +1379,10 @@ void TestMerge::testDeletedRevertedEntry()
QVERIFY(dbDestination->containsDeletedObject(entry1Uuid));
QVERIFY(!dbDestination->containsDeletedObject(entry2Uuid));
QPointer<Entry> entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
auto entry1DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry1");
QVERIFY(entry1DestinationMerged);
QVERIFY(entry1DestinationMerged->notes() == "Updated");
QPointer<Entry> entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2");
auto entry2DestinationMerged = dbDestination->rootGroup()->findEntryByPath("entry2");
QVERIFY(entry2DestinationMerged);
QVERIFY(entry2DestinationMerged->notes() == "Updated");
}
@@ -1394,7 +1395,7 @@ void TestMerge::testDeletedRevertedGroup()
m_clock->advanceSecond(1);
QPointer<Group> group2SourceInitial = dbSource->rootGroup()->findChildByName("group2");
auto group2SourceInitial = dbSource->rootGroup()->findChildByName("group2");
QVERIFY(group2SourceInitial);
QUuid group2Uuid = group2SourceInitial->uuid();
delete group2SourceInitial;
@@ -1402,7 +1403,7 @@ void TestMerge::testDeletedRevertedGroup()
m_clock->advanceSecond(1);
QPointer<Group> group1DestinationInitial = dbDestination->rootGroup()->findChildByName("group1");
auto group1DestinationInitial = dbDestination->rootGroup()->findChildByName("group1");
QVERIFY(group1DestinationInitial);
QUuid group1Uuid = group1DestinationInitial->uuid();
delete group1DestinationInitial;
@@ -1410,13 +1411,13 @@ void TestMerge::testDeletedRevertedGroup()
m_clock->advanceSecond(1);
QPointer<Group> group1SourceInitial = dbSource->rootGroup()->findChildByName("group1");
auto group1SourceInitial = dbSource->rootGroup()->findChildByName("group1");
QVERIFY(group1SourceInitial);
group1SourceInitial->setNotes("Updated");
m_clock->advanceSecond(1);
QPointer<Group> group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2");
auto group2DestinationInitial = dbDestination->rootGroup()->findChildByName("group2");
QVERIFY(group2DestinationInitial);
group2DestinationInitial->setNotes("Updated");
@@ -1429,10 +1430,10 @@ void TestMerge::testDeletedRevertedGroup()
QVERIFY(dbDestination->containsDeletedObject(group1Uuid));
QVERIFY(!dbDestination->containsDeletedObject(group2Uuid));
QPointer<Group> group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
auto group1DestinationMerged = dbDestination->rootGroup()->findChildByName("group1");
QVERIFY(group1DestinationMerged);
QVERIFY(group1DestinationMerged->notes() == "Updated");
QPointer<Group> group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2");
auto group2DestinationMerged = dbDestination->rootGroup()->findChildByName("group2");
QVERIFY(group2DestinationMerged);
QVERIFY(group2DestinationMerged->notes() == "Updated");
}
@@ -1449,7 +1450,7 @@ void TestMerge::testResolveGroupConflictOlder()
createTestDatabaseStructureClone(dbDestination.data(), Entry::CloneNoFlags, Group::CloneIncludeEntries));
// sanity check
QPointer<Group> groupSourceInitial = dbSource->rootGroup()->findChildByName("group1");
auto groupSourceInitial = dbSource->rootGroup()->findChildByName("group1");
QVERIFY(groupSourceInitial != nullptr);
// Make sure the two changes have a different timestamp.
@@ -1460,7 +1461,7 @@ void TestMerge::testResolveGroupConflictOlder()
// Make sure the two changes have a different timestamp.
m_clock->advanceSecond(1);
QPointer<Group> groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1");
auto groupDestinationUpdated = dbDestination->rootGroup()->findChildByName("group1");
groupDestinationUpdated->setName("group1 updated in destination");
m_clock->advanceSecond(1);
@@ -1469,8 +1470,7 @@ void TestMerge::testResolveGroupConflictOlder()
merger.merge();
// sanity check
QPointer<Group> groupDestinationMerged =
dbDestination->rootGroup()->findChildByName("group1 updated in destination");
auto groupDestinationMerged = dbDestination->rootGroup()->findChildByName("group1 updated in destination");
QVERIFY(groupDestinationMerged != nullptr);
}

View File

@@ -66,15 +66,15 @@ 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);
std::function<void(Database*, const QMap<QString, 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);
static void assertUpdateMergedEntry1(Entry* entry, const QMap<QString, QDateTime>& timestamps);
static void assertUpdateReappliedEntry2(Entry* entry, const QMap<QString, QDateTime>& timestamps);
static void assertUpdateReappliedEntry1(Entry* entry, const QMap<QString, QDateTime>& timestamps);
static void assertUpdateMergedEntry2(Entry* entry, const QMap<QString, QDateTime>& timestamps);
};
#endif // KEEPASSX_TESTMERGE_H

View File

@@ -17,7 +17,7 @@
#include "TestUpdateCheck.h"
#include "crypto/Crypto.h"
#include "updatecheck/UpdateChecker.h"
#include "networking/UpdateChecker.h"
#include <QTest>

View File

@@ -70,6 +70,10 @@ void TestGuiBrowser::initTestCase()
config()->set(Config::GUI_AdvancedSettings, false);
// Disable the update check first time alert
config()->set(Config::UpdateCheckMessageShown, true);
// Disable quick unlock
config()->set(Config::Security_QuickUnlock, false);
// Disable showing expired entries on unlock
config()->set(Config::GUI_ShowExpiredEntriesOnDatabaseUnlock, false);
m_mainWindow.reset(new MainWindow());
m_tabWidget = m_mainWindow->findChild<DatabaseTabWidget*>("tabWidget");