diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2012-05-08 09:00:58 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-11 18:26:00 +0200 |
commit | e96eafb2d095553e4cccd2927c0a462d8b8b8d59 (patch) | |
tree | be1a41ef7bcb979d7051ed2c76e1910a49a6cdd0 /tests | |
parent | c29da8f42556856cb7dc8538fc505b9426e0f69e (diff) |
Removed old deprecated c++ api.
This also removed old-style qml api that was using the old c++ api internally.
Change-Id: Iee809bfacb4efeb31e625156420542247354dff7
Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 1 | ||||
-rw-r--r-- | tests/auto/jsondb-listmodel/jsondb-listmodel.pro | 26 | ||||
-rw-r--r-- | tests/auto/jsondb-listmodel/partitions.json | 3 | ||||
-rw-r--r-- | tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp | 783 | ||||
-rw-r--r-- | tests/auto/jsondb-listmodel/test-jsondb-listmodel.h | 131 | ||||
-rw-r--r-- | tests/json.qrc | 2 | ||||
-rw-r--r-- | tests/shared/clientwrapper.cpp | 42 | ||||
-rw-r--r-- | tests/shared/clientwrapper.h | 229 | ||||
-rw-r--r-- | tests/shared/json/list-objects.json (renamed from tests/auto/jsondb-listmodel/list-objects.json) | 0 | ||||
-rw-r--r-- | tests/shared/shared.pri | 9 |
10 files changed, 3 insertions, 1223 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9833156f..0fb74f3a 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -5,7 +5,6 @@ SUBDIRS = \ partition \ accesscontrol \ qbtree \ - jsondb-listmodel \ jsondblistmodel \ jsondbsortinglistmodel \ jsondbcachinglistmodel \ diff --git a/tests/auto/jsondb-listmodel/jsondb-listmodel.pro b/tests/auto/jsondb-listmodel/jsondb-listmodel.pro deleted file mode 100644 index 364c654c..00000000 --- a/tests/auto/jsondb-listmodel/jsondb-listmodel.pro +++ /dev/null @@ -1,26 +0,0 @@ -TARGET = tst_jsondb-listmodel - -QT = core network testlib gui qml jsondbcompat-private -CONFIG -= app_bundle -CONFIG += testcase - -include($$PWD/../../shared/shared.pri) - -DEFINES += JSONDB_DAEMON_BASE=\\\"$$QT.jsondb.bins\\\" -DEFINES += SRCDIR=\\\"$$PWD/\\\" - -INCLUDEPATH += $$PWD/../../../src/imports/jsondb-listmodel -HEADERS += $$PWD/../../../src/imports/jsondb-listmodel/jsondb-listmodel.h -SOURCES += $$PWD/../../../src/imports/jsondb-listmodel/jsondb-listmodel.cpp - -HEADERS += test-jsondb-listmodel.h -SOURCES += test-jsondb-listmodel.cpp - -OTHER_FILES += \ - partitions.json - -data.files = $$OTHER_FILES -data.path = $$[QT_INSTALL_TESTS]/$$TARGET -INSTALLS += data - -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/jsondb-listmodel/partitions.json b/tests/auto/jsondb-listmodel/partitions.json deleted file mode 100644 index f8a7c87e..00000000 --- a/tests/auto/jsondb-listmodel/partitions.json +++ /dev/null @@ -1,3 +0,0 @@ -[ - { "name" :"com.qt-project.shared", "path":".", "default" : true } -] diff --git a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp deleted file mode 100644 index adc8396d..00000000 --- a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.cpp +++ /dev/null @@ -1,783 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QJSEngine> -#include "test-jsondb-listmodel.h" - -#include "../../shared/util.h" -#include <QQmlEngine> -#include <QQmlComponent> -#include <QQmlContext> -#include <QDir> - -ModelData::ModelData(): engine(0), component(0), model(0) -{ -} - -ModelData::~ModelData() -{ - if (model) - delete model; - if (component) - delete component; - if (engine) - delete engine; -} - -TestJsonDbListModel::TestJsonDbListModel() - : mWaitingForNotification(false), mWaitingForDataChange(false), mWaitingForRowsRemoved(false) -{ -} - -TestJsonDbListModel::~TestJsonDbListModel() -{ -} - -void TestJsonDbListModel::deleteDbFiles() -{ - // remove all the test files. - QDir currentDir; - QStringList nameFilter; - nameFilter << QString("*.db"); - nameFilter << "objectFile.bin" << "objectFile2.bin"; - QFileInfoList databaseFiles = currentDir.entryInfoList(nameFilter, QDir::Files); - foreach (QFileInfo fileInfo, databaseFiles) { - //qDebug() << "Deleted : " << fileInfo.fileName(); - QFile file(fileInfo.fileName()); - file.remove(); - } -} - -void TestJsonDbListModel::connectListModel(JsonDbListModel *model) -{ - connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(dataChanged(QModelIndex,QModelIndex))); - connect(model, SIGNAL(modelReset()), this, SLOT(modelReset())); - connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(rowsInserted(QModelIndex,int,int))); - connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); - connect(model, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), - this, SLOT(rowsMoved(QModelIndex,int,int,QModelIndex,int))); -} - -void TestJsonDbListModel::initTestCase() -{ - // make sure there is no old db files. - deleteDbFiles(); - - QString socketName = QString("testjsondb_%1").arg(getpid()); - mProcess = launchJsonDbDaemon(JSONDB_DAEMON_BASE, socketName, QStringList(), __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&))); - - QQmlEngine *engine = new QQmlEngine(); - QStringList pluginPaths = engine->importPathList(); - for (int i=0; (i<pluginPaths.count() && mPluginPath.isEmpty()); i++) { - QDir dir(pluginPaths[i]+"/QtAddOn/JsonDb"); - dir.setFilter(QDir::Files | QDir::NoSymLinks); - QFileInfoList list = dir.entryInfoList(); - for (int i = 0; i < list.size(); ++i) { - QList<QQmlError> errors; - if (engine->importPlugin(list.at(i).absoluteFilePath(), QString("QtAddOn.JsonDb"), &errors)) { - mPluginPath = list.at(i).absoluteFilePath(); - break; - } - } - } - delete engine; - -} - -JsonDbListModel *TestJsonDbListModel::createModel() -{ - ModelData *newModel = new ModelData(); - newModel->engine = new QQmlEngine(); - QList<QQmlError> errors; - if (!newModel->engine->importPlugin(mPluginPath, QString("QtAddOn.JsonDb"), &errors)) { - qDebug()<<"Unable to load the plugin :"<<errors; - delete newModel->engine; - return 0; - } - newModel->component = new QQmlComponent(newModel->engine); - newModel->component->setData("import QtQuick 2.0\nimport QtAddOn.JsonDb 1.0 \n JsonDbListModel {id: contactsModel}", QUrl()); - newModel->model = newModel->component->create(); - if (newModel->component->isError()) - qDebug() << newModel->component->errors(); - mModels.append(newModel); - return (JsonDbListModel*)(newModel->model); -} - -void TestJsonDbListModel::deleteModel(JsonDbListModel *model) -{ - for (int i = 0; i < mModels.count(); i++) { - if (mModels[i]->model == model) { - ModelData *modelData = mModels.takeAt(i); - delete modelData; - return; - } - } -} - -void TestJsonDbListModel::cleanupTestCase() -{ - if (mProcess) { - mProcess->kill(); - mProcess->waitForFinished(); - delete mProcess; - } - - deleteDbFiles(); -} - -void TestJsonDbListModel::waitForItemsCreated(int items) -{ - mItemsCreated = 0; - while(mItemsCreated != items) - mEventLoop.processEvents(QEventLoop::AllEvents, mClientTimeout); -} - -void TestJsonDbListModel::waitForExitOrTimeout() -{ - QTimer timer; - QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - QObject::connect(&timer, SIGNAL(timeout()), &mEventLoop, SLOT(quit())); - timer.start(mClientTimeout); - mElapsedTimer.start(); - mEventLoop.exec(QEventLoop::AllEvents); -} - -// Create items in the model. -void TestJsonDbListModel::createItem() -{ - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - int id = mClient->create(item); - - waitForResponse1(id); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - listModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); - - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name"); - listModel->setScriptableRoleNames(roleNames); - connectListModel(listModel); - - // now start it working - listModel->componentComplete(); - QCOMPARE(listModel->count(), 0); - - waitForExitOrTimeout(); - QCOMPARE(listModel->count(), 1); - - mItemsCreated = 0; - item.insert("_type", __FUNCTION__); - item.insert("name", "Baker"); - id = mClient->create(item); - waitForResponse1(id); - if (!mItemsCreated) - waitForExitOrTimeout();; - QCOMPARE(listModel->count(), 2); - deleteModel(listModel); -} - -// Create an item and then update it. -void TestJsonDbListModel::updateItemClient() -{ - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - int id = mClient->create(item); - waitForResponse1(id); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - listModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name"); - listModel->setScriptableRoleNames(roleNames); - connectListModel(listModel); - - // now start it working - listModel->componentComplete(); - QCOMPARE(listModel->rowCount(), 0); - - waitForExitOrTimeout(); - QCOMPARE(listModel->rowCount(), 1); - - item.insert("_uuid", mLastUuid); - item.insert("_version", mLastVersion); - item.insert("name", "Baker"); - - mWaitingForDataChange = true; - - id = mClient->update(item); - waitForResponse1(id); - - while (mWaitingForDataChange) - mEventLoop.processEvents(QEventLoop::AllEvents); - - QCOMPARE(listModel->count(), 1); - QCOMPARE(listModel->get(0, "_uuid").toString(), mLastUuid); - QCOMPARE(listModel->get(0, "_type").toString(), QLatin1String(__FUNCTION__)); - QCOMPARE(listModel->get(0, "name").toString(), QLatin1String("Baker")); - deleteModel(listModel); -} - -// Create an item and then update it. -void TestJsonDbListModel::updateItemSet() -{ - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - item.insert("phone", "123456789"); - int id = mClient->create(item); - waitForResponse1(id); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - listModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name" << "phone"); - listModel->setScriptableRoleNames(roleNames); - connectListModel(listModel); - - // now start it working - listModel->componentComplete(); - QCOMPARE(listModel->rowCount(), 0); - - waitForExitOrTimeout(); - QCOMPARE(listModel->rowCount(), 1); - - QJSEngine engine; - QJSValue value = engine.newObject(); - - value.setProperty("name", "Baker"); - value.setProperty("phone", "987654321"); - - mWaitingForDataChange = true; - - listModel->set(0,value); - - while (mWaitingForDataChange) - mEventLoop.processEvents(QEventLoop::AllEvents); - - QCOMPARE(listModel->count(), 1); - QCOMPARE(listModel->get(0, "_type").toString(), QLatin1String(__FUNCTION__)); - QCOMPARE(listModel->get(0, "name").toString(), QLatin1String("Baker")); - QCOMPARE(listModel->get(0, "phone").toString(), QLatin1String("987654321")); - deleteModel(listModel); -} - -void TestJsonDbListModel::updateItemSetProperty() -{ - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - item.insert("phone", "123456789"); - int id = mClient->create(item); - waitForResponse1(id); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - listModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name" << "phone"); - listModel->setScriptableRoleNames(roleNames); - connectListModel(listModel); - - // now start it working - listModel->componentComplete(); - QCOMPARE(listModel->rowCount(), 0); - - waitForExitOrTimeout(); - QCOMPARE(listModel->rowCount(), 1); - - mWaitingForDataChange = true; - - listModel->setProperty(0,"phone","987654321"); - - while (mWaitingForDataChange) - mEventLoop.processEvents(QEventLoop::AllEvents); - - QCOMPARE(listModel->count(), 1); - QCOMPARE(listModel->get(0, "_type").toString(), QLatin1String(__FUNCTION__)); - QCOMPARE(listModel->get(0, "name").toString(), QLatin1String("Charlie")); - QCOMPARE(listModel->get(0, "phone").toString(), QLatin1String("987654321")); - deleteModel(listModel); -} - -void TestJsonDbListModel::deleteItem() -{ - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - int id = mClient->create(item); - waitForResponse1(id); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - listModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name"); - listModel->setScriptableRoleNames(roleNames); - connectListModel(listModel); - - // now start it working - listModel->componentComplete(); - waitForExitOrTimeout(); - QCOMPARE(listModel->rowCount(), 1); - - mItemsCreated = 0; - item.insert("name", "Baker"); - id = mClient->create(item); - waitForResponse1(id); - if (!mItemsCreated) - waitForExitOrTimeout();; - QCOMPARE(listModel->rowCount(), 2); - - mWaitingForRowsRemoved = true; - item.insert("_uuid", mLastUuid); - item.insert("_version", mLastVersion); - id = mClient->remove(item); - waitForResponse1(id); - while(mWaitingForRowsRemoved) - mEventLoop.processEvents(QEventLoop::AllEvents); - - QCOMPARE(listModel->rowCount(), 1); - QCOMPARE(listModel->get(0, "_type").toString(), QLatin1String(__FUNCTION__)); - QCOMPARE(listModel->get(0, "name").toString(), QLatin1String("Charlie")); - deleteModel(listModel); -} - -void TestJsonDbListModel::sortedQuery() -{ - int id = 0; - - QVariantMap index; - index.insert("_type", "Index"); - index.insert("name", "number"); - index.insert("propertyName", "number"); - index.insert("propertyType", "number"); - id = mClient->create(index); - waitForResponse1(id); - - for (int i = 0; i < 1000; i++) { - QVariantMap item; - item.insert("_type", "RandNumber"); - item.insert("number", i); - id = mClient->create(item); - waitForResponse1(id); - } - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - - connectListModel(listModel); - - QStringList rolenames; - rolenames << "_uuid" << "_type" << "number"; - listModel->setScriptableRoleNames(rolenames); - - listModel->setQuery("[?_type=\"RandNumber\"][/number]"); - - waitForExitOrTimeout(); - QCOMPARE(listModel->count(), 1000); - for (int i = 0; i < 1000; i++) - QCOMPARE(listModel->get(i,"number").toInt(), i); - - listModel->setQuery("[?_type=\"RandNumber\"][\\number]"); - waitForExitOrTimeout(); - for (int i = 0; i < 1000; i++) - QCOMPARE(listModel->get(i,"number").toInt(), 999-i); - - QCoreApplication::instance()->processEvents(); - deleteModel(listModel); -} - -void TestJsonDbListModel::ordering() -{ - for (int i = 9; i >= 1; --i) { - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - item.insert("order", QString::number(i)); - int id = mClient->create(item); - waitForResponse1(id); - } - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - listModel->setQuery(QString("[?_type=\"%1\"][/order]").arg(__FUNCTION__)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "_version" << "name" << "order"); - listModel->setScriptableRoleNames(roleNames); - connectListModel(listModel); - - // now start it working - listModel->componentComplete(); - QCOMPARE(listModel->rowCount(), 0); - - waitForExitOrTimeout(); - - QStringList expectedOrder = QStringList() << "1" << "2" << "3" << "4" << - "5" << "6" << "7" << "8" << "9"; - QCOMPARE(getOrderValues(listModel), expectedOrder); - mWaitingForDataChange = true; - { - QVariant uuid = listModel->get(4, "_uuid"); - QVERIFY(!uuid.toString().isEmpty()); - QVariant version = listModel->get(4, "_version"); - QVERIFY(!version.toString().isEmpty()); - - QVariantMap item; - item.insert("_uuid", uuid); - item.insert("_version", version); - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - item.insert("order", "99"); // move it to the end - int id = mClient->update(item); - waitForResponse1(id); - } - - while (mWaitingForDataChange) - mEventLoop.processEvents(QEventLoop::AllEvents); - - expectedOrder = QStringList() << "1" << "2" << "3" << - "4" << "6" << "7" << "8" << "9" << "99"; - QCOMPARE(getOrderValues(listModel), expectedOrder); - mWaitingForDataChange = true; - { - QVariant uuid = listModel->get(8, "_uuid"); - QVERIFY(!uuid.toString().isEmpty()); - QVariant version = listModel->get(8, "_version"); - QVERIFY(!version.toString().isEmpty()); - - QVariantMap item; - item.insert("_uuid", uuid); - item.insert("_version", version); - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - item.insert("order", "22"); // move it after "2" - int id = mClient->update(item); - waitForResponse1(id); - } - - while (mWaitingForDataChange) - mEventLoop.processEvents(QEventLoop::AllEvents); - - expectedOrder = QStringList() << "1" << "2" << "22" << "3" << - "4" << "6" << "7" << "8" << "9"; - QCOMPARE(getOrderValues(listModel), expectedOrder); - mWaitingForDataChange = true; - { - QVariant uuid = listModel->get(5, "_uuid"); - QVERIFY(!uuid.toString().isEmpty()); - QVariant version = listModel->get(5, "_version"); - QVERIFY(!version.toString().isEmpty()); - - QVariantMap item; - item.insert("_uuid", uuid); - item.insert("_version", version); - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - item.insert("order", "0"); // move it to the beginning - int id = mClient->update(item); - waitForResponse1(id); - } - - while (mWaitingForDataChange) - mEventLoop.processEvents(QEventLoop::AllEvents); - - expectedOrder = QStringList() << "0" << "1" << "2" << "22" << "3" << - "4" << "7" << "8" << "9"; - QCOMPARE(getOrderValues(listModel), expectedOrder); - deleteModel(listModel); - -} - -void TestJsonDbListModel::itemNotInCache() -{ - QVariantMap index; - index.insert("_type", "Index"); - index.insert("name", "order"); - index.insert("propertyName", "order"); - index.insert("propertyType", "number"); - int indexId = mClient->create(index); - waitForResponse1(indexId); - - QVariantList itemList; - for (int i = 0; i < 1000; i++) { - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Number"); - item.insert("order", i); - itemList << item; - } - int id = mClient->create(itemList); - waitForResponse1(id); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - connectListModel(listModel); - listModel->setLimit(80); - listModel->setQuery(QString("[?_type=\"%1\"][/order]").arg(__FUNCTION__)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name" << "order"); - listModel->setScriptableRoleNames(roleNames); - listModel->componentComplete(); - waitForExitOrTimeout(); - - QCOMPARE(listModel->rowCount(), 1000); - - // Make sure that the first items in the list is in the cache. - QVariant result = listModel->data(listModel->index(10,0), listModel->roleFromString("order")); - QVERIFY(result.isValid()); - QCOMPARE(result.toInt(), 10); - // This item should not be in the cache now. - QVariant res = listModel->data(listModel->index(960,0), listModel->roleFromString("order")); - QCOMPARE(res.toInt(), 960); - deleteModel(listModel); -} - -void TestJsonDbListModel::roles() -{ - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("name", "Charlie"); - item.insert("phone", "123456789"); - int id = mClient->create(item); - - waitForResponse1(id); - - JsonDbListModel *listModel = createModel(); - if (!listModel) return; - listModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); - - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "name" << "phone"); - listModel->setScriptableRoleNames(roleNames); - connectListModel(listModel); - - // now start it working - listModel->componentComplete(); - waitForExitOrTimeout(); - QCOMPARE(listModel->count(), 1); - - QVariantMap roles = listModel->scriptableRoleNames().toMap(); - QCOMPARE(roles.size(), 4); - QVERIFY(roles.contains("name")) ; - QVERIFY(roles.contains("phone")); - QCOMPARE(listModel->roleFromString("_type"), 0); - QCOMPARE(listModel->roleFromString("_uuid"), 1); - QCOMPARE(listModel->roleFromString("name"), 2); - QCOMPARE(listModel->roleFromString("phone"), 3); - QCOMPARE(listModel->toString(0), QLatin1String("_type")); - QCOMPARE(listModel->toString(1), QLatin1String("_uuid")); - QCOMPARE(listModel->toString(2), QLatin1String("name")); - QCOMPARE(listModel->toString(3), QLatin1String("phone")); - QCOMPARE(listModel->toString(4), QLatin1String("")); - deleteModel(listModel); -} - -void TestJsonDbListModel::totalRowCount() -{ - int id = 0; - QVariantList insertedItems; - for (int i = 0; i < 10; i++) { - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("order", i); - id = mClient->create(item); - waitForResponse1(id); - insertedItems << mData; - } - - JsonDbListModel *listModel = createModel(); - if (!listModel) - return; - connectListModel(listModel); - - listModel->setLimit(10); - listModel->setQuery(QString("[?_type=\"%1\"]").arg(__FUNCTION__)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "order"); - listModel->setScriptableRoleNames(roleNames); - listModel->componentComplete(); - waitForExitOrTimeout(); - - QCOMPARE(listModel->rowCount(), 10); - - for (int i = 10; i < 50; i++) { - QVariantMap item; - item.insert("_type", __FUNCTION__); - item.insert("order", i); - mClient->create(item); - } - - waitForItemsCreated(40); - QCOMPARE(listModel->rowCount(), 50); - - // Change query - listModel->setQuery(QString("[?_type=\"%1\"][\\order]").arg(__FUNCTION__)); - waitForExitOrTimeout(); - - QCOMPARE(listModel->rowCount(), 50); - - // Delete the first 10 items - foreach (QVariant item, insertedItems) { - mWaitingForRowsRemoved = true; - id = mClient->remove(item.toMap()); - while(mWaitingForRowsRemoved) - mEventLoop.processEvents(QEventLoop::AllEvents); - } - - QCOMPARE(listModel->rowCount(), 40); - - deleteModel(listModel); -} - -void TestJsonDbListModel::listProperty() -{ - QVariant jsonData = readJsonFile(findFile("list-objects.json")).toVariant(); - QVariantList itemList = jsonData.toList(); - int id = 0; - for (int i = 0; i < itemList.count(); i++) { - id = mClient->create(itemList[i].toMap()); - waitForResponse1(id); - } - - JsonDbListModel *listModel = createModel(); - if (!listModel) - return; - connectListModel(listModel); - QString type = itemList[0].toMap()["_type"].toString(); - listModel->setLimit(10); - listModel->setQuery(QString("[?_type=\"%1\"][/features.0.properties.0.description]").arg(type)); - QStringList roleNames = (QStringList() << "_type" << "_uuid" << "features.0.properties.0.description"<< "features.0.feature"); - listModel->setScriptableRoleNames(roleNames); - listModel->componentComplete(); - waitForExitOrTimeout(); - - QCOMPARE(listModel->count(), itemList.count()); - QCOMPARE(listModel->get(0, "_type").toString(), type); - QCOMPARE(listModel->get(0, "features.0.properties.0.description").toString(), QLatin1String("Facebook account provider")); - QCOMPARE(listModel->get(0, "features.0.feature").toString(), QLatin1String("provide Facebook")); - QCOMPARE(listModel->get(1, "_uuid").toString(), mLastUuid); - QCOMPARE(listModel->get(1, "_type").toString(), type); - QCOMPARE(listModel->get(1, "features.0.properties.0.description").toString(), QLatin1String("Gmail account provider")); - QCOMPARE(listModel->get(1, "features.0.feature").toString(), QLatin1String("provide Gmail")); - - deleteModel(listModel); - - listModel = createModel(); - if (!listModel) - return; - connectListModel(listModel); - type = itemList[0].toMap()["_type"].toString(); - listModel->setLimit(10); - listModel->setQuery(QString("[?_type=\"%1\"][/features.0.properties.0.description]").arg(type)); - roleNames.clear(); - roleNames = (QStringList() << "_type" << "_uuid" << "features[0].properties[0].description"<< "features[0].supported[0]"); - listModel->setScriptableRoleNames(roleNames); - listModel->componentComplete(); - waitForExitOrTimeout(); - - QCOMPARE(listModel->count(), itemList.count()); - QCOMPARE(listModel->get(0, "_type").toString(), type); - QCOMPARE(listModel->get(0, "features[0].properties[0].description").toString(), QLatin1String("Facebook account provider")); - QCOMPARE(listModel->get(0, "features[0].supported[0]").toString(), QLatin1String("share")); - QCOMPARE(listModel->get(1, "_type").toString(), type); - QCOMPARE(listModel->get(1, "features[0].properties[0].description").toString(), QLatin1String("Gmail account provider")); - QCOMPARE(listModel->get(1, "features[0].supported[0]").toString(), QLatin1String("share")); - - deleteModel(listModel); -} - - -QStringList TestJsonDbListModel::getOrderValues(const JsonDbListModel *listModel) -{ - QStringList vals; - for (int i = 0; i < listModel->count(); ++i) - vals << listModel->get(i, "order").toString(); - - return vals; -} - -void TestJsonDbListModel::modelReset() -{ - //qDebug() << "TestJsonDbListModel::modelReset"; - mEventLoop.exit(0); -} -void TestJsonDbListModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) -{ - Q_UNUSED(topLeft); - Q_UNUSED(bottomRight); - //qDebug() << "TestJsonDbListModel::dataChanged"; - mWaitingForDataChange = false; -} -void TestJsonDbListModel::rowsInserted(const QModelIndex &parent, int first, int last) -{ - Q_UNUSED(parent); - Q_UNUSED(first); - Q_UNUSED(last); - mItemsCreated++; - //qDebug() << "TestJsonDbListModel::rowsInserted"; - mEventLoop.exit(0); -} -void TestJsonDbListModel::rowsRemoved(const QModelIndex &parent, int first, int last) -{ - Q_UNUSED(parent); - Q_UNUSED(first); - Q_UNUSED(last); - mWaitingForRowsRemoved = false; - //qDebug() << "TestJsonDbListModel::rowsRemoved"; -} -void TestJsonDbListModel::rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row ) -{ - Q_UNUSED(parent); - Q_UNUSED(start); - Q_UNUSED(end); - Q_UNUSED(destination); - Q_UNUSED(row); - //qDebug() << "TestJsonDbListModel::rowsMoved"; -} - -QTEST_MAIN(TestJsonDbListModel) - diff --git a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.h b/tests/auto/jsondb-listmodel/test-jsondb-listmodel.h deleted file mode 100644 index d9ed276b..00000000 --- a/tests/auto/jsondb-listmodel/test-jsondb-listmodel.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef TestJsonDbListModel_H -#define TestJsonDbListModel_H - -#include <QCoreApplication> -#include <QList> -#include <QTest> -#include <QFile> -#include <QProcess> -#include <QEventLoop> -#include <QDebug> -#include <QLocalSocket> -#include <QTimer> - -#include <jsondb-client.h> -#include <jsondb-error.h> - -#include "jsondb-listmodel.h" -#include "clientwrapper.h" - -QT_BEGIN_NAMESPACE -class QQmlEngine; -class QQmlComponent; -QT_END_NAMESPACE - -QT_USE_NAMESPACE_JSONDB - -class JsonDbListModel; - -class ModelData { -public: - ModelData(); - ~ModelData(); - QQmlEngine *engine; - QQmlComponent *component; - QObject *model; -}; - -class TestJsonDbListModel: public ClientWrapper -{ - Q_OBJECT -public: - TestJsonDbListModel(); - ~TestJsonDbListModel(); - - void deleteDbFiles(); - void connectListModel(JsonDbListModel *model); - -public slots: - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); - void rowsInserted(const QModelIndex &parent, int first, int last); - void rowsRemoved(const QModelIndex &parent, int first, int last); - void rowsMoved( const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row ); - void modelReset(); - -private slots: - void initTestCase(); - void cleanupTestCase(); - - void createItem(); - void updateItemClient(); - void updateItemSet(); - void updateItemSetProperty(); - void deleteItem(); - void sortedQuery(); - void ordering(); - void itemNotInCache(); - void roles(); - void totalRowCount(); - void listProperty(); - -private: - void waitForExitOrTimeout(); - void waitForItemsCreated(int items); - QStringList getOrderValues(const JsonDbListModel *listModel); - JsonDbListModel *createModel(); - void deleteModel(JsonDbListModel *model); - -private: - QProcess *mProcess; - QStringList mNotificationsReceived; - QList<ModelData*> mModels; - QString mPluginPath; - - // Response values - int mItemsCreated; - bool mWaitingForNotification; - bool mWaitingForDataChange; - bool mWaitingForRowsRemoved; -}; - -#endif diff --git a/tests/json.qrc b/tests/json.qrc index dc8a0d3a..cd52bf87 100644 --- a/tests/json.qrc +++ b/tests/json.qrc @@ -2,7 +2,7 @@ <qresource prefix="/json"> <file alias="create-test.json">auto/client/create-test.json</file> <file alias="client">auto/client/json</file> - <file alias="list-objects.json">auto/jsondb-listmodel/list-objects.json</file> + <file alias="list-objects.json">shared/json/list-objects.json</file> <file>auto/jsondblistmodel/list-objects.json</file> <file>auto/jsondbsortinglistmodel/list-objects.json</file> <file alias="dataset.json">auto/queries/dataset.json</file> diff --git a/tests/shared/clientwrapper.cpp b/tests/shared/clientwrapper.cpp deleted file mode 100644 index a23942b5..00000000 --- a/tests/shared/clientwrapper.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "clientwrapper.h" diff --git a/tests/shared/clientwrapper.h b/tests/shared/clientwrapper.h deleted file mode 100644 index 5883a8c2..00000000 --- a/tests/shared/clientwrapper.h +++ /dev/null @@ -1,229 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** 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, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CLIENTWRAPPER_H -#define CLIENTWRAPPER_H - -#include <QEventLoop> -#include <QElapsedTimer> -#include <QDebug> -#include <QJsonObject> -#include <QJsonArray> -#include <QJsonValue> -#include <QJsonDocument> - -#include "jsondb-client.h" - -QT_USE_NAMESPACE_JSONDB - -#define waitForResponse(eventloop, result, id_, code, notificationId, count) \ -{ \ - int givenid_ = (id_); \ - (result)->mNotificationId = QVariant(); \ - (result)->mNeedId = (givenid_ != -1); \ - (result)->mId = QVariant(); \ - (result)->mMessage = QString(); \ - (result)->mCode = -1; \ - (result)->mData = QVariant(); \ - (result)->mNotificationWaitCount = count; \ - (result)->mLastUuid = QString(); \ - \ - QTimer timer; \ - QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); \ - QObject::connect(&timer, SIGNAL(timeout()), &eventloop, SLOT(quit())); \ - timer.start(mClientTimeout); \ - mElapsedTimer.start(); \ - do { \ - eventloop.exec(QEventLoop::AllEvents); \ - } while ((result)->mNeedId && (result)->mId.toInt() < QVariant(givenid_).toInt()); \ - if (debug_output) { \ - qDebug() << "waitForResponse" << "expected id" << givenid_ << "got id" << (result)->mId; \ - qDebug() << "waitForResponse" << "expected code" << int(code) << "got code" << (result)->mCode; \ - qDebug() << "waitForResponse" << "expected notificationId" << notificationId << "got notificationId" << (result)->mNotificationId; \ - } \ - if ((result)->mNeedId) QVERIFY2(!(result)->mId.isNull(), "Failed to receive an answer from the db server"); \ - if ((result)->mNeedId) QCOMPARE((result)->mId, QVariant(givenid_)); \ - if ((result)->mNotificationId != QVariant(notificationId)) { \ - if ((result)->mNotificationId.isNull()) { \ - QVERIFY2(false, "we expected notification but did not get it :("); \ - } else { \ - QJsonValue value = QJsonValue::fromVariant((result)->mNotifications.last().mObject); \ - QString data = QString::fromUtf8(value.isArray() ? QJsonDocument(value.toArray()).toJson() : QJsonDocument(value.toObject()).toJson()); \ - QByteArray ba = QString("we didn't expect notification but got it. %1").arg(data).toLatin1(); \ - QVERIFY2(false, ba.constData()); \ - } \ - } \ - QCOMPARE((result)->mNotificationId, QVariant(notificationId)); \ - if ((result)->mCode != int(code)) \ - qDebug() << (result)->mMessage; \ - QCOMPARE((result)->mCode, int(code)); \ -} -#define waitForResponse1(id) waitForResponse(mEventLoop, this, id, -1, QVariant(), 0) -#define waitForResponse2(id, code) waitForResponse(mEventLoop, this, id, code, QVariant(), 0) -#define waitForResponse3(id, code, notificationId) waitForResponse(mEventLoop, this, id, code, notificationId, 0) -#define waitForResponse4(id, code, notificationId, count) waitForResponse(mEventLoop, this, id, code, notificationId, count) - -#define waitForCallbackGeneric(eventloop) \ -{ \ - QTimer timer; \ - QObject::connect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); \ - QObject::connect(&timer, SIGNAL(timeout()), &eventloop, SLOT(quit())); \ - timer.start(mClientTimeout); \ - mElapsedTimer.start(); \ - mTimedOut = false;\ - callbackError = false; \ - eventloop.exec(QEventLoop::AllEvents); \ - QCOMPARE(false, mTimedOut); \ -} - -#define waitForCallback() waitForCallbackGeneric(mEventLoop) -#define waitForCallback2() waitForCallbackGeneric(mEventLoop2) - -class JsonDbTestNotification -{ -public: - JsonDbTestNotification(const QString ¬ifyUuid, const QVariant &object, const QString &action) - : mNotifyUuid(notifyUuid), mObject(object), mAction(action) {} - - QString mNotifyUuid; - QVariant mObject; - QString mAction; -}; - -class ClientWrapper : public QObject -{ - Q_OBJECT -public: - ClientWrapper(QObject *parent = 0) - : QObject(parent), debug_output(false) - , mClient(0), mCode(0), mNeedId(false), mNotificationWaitCount(0), mClientTimeout(20000) - { - if (qgetenv("JSONDB_CLIENT_TIMEOUT").size()) - mClientTimeout = QString::fromLatin1(qgetenv("JSONDB_CLIENT_TIMEOUT")).toLong(); - } - - void connectToServer() - { - mClient = new QT_PREPEND_NAMESPACE_JSONDB(JsonDbClient)(this); - connect(mClient, SIGNAL(response(int,QVariant)), - this, SLOT(response(int,QVariant))); - connect(mClient, SIGNAL(error(int,int,QString)), - this, SLOT(error(int,int,QString))); - connect(mClient, SIGNAL(notified(QString,QtAddOn::JsonDb::JsonDbNotification)), - this, SLOT(notified(QString,QtAddOn::JsonDb::JsonDbNotification))); - } - - QString addNotification(JsonDbClient::NotifyTypes types, const QString &query, const QString &partition = QString()) { - QEventLoop ev; - QString uuid = mClient->registerNotification(types, query, partition, 0, 0, &ev, SLOT(quit())); - ev.exec(); - return uuid; - } - - bool debug_output; - - QT_PREPEND_NAMESPACE_JSONDB(JsonDbClient) *mClient; - - QEventLoop mEventLoop; - QString mMessage; - int mCode; - bool mNeedId; - QVariant mId, mData, mNotificationId; - QString mLastUuid, mLastVersion; - int mNotificationWaitCount; - QList<JsonDbTestNotification> mNotifications; - quint32 mClientTimeout; - QElapsedTimer mElapsedTimer; - -protected slots: - virtual void notified(const QString ¬ifyUuid, const QtAddOn::JsonDb::JsonDbNotification ¬ification) - { - if (debug_output) - qDebug() << "notified" << notifyUuid << notification.action() << endl << notification.object(); - mNotificationId = notifyUuid; - QString action; - switch (notification.action()) { - case QT_PREPEND_NAMESPACE_JSONDB(JsonDbClient)::NotifyCreate: action = QLatin1String("create"); break; - case QT_PREPEND_NAMESPACE_JSONDB(JsonDbClient)::NotifyUpdate: action = QLatin1String("update"); break; - case QT_PREPEND_NAMESPACE_JSONDB(JsonDbClient)::NotifyRemove: action = QLatin1String("remove"); break; - } - - mNotifications << JsonDbTestNotification(notifyUuid, notification.object(), action); - mNotificationWaitCount -= 1; - if (mId.isValid() && !mNotificationWaitCount) - mEventLoop.quit(); - if (!mNeedId && !mNotificationWaitCount) - mEventLoop.quit(); - } - - virtual void response(int id, const QVariant &data) - { - if (debug_output) - qDebug() << "response" << id << endl << data; - mId = id; - mData = data; - mLastUuid = data.toMap().value("_uuid").toString(); - mLastVersion = data.toMap().value("_version").toString(); - if (mId.isValid() && !mNotificationWaitCount) - mEventLoop.quit(); - if (!mNeedId && !mNotificationWaitCount) - mEventLoop.quit(); - } - - virtual void error(int id, int code, const QString &message) - { - if (debug_output) - qDebug() << "response" << id << code << message; - mId = id; - mCode = code; - mMessage = message; - mEventLoop.quit(); - } - virtual void disconnected() - { - } - virtual void timeout() - { - qDebug() << "timeout" << mElapsedTimer.elapsed(); - } -}; - -#endif // CLIENTWRAPPER_H diff --git a/tests/auto/jsondb-listmodel/list-objects.json b/tests/shared/json/list-objects.json index 79f59fbf..79f59fbf 100644 --- a/tests/auto/jsondb-listmodel/list-objects.json +++ b/tests/shared/json/list-objects.json diff --git a/tests/shared/shared.pri b/tests/shared/shared.pri index 28a75440..05aba85e 100644 --- a/tests/shared/shared.pri +++ b/tests/shared/shared.pri @@ -6,13 +6,8 @@ HEADERS += \ $$PWD/util.h \ $$PWD/qmltestutil.h -contains(QT, jsondbcompat|jsondbcompat-private) { - HEADERS += $$PWD/clientwrapper.h - SOURCES += $$PWD/clientwrapper.cpp -} else { - HEADERS += $$PWD/testhelper.h - SOURCES += $$PWD/testhelper.cpp -} +HEADERS += $$PWD/testhelper.h +SOURCES += $$PWD/testhelper.cpp RESOURCES += \ $$PWD/../json.qrc |