1 /* 2 * Copyright (C) 2019 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 _GTS_NANOAPPS_SHARED_MACROS_H_ 18 #define _GTS_NANOAPPS_SHARED_MACROS_H_ 19 20 #include "send_message.h" 21 22 /** 23 * Asserts the two provided values are equal. If the assertion fails, then a 24 * fatal failure occurs. 25 */ 26 #define ASSERT_EQ(val1, val2, failureMessage) \ 27 if ((val1) != (val2)) sendFatalFailureToHost(failureMessage) 28 29 /** 30 * Asserts the two provided values are not equal. If the assertion fails, then 31 * a fatal failure occurs. 32 */ 33 #define ASSERT_NE(val1, val2, failureMessage) \ 34 if ((val1) == (val2)) sendFatalFailureToHost(failureMessage) 35 36 /** 37 * Asserts the given value is greater than or equal to value of lower. If the 38 * value fails this assertion, then a fatal failure occurs. 39 */ 40 #define ASSERT_GE(value, lower, failureMessage) \ 41 if ((value) < (lower)) sendFatalFailureToHost(failureMessage) 42 43 /** 44 * Asserts the given value is less than or equal to value of upper. If the value 45 * fails this assertion, then a fatal failure occurs. 46 */ 47 #define ASSERT_LE(value, upper, failureMessage) \ 48 if ((value) > (upper)) sendFatalFailureToHost(failureMessage) 49 50 /** 51 * Asserts the given value is less than the value of upper. If the value fails 52 * this assertion, then a fatal failure occurs. 53 */ 54 #define ASSERT_LT(value, upper, failureMessage) \ 55 if ((value) >= (upper)) sendFatalFailureToHost(failureMessage) 56 57 /** 58 * Asserts the given value is within the range defined by lower and upper 59 * (inclusive). If the value is outside the range, then a fatal failure occurs. 60 */ 61 #define ASSERT_IN_RANGE(value, lower, upper, failureMessage) \ 62 ASSERT_GE((value), (lower), failureMessage); \ 63 ASSERT_LE((value), (upper), failureMessage) 64 65 #endif // _GTS_NANOAPPS_SHARED_MACROS_H_