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 #ifndef MEDIA_LIBAUDIOUSECASEVALIDATION_TESTS_USECASEVALIDATOR_TEST_H_ 17 #define MEDIA_LIBAUDIOUSECASEVALIDATION_TESTS_USECASEVALIDATOR_TEST_H_ 18 19 #include <gtest/gtest.h> 20 21 #include <map> 22 #include <memory> 23 #include <mutex> 24 #include <set> 25 26 #include "media/UsecaseLookup.h" 27 #include "media/UsecaseValidator.h" 28 29 namespace android { 30 namespace media { 31 32 #define MEDIA_OUTPUT_FLAGS (audio_output_flags_t)(0xFFFFF &\ 33 ~(AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_MMAP_NOIRQ)) 34 35 #define GAME_OUTPUT_FLAGS (audio_output_flags_t)\ 36 (AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) 37 38 class TestCallback : public UsecaseValidator::AttributesChangedCallback { 39 public: TestCallback()40 TestCallback() { 41 m_iCallCnt = 0; 42 } ~TestCallback()43 virtual ~TestCallback() { } onAttributesChanged(audio_port_handle_t,const audio_attributes_t &)44 virtual void onAttributesChanged(audio_port_handle_t /*portId*/, 45 const audio_attributes_t& /*attributes*/) { 46 ++m_iCallCnt; 47 } 48 49 public: 50 int m_iCallCnt; 51 }; 52 53 class UsecaseLookupTest : public UsecaseLookup, public ::testing::Test { 54 public: UsecaseLookupTest()55 UsecaseLookupTest() { } 56 virtual ~UsecaseLookupTest() = default; 57 }; 58 59 class UsecaseValidatorTest : public ::testing::Test { 60 public: UsecaseValidatorTest()61 UsecaseValidatorTest() { 62 m_validator = createUsecaseValidator(); 63 } 64 65 virtual ~UsecaseValidatorTest() = default; 66 67 protected: 68 audio_io_handle_t testRegisterStream(bool outputFlagGame); 69 audio_port_handle_t testCreatePortId(audio_io_handle_t streamId); 70 error::Result<audio_attributes_t> testStartClient(audio_io_handle_t streamId, 71 audio_port_handle_t portId, 72 audio_attributes_t attributes); 73 error::Result<audio_attributes_t> testVerifyAudioAttributes(audio_io_handle_t streamId, 74 audio_usage_t usage); 75 76 std::unique_ptr<UsecaseValidator> m_validator; 77 }; 78 79 } // namespace media 80 } // namespace android 81 82 #endif // MEDIA_LIBAUDIOUSECASEVALIDATION_TESTS_USECASEVALIDATOR_TEST_H_ 83