summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-09-12 11:37:37 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-09-23 07:24:26 +0200
commit941f49b0188c6f396a6dd6174c791029a0bed6ab (patch)
tree20ce23d388d44d4ab7626e273733a92cf193b5cb /tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp
parent9965630aaf00d81c656baff5072dda9477544d97 (diff)
JNI: treat enums as their underlying types
Android APIs use integer constants like enum values, so they are mapped to one of the integeral types (jint, jshort, jlong etc) on the C++ side. Enable C++ code to declare an equivalent enum (scoped or unscoped), and to use that enum as a type in JNI calls by treating it as the underlying type in the signature() generator. Add a helper type trait that maps enums to their underlying type and other integral types to themselves (we can't use std::underlying_type_t on a non-enum type). Add tests. Note: Java Enums are special classes with fields; this change does not add any special support for those. Change-Id: Iec430a1553152dcf7a24209aaebbeceb1c6e38a8 Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io> Reviewed-by: Zoltan Gera <zoltan.gera@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp')
-rw-r--r--tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp b/tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp
index b7685538f1..cbffb24ff8 100644
--- a/tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp
+++ b/tests/auto/corelib/kernel/qjnitypes/tst_qjnitypes.cpp
@@ -115,6 +115,23 @@ static_assert(!QtJniTypes::CTString("ABCDE").endsWith("ABCDEF"));
static_assert(QtJniTypes::CTString("ABCDE").endsWith('E'));
static_assert(!QtJniTypes::CTString("ABCDE").endsWith('F'));
+enum UnscopedEnum {};
+enum class ScopedEnum {};
+enum class IntEnum : int {};
+enum class UnsignedEnum : unsigned {};
+enum class Int8Enum : int8_t {};
+enum class ShortEnum : short {};
+enum class LongEnum : long {};
+enum class JIntEnum : jint {};
+
+static_assert(QtJniTypes::Traits<UnscopedEnum>::signature() == "I");
+static_assert(QtJniTypes::Traits<ScopedEnum>::signature() == "I");
+static_assert(QtJniTypes::Traits<IntEnum>::signature() == "I");
+static_assert(QtJniTypes::Traits<UnsignedEnum>::signature() == "I");
+static_assert(QtJniTypes::Traits<Int8Enum>::signature() == "B");
+static_assert(QtJniTypes::Traits<LongEnum>::signature() == "J");
+static_assert(QtJniTypes::Traits<JIntEnum>::signature() == "I");
+
void tst_QJniTypes::initTestCase()
{