aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@digia.com>2013-09-23 20:06:52 +0200
committerYoann Lopes <yoann.lopes@digia.com>2013-09-23 19:28:19 +0200
commite1bf247cd661e4a2e058786718f4c671fbe8977a (patch)
treecf8ca4e74b9a9f3d44190a2b6c05bc9e93bb650c /tests
parent252be0e10e66fd4d92bd59b0cf4de02a8084f5ac (diff)
Added QJNIEnvironment auto test.
Change-Id: I19aa638668ac8b4f263047d1e636d86abb73b91e Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro5
-rw-r--r--tests/auto/qjnienvironment/qjnienvironment.pro4
-rw-r--r--tests/auto/qjnienvironment/tst_qjnienvironment.cpp111
3 files changed, 118 insertions, 2 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 44b3c49..aaa0664 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,2 +1,3 @@
-TEMPLATE=subdirs
-SUBDIRS=
+TEMPLATE = subdirs
+SUBDIRS += \
+ qjnienvironment
diff --git a/tests/auto/qjnienvironment/qjnienvironment.pro b/tests/auto/qjnienvironment/qjnienvironment.pro
new file mode 100644
index 0000000..e4b7b09
--- /dev/null
+++ b/tests/auto/qjnienvironment/qjnienvironment.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase
+TARGET = tst_qjnienvironment
+QT += testlib androidextras
+SOURCES += tst_qjnienvironment.cpp
diff --git a/tests/auto/qjnienvironment/tst_qjnienvironment.cpp b/tests/auto/qjnienvironment/tst_qjnienvironment.cpp
new file mode 100644
index 0000000..7d5de58
--- /dev/null
+++ b/tests/auto/qjnienvironment/tst_qjnienvironment.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite 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 <QtAndroidExtras/QJNIEnvironment>
+
+class tst_QJNIEnvironment : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void jniEnv();
+ void javaVM();
+
+public:
+ static JavaVM *m_javaVM;
+};
+
+JavaVM *tst_QJNIEnvironment::m_javaVM = 0;
+
+void tst_QJNIEnvironment::jniEnv()
+{
+ QVERIFY(m_javaVM);
+
+ {
+ QJNIEnvironment env;
+
+ // JNI environment should now be attached to the current thread
+ JNIEnv *jni = 0;
+ QCOMPARE(m_javaVM->GetEnv((void**)&jni, JNI_VERSION_1_6), JNI_OK);
+
+ JNIEnv *e = env;
+ QVERIFY(e);
+
+ QCOMPARE(env->GetVersion(), JNI_VERSION_1_6);
+
+ // try to find an existing class
+ QVERIFY(env->FindClass("java/lang/Object"));
+ QVERIFY(!env->ExceptionCheck());
+
+ // try to find a nonexistent class
+ QVERIFY(!env->FindClass("this/doesnt/Exist"));
+ QVERIFY(env->ExceptionCheck());
+ env->ExceptionClear();
+ }
+
+ // The environment should automatically be detached when QJNIEnvironment goes out of scope
+ JNIEnv *jni = 0;
+ QCOMPARE(m_javaVM->GetEnv((void**)&jni, JNI_VERSION_1_6), JNI_EDETACHED);
+}
+
+void tst_QJNIEnvironment::javaVM()
+{
+ QVERIFY(m_javaVM);
+
+ QJNIEnvironment env;
+ QCOMPARE(env.javaVM(), m_javaVM);
+
+ JavaVM *vm = 0;
+ QCOMPARE(env->GetJavaVM(&vm), JNI_OK);
+ QCOMPARE(env.javaVM(), vm);
+}
+
+Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+ Q_UNUSED(reserved)
+ tst_QJNIEnvironment::m_javaVM = vm;
+ return JNI_VERSION_1_6;
+}
+
+QTEST_APPLESS_MAIN(tst_QJNIEnvironment)
+
+#include "tst_qjnienvironment.moc"