blob: 5e4d56a9dd64be4b125452f55f0d95abd3585e25 [file] [log] [blame]
Mikhail Naganov00bac4e2022-09-15 04:06:57 +00001/*
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#pragma once
18
19#include <iostream>
20
21#include <android/binder_auto_utils.h>
22#include <gtest/gtest_pred_impl.h>
23
Mikhail Naganov00bac4e2022-09-15 04:06:57 +000024namespace android::hardware::audio::common::testing {
25
26namespace detail {
27
28inline ::testing::AssertionResult assertIsOk(const char* expr, const ::ndk::ScopedAStatus& status) {
29 if (status.isOk()) {
30 return ::testing::AssertionSuccess();
31 }
32 return ::testing::AssertionFailure()
33 << "Expected the transaction \'" << expr << "\' to succeed\n"
34 << " but it has failed with: " << status;
35}
36
37inline ::testing::AssertionResult assertResult(const char* exp_expr, const char* act_expr,
38 int32_t expected,
39 const ::ndk::ScopedAStatus& status) {
40 if (status.getExceptionCode() == expected) {
41 return ::testing::AssertionSuccess();
42 }
43 return ::testing::AssertionFailure()
44 << "Expected the transaction \'" << act_expr << "\' to fail with " << exp_expr
45 << "\n but is has completed with: " << status;
46}
47
48} // namespace detail
49
50} // namespace android::hardware::audio::common::testing
51
52// Test that the transaction status 'isOk'
53#define ASSERT_IS_OK(ret) \
54 ASSERT_PRED_FORMAT1(::android::hardware::audio::common::testing::detail::assertIsOk, ret)
55#define EXPECT_IS_OK(ret) \
56 EXPECT_PRED_FORMAT1(::android::hardware::audio::common::testing::detail::assertIsOk, ret)
57
58// Test that the transaction status is as expected.
59#define ASSERT_STATUS(expected, ret) \
60 ASSERT_PRED_FORMAT2(::android::hardware::audio::common::testing::detail::assertResult, \
61 expected, ret)
62#define EXPECT_STATUS(expected, ret) \
63 EXPECT_PRED_FORMAT2(::android::hardware::audio::common::testing::detail::assertResult, \
64 expected, ret)