bt_device_unittest.cc revision 5b799f1d3f67c9db7d47b00dd8a8684c629862aa
10d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
20d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao// Use of this source code is governed by a BSD-style license that can be
30d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao// found in the LICENSE file.
40d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
50d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao#include <gtest/gtest.h>
60d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
70d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoextern "C" {
80d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao#include "cras_bt_io.h"
90d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao#include "cras_bt_device.h"
100d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao#include "cras_iodev.h"
110d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
120d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao#define FAKE_OBJ_PATH "/obj/path"
130d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
140d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
150d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic struct cras_iodev *cras_bt_io_create_profile_ret;
160d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic struct cras_iodev *cras_bt_io_append_btio_val;
170d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic int cras_bt_io_has_dev_ret;
180d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic unsigned int cras_bt_io_create_called;
190d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic unsigned int cras_bt_io_append_called;
200d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic unsigned int cras_bt_io_remove_called;
210d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic unsigned int cras_bt_io_destroy_called;
22e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostatic struct cras_iodev *audio_thread_add_active_dev_dev;
23e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostatic unsigned int audio_thread_add_active_dev_called;
24e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostatic unsigned int audio_thread_rm_active_dev_called;
25e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostatic int audio_thread_rm_active_dev_rets[CRAS_NUM_DIRECTIONS];
26e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostatic audio_thread* iodev_get_thread_return;
270d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic enum cras_bt_device_profile cras_bt_io_create_profile_val;
280d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostatic enum cras_bt_device_profile cras_bt_io_append_profile_val;
29b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chaostatic unsigned int cras_bt_io_try_remove_ret;
300d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
31e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostatic void (*cras_system_add_select_fd_callback)(void *data);
32e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostatic void *cras_system_add_select_fd_callback_data;
33e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
340d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaovoid ResetStubData() {
350d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_has_dev_ret = 0;
360d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_create_called = 0;
370d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_append_called = 0;
380d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_remove_called = 0;
390d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_destroy_called = 0;
40b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  cras_bt_io_try_remove_ret = 0;
41e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_add_active_dev_called = 0;
42e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_called = 0;
43e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  for (int dir = 0; dir < CRAS_NUM_DIRECTIONS; dir++)
44e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao    audio_thread_rm_active_dev_rets[dir] = 0;
450d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
460d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
470d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaonamespace {
480d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
490d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoclass BtDeviceTestSuite : public testing::Test {
500d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  protected:
510d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    virtual void SetUp() {
520d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      ResetStubData();
53e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      bt_iodev1.direction = CRAS_STREAM_OUTPUT;
54e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      bt_iodev1.is_open = is_open;
55e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      bt_iodev1.update_active_node = update_active_node;
56e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      bt_iodev2.direction = CRAS_STREAM_INPUT;
57e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      bt_iodev2.is_open = is_open;
58e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      bt_iodev2.update_active_node = update_active_node;
590d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      d1_.direction = CRAS_STREAM_OUTPUT;
600d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      d1_.is_open = is_open;
61e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      d1_.update_active_node = update_active_node;
620d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      d2_.direction = CRAS_STREAM_OUTPUT;
630d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      d2_.is_open = is_open;
64e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      d2_.update_active_node = update_active_node;
65e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      d3_.direction = CRAS_STREAM_INPUT;
66e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      d3_.is_open = is_open;
67e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      d3_.update_active_node = update_active_node;
680d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    }
690d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    static int is_open(const cras_iodev* iodev) {
700d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      return is_open_;
710d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    }
72e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao    static void update_active_node(struct cras_iodev *iodev) {
73e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao    }
740d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
750d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    struct cras_iodev bt_iodev1;
76e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao    struct cras_iodev bt_iodev2;
77e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao    struct cras_iodev d3_;
780d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    struct cras_iodev d2_;
790d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    struct cras_iodev d1_;
800d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao    static int is_open_;
810d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao};
820d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
830d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoint BtDeviceTestSuite::is_open_;
840d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
850d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu ChaoTEST(BtDeviceSuite, CreateBtDevice) {
860d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  struct cras_bt_device *device;
870d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
880d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  device = cras_bt_device_create(FAKE_OBJ_PATH);
890d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_NE((void *)NULL, device);
900d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
910d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  device = cras_bt_device_get(FAKE_OBJ_PATH);
920d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_NE((void *)NULL, device);
930d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
940d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_device_destroy(device);
950d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  device = cras_bt_device_get(FAKE_OBJ_PATH);
960d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ((void *)NULL, device);
970d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
980d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
990d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu ChaoTEST_F(BtDeviceTestSuite, AppendRmIodev) {
1000d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  struct cras_bt_device *device;
1010d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  device = cras_bt_device_create(FAKE_OBJ_PATH);
1020d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  bt_iodev1.nodes = reinterpret_cast<struct cras_ionode*>(0x123);
1030d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_create_profile_ret = &bt_iodev1;
1040d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_device_append_iodev(device, &d1_,
1050d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
1060d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(1, cras_bt_io_create_called);
1070d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(0, cras_bt_io_append_called);
1080d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE,
1090d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao            cras_bt_io_create_profile_val);
1100d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
1110d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_device_append_iodev(device, &d2_,
1120d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao      CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY);
1130d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(1, cras_bt_io_create_called);
1140d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(1, cras_bt_io_append_called);
1150d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY,
1160d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  	    cras_bt_io_append_profile_val);
1170d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(&bt_iodev1, cras_bt_io_append_btio_val);
1180d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
119b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  /* Test HFP disconnected and switch to A2DP. */
1200d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_has_dev_ret = 1;
121b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  cras_bt_io_try_remove_ret = CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE;
122b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  audio_thread_rm_active_dev_rets[CRAS_STREAM_OUTPUT] = 0;
123b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  cras_bt_device_set_active_profile(
124b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao      device, CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY);
1250d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_device_rm_iodev(device, &d2_);
1260d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(1, cras_bt_io_remove_called);
127b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  EXPECT_EQ(1, audio_thread_rm_active_dev_called);
128b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  EXPECT_EQ(1, audio_thread_add_active_dev_called);
129b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao
130b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  /* Test A2DP disconnection will cause bt_io destroy. */
131b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  cras_bt_io_try_remove_ret = 0;
1320d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_device_rm_iodev(device, &d1_);
133b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  EXPECT_EQ(1, cras_bt_io_remove_called);
1340d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  EXPECT_EQ(1, cras_bt_io_destroy_called);
1350d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
1360d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
137e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu ChaoTEST_F(BtDeviceTestSuite, SwitchProfile) {
138e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  struct cras_bt_device *device;
139e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
140e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  ResetStubData();
141e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  device = cras_bt_device_create(FAKE_OBJ_PATH);
142e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_io_create_profile_ret = &bt_iodev1;
143e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_device_append_iodev(device, &d1_,
144e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      CRAS_BT_DEVICE_PROFILE_A2DP_SOURCE);
145e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_io_create_profile_ret = &bt_iodev2;
146e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_device_append_iodev(device, &d3_,
147e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao      CRAS_BT_DEVICE_PROFILE_HFP_AUDIOGATEWAY);
148e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
149e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_device_start_monitor();
150e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_device_switch_profile_on_open(device, &bt_iodev1);
151e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
152e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  /* Two bt iodevs were all active. */
153e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_rets[CRAS_STREAM_INPUT] = 0;
154e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_rets[CRAS_STREAM_OUTPUT] = 0;
155e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_system_add_select_fd_callback(cras_system_add_select_fd_callback_data);
156e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  EXPECT_EQ(2, audio_thread_rm_active_dev_called);
157e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  EXPECT_EQ(2, audio_thread_add_active_dev_called);
158e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
159e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  /* One bt iodev was active, the other was not. */
160e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_device_switch_profile_on_open(device, &bt_iodev2);
161e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_rets[CRAS_STREAM_OUTPUT] = 0;
162e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_rets[CRAS_STREAM_INPUT] = -1;
163e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_system_add_select_fd_callback(cras_system_add_select_fd_callback_data);
164e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  EXPECT_EQ(4, audio_thread_rm_active_dev_called);
165e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  EXPECT_EQ(4, audio_thread_add_active_dev_called);
166e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
167e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  /* Output bt iodev wasn't active, close the active input iodev. */
168e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_bt_device_switch_profile_on_close(device, &bt_iodev2);
169e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_rets[CRAS_STREAM_OUTPUT] = -1;
170e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_rets[CRAS_STREAM_INPUT] = 0;
171e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_system_add_select_fd_callback(cras_system_add_select_fd_callback_data);
172e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  EXPECT_EQ(6, audio_thread_rm_active_dev_called);
173e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  EXPECT_EQ(5, audio_thread_add_active_dev_called);
174e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao}
175e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
1760d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao/* Stubs */
1770d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoextern "C" {
1780d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
1790d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao/* From bt_io */
1800d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostruct cras_iodev *cras_bt_io_create(
1810d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao        struct cras_bt_device *device,
1820d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao				struct cras_iodev *dev,
1830d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao				enum cras_bt_device_profile profile)
1840d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
1850d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_create_called++;
1860d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_create_profile_val = profile;
1870d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  return cras_bt_io_create_profile_ret;
1880d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
1890d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaovoid cras_bt_io_destroy(struct cras_iodev *bt_iodev)
1900d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
1910d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_destroy_called++;
1920d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
1930d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoint cras_bt_io_has_dev(struct cras_iodev *bt_iodev, struct cras_iodev *dev)
1940d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
1950d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  return cras_bt_io_has_dev_ret;
1960d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
1970d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoint cras_bt_io_append(struct cras_iodev *bt_iodev,
1980d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao		      struct cras_iodev *dev,
1990d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao		      enum cras_bt_device_profile profile)
2000d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
2010d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_append_called++;
2020d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_append_profile_val = profile;
2030d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_append_btio_val = bt_iodev;
2040d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  return 0;
2050d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
206b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chaounsigned int cras_bt_io_try_remove(struct cras_iodev *bt_iodev,
207b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao           struct cras_iodev *dev)
208b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao{
209b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao  return cras_bt_io_try_remove_ret;
210b514951036b0ca233d4405c0fd6310ad021f2062Hsin-Yu Chao}
2110d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoint cras_bt_io_remove(struct cras_iodev *bt_iodev,
2120d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao		                  struct cras_iodev *dev)
2130d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
2140d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  cras_bt_io_remove_called++;
2150d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  return 0;
2160d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
2170d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
2180d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao/* From bt_adapter */
2190d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaostruct cras_bt_adapter *cras_bt_adapter_get(const char *object_path)
2200d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
2210d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  return NULL;
2220d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
2230d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoconst char *cras_bt_adapter_address(const struct cras_bt_adapter *adapter)
2240d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
2250d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  return NULL;
2260d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
2270d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
2280d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao/* From bt_profile */
2290d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaovoid cras_bt_profile_on_device_disconnected(struct cras_bt_device *device)
2300d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao{
2310d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
232e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
2335b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao/* From hfp_ag_profile */
2345b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chaostruct hfp_slc_handle *cras_hfp_ag_get_slc(struct cras_bt_device *device)
2355b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao{
2365b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao  return NULL;
2375b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao}
2385b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao
2395b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao/* From hfp_slc */
2405b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chaoint hfp_event_speaker_gain(struct hfp_slc_handle *handle, int gain)
2415b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao{
2425b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao  return 0;
2435b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao}
2445b799f1d3f67c9db7d47b00dd8a8684c629862aaHsin-Yu Chao
245e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao/* From audio_thread */
246e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaoint audio_thread_add_active_dev(struct audio_thread *thread,
247e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao         struct cras_iodev *dev)
248e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao{
249e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_add_active_dev_dev = dev;
250e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_add_active_dev_called++;
251e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  return 0;
252e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao}
253e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
254e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaoint audio_thread_rm_active_dev(struct audio_thread *thread,
255e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao        struct cras_iodev *dev)
256e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao{
257e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  audio_thread_rm_active_dev_called++;
258e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  return audio_thread_rm_active_dev_rets[dev->direction];
259e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao}
260e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
261e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao/* From iodev_list */
262e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaostruct audio_thread* cras_iodev_list_get_audio_thread() {
263e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  return iodev_get_thread_return;
264e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao}
265e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
266e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chaoint cras_system_add_select_fd(int fd,
267e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao            void (*callback)(void *data),
268e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao            void *callback_data)
269e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao{
270e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_system_add_select_fd_callback = callback;
271e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  cras_system_add_select_fd_callback_data = callback_data;
272e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao  return 0;
273e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao}
274e02c0a29cd919867c024ae353010d537db7efa51Hsin-Yu Chao
2750d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao} // extern "C"
2760d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao} // namespace
2770d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
2780d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chaoint main(int argc, char **argv) {
2790d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  ::testing::InitGoogleTest(&argc, argv);
2800d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao  return RUN_ALL_TESTS();
2810d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao}
2820d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
2830d17ce053a25f0c1bb7c15573a4253372d95c8e9Hsin-Yu Chao
284