File indexing completed on 2025-02-02 05:02:41
0001 /* 0002 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef FAKE_JNI_H 0008 #define FAKE_JNI_H 0009 0010 #include <cstdint> 0011 #include <numeric> 0012 0013 #ifdef Q_OS_ANDROID 0014 #error This is a mock object for use on non-Android! 0015 #endif 0016 0017 typedef uint8_t jboolean; 0018 typedef int8_t jbyte; 0019 typedef uint16_t jchar; 0020 typedef int16_t jshort; 0021 typedef int32_t jint; 0022 typedef int64_t jlong; 0023 typedef float jfloat; 0024 typedef double jdouble; 0025 0026 typedef jint jsize; 0027 0028 typedef void* jobject; 0029 typedef jobject jclass; 0030 typedef jobject jstring; 0031 typedef jobject jarray; 0032 typedef jarray jobjectArray; 0033 typedef jarray jbooleanArray; 0034 typedef jarray jbyteArray; 0035 typedef jarray jcharArray; 0036 typedef jarray jshortArray; 0037 typedef jarray jintArray; 0038 typedef jarray jlongArray; 0039 typedef jarray jfloatArray; 0040 typedef jarray jdoubleArray; 0041 0042 namespace detail { 0043 template <typename T> 0044 inline T* getArrayElements(jsize size) 0045 { 0046 T* array = new T[size]; 0047 std::iota(array, array + size, T{}); 0048 return array; 0049 } 0050 } 0051 0052 struct JNIEnv 0053 { 0054 inline bool ExceptionCheck() { return false; } 0055 inline void ExceptionClear() {} 0056 0057 inline int GetArrayLength(jobjectArray) { return m_arrayLength; } 0058 inline jobjectArray NewObjectArray(jsize, jclass, jobject) { return nullptr; } 0059 inline jobject GetObjectArrayElement(jobjectArray, int index) { return reinterpret_cast<jobject>(index); } 0060 inline void SetObjectArrayElement(jobjectArray, jsize, jobject) {} 0061 0062 inline jbooleanArray NewBooleanArray(jsize) { return nullptr; } 0063 inline jbyteArray NewByteArray (jsize) { return nullptr; } 0064 inline jcharArray NewCharArray (jsize) { return nullptr; } 0065 inline jshortArray NewShortArray (jsize) { return nullptr; } 0066 inline jintArray NewIntArray (jsize) { return nullptr; } 0067 inline jlongArray NewLongArray (jsize) { return nullptr; } 0068 inline jfloatArray NewFloatArray (jsize) { return nullptr; } 0069 inline jdoubleArray NewDoubleArray (jsize) { return nullptr; } 0070 0071 inline jboolean* GetBooleanArrayElements(jbooleanArray, jboolean*) { return detail::getArrayElements<jboolean>(m_arrayLength); } 0072 inline jbyte* GetByteArrayElements (jbyteArray, jboolean*) { return detail::getArrayElements<jbyte>(m_arrayLength); } 0073 inline jchar* GetCharArrayElements (jcharArray, jboolean*) { return detail::getArrayElements<jchar>(m_arrayLength); } 0074 inline jshort* GetShortArrayElements (jshortArray, jboolean*) { return detail::getArrayElements<jshort>(m_arrayLength); } 0075 inline jint* GetIntArrayElements (jintArray, jboolean*) { return detail::getArrayElements<jint>(m_arrayLength); } 0076 inline jlong* GetLongArrayElements (jlongArray, jboolean*) { return detail::getArrayElements<jlong>(m_arrayLength); } 0077 inline jfloat* GetFloatArrayElements (jfloatArray, jboolean*) { return detail::getArrayElements<jfloat>(m_arrayLength); } 0078 inline jdouble* GetDoubleArrayElements (jdoubleArray, jboolean*) { return detail::getArrayElements<jdouble>(m_arrayLength); } 0079 0080 inline void ReleaseBooleanArrayElements(jbooleanArray, jboolean *data, jint) { delete[] data; } 0081 inline void ReleaseByteArrayElements (jbyteArray, jbyte *data, jint) { delete[] data; } 0082 inline void ReleaseCharArrayElements (jcharArray, jchar *data, jint) { delete[] data; } 0083 inline void ReleaseShortArrayElements (jshortArray, jshort *data, jint) { delete[] data; } 0084 inline void ReleaseIntArrayElements (jintArray, jint *data, jint) { delete[] data; } 0085 inline void ReleaseLongArrayElements (jlongArray, jlong *data, jint) { delete[] data; } 0086 inline void ReleaseFloatArrayElements (jfloatArray, jfloat *data, jint) { delete[] data; } 0087 inline void ReleaseDoubleArrayElements (jdoubleArray, jdouble *data, jint) { delete[] data; } 0088 0089 inline void SetBooleanArrayRegion(jbooleanArray, jsize, jsize, const jboolean*) {} 0090 inline void SetByteArrayRegion (jbyteArray, jsize, jsize, const jbyte*) {} 0091 inline void SetCharArrayRegion (jcharArray, jsize, jsize, const jchar*) {} 0092 inline void SetShortArrayRegion (jshortArray, jsize, jsize, const jshort*) {} 0093 inline void SetIntArrayRegion (jintArray, jsize, jsize, const jint*) {} 0094 inline void SetLongArrayRegion (jlongArray, jsize, jsize, const jlong*) {} 0095 inline void SetFloatArrayRegion (jfloatArray, jsize, jsize, const jfloat*) {} 0096 inline void SetDoubleArrayRegion (jdoubleArray, jsize, jsize, const jdouble*) {} 0097 0098 static jsize m_arrayLength; 0099 }; 0100 0101 #define JNI_COMMIT 1 0102 #define JNI_ABORT 2 0103 0104 #endif