1 /*
2 * Copyright (C) 2017 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
18 #include "nativeTestHelper.h"
19 #include <cstdlib>
20 #include <cstring>
21
22 extern int register_android_hardware_cts_SensorNativeTest(JNIEnv* env);
23 extern int register_android_hardware_cts_SensorDirectReportTest(JNIEnv* env);
24 extern int register_android_hardware_cts_helpers_SensorRatePermissionDirectReportTestHelper(
25 JNIEnv* env);
26
fail(JNIEnv * env,const char * format,...)27 void fail(JNIEnv* env, const char* format, ...) {
28 va_list args;
29
30 va_start(args, format);
31 char *msg;
32 vasprintf(&msg, format, args);
33 va_end(args);
34
35 jclass exClass;
36 const char *className = "java/lang/AssertionError";
37 exClass = env->FindClass(className);
38 jmethodID constructor = env->GetMethodID(exClass, "<init>",
39 "(Ljava/lang/String;Ljava/lang/Throwable;)V");
40 jstring msgStr = env->NewStringUTF(msg);
41 jobject exception = env->NewObject(exClass, constructor, msgStr, nullptr);
42 env->Throw(static_cast<jthrowable>(exception));
43 free(msg);
44 }
45
JNI_OnLoad(JavaVM * vm,void *)46 jint JNI_OnLoad(JavaVM *vm, void *) {
47 JNIEnv *env = NULL;
48 if (vm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) {
49 return JNI_ERR;
50 }
51 if (register_android_hardware_cts_SensorNativeTest(env)) {
52 return JNI_ERR;
53 }
54 if (register_android_hardware_cts_SensorDirectReportTest(env)) {
55 return JNI_ERR;
56 }
57 if (register_android_hardware_cts_helpers_SensorRatePermissionDirectReportTestHelper(env)) {
58 return JNI_ERR;
59 }
60 return JNI_VERSION_1_4;
61 }
62