Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 368b157b authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Cherrypicker Worker
Browse files

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
(cherry picked from https://android-review.googlesource.com/q/commit:8dd96d4c417f309824ac006cedc15118fd7a1363)
Merged-In: Icd33f3cbd1602ec5aa162fa72fc3ddd59ccffbef
Change-Id: Icd33f3cbd1602ec5aa162fa72fc3ddd59ccffbef
24D1-dev is based on 24Q2-release. Therefore, we merged this CL to 24D1-dev.
parent d2c99594
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -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;
}

@@ -4206,7 +4216,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,