• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBTEXTCLASSIFIER_UTILS_JVM_TEST_UTILS_H_
18 #define LIBTEXTCLASSIFIER_UTILS_JVM_TEST_UTILS_H_
19 
20 #include "utils/calendar/calendar.h"
21 #include "utils/utf8/unilib.h"
22 
23 #if defined(__ANDROID__)
24 #include <jni.h>
25 
26 // Use these with jvm_test_launcher which provides these global variables.
27 extern JNIEnv* g_jenv;
28 extern jobject g_context;
29 #endif
30 
31 namespace libtextclassifier3 {
CreateUniLibForTesting()32 inline std::unique_ptr<UniLib> CreateUniLibForTesting() {
33 #if defined TC3_UNILIB_JAVAICU
34   return std::make_unique<UniLib>(JniCache::Create(g_jenv));
35 #else
36   return std::make_unique<UniLib>();
37 #endif
38 }
39 
CreateCalendarLibForTesting()40 inline std::unique_ptr<CalendarLib> CreateCalendarLibForTesting() {
41 #if defined TC3_CALENDAR_JAVAICU
42   return std::make_unique<CalendarLib>(JniCache::Create(g_jenv));
43 #else
44   return std::make_unique<CalendarLib>();
45 #endif
46 }
47 
48 #if defined(__ANDROID__)
GetJenv()49 inline JNIEnv* GetJenv() { return g_jenv; }
50 
GetAndroidContext()51 inline jobject GetAndroidContext() { return g_context; }
52 #endif
53 
54 }  // namespace libtextclassifier3
55 
56 #endif  // LIBTEXTCLASSIFIER_UTILS_JVM_TEST_UTILS_H_
57