1 // Copyright 2016 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 
16 // Tests for audio daemon.
17 
18 #include "audio_daemon_mock.h"
19 
20 #include <memory>
21 #include <vector>
22 
23 #include <binder/Binder.h>
24 #include <binderwrapper/binder_test_base.h>
25 #include <binderwrapper/stub_binder_wrapper.h>
26 #include <gmock/gmock.h>
27 
28 #include "audio_device_handler_mock.h"
29 
30 using android::BinderTestBase;
31 using android::IInterface;
32 using std::make_shared;
33 using testing::_;
34 using testing::AnyNumber;
35 
36 namespace brillo {
37 
38 class AudioDaemonTest : public BinderTestBase {
39  public:
40   AudioDaemonMock daemon_;
41   AudioDeviceHandlerMock device_handler_;
42 };
43 
TEST_F(AudioDaemonTest,RegisterService)44 TEST_F(AudioDaemonTest, RegisterService) {
45   daemon_.InitializeBrilloAudioService();
46   EXPECT_EQ(daemon_.brillo_audio_service_,
47             binder_wrapper()->GetRegisteredService(
48                 "android.brillo.brilloaudioservice.BrilloAudioService"));
49 }
50 
TEST_F(AudioDaemonTest,TestAPSConnectInitializesHandlersOnlyOnce)51 TEST_F(AudioDaemonTest, TestAPSConnectInitializesHandlersOnlyOnce) {
52   binder_wrapper()->SetBinderForService("media.audio_policy",
53                                         binder_wrapper()->CreateLocalBinder());
54   daemon_.handlers_initialized_ = false;
55   EXPECT_CALL(daemon_, InitializeHandlers()).Times(1);
56   daemon_.ConnectToAPS();
57 }
58 
TEST_F(AudioDaemonTest,TestDeviceCallbackInitializesBASIfNULL)59 TEST_F(AudioDaemonTest, TestDeviceCallbackInitializesBASIfNULL) {
60   daemon_.DeviceCallback(
61       AudioDeviceHandlerMock::DeviceConnectionState::kDevicesConnected,
62       std::vector<int>());
63   EXPECT_EQ(daemon_.brillo_audio_service_,
64             binder_wrapper()->GetRegisteredService(
65                 "android.brillo.brilloaudioservice.BrilloAudioService"));
66 }
67 
68 }  // namespace brillo
69