xref: /aosp_15_r20/system/chre/util/include/chre/util/host/assert.h (revision 84e339476a462649f82315436d70fd732297a399)
1 /*
2  * Copyright (C) 2022 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 CHRE_UTIL_HOST_ASSERT_H_
18 #define CHRE_UTIL_HOST_ASSERT_H_
19 
20 /**
21  * @file
22  *
23  * Suppplies a CHRE_ASSERT macro for host to use.
24  */
25 
26 #ifdef CHRE_IS_HOST_BUILD
27 
28 #include <cassert>
29 
30 /**
31  * Provides the CHRE_ASSERT macro based on cassert.
32  *
33  * @param the condition to check for non-zero.
34  */
35 #ifdef CHRE_ASSERTIONS_ENABLED
36 #define CHRE_ASSERT(condition) assert(condition)
37 #else
38 #define CHRE_ASSERT(condition) ((void)(condition))
39 #endif  // CHRE_ASSERTIONS_ENABLED
40 
41 #ifdef __cplusplus
42 #define CHRE_ASSERT_NOT_NULL(ptr) CHRE_ASSERT((ptr) != nullptr)
43 #else
44 #define CHRE_ASSERT_NOT_NULL(ptr) CHRE_ASSERT((ptr) != NULL)
45 #endif
46 
47 #ifdef GTEST
48 // Mocks are not supported in standalone mode. Just skip the statement entirely.
49 #define EXPECT_CHRE_ASSERT(statement)
50 #endif  // GTEST
51 
52 #endif  // CHRE_IS_HOST_BUILD
53 
54 #endif  // CHRE_UTIL_HOST_ASSERT_H_
55