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

Prepare autotest

parent 1bad745a
Pipeline #29700 failed with stage
in 7 minutes and 44 seconds
......@@ -2,7 +2,7 @@ ecm_qt_declare_logging_category(kaddressbook_importexport_windowscontact_debugfi
DESCRIPTION "kdepim-addons (Import/Export Windows Contact plugin)"
EXPORT KDEPIMADDONS
)
add_definitions(-DWINDOWSCONTACT_DATADIR=\"${CMAKE_CURRENT_SOURCE_DIR}\")
macro(add_windowscontact_unittest _source _additional)
set( _test ${_source} ${_additional} ${kaddressbook_importexport_windowscontact_debugfile_autotest_SRCS})
get_filename_component(_name ${_source} NAME_WE)
......
......@@ -24,5 +24,21 @@ QTEST_MAIN(ImportWindowContactTest)
ImportWindowContactTest::ImportWindowContactTest(QObject *parent)
: QObject(parent)
{
}
void ImportWindowContactTest::shouldImportWindowContact_data()
{
QTest::addColumn<QString>("filename");
QTest::addColumn<KContacts::Addressee::List>("result");
QTest::newRow("empty") << QString() << KContacts::Addressee::List();
}
void ImportWindowContactTest::shouldImportWindowContact()
{
QFETCH(QString, filename);
QFETCH(KContacts::Addressee::List, result);
ImportWindowContact contact;
contact.setShowMessageBox(false);
const QString fullPath = QStringLiteral(WINDOWSCONTACT_DATADIR "/data/") + filename;
QCOMPARE(contact.importFile(fullPath), result);
}
......@@ -28,6 +28,9 @@ class ImportWindowContactTest : public QObject
public:
explicit ImportWindowContactTest(QObject *parent = nullptr);
~ImportWindowContactTest() = default;
private Q_SLOTS:
void shouldImportWindowContact_data();
void shouldImportWindowContact();
};
#endif // IMPORTWINDOWCONTACTTEST_H
......@@ -39,8 +39,12 @@ KContacts::Addressee::List ImportWindowContact::importFile(const QString &fileNa
KContacts::Addressee::List lst;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
const QString msg = i18n("<qt>Unable to open <b>%1</b> for reading.</qt>", fileName);
KMessageBox::error(mParentWidget, msg);
if (mShowMessageBox) {
const QString msg = i18n("<qt>Unable to open <b>%1</b> for reading.</qt>", fileName);
KMessageBox::error(mParentWidget, msg);
} else {
qCWarning(IMPORTEXPORTWINDOWSCONTACTPLUGIN_LOG) << "Impossible to open file: " << fileName;
}
return lst;
}
QDomDocument doc;
......@@ -75,3 +79,8 @@ void ImportWindowContact::setParentWidget(QWidget *parentWidget)
{
mParentWidget = parentWidget;
}
void ImportWindowContact::setShowMessageBox(bool b)
{
mShowMessageBox = b;
}
......@@ -33,9 +33,11 @@ public:
Q_REQUIRED_RESULT KContacts::Addressee::List importFile(const QString &fileName);
void setParentWidget(QWidget *parentWidget);
void setShowMessageBox(bool b); //Only for autotest
private:
Q_REQUIRED_RESULT bool loadDomElement(QDomDocument &doc, QFile *file);
bool mShowMessageBox = true;
QWidget *mParentWidget = nullptr;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment