summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qjniobject/testdata/src/org/qtproject/qt
Commit message (Collapse)AuthorAgeFilesLines
* JNI: check for pending exception first in getCleanJniObject()Assam Boudjelthia2024-04-041-0/+8
| | | | | | | | | | | | | returning early if the object is null will not clear pending exceptions from the previous failed JNI call, and that will crash the app on the next jni call if an explicit exception clearing is not done, wish mostly the case. Checking and clearing for exceptions has to always be done under this call. Pick-to: 6.7 Fixes: QTBUG-122135 Change-Id: I0d42d012a4d1305fa07147fd22860d7c005f9b83 Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* JNI: Fix error with overload resolution when passing string typesVolker Hilsheimer2024-03-061-0/+3
| | | | | | | | | | | | | | | | | | | | The variadic templates are supposed to be removed from the overload set when any of the parameters is a literal string type, as otherwise we get conflicts with the legacy overload taking class names and signatures as const char *. The detection of a literal string types was missing a few specializations, so that we ended up with the wrong overload being called, and class names getting interpreted as method names instead. Add the missing specializations, and add more test coverage for using the old overloads. Task-number: QTBUG-122235 Pick-to: 6.7 Change-Id: I5488f2009c8f62d74fac6754844f57cf64011414 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Lauri Pohjanheimo <lauri.pohjanheimo@qt.io>
* JNI: Support QStringList as a parameter of native functionsVolker Hilsheimer2024-02-231-0/+5
| | | | | | | | | | | | | | | Since we support QString and QList specializations, we should also support QStringList directly. That's a bit more involved as we need to specialize the code path for QString, which is not convertible to or from jobject. But once we have mapped the type to jstring it follows the implementation for lists of objects. We now need to generate temporary local references when converting a QString to a jstring, so manage a local frame. We do so explicitly in chunks of 100 local references. Change-Id: I7ae5cf7d0ba0099992c36f3677980c346526804b Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* JNI: implement support for native functions taking a listVolker Hilsheimer2024-02-231-0/+10
| | | | | | | | | | | | | This didn't work yet because the partial specialization of the JNITypeForArgImpl factory was missing. Add a test case for QJniArray<double> and QList<double>. What doesn't work (yet) is QStringList for a native Java function taking a String[]. That will be added in a follow-up commit. Change-Id: I4d3fa0ecc04b98b9749f8358792f86c02ddbbc14 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* JNI: allow QString as a parameter to native methodsVolker Hilsheimer2023-11-071-0/+12
| | | | | | | | | | | | | | Expect a jstring on the va_list, and implicitly construct a QString from that. As a drive-by, allow native methods to take parameters by reference, and move implementation details into a Detail namespace. Add test coverage. Change-Id: I31214938ccaea3f4d539b432e29d12434dd98377 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* JNI: add QJniArray class for easier working with arraysVolker Hilsheimer2023-10-161-0/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Implements an iterator API and other standard member access functions for sequential containers so that we can use ranged-for over an object that is a jarray. Provides read-only access to individual elements (which is mostly relevant for arrays of objects), or the entire data() as a contiguous memory block (which is useful for arrays of primitive types). QJniObject call functions can return QJniArray<T> when the return type is either explicitly QJniArray<T> or T[], or their Qt equivalent (e.g. a jbyteArray can be taken or returned as a QByteArray). If the return type is a jarray type, then a QJniObject is returned as before. Arrays can be created from a Qt container through a constructor or the generic fromData named constructor in the QJniArrayBase class, which implements the generic logic. Not documented as public API yet. Added a compile-time test to verify that types are mapped correctly. The function test coverage is added to the QJniObject auto-test, as that already provides the Java test class with functions taking and returning arrays of different types. Change-Id: I0750fc4f4cce7314df3b10e122eafbcfd68297b6 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Simplify Qt for Android hierarchy, less Java reflection!Assam Boudjelthia2023-10-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes takes Qt for Android Java code away from the Delegate classes that uses heavily Java reflection to invoke Activity/Service calls and overrides. So instead of that, now, we have a QtActivityBase and a QtServiceBase classes which handle the override logic needed for Qt directly without reflection. These Base classes extend Android's Activity and Service directly, and are inside the internal Qt android package (under Qt6Android.jar). For example, to handle onConfigurationChanged, instead of the current way where we need this in QtActivityDelegate: public void onConfigurationChanged(Configuration configuration) { try { m_super_onConfigurationChanged.invoke(m_activity, configuration); } catch (Exception e) { e.printStackTrace(); } handleUiModeChange(configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK); } And then this in QtActivity: @Override public void onConfigurationChanged(Configuration newConfig) { if (!QtLoader.invokeDelegate(newConfig).invoked) super.onConfigurationChanged(newConfig); } public void super_onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } And having to keep it's Method handles around and then use Java reflection to call the override behavior done by Qt and the superclass methods. instead of that, we can do it now in QtActivityBase like: @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); handleUiModeChange(newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK); } Then, we would still have our user facing QtActivity class which extends QtActivityBase and benefit from the same implementation of Qt logic done in the base class. An additional benefit to this approach is that now QtActivity will be very lightweight and doesn't need to have all the boilerplate code as before. [ChangeLog][Android] Simplify Qt for Android public bindings (QActivity, QtService and QtApplication) by implementing base classes which use the delegate implementions directly and avoid reflection. Task-number: QTBUG-115014 Task-number: QTBUG-114593 Change-Id: Ie1eca74f989627be4468786a27e30b16209fc521 Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
* JNI: Add promotion for signed char and extend test caseVolker Hilsheimer2023-09-291-0/+24
| | | | | | | | | | | | The jbyte type is a signed char, which also promotes to int in variadic argument functions. Extend the test case to make sure that we don't get any warnings for the most relevant parameter types. Change-Id: I7811e1eebdbc989ab5989eb1a2c502acd0540bc7 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> Reviewed-by: Zoltan Gera <zoltan.gera@qt.io>
* JNI: Fix native functions that take a declared QtJniTypes classVolker Hilsheimer2023-09-271-1/+8
| | | | | | | | | | | | | | | | | | | Now that QtJniTypes::Objects are no longer primitive types that are the same as a jobject, using those types in registered native functions breaks. JNI will call those function with a jobject on the function pointer, and lacking any type safety, the call to the registered function will proceed with a wrong type of object on the stack. To fix that, register the native function via a proxy that is a variadic argument function, and unpack the variadic arguments into a list of typed arguments, using the types we know the user-code function wants. Then call the function with a tuple of those types using std::apply, which gives us type safety and implicit conversion for free. Add a test that exercises this. Change-Id: I9f980e55d3d13f8fc16c410dc0d17dbdc200cb47 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-27/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Fix set*Field JNI template callsAssam Boudjelthia2021-05-051-0/+22
| | | | | | | | | | | The calls were trying to pass a JNIEnv* from a QJniEnvironment using conversion operator which was removed, and weren't detected since they are templates and were missing tests. This fix that and add test cases for setField() and setStaticField() calls. Pick-to: 6.1 Change-Id: I6e1e6b7f557bbc664248ad364c48d63f58b70756 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Make QJniObject and QJniEnvironment public APIAssam Boudjelthia2021-01-271-0/+177
As part of Qt 6 restructring for the extras modules, this change exposes the Jni APIs which are very important for Android platform. This patch adds the APIs QJniObject, QJniEnvironment, QJniExceptionCleaner based from private QtCore and QtAndroidExtras. The Jni interface is cross-platform which justifies the name, but currently, this API is used mainly for Android, and the naming comes generic without Android keyword to avoid any future limitation on supporting other platforms. [ChangeLog][QtCore] Add new QJniObject, QJniEnvironment and QJniExceptionCleaner APIs. Task-number: QTBUG-89482 Fixes: QTBUG-89633 Change-Id: I4382dd53a225375759b9d042f6035a4a9810572b Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>