mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 22:04:26 +00:00
Audio Hal VTS: Refactor ASSERT_RESULT helper
ASSERT_INVALID_ARGUMENTS was a macro that asserted that a given Result or Return contained INVALID_ARGUMENT. The problem was that a result can have lots of other values like INVALID_STATE or NOT_SUPPORTED. Additionally not all test expect only one possible result. Introduce two overload of ASSERT_RESULT() The first one takes an expected Result value and compare it to the obtained one. The second take a list and expect the obtained one to be in this list. Test: run the test on target Bug: 34170075 Change-Id: I798729f27f723c98292610bfb43dbdb2724ec2ca Signed-off-by: Kevin Rocard <krocard@google.com>
This commit is contained in:
@@ -217,7 +217,7 @@ protected:
|
||||
for (Property invalidValue : invalidValues) {
|
||||
SCOPED_TRACE("Try to set " + propertyName + " with the invalid value " +
|
||||
testing::PrintToString(invalidValue));
|
||||
EXPECT_INVALID_ARGUMENTS((device.get()->*setter)(invalidValue));
|
||||
EXPECT_RESULT(Result::INVALID_ARGUMENTS, (device.get()->*setter)(invalidValue));
|
||||
}
|
||||
|
||||
ASSERT_OK((device.get()->*setter)(initialValue)); // restore initial value
|
||||
@@ -714,7 +714,7 @@ TEST_F(AudioPrimaryHidlTest, setVoiceVolume) {
|
||||
SCOPED_TRACE("volume=" + to_string(volume));
|
||||
// FIXME: NAN should never be accepted
|
||||
// FIXME: Missing api doc. What should the impl do if the volume is outside [0,1] ?
|
||||
ASSERT_INVALID_ARGUMENTS(device->setVoiceVolume(volume));
|
||||
ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setVoiceVolume(volume));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -728,7 +728,7 @@ TEST_F(AudioPrimaryHidlTest, setMode) {
|
||||
}
|
||||
|
||||
// FIXME: Missing api doc. What should the impl do if the mode is invalid ?
|
||||
ASSERT_INVALID_ARGUMENTS(device->setMode(AudioMode::INVALID));
|
||||
ASSERT_RESULT(Result::INVALID_ARGUMENTS, device->setMode(AudioMode::INVALID));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,39 +13,59 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <hidl/Status.h>
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline void assertOk(::android::hardware::Return<void> ret) {
|
||||
// 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;
|
||||
|
||||
inline void assertResult(Result expected, Result result) {
|
||||
ASSERT_EQ(expected, result);
|
||||
}
|
||||
|
||||
inline void assertResult(Result expected, Return<Result> ret) {
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
Result result = ret;
|
||||
assertResult(expected, result);
|
||||
}
|
||||
|
||||
inline void assertResult(std::vector<Result> expected, Result result) {
|
||||
if (std::find(expected.begin(), expected.end(), result) != expected.end()) {
|
||||
return; // result is in expected
|
||||
}
|
||||
FAIL() << "Expected result " << ::testing::PrintToString(result)
|
||||
<< " to be one of " << ::testing::PrintToString(expected);
|
||||
}
|
||||
|
||||
inline void assertResult(std::vector<Result> expected, Return<Result> ret) {
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
Result result = ret;
|
||||
assertResult(expected, result);
|
||||
}
|
||||
|
||||
inline void assertOk(Return<void> ret) {
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
}
|
||||
|
||||
inline void assertOk(::android::hardware::audio::V2_0::Result result) {
|
||||
ASSERT_EQ(decltype(result)::OK, result);
|
||||
inline void assertOk(Result result) {
|
||||
assertResult(Result::OK, result);
|
||||
}
|
||||
|
||||
inline void assertOk(::android::hardware::Return<::android::hardware::audio::V2_0::Result> ret) {
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
::android::hardware::audio::V2_0::Result result = ret;
|
||||
assertOk(result);
|
||||
inline void assertOk(Return<Result> ret) {
|
||||
assertResult(Result::OK, std::move(ret));
|
||||
}
|
||||
|
||||
inline void assertInvalidArguments(::android::hardware::audio::V2_0::Result result) {
|
||||
ASSERT_EQ(decltype(result)::INVALID_ARGUMENTS, result);
|
||||
}
|
||||
|
||||
inline void assertInvalidArguments(
|
||||
::android::hardware::Return<::android::hardware::audio::V2_0::Result> ret) {
|
||||
ASSERT_TRUE(ret.isOk());
|
||||
::android::hardware::audio::V2_0::Result result = ret;
|
||||
assertInvalidArguments(result);
|
||||
}
|
||||
}
|
||||
|
||||
// Test anything provided is and contains only OK
|
||||
#define ASSERT_OK(ret) ASSERT_NO_FATAL_FAILURE(detail::assertOk(ret))
|
||||
#define EXPECT_OK(ret) EXPECT_NO_FATAL_FAILURE(detail::assertOk(ret))
|
||||
|
||||
#define ASSERT_INVALID_ARGUMENTS(ret) ASSERT_NO_FATAL_FAILURE(detail::assertInvalidArguments(ret))
|
||||
#define EXPECT_INVALID_ARGUMENTS(ret) EXPECT_NO_FATAL_FAILURE(detail::assertInvalidArguments(ret))
|
||||
#define ASSERT_RESULT(expected, ret) ASSERT_NO_FATAL_FAILURE(detail::assertResult(expected, ret))
|
||||
#define EXPECT_RESULT(expected, ret) ASSERT_NO_FATAL_FAILURE(detail::assertResult(expected, ret))
|
||||
|
||||
Reference in New Issue
Block a user