diff options
author | Kevin Wu Won <kevin.wu-won@nokia.com> | 2010-10-18 14:46:22 +1000 |
---|---|---|
committer | Kevin Wu Won <kevin.wu-won@nokia.com> | 2010-10-19 11:52:45 +1000 |
commit | eebe7bcdc61d415d94087227eadba69c07690d7e (patch) | |
tree | 04e1536d08b8d84c313a29dc93a63174cb0850dd | |
parent | 5e95458708f7e97655e340959743064f3e0d3218 (diff) |
Add test for QVersitContactHandler plugins
Checks that they are loaded and run in the correct order for the importer
and exporter
24 files changed, 1232 insertions, 11 deletions
diff --git a/src/versit/qversitcontactexporter_p.cpp b/src/versit/qversitcontactexporter_p.cpp index ef76f9550d..9346645dd9 100644 --- a/src/versit/qversitcontactexporter_p.cpp +++ b/src/versit/qversitcontactexporter_p.cpp @@ -135,10 +135,6 @@ bool QVersitContactExporterPrivate::exportContact( QVersitContactExporter::Error* error) { QList<QContactDetail> allDetails = contact.details(); - if (allDetails.isEmpty()) { - *error = QVersitContactExporter::EmptyContactError; - return false; - } foreach (const QContactDetail& detail, allDetails) { // If the custom detail handler handles it, we don't have to. if (mDetailHandler diff --git a/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.cpp b/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.cpp index 282ce84e80..646728ab1c 100644 --- a/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.cpp +++ b/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.cpp @@ -245,6 +245,26 @@ void tst_QVersitContactExporter::testConvertContact() QCOMPARE(documents.first().properties().count(), 3); } +void tst_QVersitContactExporter::testEmptyContact() +{ + QContact contact1; // empty + QList<QContact> contacts; + contacts << contact1; + + QVERIFY(mExporter->exportContacts(contacts)); // do not fail on empty contact1 + QMap<int, QVersitContactExporter::Error> errorMap = mExporter->errorMap(); + QVERIFY(errorMap.isEmpty()); + QList<QVersitDocument> documents = mExporter->documents(); + QCOMPARE(documents.size(), 1); // only contact2 was exported + QVersitDocument document1 = documents.first(); + QVersitProperty property = findPropertyByName(document1, "N"); + QCOMPARE(property.valueType(), QVersitProperty::CompoundType); + QCOMPARE(property.value<QStringList>(), + QStringList() << QString() << QString() << QString() << QString() << QString()); + property = findPropertyByName(document1, "FN"); + QCOMPARE(property.value(), QString()); +} + void tst_QVersitContactExporter::testContactDetailHandler() { MyQVersitContactExporterDetailHandler detailHandler;; diff --git a/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.h b/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.h index a0b30edeb9..782b6d6568 100644 --- a/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.h +++ b/tests/auto/qversitcontactexporter/tst_qversitcontactexporter.h @@ -69,6 +69,7 @@ private slots: void cleanup(); void testConvertContact(); + void testEmptyContact(); void testContactDetailHandler(); void testContactDetailHandlerV2(); void testEncodeName(); diff --git a/tests/auto/qversitcontactimporter/tst_qversitcontactimporter.cpp b/tests/auto/qversitcontactimporter/tst_qversitcontactimporter.cpp index f68bd64372..997dfb003b 100644 --- a/tests/auto/qversitcontactimporter/tst_qversitcontactimporter.cpp +++ b/tests/auto/qversitcontactimporter/tst_qversitcontactimporter.cpp @@ -1345,10 +1345,10 @@ void tst_QVersitContactImporter::testInvalidDocument() document.setType(QVersitDocument::VCard21Type); documents.append(document); QVERIFY(!mImporter->importDocuments(documents)); - QMap<int, QVersitContactImporter::Error> errors = mImporter->errorMap(); - QCOMPARE(errors.size(), 1); - QVERIFY(errors.contains(0)); - QVERIFY(errors.value(0) == QVersitContactImporter::InvalidDocumentError); + QMap<int, QVersitContactImporter::Error> errorMap = mImporter->errorMap(); + QCOMPARE(errorMap.size(), 1); + QVERIFY(errorMap.contains(0)); + QVERIFY(errorMap.value(0) == QVersitContactImporter::InvalidDocumentError); QList<QContact> contacts = mImporter->contacts(); QCOMPARE(contacts.size(), 1); QContactPhoneNumber phoneDetail = contacts.first().detail<QContactPhoneNumber>(); @@ -1358,9 +1358,11 @@ void tst_QVersitContactImporter::testInvalidDocument() document.clear(); document.setType(QVersitDocument::VCard21Type); QVERIFY(!mImporter->importDocuments(QList<QVersitDocument>() << document)); - errors = mImporter->errorMap(); - QCOMPARE(errors.size(), 1); - QCOMPARE(errors.value(0), QVersitContactImporter::EmptyDocumentError); + errorMap = mImporter->errorMap(); + QCOMPARE(errorMap.size(), 1); + QCOMPARE(errorMap.value(0), QVersitContactImporter::EmptyDocumentError); + QCOMPARE(mImporter->errors(), errorMap); + } QVersitDocument tst_QVersitContactImporter::createDocumentWithProperty( diff --git a/tests/auto/qversitcontactplugins/plugin1/plugin1.cpp b/tests/auto/qversitcontactplugins/plugin1/plugin1.cpp new file mode 100644 index 0000000000..0f3e989e77 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin1/plugin1.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtPlugin> +#include "plugin1.h" + +QTM_USE_NAMESPACE + +class ContactHandler1 : public QVersitContactHandler +{ +public: + void propertyProcessed(const QVersitDocument& document, + const QVersitProperty& property, + const QContact& contact, + bool* alreadyProcessed, + QList<QContactDetail>* updatedDetails) + { + Q_UNUSED(document) + Q_UNUSED(property) + Q_UNUSED(contact) + Q_UNUSED(alreadyProcessed) + Q_UNUSED(updatedDetails) + } + void documentProcessed(const QVersitDocument& document, + QContact* contact) + { + Q_UNUSED(document) + QContactDetail detail("TestDetail"); + detail.setValue("Plugin", 1); + contact->saveDetail(&detail); + } + void detailProcessed(const QContact& contact, + const QContactDetail& detail, + const QVersitDocument& document, + QSet<QString>* processedFields, + QList<QVersitProperty>* toBeRemoved, + QList<QVersitProperty>* toBeAdded) + { + Q_UNUSED(contact) + Q_UNUSED(detail) + Q_UNUSED(document) + Q_UNUSED(processedFields) + Q_UNUSED(toBeRemoved) + Q_UNUSED(toBeAdded) + } + void contactProcessed(const QContact& contact, + QVersitDocument* document) + { + Q_UNUSED(contact) + QVersitProperty property; + property.setName("TEST-PROPERTY"); + property.setValue("1"); + document->addProperty(property); + } +}; + +QString Plugin1::name() const +{ + return "com.nokia.qt.mobility.versit.plugin1"; +} + +int Plugin1::index() const +{ + return 5; +} + +QVersitContactHandler* Plugin1::createHandler() const +{ + return new ContactHandler1; +} + +QSet<QString> Plugin1::profiles() const +{ + return QSet<QString>() << "Test"; +} + +Q_EXPORT_PLUGIN2(versit_plugin1, Plugin1); diff --git a/tests/auto/qversitcontactplugins/plugin1/plugin1.h b/tests/auto/qversitcontactplugins/plugin1/plugin1.h new file mode 100644 index 0000000000..e5300f1ba9 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin1/plugin1.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include <QObject> +#include "qversitcontacthandler.h" +#include "qversitproperty.h" + +QTM_USE_NAMESPACE + +class Plugin1 : public QObject, public QVersitContactHandlerFactory +{ + Q_OBJECT + Q_INTERFACES(QtMobility::QVersitContactHandlerFactory) + +public: + QString name() const; + int index() const; + QVersitContactHandler* createHandler() const; + QSet<QString> profiles() const; +}; + +#endif diff --git a/tests/auto/qversitcontactplugins/plugin1/plugin1.pro b/tests/auto/qversitcontactplugins/plugin1/plugin1.pro new file mode 100644 index 0000000000..c28ff7eda2 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin1/plugin1.pro @@ -0,0 +1,24 @@ +TEMPLATE = lib +CONFIG += plugin testplugin +TARGET = $$qtLibraryTarget(versit_plugin1) +PLUGIN_TYPE=versit + +include(../../../../common.pri) + +INCLUDEPATH += \ + ../../../../src/versit \ + ../../../../src/contacts \ + ../../../../src/contacts/details \ + ../../../../src/contacts/requests \ + ../../../../src/contacts/filters + + +INCLUDEPATH += $$MOC_DIR + +CONFIG += mobility +MOBILITY = versit +SOURCES += plugin1.cpp +HEADERS += plugin1.h + +include(../../versit_plugins.pri) + diff --git a/tests/auto/qversitcontactplugins/plugin2/plugin2.cpp b/tests/auto/qversitcontactplugins/plugin2/plugin2.cpp new file mode 100644 index 0000000000..c83d896597 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin2/plugin2.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtPlugin> +#include "plugin2.h" + +QTM_USE_NAMESPACE + +class ContactHandler2 : public QVersitContactHandler +{ +public: + void propertyProcessed(const QVersitDocument& document, + const QVersitProperty& property, + const QContact& contact, + bool* alreadyProcessed, + QList<QContactDetail>* updatedDetails) + { + Q_UNUSED(document) + Q_UNUSED(property) + Q_UNUSED(contact) + Q_UNUSED(alreadyProcessed) + Q_UNUSED(updatedDetails) + } + void documentProcessed(const QVersitDocument& document, + QContact* contact) + { + Q_UNUSED(document) + QContactDetail detail("TestDetail"); + detail.setValue("Plugin", 2); + contact->saveDetail(&detail); + } + void detailProcessed(const QContact& contact, + const QContactDetail& detail, + const QVersitDocument& document, + QSet<QString>* processedFields, + QList<QVersitProperty>* toBeRemoved, + QList<QVersitProperty>* toBeAdded) + { + Q_UNUSED(contact) + Q_UNUSED(detail) + Q_UNUSED(document) + Q_UNUSED(processedFields) + Q_UNUSED(toBeRemoved) + Q_UNUSED(toBeAdded) + } + void contactProcessed(const QContact& contact, + QVersitDocument* document) + { + Q_UNUSED(contact) + QVersitProperty property; + property.setName("TEST-PROPERTY"); + property.setValue("2"); + document->addProperty(property); + } +}; + +QString Plugin2::name() const +{ + return "com.nokia.qt.mobility.versit.plugin2"; +} + +int Plugin2::index() const +{ + return 4; +} + +QVersitContactHandler* Plugin2::createHandler() const +{ + return new ContactHandler2; +} + +QSet<QString> Plugin2::profiles() const +{ + return QSet<QString>() << "Test"; +} + +Q_EXPORT_PLUGIN2(versit_plugin2, Plugin2); diff --git a/tests/auto/qversitcontactplugins/plugin2/plugin2.h b/tests/auto/qversitcontactplugins/plugin2/plugin2.h new file mode 100644 index 0000000000..319f49cb2c --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin2/plugin2.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include <QObject> +#include "qversitcontacthandler.h" +#include "qversitproperty.h" + +QTM_USE_NAMESPACE + +class Plugin2 : public QObject, public QVersitContactHandlerFactory +{ + Q_OBJECT + Q_INTERFACES(QtMobility::QVersitContactHandlerFactory) + +public: + QString name() const; + int index() const; + QVersitContactHandler* createHandler() const; + QSet<QString> profiles() const; +}; + +#endif diff --git a/tests/auto/qversitcontactplugins/plugin2/plugin2.pro b/tests/auto/qversitcontactplugins/plugin2/plugin2.pro new file mode 100644 index 0000000000..d39ab72bbe --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin2/plugin2.pro @@ -0,0 +1,23 @@ +TEMPLATE = lib +CONFIG += plugin testplugin +TARGET = $$qtLibraryTarget(versit_plugin2) +PLUGIN_TYPE=versit + +include(../../../../common.pri) + +INCLUDEPATH += \ + ../../../../src/versit \ + ../../../../src/contacts \ + ../../../../src/contacts/details \ + ../../../../src/contacts/requests \ + ../../../../src/contacts/filters + +INCLUDEPATH += $$MOC_DIR + +CONFIG += mobility +MOBILITY = versit +SOURCES += plugin2.cpp +HEADERS += plugin2.h + +include(../../versit_plugins.pri) + diff --git a/tests/auto/qversitcontactplugins/plugin3/plugin3.cpp b/tests/auto/qversitcontactplugins/plugin3/plugin3.cpp new file mode 100644 index 0000000000..13d3af408e --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin3/plugin3.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtPlugin> +#include "plugin3.h" + +QTM_USE_NAMESPACE + +class ContactHandler3 : public QVersitContactHandler +{ +public: + void propertyProcessed(const QVersitDocument& document, + const QVersitProperty& property, + const QContact& contact, + bool* alreadyProcessed, + QList<QContactDetail>* updatedDetails) + { + Q_UNUSED(document) + Q_UNUSED(property) + Q_UNUSED(contact) + Q_UNUSED(alreadyProcessed) + Q_UNUSED(updatedDetails) + } + void documentProcessed(const QVersitDocument& document, + QContact* contact) + { + Q_UNUSED(document) + QContactDetail detail("TestDetail"); + detail.setValue("Plugin", 3); + contact->saveDetail(&detail); + } + void detailProcessed(const QContact& contact, + const QContactDetail& detail, + const QVersitDocument& document, + QSet<QString>* processedFields, + QList<QVersitProperty>* toBeRemoved, + QList<QVersitProperty>* toBeAdded) + { + Q_UNUSED(contact) + Q_UNUSED(detail) + Q_UNUSED(document) + Q_UNUSED(processedFields) + Q_UNUSED(toBeRemoved) + Q_UNUSED(toBeAdded) + } + void contactProcessed(const QContact& contact, + QVersitDocument* document) + { + Q_UNUSED(contact) + QVersitProperty property; + property.setName("TEST-PROPERTY"); + property.setValue("3"); + document->addProperty(property); + } +}; + +QString Plugin3::name() const +{ + return "com.nokia.qt.mobility.versit.plugin3"; +} + +int Plugin3::index() const +{ + return 3; +} + +QVersitContactHandler* Plugin3::createHandler() const +{ + return new ContactHandler3; +} + +QSet<QString> Plugin3::profiles() const +{ + return QSet<QString>() << "Test"; +} + +Q_EXPORT_PLUGIN2(versit_plugin3, Plugin3); diff --git a/tests/auto/qversitcontactplugins/plugin3/plugin3.h b/tests/auto/qversitcontactplugins/plugin3/plugin3.h new file mode 100644 index 0000000000..d098161805 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin3/plugin3.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include <QObject> +#include "qversitcontacthandler.h" +#include "qversitproperty.h" + +QTM_USE_NAMESPACE + +class Plugin3 : public QObject, public QVersitContactHandlerFactory +{ + Q_OBJECT + Q_INTERFACES(QtMobility::QVersitContactHandlerFactory) + +public: + QString name() const; + int index() const; + QVersitContactHandler* createHandler() const; + QSet<QString> profiles() const; +}; + +#endif diff --git a/tests/auto/qversitcontactplugins/plugin3/plugin3.pro b/tests/auto/qversitcontactplugins/plugin3/plugin3.pro new file mode 100644 index 0000000000..b5e4a7501f --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin3/plugin3.pro @@ -0,0 +1,23 @@ +TEMPLATE = lib +CONFIG += plugin testplugin +TARGET = $$qtLibraryTarget(versit_plugin3) +PLUGIN_TYPE=versit + +include(../../../../common.pri) + +INCLUDEPATH += \ + ../../../../src/versit \ + ../../../../src/contacts \ + ../../../../src/contacts/details \ + ../../../../src/contacts/requests \ + ../../../../src/contacts/filters + +INCLUDEPATH += $$MOC_DIR + +CONFIG += mobility +MOBILITY = versit +SOURCES += plugin3.cpp +HEADERS += plugin3.h + +include(../../versit_plugins.pri) + diff --git a/tests/auto/qversitcontactplugins/plugin4/plugin4.cpp b/tests/auto/qversitcontactplugins/plugin4/plugin4.cpp new file mode 100644 index 0000000000..d22cf0588e --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin4/plugin4.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtPlugin> +#include "plugin4.h" + +QTM_USE_NAMESPACE + +class ContactHandler4 : public QVersitContactHandler +{ +public: + void propertyProcessed(const QVersitDocument& document, + const QVersitProperty& property, + const QContact& contact, + bool* alreadyProcessed, + QList<QContactDetail>* updatedDetails) + { + Q_UNUSED(document) + Q_UNUSED(property) + Q_UNUSED(contact) + Q_UNUSED(alreadyProcessed) + Q_UNUSED(updatedDetails) + } + void documentProcessed(const QVersitDocument& document, + QContact* contact) + { + Q_UNUSED(document) + QContactDetail detail("TestDetail"); + detail.setValue("Plugin", 4); + contact->saveDetail(&detail); + } + void detailProcessed(const QContact& contact, + const QContactDetail& detail, + const QVersitDocument& document, + QSet<QString>* processedFields, + QList<QVersitProperty>* toBeRemoved, + QList<QVersitProperty>* toBeAdded) + { + Q_UNUSED(contact) + Q_UNUSED(detail) + Q_UNUSED(document) + Q_UNUSED(processedFields) + Q_UNUSED(toBeRemoved) + Q_UNUSED(toBeAdded) + } + void contactProcessed(const QContact& contact, + QVersitDocument* document) + { + Q_UNUSED(contact) + QVersitProperty property; + property.setName("TEST-PROPERTY"); + property.setValue("4"); + document->addProperty(property); + } +}; + +QString Plugin4::name() const +{ + return "com.nokia.qt.mobility.versit.plugin4"; +} + +int Plugin4::index() const +{ + return 2; +} + +QVersitContactHandler* Plugin4::createHandler() const +{ + return new ContactHandler4; +} + +QSet<QString> Plugin4::profiles() const +{ + return QSet<QString>() << "Test"; +} + +Q_EXPORT_PLUGIN2(versit_plugin4, Plugin4); diff --git a/tests/auto/qversitcontactplugins/plugin4/plugin4.h b/tests/auto/qversitcontactplugins/plugin4/plugin4.h new file mode 100644 index 0000000000..9ba8ad8b2c --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin4/plugin4.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include <QObject> +#include "qversitcontacthandler.h" +#include "qversitproperty.h" + +QTM_USE_NAMESPACE + +class Plugin4 : public QObject, public QVersitContactHandlerFactory +{ + Q_OBJECT + Q_INTERFACES(QtMobility::QVersitContactHandlerFactory) + +public: + QString name() const; + int index() const; + QVersitContactHandler* createHandler() const; + QSet<QString> profiles() const; +}; + +#endif diff --git a/tests/auto/qversitcontactplugins/plugin4/plugin4.pro b/tests/auto/qversitcontactplugins/plugin4/plugin4.pro new file mode 100644 index 0000000000..90c4151d45 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin4/plugin4.pro @@ -0,0 +1,23 @@ +TEMPLATE = lib +CONFIG += plugin testplugin +TARGET = $$qtLibraryTarget(versit_plugin4) +PLUGIN_TYPE=versit + +include(../../../../common.pri) + +INCLUDEPATH += \ + ../../../../src/versit \ + ../../../../src/contacts \ + ../../../../src/contacts/details \ + ../../../../src/contacts/requests \ + ../../../../src/contacts/filters + +INCLUDEPATH += $$MOC_DIR + +CONFIG += mobility +MOBILITY = versit +SOURCES += plugin4.cpp +HEADERS += plugin4.h + +include(../../versit_plugins.pri) + diff --git a/tests/auto/qversitcontactplugins/plugin5/plugin5.cpp b/tests/auto/qversitcontactplugins/plugin5/plugin5.cpp new file mode 100644 index 0000000000..76da7f310a --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin5/plugin5.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtPlugin> +#include "plugin5.h" + +QTM_USE_NAMESPACE + +class ContactHandler5 : public QVersitContactHandler +{ +public: + void propertyProcessed(const QVersitDocument& document, + const QVersitProperty& property, + const QContact& contact, + bool* alreadyProcessed, + QList<QContactDetail>* updatedDetails) + { + Q_UNUSED(document) + Q_UNUSED(property) + Q_UNUSED(contact) + Q_UNUSED(alreadyProcessed) + Q_UNUSED(updatedDetails) + } + void documentProcessed(const QVersitDocument& document, + QContact* contact) + { + Q_UNUSED(document) + QContactDetail detail("TestDetail"); + detail.setValue("Plugin", 5); + contact->saveDetail(&detail); + } + void detailProcessed(const QContact& contact, + const QContactDetail& detail, + const QVersitDocument& document, + QSet<QString>* processedFields, + QList<QVersitProperty>* toBeRemoved, + QList<QVersitProperty>* toBeAdded) + { + Q_UNUSED(contact) + Q_UNUSED(detail) + Q_UNUSED(document) + Q_UNUSED(processedFields) + Q_UNUSED(toBeRemoved) + Q_UNUSED(toBeAdded) + } + void contactProcessed(const QContact& contact, + QVersitDocument* document) + { + Q_UNUSED(contact) + QVersitProperty property; + property.setName("TEST-PROPERTY"); + property.setValue("5"); + document->addProperty(property); + } +}; + +QString Plugin5::name() const +{ + return "com.nokia.qt.mobility.versit.plugin5"; +} + +int Plugin5::index() const +{ + return 1; +} + +QVersitContactHandler* Plugin5::createHandler() const +{ + return new ContactHandler5; +} + +QSet<QString> Plugin5::profiles() const +{ + return QSet<QString>() << "Test"; +} + +Q_EXPORT_PLUGIN2(versit_plugin5, Plugin5); diff --git a/tests/auto/qversitcontactplugins/plugin5/plugin5.h b/tests/auto/qversitcontactplugins/plugin5/plugin5.h new file mode 100644 index 0000000000..85029504e5 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin5/plugin5.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PLUGIN_H +#define PLUGIN_H + +#include <QObject> +#include "qversitcontacthandler.h" +#include "qversitproperty.h" + +QTM_USE_NAMESPACE + +class Plugin5 : public QObject, public QVersitContactHandlerFactory +{ + Q_OBJECT + Q_INTERFACES(QtMobility::QVersitContactHandlerFactory) + +public: + QString name() const; + int index() const; + QVersitContactHandler* createHandler() const; + QSet<QString> profiles() const; +}; + +#endif diff --git a/tests/auto/qversitcontactplugins/plugin5/plugin5.pro b/tests/auto/qversitcontactplugins/plugin5/plugin5.pro new file mode 100644 index 0000000000..a32b5fb1a0 --- /dev/null +++ b/tests/auto/qversitcontactplugins/plugin5/plugin5.pro @@ -0,0 +1,23 @@ +TEMPLATE = lib +CONFIG += plugin testplugin +TARGET = $$qtLibraryTarget(versit_plugin5) +PLUGIN_TYPE=versit + +include(../../../../common.pri) + +INCLUDEPATH += \ + ../../../../src/versit \ + ../../../../src/contacts \ + ../../../../src/contacts/details \ + ../../../../src/contacts/requests \ + ../../../../src/contacts/filters + +INCLUDEPATH += $$MOC_DIR + +CONFIG += mobility +MOBILITY = versit +SOURCES += plugin5.cpp +HEADERS += plugin5.h + +include(../../versit_plugins.pri) + diff --git a/tests/auto/qversitcontactplugins/qversitcontactplugins.pro b/tests/auto/qversitcontactplugins/qversitcontactplugins.pro new file mode 100644 index 0000000000..cc636c9069 --- /dev/null +++ b/tests/auto/qversitcontactplugins/qversitcontactplugins.pro @@ -0,0 +1,8 @@ +TEMPLATE=subdirs + +SUBDIRS+=plugin1 +SUBDIRS+=plugin2 +SUBDIRS+=plugin3 +SUBDIRS+=plugin4 +SUBDIRS+=plugin5 +SUBDIRS+=unittest diff --git a/tests/auto/qversitcontactplugins/unittest/tst_qversitcontactplugins.cpp b/tests/auto/qversitcontactplugins/unittest/tst_qversitcontactplugins.cpp new file mode 100644 index 0000000000..1162a8d5c0 --- /dev/null +++ b/tests/auto/qversitcontactplugins/unittest/tst_qversitcontactplugins.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qversitcontacthandler.h" +#include "qversitproperty.h" + +#include <QObject> +#include <QtTest/QtTest> + +QTM_USE_NAMESPACE + +class TestFactory1 : public QVersitContactHandlerFactory +{ + public: + QString name() const { return "factory1"; } + QVersitContactHandler* createHandler() const { return NULL; } +}; + +class tst_QVersitContactPlugins : public QObject +{ + Q_OBJECT + +private slots: + void testDefaultFactory(); + void testImporterPlugins(); + void testExporterPlugins(); +}; + +void tst_QVersitContactPlugins::testDefaultFactory() { + TestFactory1 factory; + QCOMPARE(factory.profiles(), QSet<QString>()); + QCOMPARE(factory.index(), 0); +} + +void tst_QVersitContactPlugins::testImporterPlugins() { + QVersitContactImporter importer("Test"); + QVersitDocument document; + document.setComponentType("VCARD"); + QVersitProperty property; + property.setName("FN"); + property.setValue("Bob"); + document.addProperty(property); + QVERIFY(importer.importDocuments(QList<QVersitDocument>() << document)); + QCOMPARE(importer.contacts().size(), 1); + QList<QContactDetail> details(importer.contacts().first().details("TestDetail")); + QCOMPARE(details.size(), 5); + // The plugins have had their index set such that they should be executed in reverse order + // Check that they are all loaded, and run in the correct order + QCOMPARE(details.at(0).value<int>("Plugin"), 5); + QCOMPARE(details.at(1).value<int>("Plugin"), 4); + QCOMPARE(details.at(2).value<int>("Plugin"), 3); + QCOMPARE(details.at(3).value<int>("Plugin"), 2); + QCOMPARE(details.at(4).value<int>("Plugin"), 1); +} + +void tst_QVersitContactPlugins::testExporterPlugins() { + QVersitContactExporter exporter("Test"); + QContact contact; + QVERIFY(exporter.exportContacts(QList<QContact>() << contact)); + QCOMPARE(exporter.documents().size(), 1); + QList<QVersitProperty> properties(exporter.documents().first().properties()); + + // The plugins have had their index set such that they should be executed in reverse order + // Check that they are all loaded, and run in the correct order + int n = 0; + foreach (QVersitProperty property, properties) { + if (property.name() == "TEST-PROPERTY") { + switch (n) { + case 0: QCOMPARE(property.value(), QLatin1String("5")); break; + case 1: QCOMPARE(property.value(), QLatin1String("4")); break; + case 2: QCOMPARE(property.value(), QLatin1String("3")); break; + case 3: QCOMPARE(property.value(), QLatin1String("2")); break; + case 4: QCOMPARE(property.value(), QLatin1String("1")); break; + } + n++; + } + } + QCOMPARE(n, 5); +} + +QTEST_MAIN(tst_QVersitContactPlugins) + +#include "tst_qversitcontactplugins.moc" diff --git a/tests/auto/qversitcontactplugins/unittest/unittest.pro b/tests/auto/qversitcontactplugins/unittest/unittest.pro new file mode 100644 index 0000000000..e6cedaf57c --- /dev/null +++ b/tests/auto/qversitcontactplugins/unittest/unittest.pro @@ -0,0 +1,29 @@ +QT += testlib +TEMPLATE=app +TARGET=tst_qversitcontactplugins +CONFIG+=testcase +CONFIG+=parallel_test + +include(../../../../common.pri) + +DEPENDPATH += . +INCLUDEPATH += \ + . \ + ../../../ \ + ../../../../src/versit \ + ../../../../src/contacts \ + ../../../../src/contacts/details \ + ../../../../src/contacts/requests \ + ../../../../src/contacts/filters + +SOURCES += tst_qversitcontactplugins.cpp + +CONFIG += mobility +MOBILITY += versit + +symbian: { + TARGET.CAPABILITY = ALL \ + -TCB + LIBS += -lws32 \ + -lbafl +} diff --git a/tests/auto/versit.pro b/tests/auto/versit.pro index d7adefde73..81be11510a 100644 --- a/tests/auto/versit.pro +++ b/tests/auto/versit.pro @@ -8,6 +8,7 @@ SUBDIRS += \ qvcard30writer \ qversitcontactexporter \ qversitcontactimporter \ + qversitcontactplugins \ qversitdocument \ qversitproperty \ qversitreader \ diff --git a/tests/auto/versit_plugins.pri b/tests/auto/versit_plugins.pri new file mode 100644 index 0000000000..fabee8a1b1 --- /dev/null +++ b/tests/auto/versit_plugins.pri @@ -0,0 +1,37 @@ +# +# Code for making sure our test plugins go to the right places +# (by default, these are private plugins for cross compilation platforms) +# +# There is typically a completely separate folder for each unit test +# on these platforms, so installing plugins to those dirs is acceptable. +# +# On other platforms, all tests are built and live in a single place +# so we put the test plugins into a separate dir, since we don't want +# these test plugins available for all unit tests. +# +symbian{ + TARGET.EPOCALLOWDLLDATA = 1 + TARGET.CAPABILITY = ALL -TCB + + testplugin.sources = $${TARGET}.dll + testplugin.path = plugins/versit + DEPLOYMENT += testplugin + + target.path = plugins/versit + INSTALLS += target +} + +wince* { + testplugin.sources = $${TARGET}.dll + testplugin.path = ./plugins + DEPLOYMENT += testplugin + + target.path = ./plugins + INSTALLS += target +} + +# Add this too +CONFIG *= mobility +MOBILITY *= versit + + |