Effect AIDL: Refactor effect capability with Range vts test cases

Disable dynamicsProcessing in presubmit temporary because it's currently
not following the range definition, and needs customize inRange method
implementationm which will be a followup.

Bug: 258124419
Test: atest --test-mapping hardware/interfaces/audio/aidl/vts:presubmit
Change-Id: Ib38145896d66b65c093c247c86a9fba76489ba84
diff --git a/audio/aidl/vts/VtsHalEnvironmentalReverbTargetTest.cpp b/audio/aidl/vts/VtsHalEnvironmentalReverbTargetTest.cpp
index 82c8757..fea41cb 100644
--- a/audio/aidl/vts/VtsHalEnvironmentalReverbTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalEnvironmentalReverbTargetTest.cpp
@@ -23,7 +23,6 @@
 
 using namespace android;
 
-using aidl::android::hardware::audio::effect::Capability;
 using aidl::android::hardware::audio::effect::Descriptor;
 using aidl::android::hardware::audio::effect::EnvironmentalReverb;
 using aidl::android::hardware::audio::effect::IEffect;
@@ -93,7 +92,8 @@
             // validate parameter
             Descriptor desc;
             ASSERT_STATUS(EX_NONE, mEffect->getDescriptor(&desc));
-            const bool valid = isTagInRange(it.first, it.second, desc);
+            const bool valid = isParameterValid<EnvironmentalReverb, Range::environmentalReverb>(
+                    it.second, desc);
             const binder_exception_t expected = valid ? EX_NONE : EX_ILLEGAL_ARGUMENT;
 
             // set
@@ -171,239 +171,6 @@
         mTags.push_back({EnvironmentalReverb::bypass, er});
     }
 
