• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 HELPER_H
18 #define HELPER_H
19 
20 #include <jni.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /** A JNI test function */
27 typedef char *JniTestFunction(JNIEnv *env);
28 
29 /**
30  * Used as arguments to runTest(), it takes a simple name and expands
31  * it to both a string name and function pointer.
32  */
33 #define RUN_TEST(name) #name, test_##name
34 
35 /**
36  * Standard function delcaration for a test of the JNI function with
37  * the given name. The function is static, returns a (char *), and
38  * takes a (JNIEnv *) named "env".
39  */
40 #define TEST_DECLARATION(name) static char *test_##name(JNIEnv *env) /* NOLINT */
41 
42 /**
43  * Logs and returns an error message, passed and formatted in printf()
44  * style. The returned string should be freed by calling free().
45  *
46  * @param format printf format string
47  * @param ... printf-style arguments
48  * @return an allocated (char *) containing the formatted result
49  */
50 char *failure(const char *format, ...) __attribute__((format(printf, 1, 2)));
51 
52 /**
53  * Runs a list of tests. It will run all the tests, collecting as output
54  * information about all the failures. If non-null, the return value should
55  * be freed by calling free().
56  *
57  * @param env the JNI environment to pass to tests
58  * @param ... the tests to run as name-function pairs, ending with a NULL
59  * @return a string containing information about all the failures
60  */
61 char *runJniTests(JNIEnv *env, ...);
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif // HELPER_H
68