audio: Fix AudioPatchTest/AudioModulePatch#UpdateInvalidPatchId VTS test

The test was using '0' as an "invalid" patch ID value, however
this value is valid in the context of 'IModule.setAudioPatch'
method and means "create a new patch and allocate and ID for it".

Bug: 328010709
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Icd33f3cbd1602ec5aa162fa72fc3ddd59ccffbef
This commit is contained in:
Mikhail Naganov 2024-04-18 13:18:09 -07:00
parent a62c5df181
commit 8dd96d4c41

View file

@ -133,13 +133,23 @@ auto findAny(const std::vector<T>& v, const std::set<int32_t>& ids) {
}
template <typename C>
std::vector<int32_t> GetNonExistentIds(const C& allIds) {
std::vector<int32_t> GetNonExistentIds(const C& allIds, bool includeZero = true) {
if (allIds.empty()) {
return std::vector<int32_t>{-1, 0, 1};
return includeZero ? std::vector<int32_t>{-1, 0, 1} : std::vector<int32_t>{-1, 1};
}
std::vector<int32_t> nonExistentIds;
nonExistentIds.push_back(*std::min_element(allIds.begin(), allIds.end()) - 1);
nonExistentIds.push_back(*std::max_element(allIds.begin(), allIds.end()) + 1);
if (auto value = *std::min_element(allIds.begin(), allIds.end()) - 1;
includeZero || value != 0) {
nonExistentIds.push_back(value);
} else {
nonExistentIds.push_back(value - 1);
}
if (auto value = *std::max_element(allIds.begin(), allIds.end()) + 1;
includeZero || value != 0) {
nonExistentIds.push_back(value);
} else {
nonExistentIds.push_back(value + 1);
}
return nonExistentIds;
}
@ -4204,7 +4214,7 @@ class AudioModulePatch : public AudioCoreModule {
// Then use the same patch setting, except for having an invalid ID.
std::set<int32_t> patchIds;
ASSERT_NO_FATAL_FAILURE(GetAllPatchIds(&patchIds));
for (const auto patchId : GetNonExistentIds(patchIds)) {
for (const auto patchId : GetNonExistentIds(patchIds, false /*includeZero*/)) {
AudioPatch patchWithNonExistendId = patch.get();
patchWithNonExistendId.id = patchId;
EXPECT_STATUS(EX_ILLEGAL_ARGUMENT,