-    bool isTagInRange(const EnvironmentalReverb::Tag& tag, const EnvironmentalReverb er,
-                      const Descriptor& desc) const {
-        const EnvironmentalReverb::Capability& erCap =
-                desc.capability.get<Capability::environmentalReverb>();
-        switch (tag) {
-            case EnvironmentalReverb::roomLevelMb: {
-                int roomLevel = er.get<EnvironmentalReverb::roomLevelMb>();
-                return isRoomLevelInRange(erCap, roomLevel);
-            }
-            case EnvironmentalReverb::roomHfLevelMb: {
-                int roomHfLevel = er.get<EnvironmentalReverb::roomHfLevelMb>();
-                return isRoomHfLevelInRange(erCap, roomHfLevel);
-            }
-            case EnvironmentalReverb::decayTimeMs: {
-                int decayTime = er.get<EnvironmentalReverb::decayTimeMs>();
-                return isDecayTimeInRange(erCap, decayTime);
-            }
-            case EnvironmentalReverb::decayHfRatioPm: {
-                int decayHfRatio = er.get<EnvironmentalReverb::decayHfRatioPm>();
-                return isDecayHfRatioInRange(erCap, decayHfRatio);
-            }
-            case EnvironmentalReverb::levelMb: {
-                int level = er.get<EnvironmentalReverb::levelMb>();
-                return isLevelInRange(erCap, level);
-            }
-            case EnvironmentalReverb::delayMs: {
-                int delay = er.get<EnvironmentalReverb::delayMs>();
-                return isDelayInRange(erCap, delay);
-            }
-            case EnvironmentalReverb::diffusionPm: {
-                int diffusion = er.get<EnvironmentalReverb::diffusionPm>();
-                return isDiffusionInRange(erCap, diffusion);
-            }
-            case EnvironmentalReverb::densityPm: {
-                int density = er.get<EnvironmentalReverb::densityPm>();
-                return isDensityInRange(erCap, density);
-            }
-            case EnvironmentalReverb::bypass: {
-                return true;
-            }
-            default:
-                return false;
-        }
-        return false;
-    }
-
-    bool isRoomLevelInRange(const EnvironmentalReverb::Capability& cap, int roomLevel) const {
-        return roomLevel >= cap.minRoomLevelMb && roomLevel <= cap.maxRoomLevelMb;
-    }
-
-    bool isRoomHfLevelInRange(const EnvironmentalReverb::Capability& cap, int roomHfLevel) const {
-        return roomHfLevel >= cap.minRoomHfLevelMb && roomHfLevel <= cap.maxRoomHfLevelMb;
-    }
-
-    bool isDecayTimeInRange(const EnvironmentalReverb::Capability& cap, int decayTime) const {
-        return decayTime >= 0 && decayTime <= cap.maxDecayTimeMs;
-    }
-
-    bool isDecayHfRatioInRange(const EnvironmentalReverb::Capability& cap, int decayHfRatio) const {
-        return decayHfRatio >= cap.minDecayHfRatioPm && decayHfRatio <= cap.maxDecayHfRatioPm;
-    }
-
-    bool isLevelInRange(const EnvironmentalReverb::Capability& cap, int level) const {
-        return level >= cap.minLevelMb && level <= cap.maxLevelMb;
-    }
-
-    bool isDelayInRange(const EnvironmentalReverb::Capability& cap, int delay) const {
-        return delay >= 0 && delay <= cap.maxDelayMs;
-    }
-
-    bool isDiffusionInRange(const EnvironmentalReverb::Capability& cap, int diffusion) const {
-        return diffusion >= 0 && diffusion <= cap.maxDiffusionPm;
-    }
-
-    bool isDensityInRange(const EnvironmentalReverb::Capability& cap, int density) const {
-        return density >= 0 && density <= cap.maxDensityPm;
-    }
-
-    static std::unordered_set<int> getRoomLevelValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        int minRoomLevelMb = std::numeric_limits<int>::max();
-        int maxRoomLevelMb = std::numeric_limits<int>::min();
-        for (const auto& it : descList) {
-            maxRoomLevelMb = std::max(
-                    it.second.capability.get<Capability::environmentalReverb>().maxRoomLevelMb,
-                    maxRoomLevelMb);
-            minRoomLevelMb = std::min(
-                    it.second.capability.get<Capability::environmentalReverb>().minRoomLevelMb,
-                    minRoomLevelMb);
-        }
-        return {std::numeric_limits<int>::min(),        minRoomLevelMb - 1, minRoomLevelMb,
-                (minRoomLevelMb + maxRoomLevelMb) >> 1, maxRoomLevelMb,     maxRoomLevelMb + 1,
-                std::numeric_limits<int>::max()};
-    }
-
-    static std::unordered_set<int> getRoomHfLevelValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        int minRoomHfLevelMb = std::numeric_limits<int>::max();
-        int maxRoomHfLevelMb = std::numeric_limits<int>::min();
-        for (const auto& it : descList) {
-            maxRoomHfLevelMb = std::max(
-                    it.second.capability.get<Capability::environmentalReverb>().maxRoomHfLevelMb,
-                    maxRoomHfLevelMb);
-            minRoomHfLevelMb = std::min(
-                    it.second.capability.get<Capability::environmentalReverb>().minRoomHfLevelMb,
-                    minRoomHfLevelMb);
-        }
-        return {std::numeric_limits<int>::min(),
-                minRoomHfLevelMb - 1,
-                minRoomHfLevelMb,
-                (minRoomHfLevelMb + maxRoomHfLevelMb) >> 1,
-                maxRoomHfLevelMb,
-                maxRoomHfLevelMb + 1,
-                std::numeric_limits<int>::max()};
-    }
-
-    static std::unordered_set<int> getDecayTimeValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        const auto max = std::max_element(
-                descList.begin(), descList.end(),
-                [](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
-                   const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
-                    return a.second.capability.get<Capability::environmentalReverb>()
-                                   .maxDecayTimeMs <
-                           b.second.capability.get<Capability::environmentalReverb>()
-                                   .maxDecayTimeMs;
-                });
-        if (max == descList.end()) {
-            return {0};
-        }
-        int maxDecayTimeMs =
-                max->second.capability.get<Capability::environmentalReverb>().maxDecayTimeMs;
-        return {-1, 0, maxDecayTimeMs >> 1, maxDecayTimeMs - 1, maxDecayTimeMs, maxDecayTimeMs + 1};
-    }
-
-    static std::unordered_set<int> getDecayHfRatioValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        int minDecayHfRatioPm = std::numeric_limits<int>::max();
-        int maxDecayHfRatioPm = std::numeric_limits<int>::min();
-        for (const auto& it : descList) {
-            maxDecayHfRatioPm = std::max(
-                    it.second.capability.get<Capability::environmentalReverb>().maxDecayHfRatioPm,
-                    maxDecayHfRatioPm);
-            minDecayHfRatioPm = std::min(
-                    it.second.capability.get<Capability::environmentalReverb>().minDecayHfRatioPm,
-                    minDecayHfRatioPm);
-        }
-        return {std::numeric_limits<int>::min(),
-                minDecayHfRatioPm - 1,
-                minDecayHfRatioPm,
-                (minDecayHfRatioPm + maxDecayHfRatioPm) >> 1,
-                maxDecayHfRatioPm,
-                maxDecayHfRatioPm + 1,
-                std::numeric_limits<int>::max()};
-    }
-
-    static std::unordered_set<int> getLevelValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        int minLevelMb = std::numeric_limits<int>::max();
-        int maxLevelMb = std::numeric_limits<int>::min();
-        for (const auto& it : descList) {
-            maxLevelMb =
-                    std::max(it.second.capability.get<Capability::environmentalReverb>().maxLevelMb,
-                             maxLevelMb);
-            minLevelMb =
-                    std::min(it.second.capability.get<Capability::environmentalReverb>().minLevelMb,
-                             minLevelMb);
-        }
-        return {std::numeric_limits<int>::min(), minLevelMb - 1, minLevelMb,
-                (minLevelMb + maxLevelMb) >> 1,  maxLevelMb,     maxLevelMb + 1,
-                std::numeric_limits<int>::max()};
-    }
-
-    static std::unordered_set<int> getDelayValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        const auto max = std::max_element(
-                descList.begin(), descList.end(),
-                [](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
-                   const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
-                    return a.second.capability.get<Capability::environmentalReverb>().maxDelayMs <
-                           b.second.capability.get<Capability::environmentalReverb>().maxDelayMs;
-                });
-        if (max == descList.end()) {
-            return {0};
-        }
-        int maxDelayMs = max->second.capability.get<Capability::environmentalReverb>().maxDelayMs;
-        return {-1, 0, maxDelayMs >> 1, maxDelayMs - 1, maxDelayMs, maxDelayMs + 1};
-    }
-
-    static std::unordered_set<int> getDiffusionValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        const auto max = std::max_element(
-                descList.begin(), descList.end(),
-                [](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
-                   const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
-                    return a.second.capability.get<Capability::environmentalReverb>()
-                                   .maxDiffusionPm <
-                           b.second.capability.get<Capability::environmentalReverb>()
-                                   .maxDiffusionPm;
-                });
-        if (max == descList.end()) {
-            return {0};
-        }
-        int maxDiffusionPm =
-                max->second.capability.get<Capability::environmentalReverb>().maxDiffusionPm;
-        return {-1, 0, maxDiffusionPm >> 1, maxDiffusionPm - 1, maxDiffusionPm, maxDiffusionPm + 1};
-    }
-
-    static std::unordered_set<int> getDensityValues() {
-        auto descList = EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
-                                                                     kEnvReverbTypeUUID);
-        const auto max = std::max_element(
-                descList.begin(), descList.end(),
-                [](const std::pair<std::shared_ptr<IFactory>, Descriptor>& a,
-                   const std::pair<std::shared_ptr<IFactory>, Descriptor>& b) {
-                    return a.second.capability.get<Capability::environmentalReverb>().maxDensityPm <
-                           b.second.capability.get<Capability::environmentalReverb>().maxDensityPm;
-                });
-        if (max == descList.end()) {
-            return {0};
-        }
-        int maxDensityPm =
-                max->second.capability.get<Capability::environmentalReverb>().maxDensityPm;
-        return {-1, 0, maxDensityPm >> 1, maxDensityPm - 1, maxDensityPm, maxDensityPm + 1};
-    }
-
   private:
     std::vector<std::pair<EnvironmentalReverb::Tag, EnvironmentalReverb>> mTags;
     void CleanUp() { mTags.clear(); }
