Merge "NNAPI VTS update in response to utility function change"
diff --git a/audio/common/all-versions/test/utility/include/utility/AssertOk.h b/audio/common/all-versions/test/utility/include/utility/AssertOk.h
index 5ac2fdc..03a6305 100644
--- a/audio/common/all-versions/test/utility/include/utility/AssertOk.h
+++ b/audio/common/all-versions/test/utility/include/utility/AssertOk.h
@@ -114,6 +114,27 @@
#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
diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
index 0778720..6c51c1b 100644
--- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
+++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h
@@ -408,11 +408,7 @@
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 @@
////////////////////////////// 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 @@
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 @@
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 @@
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 @@
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. */