Commit a1260ed5 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add mergelib here

parent 69f86dec
#add_subdirectory(mergelib)
add_subdirectory(mergecontacts)
add_subdirectory(searchduplicates)
set(kaddressbookmergelibprivate_SRCS
job/searchpotentialduplicatecontactjob.cpp
job/mergecontactsjob.cpp
job/mergecontacts.cpp
manualmerge/mergecontactsdialog.cpp
manualmerge/mergecontactwidget.cpp
manualmerge/mergecontactwidgetlist.cpp
searchduplicate/searchandmergecontactduplicatecontactdialog.cpp
searchduplicate/searchduplicateresultwidget.cpp
searchduplicate/resultduplicatetreewidget.cpp
searchduplicate/mergecontactselectinformationtabwidget.cpp
widgets/mergecontactinfowidget.cpp
widgets/mergecontactshowresulttabwidget.cpp
widgets/mergecontactselectinformationwidget.cpp
widgets/mergecontactselectlistwidget.cpp
widgets/mergecontactloseinformationwarning.cpp
widgets/mergecontactselectinformationscrollarea.cpp
widgets/mergecontacterrorlabel.cpp
)
add_library(kaddressbookmergelibprivate ${kaddressbookmergelibprivate_SRCS})
generate_export_header(kaddressbookmergelibprivate BASE_NAME kaddressbookmergelib)
target_link_libraries(kaddressbookmergelibprivate
PRIVATE
Qt5::Network KF5::I18n KF5::KaddressbookGrantlee KF5::Contacts KF5::AkonadiContact KF5::ConfigCore
)
set_target_properties(kaddressbookmergelibprivate
PROPERTIES VERSION ${KDEPIMADDONS_LIB_VERSION} SOVERSION ${KDEPIMADDONS_LIB_SOVERSION}
)
install(TARGETS kaddressbookmergelibprivate ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
if (BUILD_TESTING)
add_subdirectory(autotests)
endif()
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../.. )
include_directories(${CMAKE_BINARY_DIR}/kaddressbook/)
# Convenience macro to add unit tests.
macro( kaddressbook_merge _source _additional _additionallib)
set( _test ${_source} ${_additional})
get_filename_component( _name ${_source} NAME_WE )
add_executable( ${_name} ${_test} )
add_test( ${_name} ${_name} )
ecm_mark_as_test(kaddressbookmerge-${_name})
target_link_libraries( ${_name} kaddressbookprivate Qt5::Test KF5::AkonadiCore KF5::Contacts ${_additionallib})
endmacro()
kaddressbook_merge(mergecontactstest.cpp "../job/mergecontacts.cpp" "")
set(KDEPIMLIBS_RUN_ISOLATED_TESTS TRUE)
set(KDEPIMLIBS_RUN_SQLITE_ISOLATED_TESTS TRUE)
add_akonadi_isolated_test_advanced( mergecontactinfowidgettest.cpp "../widgets/mergecontactinfowidget.cpp" "KF5::AkonadiContact;KF5::KaddressbookGrantlee")
add_akonadi_isolated_test_advanced( mergecontactwidgettest.cpp "../widgets/mergecontactinfowidget.cpp" "kaddressbookprivate;KF5::KaddressbookGrantlee;KF5::Contacts;KF5::AkonadiContact")
add_akonadi_isolated_test_advanced( searchandmergecontactduplicatecontactdialogtest.cpp "" "kaddressbookprivate")
add_akonadi_isolated_test_advanced( searchduplicateresultwidgettest.cpp "" "kaddressbookprivate;KF5::KaddressbookGrantlee;KF5::Contacts")
add_akonadi_isolated_test_advanced( resultduplicatetreewidgettest.cpp "" "kaddressbookprivate;KF5::Contacts")
add_akonadi_isolated_test_advanced( searchpotentialduplicatecontactjobtest.cpp "../job/searchpotentialduplicatecontactjob.cpp" "KF5::Contacts")
add_akonadi_isolated_test_advanced( mergecontactselectinformationwidgettest.cpp "" "kaddressbookprivate;KF5::Contacts")
add_akonadi_isolated_test_advanced( mergecontactselectlistwidgettest.cpp "" "kaddressbookprivate;KF5::Contacts")
add_akonadi_isolated_test_advanced( mergecontactselectinformationscrollareatest.cpp "../widgets/mergecontactinfowidget.cpp" "kaddressbookprivate;KF5::Contacts;KF5::AkonadiContact;KF5::KaddressbookGrantlee")
add_akonadi_isolated_test_advanced( mergecontactselectinformationtabwidgettest.cpp "" "kaddressbookprivate;KF5::Contacts")
add_akonadi_isolated_test_advanced(mergecontactsdialogtest.cpp "../manualmerge/mergecontactsdialog.cpp;../widgets/mergecontacterrorlabel.cpp;../widgets/mergecontactinfowidget.cpp" "kaddressbookprivate;KF5::Contacts;KF5::AkonadiContact;KF5::KaddressbookGrantlee")
add_akonadi_isolated_test_advanced(mergecontactwidgetlisttest.cpp "../manualmerge/mergecontactwidgetlist.cpp;" "kaddressbookprivate;KF5::Contacts;KF5::AkonadiContact")
set( kaddressbook_merge_mergecontactloseinformationwarning_source mergecontactloseinformationwarningtest.cpp ../widgets/mergecontactloseinformationwarning.cpp )
add_executable( mergecontactloseinformationwarningtest ${kaddressbook_merge_mergecontactloseinformationwarning_source})
add_test(mergecontactloseinformationwarningtest mergecontactloseinformationwarningtest)
ecm_mark_as_test(mergecontactloseinformationwarningtest)
target_link_libraries( mergecontactloseinformationwarningtest Qt5::Test Qt5::Gui kaddressbookprivate)
/*
Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mergecontactinfowidgettest.h"
#include <qtest.h>
#include "merge/widgets/mergecontactinfowidget.h"
#include <QStackedWidget>
#include <QStandardPaths>
using namespace KABMergeContacts;
MergeContactInfoWidgetTest::MergeContactInfoWidgetTest()
{
}
void MergeContactInfoWidgetTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
}
void MergeContactInfoWidgetTest::shouldHaveDefaultValueOnCreation()
{
MergeContactInfoWidget infoWidget;
QStackedWidget *stackedWidget = infoWidget.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
QVERIFY(stackedWidget);
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontact"));
}
void MergeContactInfoWidgetTest::shouldHaveActivateDisplayWidgetWhenSelectOneContact()
{
MergeContactInfoWidget infoWidget;
Akonadi::Item item(4);
infoWidget.setContact(item);
QStackedWidget *stackedWidget = infoWidget.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("contactwidget"));
}
void MergeContactInfoWidgetTest::shouldHaveActivateNoWidgetWhenSelectNoContact()
{
MergeContactInfoWidget infoWidget;
Akonadi::Item item(4);
infoWidget.setContact(item);
QStackedWidget *stackedWidget = infoWidget.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("contactwidget"));
infoWidget.setContact(Akonadi::Item());
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontact"));
}
QTEST_MAIN(MergeContactInfoWidgetTest)
/*
Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MERGECONTACTINFOWIDGETTEST_H
#define MERGECONTACTINFOWIDGETTEST_H
#include <QObject>
class MergeContactInfoWidgetTest : public QObject
{
Q_OBJECT
public:
MergeContactInfoWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValueOnCreation();
void shouldHaveActivateDisplayWidgetWhenSelectOneContact();
void shouldHaveActivateNoWidgetWhenSelectNoContact();
void initTestCase();
};
#endif // MERGECONTACTINFOWIDGETTEST_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mergecontactloseinformationwarningtest.h"
#include "../widgets/mergecontactloseinformationwarning.h"
#include <QAction>
#include <qtest.h>
#include <QSignalSpy>
#include <qtestmouse.h>
MergeContactLoseInformationWarningTest::MergeContactLoseInformationWarningTest(QObject *parent)
: QObject(parent)
{
}
void MergeContactLoseInformationWarningTest::shouldHaveDefaultValue()
{
KABMergeContacts::MergeContactLoseInformationWarning w;
QVERIFY(!w.isCloseButtonVisible());
QVERIFY(!w.isVisible());
QAction *customize = w.findChild<QAction *>(QStringLiteral("customize"));
QVERIFY(customize);
QAction *automatic = w.findChild<QAction *>(QStringLiteral("automatic"));
QVERIFY(automatic);
}
void MergeContactLoseInformationWarningTest::shouldEmitSignals()
{
KABMergeContacts::MergeContactLoseInformationWarning w;
w.show();
QTest::qWaitForWindowExposed(&w);
QVERIFY(w.isVisible());
QAction *customize = w.findChild<QAction *>(QStringLiteral("customize"));
QAction *automatic = w.findChild<QAction *>(QStringLiteral("automatic"));
QSignalSpy spy1(&w, SIGNAL(continueMerging()));
QSignalSpy spy2(&w, SIGNAL(customizeMergingContacts()));
customize->trigger();
QCOMPARE(spy1.count(), 0);
QCOMPARE(spy2.count(), 1);
automatic->trigger();
QCOMPARE(spy2.count(), 1);
QCOMPARE(spy1.count(), 1);
}
QTEST_MAIN(MergeContactLoseInformationWarningTest)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MERGECONTACTLOSEINFORMATIONWARNINGTEST_H
#define MERGECONTACTLOSEINFORMATIONWARNINGTEST_H
#include <QObject>
class MergeContactLoseInformationWarningTest : public QObject
{
Q_OBJECT
public:
explicit MergeContactLoseInformationWarningTest(QObject *parent = Q_NULLPTR);
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldEmitSignals();
};
#endif // MERGECONTACTLOSEINFORMATIONWARNINGTEST_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mergecontactsdialogtest.h"
#include "merge/manualmerge/mergecontactsdialog.h"
#include <QStackedWidget>
#include <qtest.h>
#include <QDialogButtonBox>
#include <QStandardPaths>
MergeContactsDialogTest::MergeContactsDialogTest(QObject *parent)
: QObject(parent)
{
}
MergeContactsDialogTest::~MergeContactsDialogTest()
{
}
void MergeContactsDialogTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
}
void MergeContactsDialogTest::shouldHaveDefaultValue()
{
KABMergeContacts::MergeContactsDialog dlg;
dlg.show();
QDialogButtonBox *buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
QVERIFY(buttonBox);
QStackedWidget *stackedWidget = dlg.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
QVERIFY(stackedWidget);
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontactselected"));
for (int i = 0; i < stackedWidget->count(); ++i) {
QWidget *w = stackedWidget->widget(i);
const QString objName = w->objectName();
const bool hasGoodNamePage = (objName == QLatin1String("notenoughcontactselected") ||
objName == QLatin1String("nocontactselected") ||
objName == QLatin1String("manualmergeresultwidget") ||
objName == QLatin1String("selectioninformation") ||
objName == QLatin1String("mergecontactinfowidget"));
QVERIFY(hasGoodNamePage);
}
}
void MergeContactsDialogTest::shouldSwithStackedWidget()
{
KABMergeContacts::MergeContactsDialog dlg;
dlg.show();
QStackedWidget *stackedWidget = dlg.findChild<QStackedWidget *>(QStringLiteral("stackedwidget"));
Akonadi::Item::List lst;
//Empty
dlg.setContacts(lst);
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("nocontactselected"));
lst << Akonadi::Item(42);
//1 element
dlg.setContacts(lst);
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("notenoughcontactselected"));
lst.clear();
//1 element
lst << Akonadi::Item(42);
dlg.setContacts(lst);
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("notenoughcontactselected"));
// 2 elements
lst.clear();
lst << Akonadi::Item(42) << Akonadi::Item(42);
dlg.setContacts(lst);
QCOMPARE(stackedWidget->currentWidget()->objectName(), QStringLiteral("manualmergeresultwidget"));
}
QTEST_MAIN(MergeContactsDialogTest)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MERGECONTACTSDIALOGTEST_H
#define MERGECONTACTSDIALOGTEST_H
#include <QObject>
class MergeContactsDialogTest : public QObject
{
Q_OBJECT
public:
explicit MergeContactsDialogTest(QObject *parent = Q_NULLPTR);
~MergeContactsDialogTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldSwithStackedWidget();
void initTestCase();
};
#endif // MERGECONTACTSDIALOGTEST_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mergecontactselectinformationscrollareatest.h"
#include <qtest.h>
#include "../widgets/mergecontactselectinformationwidget.h"
#include "../widgets/mergecontactselectinformationscrollarea.h"
#include "../widgets/mergecontactinfowidget.h"
#include <QScrollArea>
#include <QPushButton>
#include <QStackedWidget>
MergeContactSelectInformationScrollAreaTest::MergeContactSelectInformationScrollAreaTest(QObject *parent)
: QObject(parent)
{
}
MergeContactSelectInformationScrollAreaTest::~MergeContactSelectInformationScrollAreaTest()
{
}
void MergeContactSelectInformationScrollAreaTest::shouldHaveDefaultValue()
{
KABMergeContacts::MergeContactSelectInformationScrollArea w;
QScrollArea *area = w.findChild<QScrollArea *>(QStringLiteral("scrollarea"));
QVERIFY(area);
QPushButton *mergeButton = w.findChild<QPushButton *>(QStringLiteral("merge"));
QVERIFY(mergeButton);
QStackedWidget *stackedwidget = w.findChild<QStackedWidget *>(QStringLiteral("stackwidget"));
QVERIFY(stackedwidget);
KABMergeContacts::MergeContactSelectInformationWidget *widget = w.findChild<KABMergeContacts::MergeContactSelectInformationWidget *>(QStringLiteral("selectinformationwidget"));
QVERIFY(widget);
for (int i = 0; i < stackedwidget->count(); ++i) {
QWidget *w = stackedwidget->widget(i);
const QString objName = w->objectName();
bool hasCorrectName = (objName == QLatin1String("mergedcontactwidget")) || (objName == QLatin1String("selectwidget"));
QVERIFY(hasCorrectName);
}
QCOMPARE(stackedwidget->currentWidget()->objectName(), QStringLiteral("selectwidget"));
}
QTEST_MAIN(MergeContactSelectInformationScrollAreaTest)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MERGECONTACTSELECTINFORMATIONSCROLLAREATEST_H
#define MERGECONTACTSELECTINFORMATIONSCROLLAREATEST_H
#include <QObject>
class MergeContactSelectInformationScrollAreaTest : public QObject
{
Q_OBJECT
public:
explicit MergeContactSelectInformationScrollAreaTest(QObject *parent = Q_NULLPTR);
~MergeContactSelectInformationScrollAreaTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // MERGECONTACTSELECTINFORMATIONSCROLLAREATEST_H
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mergecontactselectinformationtabwidgettest.h"
#include "../searchduplicate/mergecontactselectinformationtabwidget.h"
#include <qtest.h>
MergeContactSelectInformationTabWidgetTest::MergeContactSelectInformationTabWidgetTest(QObject *parent)
: QObject(parent)
{
}
MergeContactSelectInformationTabWidgetTest::~MergeContactSelectInformationTabWidgetTest()
{
}
void MergeContactSelectInformationTabWidgetTest::shouldHaveDefaultValue()
{
KABMergeContacts::MergeContactSelectInformationTabWidget w;
QVERIFY(!w.tabBarVisible());
QCOMPARE(w.count(), 0);
}
void MergeContactSelectInformationTabWidgetTest::shouldAddTab()
{
KABMergeContacts::MergeContactSelectInformationTabWidget w;
QVector<KABMergeContacts::MergeConflictResult> list;
KABMergeContacts::MergeConflictResult conflict;
Akonadi::Item::List listItem;
KContacts::Addressee address1;
Akonadi::Item item1;
address1.setName(QStringLiteral("foo1"));
item1.setPayload<KContacts::Addressee>(address1);
KContacts::Addressee address2;
Akonadi::Item item2;
address2.setName(QStringLiteral("foo2"));
item2.setPayload<KContacts::Addressee>(address2);
listItem << item1;
listItem << item2;
conflict.list = listItem;
KABMergeContacts::MergeContacts::ConflictInformations conflictInformation = KABMergeContacts::MergeContacts::Birthday;
conflict.list = listItem;
conflict.conflictInformation = conflictInformation;
list << conflict;
w.setRequiresSelectInformationWidgets(list, Akonadi::Collection(42));