1 /* 2 * Copyright (C) 2024 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 #ifndef VIBRATOR_HAL_TEST_UTILS_H 17 #define VIBRATOR_HAL_TEST_UTILS_H 18 19 #include <android/binder_auto_utils.h> 20 #include <gtest/gtest.h> 21 22 #if !defined(EXPECT_OK) 23 #define EXPECT_OK(expression) \ 24 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 25 if (const ::ndk::ScopedAStatus&& _status = (expression); _status.isOk()) \ 26 ; \ 27 else \ 28 ADD_FAILURE() << "Expected STATUS_OK for: " << #expression << "\n Actual: " << _status 29 #else 30 #error Macro EXPECT_OK already defined unexpectedly 31 #endif 32 33 #if !defined(EXPECT_UNKNOWN_OR_UNSUPPORTED) 34 #define EXPECT_UNKNOWN_OR_UNSUPPORTED(expression) \ 35 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 36 if (const ::ndk::ScopedAStatus&& _status = (expression); \ 37 _status.getExceptionCode() == EX_UNSUPPORTED_OPERATION || \ 38 _status.getStatus() == STATUS_UNKNOWN_TRANSACTION) \ 39 ; \ 40 else \ 41 ADD_FAILURE() << "Expected STATUS_UNKNOWN_TRANSACTION or EX_UNSUPPORTED_OPERATION for: " \ 42 << #expression << "\n Actual: " << _status 43 #else 44 #error Macro EXPECT_UNKNOWN_OR_UNSUPPORTED already defined unexpectedly 45 #endif 46 47 #if !defined(EXPECT_ILLEGAL_ARGUMENT) 48 #define EXPECT_ILLEGAL_ARGUMENT(expression) \ 49 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 50 if (const ::ndk::ScopedAStatus&& _status = (expression); \ 51 _status.getExceptionCode() == EX_ILLEGAL_ARGUMENT) \ 52 ; \ 53 else \ 54 ADD_FAILURE() << "Expected EX_ILLEGAL_ARGUMENT for: " << #expression \ 55 << "\n Actual: " << _status 56 #else 57 #error Macro EXPECT_ILLEGAL_ARGUMENT already defined unexpectedly 58 #endif 59 60 #if !defined(EXPECT_ILLEGAL_STATE) 61 #define EXPECT_ILLEGAL_STATE(expression) \ 62 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 63 if (const ::ndk::ScopedAStatus&& _status = (expression); \ 64 _status.getExceptionCode() == EX_ILLEGAL_STATE) \ 65 ; \ 66 else \ 67 ADD_FAILURE() << "Expected EX_ILLEGAL_STATE for: " << #expression \ 68 << "\n Actual: " << _status 69 #else 70 #error Macro EXPECT_ILLEGAL_STATE already defined unexpectedly 71 #endif 72 73 #endif // VIBRATOR_HAL_TEST_UTILS_H 74