mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 22:04:26 +00:00
Audio V4: Make test helper version independent
Bug: 38184704 Test: compile Change-Id: Ia9ec81ccbad1d7411fdc570ae6dd728dd1520065
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <initializer_list>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -40,9 +41,11 @@
|
||||
#include "utility/AssertOk.h"
|
||||
#include "utility/Documentation.h"
|
||||
#include "utility/EnvironmentTearDown.h"
|
||||
#define AUDIO_HAL_VERSION V2_0
|
||||
#include "utility/PrettyPrintAudioTypes.h"
|
||||
#include "utility/ReturnIn.h"
|
||||
|
||||
using std::initializer_list;
|
||||
using std::string;
|
||||
using std::to_string;
|
||||
using std::vector;
|
||||
@@ -856,7 +859,7 @@ TEST_IO_STREAM(GetHwAvSync, "Get hardware sync can not fail",
|
||||
ASSERT_IS_OK(device->getHwAvSync()));
|
||||
|
||||
static void checkGetNoParameter(IStream* stream, hidl_vec<hidl_string> keys,
|
||||
vector<Result> expectedResults) {
|
||||
initializer_list<Result> expectedResults) {
|
||||
hidl_vec<ParameterValue> parameters;
|
||||
Result res;
|
||||
ASSERT_OK(stream->getParameters(keys, returnIn(res, parameters)));
|
||||
@@ -924,8 +927,7 @@ TEST_IO_STREAM(RemoveNonExistingEffect,
|
||||
TEST_IO_STREAM(standby, "Make sure the stream can be put in stanby",
|
||||
ASSERT_OK(stream->standby())) // can not fail
|
||||
|
||||
static vector<Result> invalidStateOrNotSupported = {Result::INVALID_STATE,
|
||||
Result::NOT_SUPPORTED};
|
||||
static constexpr auto invalidStateOrNotSupported = {Result::INVALID_STATE, Result::NOT_SUPPORTED};
|
||||
|
||||
TEST_IO_STREAM(startNoMmap,
|
||||
"Starting a mmaped stream before mapping it should fail",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (C) 2017 The Android Open Source Project
|
||||
// Copyright (C) 2016 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* Copyright (C) 2016 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* Copyright (C) 2016 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.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_ASSERTOK_H
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <initializer_list>
|
||||
|
||||
#include <hidl/Status.h>
|
||||
|
||||
@@ -33,7 +33,6 @@ namespace detail {
|
||||
// This is a detail namespace, thus it is OK to import a class as nobody else is
|
||||
// allowed to use it
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::audio::V2_0::Result;
|
||||
|
||||
template <class T>
|
||||
inline ::testing::AssertionResult assertIsOk(const char* expr, const Return<T>& ret) {
|
||||
@@ -50,6 +49,7 @@ inline ::testing::AssertionResult continueIfIsOk(const char* expr, const Return<
|
||||
}
|
||||
|
||||
// Expect two equal Results
|
||||
template <class Result>
|
||||
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
|
||||
Result expected, Result result) {
|
||||
return ::testing::AssertionResult(expected == result)
|
||||
@@ -58,6 +58,7 @@ inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r
|
||||
}
|
||||
|
||||
// Expect two equal Results one being wrapped in an OK Return
|
||||
template <class Result>
|
||||
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
|
||||
Result expected, const Return<Result>& ret) {
|
||||
return continueIfIsOk(r_expr, ret,
|
||||
@@ -65,8 +66,10 @@ inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r
|
||||
}
|
||||
|
||||
// Expect a Result to be part of a list of Results
|
||||
template <class Result>
|
||||
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
|
||||
const std::vector<Result>& expected, Result result) {
|
||||
const std::initializer_list<Result>& expected,
|
||||
Result result) {
|
||||
if (std::find(expected.begin(), expected.end(), result) != expected.end()) {
|
||||
return ::testing::AssertionSuccess(); // result is in expected
|
||||
}
|
||||
@@ -77,8 +80,9 @@ inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r
|
||||
}
|
||||
|
||||
// Expect a Result wrapped in an OK Return to be part of a list of Results
|
||||
template <class Result>
|
||||
inline ::testing::AssertionResult assertResult(const char* e_expr, const char* r_expr,
|
||||
const std::vector<Result>& expected,
|
||||
const std::initializer_list<Result>& expected,
|
||||
const Return<Result>& ret) {
|
||||
return continueIfIsOk(r_expr, ret,
|
||||
[&] { return assertResult(e_expr, r_expr, expected, Result{ret}); });
|
||||
@@ -88,11 +92,13 @@ inline ::testing::AssertionResult assertOk(const char* expr, const Return<void>&
|
||||
return assertIsOk(expr, ret);
|
||||
}
|
||||
|
||||
template <class Result>
|
||||
inline ::testing::AssertionResult assertOk(const char* expr, Result result) {
|
||||
return ::testing::AssertionResult(result == Result::OK)
|
||||
<< "Expected success: " << expr << "\nActual: " << ::testing::PrintToString(result);
|
||||
}
|
||||
|
||||
template <class Result>
|
||||
inline ::testing::AssertionResult assertOk(const char* expr, const Return<Result>& ret) {
|
||||
return continueIfIsOk(expr, ret, [&] { return assertOk(expr, Result{ret}); });
|
||||
}
|
||||
|
||||
@@ -14,57 +14,46 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef AUDIO_HAL_VERSION
|
||||
#error "AUDIO_HAL_VERSION must be set before including this file."
|
||||
#endif
|
||||
|
||||
#ifndef ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_PRETTY_PRINT_AUDIO_TYPES_H
|
||||
#define ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_PRETTY_PRINT_AUDIO_TYPES_H
|
||||
|
||||
#include <iosfwd>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <android/hardware/audio/2.0/types.h>
|
||||
#include <android/hardware/audio/common/2.0/types.h>
|
||||
|
||||
/** @file Use HIDL generated toString methods to pretty print gtest errors */
|
||||
|
||||
namespace prettyPrintAudioTypesDetail {
|
||||
|
||||
// Print the value of an enum as hex
|
||||
template <class Enum>
|
||||
inline void printUnderlyingValue(Enum value, ::std::ostream* os) {
|
||||
*os << std::hex << " (0x" << static_cast<std::underlying_type_t<Enum>>(value) << ")";
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
/** @file Use HIDL generated toString methods to pretty print gtest errors
|
||||
* Unfortunately Gtest does not offer a template to specialize, only
|
||||
* overloading PrintTo.
|
||||
* @note that this overload can NOT be template because
|
||||
* the fallback is already template, resulting in ambiguity.
|
||||
* @note that the overload MUST be in the exact namespace
|
||||
* the type is declared in, as per the ADL rules.
|
||||
*/
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace audio {
|
||||
namespace V2_0 {
|
||||
|
||||
inline void PrintTo(const Result& result, ::std::ostream* os) {
|
||||
*os << toString(result);
|
||||
prettyPrintAudioTypesDetail::printUnderlyingValue(result, os);
|
||||
}
|
||||
#define DEFINE_GTEST_PRINT_TO(T) \
|
||||
inline void PrintTo(const T& val, ::std::ostream* os) { *os << toString(val); }
|
||||
|
||||
namespace AUDIO_HAL_VERSION {
|
||||
DEFINE_GTEST_PRINT_TO(Result)
|
||||
} // namespace AUDIO_HAL_VERSION
|
||||
|
||||
} // namespace V2_0
|
||||
namespace common {
|
||||
namespace V2_0 {
|
||||
|
||||
inline void PrintTo(const AudioConfig& config, ::std::ostream* os) {
|
||||
*os << toString(config);
|
||||
}
|
||||
|
||||
inline void PrintTo(const AudioDevice& device, ::std::ostream* os) {
|
||||
*os << toString(device);
|
||||
prettyPrintAudioTypesDetail::printUnderlyingValue(device, os);
|
||||
}
|
||||
|
||||
inline void PrintTo(const AudioChannelMask& channelMask, ::std::ostream* os) {
|
||||
*os << toString(channelMask);
|
||||
prettyPrintAudioTypesDetail::printUnderlyingValue(channelMask, os);
|
||||
}
|
||||
|
||||
} // namespace V2_0
|
||||
namespace AUDIO_HAL_VERSION {
|
||||
DEFINE_GTEST_PRINT_TO(AudioConfig)
|
||||
DEFINE_GTEST_PRINT_TO(AudioDevice)
|
||||
DEFINE_GTEST_PRINT_TO(AudioChannelMask)
|
||||
} // namespace AUDIO_HAL_VERSION
|
||||
} // namespace common
|
||||
|
||||
#undef DEFINE_GTEST_PRINT_TO
|
||||
|
||||
} // namespace audio
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
Reference in New Issue
Block a user