@@ -428,11 +195,17 @@
     SetAndGetReverbParameters();
 }
 
+std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> kDescPair;
+
 INSTANTIATE_TEST_SUITE_P(
         EnvironmentalReverbTest, EnvironmentalReverbRoomLevelTest,
-        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
-                                   IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getRoomLevelValues())),
+        ::testing::Combine(
+                testing::ValuesIn(kDescPair = EffectFactoryHelper::getAllEffectDescriptors(
+                                          IFactory::descriptor, kEnvReverbTypeUUID)),
+                testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
+                                                                Range::environmentalReverb,
+                                                                EnvironmentalReverb::roomLevelMb>(
+                        kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbRoomLevelTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string roomLevel = std::to_string(std::get<1>(info.param));
@@ -467,9 +240,13 @@
 
 INSTANTIATE_TEST_SUITE_P(
         EnvironmentalReverbTest, EnvironmentalReverbRoomHfLevelTest,
-        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
-                                   IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getRoomHfLevelValues())),
+        ::testing::Combine(
+                testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+                                                                               kEnvReverbTypeUUID)),
+                testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
+                                                                Range::environmentalReverb,
+                                                                EnvironmentalReverb::roomHfLevelMb>(
+                        kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbRoomHfLevelTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string roomHfLevel = std::to_string(std::get<1>(info.param));
@@ -504,9 +281,13 @@
 
 INSTANTIATE_TEST_SUITE_P(
         EnvironmentalReverbTest, EnvironmentalReverbDecayTimeTest,
-        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
-                                   IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getDecayTimeValues())),
+        ::testing::Combine(
+                testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+                                                                               kEnvReverbTypeUUID)),
+                testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
+                                                                Range::environmentalReverb,
+                                                                EnvironmentalReverb::decayTimeMs>(
+                        kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbDecayTimeTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string decayTime = std::to_string(std::get<1>(info.param));
@@ -543,7 +324,10 @@
         EnvironmentalReverbTest, EnvironmentalReverbDecayHfRatioTest,
         ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
                                    IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getDecayHfRatioValues())),
