summaryrefslogtreecommitdiffstats
path: root/tests/auto/jsondbnotification
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/jsondbnotification')
-rw-r--r--tests/auto/jsondbnotification/jsondbnotification.pro11
-rw-r--r--tests/auto/jsondbnotification/partitions.json3
-rw-r--r--tests/auto/jsondbnotification/testjsondbnotification.cpp156
-rw-r--r--tests/auto/jsondbnotification/testjsondbnotification.h31
4 files changed, 110 insertions, 91 deletions
diff --git a/tests/auto/jsondbnotification/jsondbnotification.pro b/tests/auto/jsondbnotification/jsondbnotification.pro
index f4e1fd6..1703343 100644
--- a/tests/auto/jsondbnotification/jsondbnotification.pro
+++ b/tests/auto/jsondbnotification/jsondbnotification.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondbnotification
DEPENDPATH += .
-INCLUDEPATH += .
+INCLUDEPATH += . ../../shared/
-QT = core network testlib gui qml jsondbcompat-private
+QT = core network testlib gui qml jsondb
CONFIG -= app_bundle
CONFIG += testcase
include($$PWD/../../shared/shared.pri)
-include($$PWD/../../../src/3rdparty/qjson/qjson.pri)
DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\"
DEFINES += SRCDIR=\\\"$$PWD/\\\"
-HEADERS += testjsondbnotification.h
+HEADERS += testjsondbnotification.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbnotification.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbnotification/partitions.json b/tests/auto/jsondbnotification/partitions.json
new file mode 100644
index 0000000..c77651a
--- /dev/null
+++ b/tests/auto/jsondbnotification/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared" }
+]
diff --git a/tests/auto/jsondbnotification/testjsondbnotification.cpp b/tests/auto/jsondbnotification/testjsondbnotification.cpp
index 6e3610f..418b110 100644
--- a/tests/auto/jsondbnotification/testjsondbnotification.cpp
+++ b/tests/auto/jsondbnotification/testjsondbnotification.cpp
@@ -41,10 +41,9 @@
#include <QtTest/QtTest>
#include <QJSEngine>
+#include <QJSValueIterator>
#include "testjsondbnotification.h"
#include "../../shared/util.h"
-#include <QJSValueIterator>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-partition";
@@ -71,6 +70,20 @@ const QString qmlProgramForPartition = QLatin1String(
"name: \"com.nokia.shared\";"
"}");
+#define waitForReadyStatus(obj) \
+ { \
+ int status = 0; \
+ while ((status = obj->property("status").toInt()) < 2) { \
+ waitForCallback1(); \
+ } \
+ }
+
+#define waitForCallbackNId(id) \
+ { \
+ waitForCallback1(); \
+ if (id != lastRequestId) \
+ waitForResponse1(id); \
+ }
TestJsonDbNotification::TestJsonDbNotification()
: mTimedOut(false)
@@ -84,8 +97,9 @@ TestJsonDbNotification::~TestJsonDbNotification()
void TestJsonDbNotification::timeout()
{
- ClientWrapper::timeout();
+ RequestWrapper::timeout();
mTimedOut = true;
+ eventLoop1.quit();
}
void TestJsonDbNotification::deleteDbFiles()
@@ -108,25 +122,12 @@ void TestJsonDbNotification::initTestCase()
deleteDbFiles();
QString socketName = QString("testjsondb_%1").arg(getpid());
- mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile);
+ mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList() << "-base-name" << dbfile, __FILE__);
- mClient = new JsonDbClient(this);
- connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)),
- this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification)));
- connect( mClient, SIGNAL(response(int, const QVariant&)),
- this, SLOT(response(int, const QVariant&)));
- connect( mClient, SIGNAL(error(int, int, const QString&)),
- this, SLOT(error(int, int, const QString&)));
+ connection = new QJsonDbConnection();
+ connection->connectToServer();
mPluginPath = findQMLPluginPath("QtJsonDb");
-
- // Create the shared Partitions
- QVariantMap item;
- item.insert("_type", "Partition");
- item.insert("name", "com.nokia.shared");
- int id = mClient->create(item);
- waitForResponse1(id);
-
}
ComponentData *TestJsonDbNotification::createComponent()
@@ -146,6 +147,8 @@ ComponentData *TestJsonDbNotification::createComponent()
qDebug() << componentData->component->errors();
QObject::connect(componentData->qmlElement, SIGNAL(notificationSignal(QVariant, int, int)),
this, SLOT(notificationSlot(QVariant, int, int)));
+ QObject::connect(componentData->qmlElement, SIGNAL(statusChanged(JsonDbNotify::Status)),
+ this, SLOT(statusChangedSlot2()));
mComponents.append(componentData);
return componentData;
}
@@ -193,8 +196,8 @@ void TestJsonDbNotification::notificationSlot(QVariant result, int action, int s
data.result = result.toMap();
data.action = action;
data.stateNumber = stateNumber;
- cbData.append(data);
- mEventLoop2.quit();
+ callbackData.append(data);
+ eventLoop1.quit();
}
void TestJsonDbNotification::errorSlot(int code, const QString &message)
@@ -202,7 +205,7 @@ void TestJsonDbNotification::errorSlot(int code, const QString &message)
callbackError = true;
callbackErrorCode = code;
callbackErrorMessage = message;
- mEventLoop2.quit();
+ eventLoop1.quit();
}
void TestJsonDbNotification::notificationSlot2(QJSValue result, Actions action, int stateNumber)
@@ -211,8 +214,13 @@ void TestJsonDbNotification::notificationSlot2(QJSValue result, Actions action,
data.result = result.toVariant().toMap();
data.action = action;
data.stateNumber = stateNumber;
- cbData.append(data);
- mEventLoop2.quit();
+ callbackData.append(data);
+ eventLoop1.quit();
+}
+
+void TestJsonDbNotification::statusChangedSlot2()
+{
+ eventLoop1.quit();
}
void TestJsonDbNotification::singleObjectNotifications()
@@ -227,31 +235,35 @@ void TestJsonDbNotification::singleObjectNotifications()
actionsList.append(2);
actionsList.append(4);
notification->qmlElement->setProperty("actions", actionsList);
+ waitForReadyStatus(notification->qmlElement);
CallbackData data;
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ int id = create(item, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 1);
QCOMPARE(data.result.value("alphabet"), item.value("alphabet"));
QString uuid = data.result.value("_uuid").toString();
//update the object
QString newAlphabet = data.result.value("alphabet").toString()+QString("**");
data.result.insert("alphabet", newAlphabet);
- mClient->update(data.result, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ id = update(data.result, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 2);
QCOMPARE(data.result.value("alphabet").toString(), newAlphabet);
//Remove the object
- mClient->remove(data.result, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ id = remove(data.result, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 4);
QCOMPARE(data.result.value("_uuid").toString(), uuid);
deleteComponent(notification);
@@ -269,62 +281,72 @@ void TestJsonDbNotification::multipleObjectNotifications()
actionsList.append(2);
actionsList.append(4);
notification->qmlElement->setProperty("actions", actionsList);
+ waitForReadyStatus(notification->qmlElement);
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items), "com.nokia.shared");
+ int id = create(items, "com.nokia.shared");
for (int i = 0; i<10; i++) {
- waitForCallback2();
- if (cbData.size() >= 10)
+ waitForCallback1();
+ if (callbackData.size() >= 10)
break;
}
- QCOMPARE(cbData.size(), 10);
+ if (id != lastRequestId)
+ waitForResponse1(id);
+
+ QCOMPARE(callbackData.size(), 10);
QVariantList objList;
for (int i = 0; i<10; i++) {
- QCOMPARE(cbData[i].action, 1);
+ QCOMPARE(callbackData[i].action, 1);
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].result;
+ QVariantMap obj = callbackData[i].result;
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
- QString newAlphabet = cbData[i].result.value("alphabet").toString()+QString("**");
+ QString newAlphabet = callbackData[i].result.value("alphabet").toString()+QString("**");
obj.insert("alphabet", newAlphabet);
objList.append(obj);
}
- cbData.clear();
+ callbackData.clear();
//update the object
- mClient->update(QVariant(objList), "com.nokia.shared");
+ id = update(objList, "com.nokia.shared");
for (int i = 0; i<10; i++) {
- waitForCallback2();
- if (cbData.size() >= 10)
+ waitForCallback1();
+ if (callbackData.size() >= 10)
break;
}
- QCOMPARE(cbData.size(), 10);
+ if (id != lastRequestId)
+ waitForResponse1(id);
+
+ QCOMPARE(callbackData.size(), 10);
QVariantList lst = objList;
objList.clear();
for (int i = 0; i<10; i++) {
- QCOMPARE(cbData[i].action, 2);
+ QCOMPARE(callbackData[i].action, 2);
QVariantMap item = lst[i].toMap();
- QVariantMap obj = cbData[i].result;
+ QVariantMap obj = callbackData[i].result;
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
objList.append(obj);
}
- cbData.clear();
+ callbackData.clear();
//Remove the object
- mClient->remove(objList, "com.nokia.shared");
+ id = remove(objList, "com.nokia.shared");
for (int i = 0; i<10; i++) {
- waitForCallback2();
- if (cbData.size() >= 10)
+ waitForCallback1();
+ if (callbackData.size() >= 10)
break;
}
- QCOMPARE(cbData.size(), 10);
+ if (id != lastRequestId)
+ waitForResponse1(id);
+
+ QCOMPARE(callbackData.size(), 10);
for (int i = 0; i<10; i++) {
- QCOMPARE(cbData[i].action, 4);
+ QCOMPARE(callbackData[i].action, 4);
QVariantMap item = objList[i].toMap();
- QVariantMap obj = cbData[i].result;
+ QVariantMap obj = callbackData[i].result;
QCOMPARE(obj.value("_uuid"), item.value("_uuid"));
}
- cbData.clear();
+ callbackData.clear();
deleteComponent(notification);
}
@@ -341,15 +363,21 @@ void TestJsonDbNotification::createNotification()
QPointer<QObject> notification = expr->evaluate().value<QObject*>();
QVERIFY(!notification.isNull());
notification->setParent(partition->qmlElement);
- QObject::connect(notification, SIGNAL(notification(QJSValue, Actions, int)),
- this, SLOT(notificationSlot2(QJSValue, Actions, int)));
+ QObject::connect(notification, SIGNAL(notification(QJSValue,Actions,int)),
+ this, SLOT(notificationSlot2(QJSValue,Actions,int)));
+ QObject::connect(notification, SIGNAL(statusChanged(JsonDbNotify::Status)),
+ this, SLOT(statusChangedSlot2()));
+ waitForReadyStatus(notification);
+
+
CallbackData data;
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
- data = cbData.takeAt(0);
+ int id = create(item, "com.nokia.shared");
+ waitForCallbackNId(id);
+
+ QCOMPARE(callbackData.size(), 1);
+ data = callbackData.takeAt(0);
QCOMPARE(data.action, 1);
QCOMPARE(data.result.value("alphabet"), item.value("alphabet"));
diff --git a/tests/auto/jsondbnotification/testjsondbnotification.h b/tests/auto/jsondbnotification/testjsondbnotification.h
index 9b728a6..158eba5 100644
--- a/tests/auto/jsondbnotification/testjsondbnotification.h
+++ b/tests/auto/jsondbnotification/testjsondbnotification.h
@@ -41,23 +41,9 @@
#ifndef TESTJSONDBNOTIFICATION_H
#define TESTJSONDBNOTIFICATION_H
-#include <QCoreApplication>
-#include <QList>
-#include <QTest>
-#include <QFile>
-#include <QProcess>
-#include <QEventLoop>
-#include <QDebug>
-#include <QLocalSocket>
-#include <QTimer>
-#include <QJSValue>
-
-#include <jsondb-client.h>
-#include <jsondb-error.h>
-
#include <QAbstractItemModel>
-#include "clientwrapper.h"
-#include "../../shared/qmltestutil.h"
+#include "requestwrapper.h"
+#include "qmltestutil.h"
QT_USE_NAMESPACE_JSONDB
@@ -67,7 +53,7 @@ struct CallbackData {
QVariantMap result;
};
-class TestJsonDbNotification: public ClientWrapper
+class TestJsonDbNotification: public RequestWrapper
{
Q_OBJECT
public:
@@ -91,8 +77,9 @@ public slots:
void notificationSlot(QVariant result, int action, int stateNumber);
void errorSlot(int code, const QString &message);
void notificationSlot2(QJSValue result, Actions action, int stateNumber);
+ void statusChangedSlot2();
-protected slots:
+public:
void timeout();
private:
@@ -105,12 +92,10 @@ private:
QStringList mNotificationsReceived;
QList<ComponentData*> mComponents;
QString mPluginPath;
+
+ // Response values
bool mTimedOut;
- bool callbackError;
- int callbackErrorCode;
- QString callbackErrorMessage;
- QList<CallbackData> cbData;
- QEventLoop mEventLoop2;
+ QList<CallbackData> callbackData;
};
#endif