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