audio: Extract utility functions
Move common code out of the test source. Test: atest VtsHalAudioV5_0TargetTest Change-Id: I86cf399029a0a5f3f08c7e82713ae62df03dee3f
This commit is contained in:
parent
aa0e7d66f7
commit
d306cccd0b
2 changed files with 25 additions and 36 deletions
|
@ -114,6 +114,27 @@ inline ::testing::AssertionResult assertOk(const char* expr, const Return<Result
|
|||
#define ASSERT_RESULT(expected, ret) ASSERT_PRED_FORMAT2(detail::assertResult, expected, ret)
|
||||
#define EXPECT_RESULT(expected, ret) EXPECT_PRED_FORMAT2(detail::assertResult, expected, ret)
|
||||
|
||||
/** Unpack the provided result.
|
||||
* If the result is not OK, register a failure and return the default initializer value. */
|
||||
template <class R>
|
||||
static R extract(const Return<R>& ret) {
|
||||
if (!ret.isOk()) {
|
||||
EXPECT_IS_OK(ret);
|
||||
return R{};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <class Result, class Value>
|
||||
static void expectValueOrFailure(Result res, Value expectedValue, Value actualValue,
|
||||
Result expectedFailure) {
|
||||
if (res == Result::OK) {
|
||||
ASSERT_EQ(expectedValue, actualValue);
|
||||
} else {
|
||||
ASSERT_EQ(expectedFailure, res) << "Unexpected result " << toString(res);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace utility
|
||||
} // namespace test
|
||||
} // namespace common
|
||||
|
|
|
@ -408,11 +408,7 @@ TEST_F(FloatAccessorPrimaryHidlTest, MasterVolumeTest) {
|
|||
|
||||
class AudioPatchPrimaryHidlTest : public AudioPrimaryHidlTest {
|
||||
protected:
|
||||
bool areAudioPatchesSupported() {
|
||||
auto result = device->supportsAudioPatches();
|
||||
EXPECT_IS_OK(result);
|
||||
return result;
|
||||
}
|
||||
bool areAudioPatchesSupported() { return extract(device->supportsAudioPatches()); }
|
||||
};
|
||||
|
||||
TEST_F(AudioPatchPrimaryHidlTest, AudioPatches) {
|
||||
|
@ -829,17 +825,6 @@ INSTANTIATE_TEST_CASE_P(
|
|||
////////////////////////////// IStream getters ///////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Unpack the provided result.
|
||||
* If the result is not OK, register a failure and return an undefined value. */
|
||||
template <class R>
|
||||
static R extract(Return<R> ret) {
|
||||
if (!ret.isOk()) {
|
||||
EXPECT_IS_OK(ret);
|
||||
return R{};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Could not find a way to write a test for two parametrized class fixure
|
||||
* thus use this macro do duplicate tests for Input and Output stream */
|
||||
#define TEST_IO_STREAM(test_name, documentation, code) \
|
||||
|
@ -1189,11 +1174,7 @@ TEST_P(OutputStreamTest, PrepareForWritingCheckOverflow) {
|
|||
struct Capability {
|
||||
Capability(IStreamOut* stream) {
|
||||
EXPECT_OK(stream->supportsPauseAndResume(returnIn(pause, resume)));
|
||||
auto ret = stream->supportsDrain();
|
||||
EXPECT_IS_OK(ret);
|
||||
if (ret.isOk()) {
|
||||
drain = ret;
|
||||
}
|
||||
drain = extract(stream->supportsDrain());
|
||||
}
|
||||
bool pause = false;
|
||||
bool resume = false;
|
||||
|
@ -1205,19 +1186,6 @@ TEST_P(OutputStreamTest, SupportsPauseAndResumeAndDrain) {
|
|||
Capability(stream.get());
|
||||
}
|
||||
|
||||
template <class Value>
|
||||
static void checkInvalidStateOr0(Result res, Value value) {
|
||||
switch (res) {
|
||||
case Result::INVALID_STATE:
|
||||
break;
|
||||
case Result::OK:
|
||||
ASSERT_EQ(0U, value);
|
||||
break;
|
||||
default:
|
||||
FAIL() << "Unexpected result " << toString(res);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(OutputStreamTest, GetRenderPosition) {
|
||||
doc::test("A new stream render position should be 0 or INVALID_STATE");
|
||||
uint32_t dspFrames;
|
||||
|
@ -1226,7 +1194,7 @@ TEST_P(OutputStreamTest, GetRenderPosition) {
|
|||
doc::partialTest("getRenderPosition is not supported");
|
||||
return;
|
||||
}
|
||||
checkInvalidStateOr0(res, dspFrames);
|
||||
expectValueOrFailure(res, 0U, dspFrames, Result::INVALID_STATE);
|
||||
}
|
||||
|
||||
TEST_P(OutputStreamTest, GetNextWriteTimestamp) {
|
||||
|
@ -1237,7 +1205,7 @@ TEST_P(OutputStreamTest, GetNextWriteTimestamp) {
|
|||
doc::partialTest("getNextWriteTimestamp is not supported");
|
||||
return;
|
||||
}
|
||||
checkInvalidStateOr0(res, timestampUs);
|
||||
expectValueOrFailure(res, uint64_t{0}, timestampUs, Result::INVALID_STATE);
|
||||
}
|
||||
|
||||
/** Stub implementation of out stream callback. */
|
||||
|
|
Loading…
Reference in a new issue