blob: de26ab0bed697a99a160a2dec13c43f28fca4824 [file] [log] [blame]
Mikhail Naganovad3f8a12017-12-12 13:24:23 -08001/*
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
22using namespace android;
23
Mikhail Naganovbcbcb1b2017-12-13 13:03:35 -080024TEST(AudioPolicyManager, InitFailure) {
Mikhail Naganovad3f8a12017-12-12 13:24:23 -080025 AudioPolicyTestClient client;
26 AudioPolicyTestManager manager(&client);
27 manager.getConfig().setDefault();
Mikhail Naganovbcbcb1b2017-12-13 13:03:35 -080028 // Since the default client fails to open anything,
29 // APM should indicate that the initialization didn't succeed.
Mikhail Naganovad3f8a12017-12-12 13:24:23 -080030 ASSERT_EQ(NO_INIT, manager.initialize());
Mikhail Naganovbcbcb1b2017-12-13 13:03:35 -080031 ASSERT_EQ(NO_INIT, manager.initCheck());
32}
33
34
35// A client that provides correct module and IO handles for inputs and outputs.
36class 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
76TEST(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 Naganovad3f8a12017-12-12 13:24:23 -080082}