summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2018-06-01 13:22:26 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2018-06-26 08:17:32 +0000
commit96bd8a5804e5dd5fdcbc88d4491693169a518d7b (patch)
tree07fe19f9636260829ddbc60addc8f46a373ab299 /tests
parentdf2d5fa1da9fdd6264377a14fa319eaa751fb9d2 (diff)
downloadqtivi-96bd8a5804e5dd5fdcbc88d4491693169a518d7b.tar.gz
Add new (un)registerInstance functions to the QIviPagingModelInterface
These functions help to maintain the state in the backend implementations. The registerInstance function is called for every new instance of a model using this backend. The unregisterInstance is called once the model instance is destroyed and the all data for this model can be cleanup in the backend as well. Task-number: AUTOSUITE-435 Change-Id: I2390c4fd423acb40cd50c6a2d2ff22c15aef15ab Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/qivipagingmodel/qivipagingmodel.pro2
-rw-r--r--tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp48
-rw-r--r--tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp10
3 files changed, 59 insertions, 1 deletions
diff --git a/tests/auto/core/qivipagingmodel/qivipagingmodel.pro b/tests/auto/core/qivipagingmodel/qivipagingmodel.pro
index cbd880f..9f632db 100644
--- a/tests/auto/core/qivipagingmodel/qivipagingmodel.pro
+++ b/tests/auto/core/qivipagingmodel/qivipagingmodel.pro
@@ -1,4 +1,4 @@
-QT += testlib ivicore quick
+QT += testlib ivicore quick ivicore-private core-private
TARGET = tst_qivipagingmodel
QMAKE_PROJECT_NAME = $$TARGET
diff --git a/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp b/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp
index daebd68..5f565cf 100644
--- a/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp
+++ b/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp
@@ -30,12 +30,14 @@
#include <QIviAbstractFeature>
#include <QIviServiceManager>
#include <QIviPagingModel>
+#include <private/qivipagingmodel_p.h>
#include <QIviPagingModelInterface>
#include <QIviSearchAndBrowseModelItem>
#include <QQmlEngine>
#include <QQmlContext>
#include <QQmlComponent>
#include <QScopedPointer>
+#include <private/qobject_p.h>
//TODO Add test with multiple model instances, requesting different data at the same time
//TODO Test the signal without a valid identifier
@@ -78,6 +80,16 @@ public:
emit initializationDone();
}
+ void registerInstance(const QUuid &identifier) override
+ {
+ emit registerInstanceCalled(identifier);
+ }
+
+ void unregisterInstance(const QUuid &identifier) override
+ {
+ emit unregisterInstanceCalled(identifier);
+ }
+
void fetchData(const QUuid &identifier, int start, int count) override
{
emit supportedCapabilitiesChanged(identifier, m_caps);
@@ -122,6 +134,10 @@ public:
emit dataChanged(QUuid(), variantLIst, min, max - min + 1);
}
+Q_SIGNALS:
+ void registerInstanceCalled(const QUuid &identifier);
+ void unregisterInstanceCalled(const QUuid &identifier);
+
private:
QList<QIviSearchAndBrowseModelItem> m_list;
QtIviCoreModule::ModelCapabilities m_caps;
@@ -178,6 +194,7 @@ private Q_SLOTS:
void testClearServiceObject();
+ void testRegisterInstance();
void testBasic_qml();
void testGetAt();
void testFetchMore_data();
@@ -233,6 +250,37 @@ void tst_QIviPagingModel::testClearServiceObject()
QVERIFY(model.rowCount() == defaultModel.rowCount());
}
+void tst_QIviPagingModel::testRegisterInstance()
+{
+ TestServiceObject *service = new TestServiceObject();
+ manager->registerService(service, service->interfaces());
+ service->testBackend()->initializeSimpleData();
+
+ QSignalSpy registerSpy(service->testBackend(), SIGNAL(registerInstanceCalled(QUuid)));
+ QIviPagingModel firstModel;
+ firstModel.setServiceObject(service);
+ QCOMPARE(registerSpy.count(), 1);
+ auto *firstModelPrivate = reinterpret_cast<QIviPagingModelPrivate*> (QObjectPrivate::get(&firstModel));
+ QUuid firstModelIdentifier = firstModelPrivate->m_identifier;
+ QCOMPARE(registerSpy.at(0).at(0).toUuid(), firstModelIdentifier);
+
+ QIviPagingModel secondModel;
+ secondModel.setServiceObject(service);
+ QCOMPARE(registerSpy.count(), 2);
+ auto *secondModelPrivate = reinterpret_cast<QIviPagingModelPrivate*> (QObjectPrivate::get(&secondModel));
+ QUuid secondModelIdentifier = secondModelPrivate->m_identifier;
+ QCOMPARE(registerSpy.at(1).at(0).toUuid(), secondModelIdentifier);
+
+ QSignalSpy unregisterSpy(service->testBackend(), SIGNAL(unregisterInstanceCalled(QUuid)));
+ secondModel.setServiceObject(nullptr);
+ QCOMPARE(unregisterSpy.count(), 1);
+ QCOMPARE(unregisterSpy.at(0).at(0).toUuid(), secondModelIdentifier);
+
+ firstModel.setServiceObject(nullptr);
+ QCOMPARE(unregisterSpy.count(), 2);
+ QCOMPARE(unregisterSpy.at(1).at(0).toUuid(), firstModelIdentifier);
+}
+
void tst_QIviPagingModel::testBasic_qml()
{
TestServiceObject *service = new TestServiceObject();
diff --git a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
index 4f46ff5..a069c1c 100644
--- a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
+++ b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
@@ -111,6 +111,16 @@ public:
emit initializationDone();
}
+ void registerInstance(const QUuid &identifier) override
+ {
+ Q_UNUSED(identifier);
+ }
+
+ void unregisterInstance(const QUuid &identifier) override
+ {
+ Q_UNUSED(identifier);
+ }
+
void setContentType(const QUuid &identifier, const QString &contentType) override
{
Q_UNUSED(identifier)