Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b62c5c0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "audio: Refactor transaction status checks in VTS" am: 857e3d98 am:...

Merge "audio: Refactor transaction status checks in VTS" am: 857e3d98 am: 391bc4c9 am: 8de860c5

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2215767



Change-Id: I142bf532500acdbd51e051e02788697cda68eb32
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 1b2c440d 8de860c5
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <iostream>

#include <android/binder_auto_utils.h>
#include <gtest/gtest_pred_impl.h>

namespace ndk {

std::ostream& operator<<(std::ostream& str, const ScopedAStatus& status) {
    str << status.getDescription();
    return str;
}

}  // namespace ndk

namespace android::hardware::audio::common::testing {

namespace detail {

inline ::testing::AssertionResult assertIsOk(const char* expr, const ::ndk::ScopedAStatus& status) {
    if (status.isOk()) {
        return ::testing::AssertionSuccess();
    }
    return ::testing::AssertionFailure()
           << "Expected the transaction \'" << expr << "\' to succeed\n"
           << "  but it has failed with: " << status;
}

inline ::testing::AssertionResult assertResult(const char* exp_expr, const char* act_expr,
                                               int32_t expected,
                                               const ::ndk::ScopedAStatus& status) {
    if (status.getExceptionCode() == expected) {
        return ::testing::AssertionSuccess();
    }
    return ::testing::AssertionFailure()
           << "Expected the transaction \'" << act_expr << "\' to fail with " << exp_expr
           << "\n  but is has completed with: " << status;
}

}  // namespace detail

}  // namespace android::hardware::audio::common::testing

// Test that the transaction status 'isOk'
#define ASSERT_IS_OK(ret) \
    ASSERT_PRED_FORMAT1(::android::hardware::audio::common::testing::detail::assertIsOk, ret)
#define EXPECT_IS_OK(ret) \
    EXPECT_PRED_FORMAT1(::android::hardware::audio::common::testing::detail::assertIsOk, ret)

// Test that the transaction status is as expected.
#define ASSERT_STATUS(expected, ret)                                                       \
    ASSERT_PRED_FORMAT2(::android::hardware::audio::common::testing::detail::assertResult, \
                        expected, ret)
#define EXPECT_STATUS(expected, ret)                                                       \
    EXPECT_PRED_FORMAT2(::android::hardware::audio::common::testing::detail::assertResult, \
                        expected, ret)
+121 −260

File changed.

Preview size limit exceeded, changes collapsed.