Shraddha Basantwani | 68041ca | 2022-11-04 15:13:32 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <aidl/Vintf.h> |
| 18 | |
| 19 | #define LOG_TAG "VtsHalLoudnessEnhancerTest" |
| 20 | |
| 21 | #include <Utils.h> |
| 22 | #include "EffectHelper.h" |
| 23 | |
| 24 | using namespace android; |
| 25 | |
| 26 | using aidl::android::hardware::audio::effect::Capability; |
| 27 | using aidl::android::hardware::audio::effect::Descriptor; |
| 28 | using aidl::android::hardware::audio::effect::IEffect; |
| 29 | using aidl::android::hardware::audio::effect::IFactory; |
| 30 | using aidl::android::hardware::audio::effect::LoudnessEnhancer; |
| 31 | using aidl::android::hardware::audio::effect::LoudnessEnhancerTypeUUID; |
| 32 | using aidl::android::hardware::audio::effect::Parameter; |
| 33 | |
| 34 | /** |
| 35 | * Here we focus on specific parameter checking, general IEffect interfaces testing performed in |
| 36 | * VtsAudioEffectTargetTest. |
| 37 | */ |
| 38 | enum ParamName { PARAM_INSTANCE_NAME, PARAM_GAIN_MB }; |
| 39 | using LoudnessEnhancerParamTestParam = std::tuple<std::string, int>; |
| 40 | |
| 41 | // Every int 32 bit value is a valid gain, so testing the corner cases and one regular value. |
| 42 | // TODO : Update the test values once range/capability is updated by implementation. |
| 43 | const std::vector<int> kGainMbValues = {std::numeric_limits<int>::min(), 100, |
| 44 | std::numeric_limits<int>::max()}; |
| 45 | |
| 46 | class LoudnessEnhancerParamTest : public ::testing::TestWithParam<LoudnessEnhancerParamTestParam>, |
| 47 | public EffectHelper { |
| 48 | public: |
| 49 | LoudnessEnhancerParamTest() |
| 50 | : EffectHelper(std::get<PARAM_INSTANCE_NAME>(GetParam())), |
| 51 | mParamGainMb(std::get<PARAM_GAIN_MB>(GetParam())) {} |
| 52 | |
| 53 | void SetUp() override { |
| 54 | CreateEffectsWithUUID(LoudnessEnhancerTypeUUID); |
| 55 | initParamCommonFormat(); |
| 56 | initParamCommon(); |
| 57 | initParamSpecific(); |
| 58 | OpenEffects(LoudnessEnhancerTypeUUID); |
| 59 | SCOPED_TRACE(testing::Message() << "gainMb: " << mParamGainMb); |
| 60 | } |
| 61 | |
| 62 | void TearDown() override { |
| 63 | CloseEffects(); |
| 64 | DestroyEffects(); |
| 65 | CleanUp(); |
| 66 | } |
| 67 | |
| 68 | int mParamGainMb = 0; |
| 69 | |
| 70 | void SetAndGetLoudnessEnhancerParameters() { |
| 71 | auto functor = [&](const std::shared_ptr<IEffect>& effect) { |
| 72 | for (auto& it : mTags) { |
| 73 | auto& tag = it.first; |
| 74 | auto& le = it.second; |
| 75 | |
| 76 | // set parameter |
| 77 | Parameter expectParam; |
| 78 | Parameter::Specific specific; |
| 79 | specific.set<Parameter::Specific::loudnessEnhancer>(le); |
| 80 | expectParam.set<Parameter::specific>(specific); |
| 81 | // All values are valid, set parameter should succeed |
| 82 | EXPECT_STATUS(EX_NONE, effect->setParameter(expectParam)) << expectParam.toString(); |
| 83 | |
| 84 | // get parameter |
| 85 | Parameter getParam; |
| 86 | Parameter::Id id; |
| 87 | LoudnessEnhancer::Id leId; |
| 88 | leId.set<LoudnessEnhancer::Id::commonTag>(tag); |
| 89 | id.set<Parameter::Id::loudnessEnhancerTag>(leId); |
| 90 | EXPECT_STATUS(EX_NONE, effect->getParameter(id, &getParam)); |
| 91 | |
| 92 | EXPECT_EQ(expectParam, getParam); |
| 93 | } |
| 94 | }; |
| 95 | EXPECT_NO_FATAL_FAILURE(ForEachEffect(functor)); |
| 96 | } |
| 97 | |
| 98 | void addGainMbParam(int gainMb) { |
| 99 | LoudnessEnhancer le; |
| 100 | le.set<LoudnessEnhancer::gainMb>(gainMb); |
| 101 | mTags.push_back({LoudnessEnhancer::gainMb, le}); |
| 102 | } |
| 103 | |
| 104 | private: |
| 105 | std::vector<std::pair<LoudnessEnhancer::Tag, LoudnessEnhancer>> mTags; |
| 106 | |
| 107 | void initParamSpecific() { |
| 108 | LoudnessEnhancer le; |
| 109 | le.set<LoudnessEnhancer::gainMb>(0); |
| 110 | Parameter::Specific specific; |
| 111 | specific.set<Parameter::Specific::loudnessEnhancer>(le); |
| 112 | setSpecific(specific); |
| 113 | } |
| 114 | |
| 115 | void CleanUp() { mTags.clear(); } |
| 116 | }; |
| 117 | |
| 118 | TEST_P(LoudnessEnhancerParamTest, SetAndGetGainMb) { |
| 119 | EXPECT_NO_FATAL_FAILURE(addGainMbParam(mParamGainMb)); |
| 120 | SetAndGetLoudnessEnhancerParameters(); |
| 121 | } |
| 122 | |
| 123 | INSTANTIATE_TEST_SUITE_P( |
| 124 | LoudnessEnhancerTest, LoudnessEnhancerParamTest, |
| 125 | ::testing::Combine( |
| 126 | testing::ValuesIn(android::getAidlHalInstanceNames(IFactory::descriptor)), |
| 127 | testing::ValuesIn(kGainMbValues)), |
| 128 | [](const testing::TestParamInfo<LoudnessEnhancerParamTest::ParamType>& info) { |
| 129 | std::string instance = std::get<PARAM_INSTANCE_NAME>(info.param); |
| 130 | std::string gainMb = std::to_string(std::get<PARAM_GAIN_MB>(info.param)); |
| 131 | |
| 132 | std::string name = instance + "_gainMb" + gainMb; |
| 133 | std::replace_if( |
| 134 | name.begin(), name.end(), [](const char c) { return !std::isalnum(c); }, '_'); |
| 135 | return name; |
| 136 | }); |
| 137 | |
| 138 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(LoudnessEnhancerParamTest); |
| 139 | |
| 140 | int main(int argc, char** argv) { |
| 141 | ::testing::InitGoogleTest(&argc, argv); |
| 142 | ABinderProcess_setThreadPoolMaxThreadCount(1); |
| 143 | ABinderProcess_startThreadPool(); |
| 144 | return RUN_ALL_TESTS(); |
| 145 | } |