• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <jni.h>
19 
20 #include <android/log.h>
21 #define TAG "SensorNativeTest"
22 #define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
23 #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
24 #define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
25 
26 #define ASSERT(condition, format, args...) \
27         if (!(condition)) { \
28             fail(env, format, ## args); \
29             return; \
30         }
31 
32 // gtest style assert
33 #define ASSERT_TRUE(a) ASSERT((a), "assert failed on (" #a ") at " __FILE__ ":%d", __LINE__)
34 #define ASSERT_FALSE(a) ASSERT(!(a), "assert failed on (!" #a ") at " __FILE__ ":%d", __LINE__)
35 #define ASSERT_EQ(a, b) \
36         ASSERT((a) == (b), "assert failed on (" #a " == " #b ") at " __FILE__ ":%d", __LINE__)
37 #define ASSERT_NE(a, b) \
38         ASSERT((a) != (b), "assert failed on (" #a " != " #b ") at " __FILE__ ":%d", __LINE__)
39 #define ASSERT_GT(a, b) \
40         ASSERT((a) > (b), "assert failed on (" #a " > " #b ") at " __FILE__ ":%d", __LINE__)
41 #define ASSERT_GE(a, b) \
42         ASSERT((a) >= (b), "assert failed on (" #a " >= " #b ") at " __FILE__ ":%d", __LINE__)
43 #define ASSERT_LT(a, b) \
44         ASSERT((a) < (b), "assert failed on (" #a " < " #b ") at " __FILE__ ":%d", __LINE__)
45 #define ASSERT_LE(a, b) \
46         ASSERT((a) <= (b), "assert failed on (" #a " <= " #b ") at " __FILE__ ":%d", __LINE__)
47 #define ASSERT_NULL(a) \
48         ASSERT((a) == nullptr, "assert failed on isNull(" #a ") at " __FILE__ ":%d", __LINE__)
49 #define ASSERT_NOT_NULL(a) \
50         ASSERT((a) != nullptr, "assert failed on isNotNull(" #a ") at " __FILE__ ":%d", __LINE__)
51 #define ASSERT_NAN(a) \
52         ASSERT(isnan(a), "assert failed on isNan(" #a ") at " __FILE__ ":%d", __LINE__)
53 #define ASSERT_EMPTY_CSTR(a) do { \
54         const char *tmp = a; \
55         ASSERT(tmp != nullptr, \
56                "assert failed on (empty_cstr(" #a "): " #a " != nullptr) " \
57                "at " __FILE__ ":%d", __LINE__); \
58         ASSERT(tmp[0] == '\0', \
59                "assert failed on (empty_cstr(" #a "): strlen() == 0) " \
60                "at " __FILE__ ":%d", __LINE__); \
61     } while (false)
62 
63 
64 void fail(JNIEnv* env, const char* format, ...);
65