xref: /aosp_15_r20/external/icing/icing/icing-search-engine-test-jni-layer.cc (revision 8b6cd535a057e39b3b86660c4aa06c99747c2136)
1 // Copyright (C) 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <jni.h>
16 
17 #include "gtest/gtest.h"
18 #include "icing/testing/logging-event-listener.h"
19 
20 // Global variable used so that the test implementation can access the JNIEnv.
21 JNIEnv* g_jenv = nullptr;
22 
23 extern "C" JNIEXPORT jboolean JNICALL
Java_icing_jni_IcingSearchEngineJniTest_testsMain(JNIEnv * env,jclass ignored)24 Java_icing_jni_IcingSearchEngineJniTest_testsMain(JNIEnv* env, jclass ignored) {
25   g_jenv = env;
26 
27   std::vector<char*> my_argv;
28   char arg[] = "jni-test-lib";
29   my_argv.push_back(arg);
30   int argc = 1;
31   char** argv = &(my_argv[0]);
32   testing::InitGoogleTest(&argc, argv);
33   testing::UnitTest::GetInstance()->listeners().Append(
34       new icing::lib::LoggingEventListener());
35   return RUN_ALL_TESTS() == 0;
36 }
37