summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGuenter Schwann <guenter.schwann@nokia.com>2012-06-05 12:03:23 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-06 16:38:47 +0200
commit1d38eaffd657763bfad63fd38dbc1d2ce3fa4e10 (patch)
tree4e0a580c07add24e74f810bb8532f2bc0029904c /tests
parent1eba2be34bbf26abd47cc3c4f96a44d1e6c3bc0b (diff)
Enable JS injection in Json Db
Change-Id: I0a0a4497fda098d9bbe6f97d32bcfd4f2a872137 Reviewed-by: Jamey Hicks <jamey.hicks@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/jsondbscriptengine/jsondbscriptengine.pro17
-rw-r--r--tests/auto/jsondbscriptengine/test-jsondbscriptengine.cpp75
-rw-r--r--tests/auto/jsondbscriptengine/test_inject.js6
4 files changed, 99 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 0f046aae..84e71946 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -11,6 +11,7 @@ SUBDIRS = \
jsondbpartition \
jsondbnotification \
jsondbqueryobject \
+ jsondbscriptengine \
queries \
qjsondbrequest \
qjsondbwatcher \
diff --git a/tests/auto/jsondbscriptengine/jsondbscriptengine.pro b/tests/auto/jsondbscriptengine/jsondbscriptengine.pro
new file mode 100644
index 00000000..5cffe80d
--- /dev/null
+++ b/tests/auto/jsondbscriptengine/jsondbscriptengine.pro
@@ -0,0 +1,17 @@
+TARGET = tst_jsondbscriptengine
+
+QT = testlib jsondbpartition jsondbpartition-private
+CONFIG -= app_bundle
+CONFIG += testcase
+
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+
+SOURCES += \
+ test-jsondbscriptengine.cpp
+
+OTHER_FILES += \
+ test_inject.js
+
+data.files = $$OTHER_FILES
+data.path = $$[QT_INSTALL_TESTS]/$$TARGET
+INSTALLS += data
diff --git a/tests/auto/jsondbscriptengine/test-jsondbscriptengine.cpp b/tests/auto/jsondbscriptengine/test-jsondbscriptengine.cpp
new file mode 100644
index 00000000..81ee478a
--- /dev/null
+++ b/tests/auto/jsondbscriptengine/test-jsondbscriptengine.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtAddOn.JsonDb module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.
+**
+** 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "jsondbscriptengine.h"
+#include "jsondbsettings.h"
+#include <QtJsonDbPartition/jsondbpartitionglobal.h>
+#include <QtTest/QtTest>
+
+QT_USE_NAMESPACE_JSONDB_PARTITION
+
+class TestJsonDbScriptEngine: public QObject
+{
+ Q_OBJECT
+private slots:
+ void injectScript();
+};
+
+void TestJsonDbScriptEngine::injectScript()
+{
+ qputenv("JSONDB_INJECTION_SCRIPT", "");
+ QJSEngine *engine = JsonDbScriptEngine::scriptEngine();
+ QJSValue obj = engine->evaluate("isEqual(3, 3);");
+ QVERIFY(obj.isError());
+ JsonDbScriptEngine::releaseScriptEngine();
+
+ qputenv("JSONDB_INJECTION_SCRIPT", QFINDTESTDATA("test_inject.js").toLocal8Bit());
+ jsondbSettings->reload();
+ engine = JsonDbScriptEngine::scriptEngine();
+ obj = engine->evaluate("isEqual(3, 3);");
+ QCOMPARE(obj.toBool(), true);
+ obj = engine->evaluate("isEqual(3, 0);");
+ QCOMPARE(obj.toBool(), false);
+}
+
+QTEST_MAIN(TestJsonDbScriptEngine)
+
+#include "test-jsondbscriptengine.moc"
diff --git a/tests/auto/jsondbscriptengine/test_inject.js b/tests/auto/jsondbscriptengine/test_inject.js
new file mode 100644
index 00000000..7d1a10bf
--- /dev/null
+++ b/tests/auto/jsondbscriptengine/test_inject.js
@@ -0,0 +1,6 @@
+(function() {
+ isEqual = function(a, b) {
+ if (a === null || b === null) return false;
+ return a === b;
+ };
+}).call(this);