Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 <gtest/gtest.h> |
| 18 | |
| 19 | #include "AudioPolicyTestClient.h" |
| 20 | #include "AudioPolicyTestManager.h" |
| 21 | |
| 22 | using namespace android; |
| 23 | |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame^] | 24 | TEST(AudioPolicyManager, InitFailure) { |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 25 | AudioPolicyTestClient client; |
| 26 | AudioPolicyTestManager manager(&client); |
| 27 | manager.getConfig().setDefault(); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame^] | 28 | // Since the default client fails to open anything, |
| 29 | // APM should indicate that the initialization didn't succeed. |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 30 | ASSERT_EQ(NO_INIT, manager.initialize()); |
Mikhail Naganov | bcbcb1b | 2017-12-13 13:03:35 -0800 | [diff] [blame^] | 31 | ASSERT_EQ(NO_INIT, manager.initCheck()); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | // A client that provides correct module and IO handles for inputs and outputs. |
| 36 | class AudioPolicyTestClientWithModulesIoHandles : public AudioPolicyTestClient { |
| 37 | public: |
| 38 | audio_module_handle_t loadHwModule(const char* /*name*/) override { |
| 39 | return mNextModule++; |
| 40 | } |
| 41 | status_t openOutput(audio_module_handle_t module, |
| 42 | audio_io_handle_t* output, |
| 43 | audio_config_t* /*config*/, |
| 44 | audio_devices_t* /*devices*/, |
| 45 | const String8& /*address*/, |
| 46 | uint32_t* /*latencyMs*/, |
| 47 | audio_output_flags_t /*flags*/) override { |
| 48 | if (module >= mNextModule) { |
| 49 | ALOGE("%s: Module handle %d has not been allocated yet (next is %d)", |
| 50 | __func__, module, mNextModule); |
| 51 | return BAD_VALUE; |
| 52 | } |
| 53 | *output = mNextIoHandle++; |
| 54 | return NO_ERROR; |
| 55 | } |
| 56 | status_t openInput(audio_module_handle_t module, |
| 57 | audio_io_handle_t* input, |
| 58 | audio_config_t* /*config*/, |
| 59 | audio_devices_t* /*device*/, |
| 60 | const String8& /*address*/, |
| 61 | audio_source_t /*source*/, |
| 62 | audio_input_flags_t /*flags*/) override { |
| 63 | if (module >= mNextModule) { |
| 64 | ALOGE("%s: Module handle %d has not been allocated yet (next is %d)", |
| 65 | __func__, module, mNextModule); |
| 66 | return BAD_VALUE; |
| 67 | } |
| 68 | *input = mNextIoHandle++; |
| 69 | return NO_ERROR; |
| 70 | } |
| 71 | private: |
| 72 | audio_module_handle_t mNextModule = AUDIO_MODULE_HANDLE_NONE + 1; |
| 73 | audio_io_handle_t mNextIoHandle = AUDIO_IO_HANDLE_NONE + 1; |
| 74 | }; |
| 75 | |
| 76 | TEST(AudioPolicyManager, InitSuccess) { |
| 77 | AudioPolicyTestClientWithModulesIoHandles client; |
| 78 | AudioPolicyTestManager manager(&client); |
| 79 | manager.getConfig().setDefault(); |
| 80 | ASSERT_EQ(NO_ERROR, manager.initialize()); |
| 81 | ASSERT_EQ(NO_ERROR, manager.initCheck()); |
Mikhail Naganov | ad3f8a1 | 2017-12-12 13:24:23 -0800 | [diff] [blame] | 82 | } |