Home | History | Annotate | Download | only in jni
      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 
     25 void fail(JNIEnv* env, const char* format, ...) {
     26     va_list args;
     27 
     28     va_start(args, format);
     29     char *msg;
     30     vasprintf(&msg, format, args);
     31     va_end(args);
     32 
     33     jclass exClass;
     34     const char *className = "java/lang/AssertionError";
     35     exClass = env->FindClass(className);
     36     env->ThrowNew(exClass, msg);
     37     free(msg);
     38 }
     39 
     40 jint JNI_OnLoad(JavaVM *vm, void *) {
     41     JNIEnv *env = NULL;
     42     if (vm->GetEnv((void**)&env, JNI_VERSION_1_4) != JNI_OK) {
     43         return JNI_ERR;
     44     }
     45     if (register_android_hardware_cts_SensorNativeTest(env)) {
     46         return JNI_ERR;
     47     }
     48     if (register_android_hardware_cts_SensorDirectReportTest(env)) {
     49         return JNI_ERR;
     50     }
     51     return JNI_VERSION_1_4;
     52 }
     53