summaryrefslogtreecommitdiffstats
path: root/tests/auto/jsondbqueryobject
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/jsondbqueryobject')
-rw-r--r--tests/auto/jsondbqueryobject/jsondbqueryobject.pro11
-rw-r--r--tests/auto/jsondbqueryobject/partitions.json3
-rw-r--r--tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp101
-rw-r--r--tests/auto/jsondbqueryobject/testjsondbqueryobject.h31
4 files changed, 66 insertions, 80 deletions
diff --git a/tests/auto/jsondbqueryobject/jsondbqueryobject.pro b/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
index 62157bb..717acef 100644
--- a/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
+++ b/tests/auto/jsondbqueryobject/jsondbqueryobject.pro
@@ -1,17 +1,20 @@
TEMPLATE = app
TARGET = tst_jsondbqueryobject
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 += testjsondbqueryobject.h
+HEADERS += testjsondbqueryobject.h \
+ $$PWD/../../shared/requestwrapper.h
SOURCES += testjsondbqueryobject.cpp
+
+OTHER_FILES += \
+ partitions.json
diff --git a/tests/auto/jsondbqueryobject/partitions.json b/tests/auto/jsondbqueryobject/partitions.json
new file mode 100644
index 0000000..c77651a
--- /dev/null
+++ b/tests/auto/jsondbqueryobject/partitions.json
@@ -0,0 +1,3 @@
+[
+ { "name" :"com.nokia.shared" }
+]
diff --git a/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp b/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
index 8205a18..2a214db 100644
--- a/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
+++ b/tests/auto/jsondbqueryobject/testjsondbqueryobject.cpp
@@ -41,10 +41,9 @@
#include <QtTest/QtTest>
#include <QJSEngine>
+#include <QJSValueIterator>
#include "testjsondbqueryobject.h"
#include "../../shared/util.h"
-#include <QJSValueIterator>
-#include "json.h"
static const char dbfile[] = "dbFile-jsondb-partition";
@@ -86,8 +85,9 @@ TestJsonDbQueryObject::~TestJsonDbQueryObject()
void TestJsonDbQueryObject::timeout()
{
- ClientWrapper::timeout();
+ RequestWrapper::timeout();
mTimedOut = true;
+ eventLoop1.quit();
}
void TestJsonDbQueryObject::deleteDbFiles()
@@ -110,25 +110,14 @@ void TestJsonDbQueryObject::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);
-
+ if (mPluginPath.isEmpty())
+ qDebug() << "Couldn't find the plugin path for the plugin QtJsonDb";
}
ComponentData *TestJsonDbQueryObject::createComponent(const QString &qml)
@@ -201,14 +190,14 @@ void TestJsonDbQueryObject::errorSlot(const QVariantMap &newError)
callbackError = true;
callbackErrorCode = code;
callbackErrorMessage = message;
- mEventLoop2.quit();
+ eventLoop1.quit();
}
void TestJsonDbQueryObject::finishedSlot()
{
QMetaObject::invokeMethod(currentQmlElement, "takeResults", Qt::DirectConnection,
- Q_RETURN_ARG(QVariantList, cbData));
- mEventLoop2.quit();
+ Q_RETURN_ARG(QVariantList, callbackData));
+ eventLoop1.quit();
}
bool posLessThan(const QVariant &v1, const QVariant &v2)
@@ -230,13 +219,14 @@ void TestJsonDbQueryObject::singleObject()
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
+ create(item, "com.nokia.shared");
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
+ callbackData.clear();
+ waitForCallback1();
+ QCOMPARE(callbackData.size(), 1);
QCOMPARE(callbackError, false);
delete expr;
deleteComponent(queryObject);
@@ -252,7 +242,8 @@ void TestJsonDbQueryObject::multipleObjects()
index.insert("_type", "Index");
index.insert("propertyName", "pos");
index.insert("propertyType", "number");
- mClient->create(index, "com.nokia.shared");
+ int id = create(index, "com.nokia.shared");
+ waitForResponse1(id);
const QString queryString = QString("[?_type = \""+QString( __FUNCTION__ )+"\"][/pos]");
queryObject->qmlElement->setProperty("query", queryString);
@@ -260,18 +251,19 @@ void TestJsonDbQueryObject::multipleObjects()
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 10);
+ QCOMPARE(callbackData.size(), 10);
for (int i = 0; i<10; i++) {
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].toMap();
+ QVariantMap obj = callbackData[i].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
}
@@ -299,11 +291,13 @@ void TestJsonDbQueryObject::createQuery()
this, SLOT(errorSlot(QVariantMap)));
//Create an object
QVariantMap item = createObject(__FUNCTION__).toMap();
- mClient->create(item, "com.nokia.shared");
+ int id = create(item, "com.nokia.shared");
+ waitForResponse1(id);
+
QMetaObject::invokeMethod(currentQmlElement, "start", Qt::DirectConnection);
- cbData.clear();
- waitForCallback2();
- QCOMPARE(cbData.size(), 1);
+ callbackData.clear();
+ waitForCallback1();
+ QCOMPARE(callbackData.size(), 1);
QCOMPARE(callbackError, false);
delete expr;
deleteComponent(partition);
@@ -319,7 +313,8 @@ void TestJsonDbQueryObject::queryWithoutPartition()
index.insert("_type", "Index");
index.insert("propertyName", "pos");
index.insert("propertyType", "number");
- mClient->create(index);
+ int id = create(index);
+ waitForResponse1(id);
const QString queryString = QString("[?_type = \""+QString( __FUNCTION__ )+"\"][/pos]");
queryObject->qmlElement->setProperty("query", queryString);
@@ -327,18 +322,19 @@ void TestJsonDbQueryObject::queryWithoutPartition()
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items));
+ create(items);
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 10);
+ QCOMPARE(callbackData.size(), 10);
for (int i = 0; i<10; i++) {
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].toMap();
+ QVariantMap obj = callbackData[i].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
}
@@ -361,19 +357,20 @@ void TestJsonDbQueryObject::queryBinding()
queryObject->qmlElement->setProperty("bindings", bindingMap);
currentQmlElement = queryObject->qmlElement;
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 1);
+ QCOMPARE(callbackData.size(), 1);
QVariantMap item = items[0].toMap();
- QVariantMap obj = cbData[0].toMap();
+ QVariantMap obj = callbackData[0].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
delete expr;
deleteComponent(queryObject);
@@ -394,13 +391,14 @@ void TestJsonDbQueryObject::queryError()
queryObject->qmlElement->setProperty("bindings", bindingMap);
currentQmlElement = queryObject->qmlElement;
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, true);
delete expr;
@@ -417,7 +415,8 @@ void TestJsonDbQueryObject::queryLimit()
index.insert("_type", "Index");
index.insert("propertyName", "pos");
index.insert("propertyType", "number");
- mClient->create(index, "com.nokia.shared");
+ int id = create(index, "com.nokia.shared");
+ waitForResponse1(id);
const QString queryString = QString("[?_type = \""+QString( __FUNCTION__ )+"\"][/pos]");
queryObject->qmlElement->setProperty("query", queryString);
@@ -426,18 +425,19 @@ void TestJsonDbQueryObject::queryLimit()
//Create objects
QVariantList items = createObjectList(__FUNCTION__, 10).toList();
- mClient->create(QVariant(items), "com.nokia.shared");
+ create(items, "com.nokia.shared");
qSort(items.begin(), items.end(), posLessThan);
const QString expression("start();");
QQmlExpression *expr;
expr = new QQmlExpression(queryObject->engine->rootContext(), queryObject->qmlElement, expression);
expr->evaluate();
- waitForCallback2();
+ callbackData.clear();
+ waitForCallback1();
QCOMPARE(callbackError, false);
- QCOMPARE(cbData.size(), 5);
+ QCOMPARE(callbackData.size(), 5);
for (int i = 0; i<5; i++) {
QVariantMap item = items[i].toMap();
- QVariantMap obj = cbData[i].toMap();
+ QVariantMap obj = callbackData[i].toMap();
QCOMPARE(obj.value("alphabet"), item.value("alphabet"));
}
@@ -445,6 +445,5 @@ void TestJsonDbQueryObject::queryLimit()
deleteComponent(queryObject);
}
-
QTEST_MAIN(TestJsonDbQueryObject)
diff --git a/tests/auto/jsondbqueryobject/testjsondbqueryobject.h b/tests/auto/jsondbqueryobject/testjsondbqueryobject.h
index c79745a..4c2645f 100644
--- a/tests/auto/jsondbqueryobject/testjsondbqueryobject.h
+++ b/tests/auto/jsondbqueryobject/testjsondbqueryobject.h
@@ -41,27 +41,13 @@
#ifndef TESTJSONDBQUERYOBJECT_H
#define TESTJSONDBQUERYOBJECT_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
-class TestJsonDbQueryObject: public ClientWrapper
+class TestJsonDbQueryObject: public RequestWrapper
{
Q_OBJECT
public:
@@ -85,7 +71,7 @@ public slots:
void errorSlot(const QVariantMap &newError);
void finishedSlot();
-protected slots:
+public:
void timeout();
private:
@@ -95,17 +81,12 @@ private:
private:
QProcess *mProcess;
- QStringList mNotificationsReceived;
QList<ComponentData*> mComponents;
QString mPluginPath;
+
bool mTimedOut;
- bool callbackError;
- int callbackErrorCode;
- QString callbackErrorMessage;
- QVariantList cbData;
- QEventLoop mEventLoop2;
QObject *currentQmlElement;
-
+ QVariantList callbackData;
};
#endif