+                           testing::ValuesIn(EffectHelper::getTestValueSet<
+                                             EnvironmentalReverb, int, Range::environmentalReverb,
+                                             EnvironmentalReverb::decayHfRatioPm>(
+                                   kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbDecayHfRatioTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string decayHfRatio = std::to_string(std::get<1>(info.param));
@@ -579,9 +363,13 @@
 
 INSTANTIATE_TEST_SUITE_P(
         EnvironmentalReverbTest, EnvironmentalReverbLevelTest,
-        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
-                                   IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getLevelValues())),
+        ::testing::Combine(
+                testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+                                                                               kEnvReverbTypeUUID)),
+                testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
+                                                                Range::environmentalReverb,
+                                                                EnvironmentalReverb::levelMb>(
+                        kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbDecayHfRatioTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string level = std::to_string(std::get<1>(info.param));
@@ -616,9 +404,13 @@
 
 INSTANTIATE_TEST_SUITE_P(
         EnvironmentalReverbTest, EnvironmentalReverbDelayTest,
-        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
-                                   IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getDelayValues())),
+        ::testing::Combine(
+                testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+                                                                               kEnvReverbTypeUUID)),
+                testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
+                                                                Range::environmentalReverb,
+                                                                EnvironmentalReverb::delayMs>(
+                        kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbDelayTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string delay = std::to_string(std::get<1>(info.param));
@@ -653,9 +445,13 @@
 
 INSTANTIATE_TEST_SUITE_P(
         EnvironmentalReverbTest, EnvironmentalReverbDiffusionTest,
-        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
-                                   IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getDiffusionValues())),
+        ::testing::Combine(
+                testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+                                                                               kEnvReverbTypeUUID)),
+                testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
+                                                                Range::environmentalReverb,
+                                                                EnvironmentalReverb::diffusionPm>(
+                        kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbDiffusionTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string diffusion = std::to_string(std::get<1>(info.param));
@@ -690,9 +486,13 @@
 
 INSTANTIATE_TEST_SUITE_P(
         EnvironmentalReverbTest, EnvironmentalReverbDensityTest,
-        ::testing::Combine(testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(
-                                   IFactory::descriptor, kEnvReverbTypeUUID)),
-                           testing::ValuesIn(EnvironmentalReverbHelper::getDensityValues())),
+        ::testing::Combine(
+                testing::ValuesIn(EffectFactoryHelper::getAllEffectDescriptors(IFactory::descriptor,
+                                                                               kEnvReverbTypeUUID)),
+                testing::ValuesIn(EffectHelper::getTestValueSet<EnvironmentalReverb, int,
+                                                                Range::environmentalReverb,
+                                                                EnvironmentalReverb::densityPm>(
+                        kDescPair, EffectHelper::expandTestValueBasic<int>))),
         [](const testing::TestParamInfo<EnvironmentalReverbDensityTest::ParamType>& info) {
             auto descriptor = std::get<0>(info.param).second;
             std::string density = std::to_string(std::get<1>(info.param));