// Copyright 2024 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef _JNI_ZERO_STUB_CONVERSIONS_H_ #define _JNI_ZERO_STUB_CONVERSIONS_H_ #include #include #include #include #include #include "third_party/jni_zero/jni_zero.h" #include "third_party/jni_zero/test/sample_for_tests.h" // This file contains empty conversion functions needed by the compile tests. #define EMPTY_TYPE_CONVERSIONS(T) \ template <> \ T FromJniType(JNIEnv * env, const JavaRef& j_object) { \ return {}; \ } \ template <> \ ScopedJavaLocalRef ToJniType(JNIEnv * env, const T& input) { \ return nullptr; \ } #define EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(T) \ template <> \ std::vector FromJniArray>( \ JNIEnv * env, const JavaRef& j_object) { \ return {}; \ } \ template <> \ ScopedJavaLocalRef ToJniArray>( \ JNIEnv * env, const std::vector& vec) { \ return nullptr; \ } #define EMPTY_OBJECT_ARRAY_CONVERSIONS(T) \ template <> \ std::vector FromJniArray>( \ JNIEnv * env, const JavaRef& j_object) { \ return {}; \ } \ template <> \ ScopedJavaLocalRef ToJniArray>( \ JNIEnv * env, const std::vector& vec, jclass clazz) { \ return nullptr; \ } #define EMPTY_LIST_CONVERSIONS(T) \ template <> \ ScopedJavaLocalRef ToJniList>( \ JNIEnv * env, const std::vector& vec) { \ return nullptr; \ } #define EMPTY_COLLECTION_CONVERSIONS(T) \ template <> \ std::vector FromJniCollection>( \ JNIEnv * env, const JavaRef& j_object) { \ return {}; \ } namespace jni_zero { // These conversion functions are normally provided by the embedding app. EMPTY_TYPE_CONVERSIONS(tests::CPPClass) EMPTY_TYPE_CONVERSIONS(std::string) EMPTY_TYPE_CONVERSIONS(std::u16string) EMPTY_TYPE_CONVERSIONS(std::optional) template <> ScopedJavaLocalRef ToJniType(JNIEnv* env, const char* input) { return {}; } template <> tests::CPPClass* FromJniType(JNIEnv* env, const JavaRef& j_obj) { return nullptr; } // If concepts are unavailable, we need these stubs to replace // default_conversions.h/cc #ifndef JNI_ZERO_ENABLE_TYPE_CONVERSIONS EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(int64_t) EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(int32_t) EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(int16_t) EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(uint16_t) EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(uint8_t) EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(float) EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(double) EMPTY_PRIMITIVE_ARRAY_CONVERSIONS(bool) EMPTY_OBJECT_ARRAY_CONVERSIONS(const char*) EMPTY_OBJECT_ARRAY_CONVERSIONS(std::string) EMPTY_OBJECT_ARRAY_CONVERSIONS(ScopedJavaLocalRef) EMPTY_OBJECT_ARRAY_CONVERSIONS(tests::CPPClass) EMPTY_LIST_CONVERSIONS(std::string) EMPTY_LIST_CONVERSIONS(ScopedJavaLocalRef) EMPTY_COLLECTION_CONVERSIONS(std::string) EMPTY_COLLECTION_CONVERSIONS(ScopedJavaLocalRef) template <> std::map FromJniType>(JNIEnv* env, const JavaRef& input) { return {}; } template <> ScopedJavaLocalRef ToJniType>( JNIEnv* env, const std::map& input) { return {}; } template <> inline ByteArrayView FromJniArray( JNIEnv* env, const JavaRef& j_object) { return ByteArrayView(env, nullptr); } #endif // #ifndef JNI_ZERO_ENABLE_TYPE_CONVERSIONS } // namespace jni_zero #endif