4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * @file bluetooth-telephony-test.c
22 * @brief This is the source file for bluetooth telephony test suite.
28 #include <dbus/dbus-glib.h>
31 #include "bluetooth-telephony-api.h"
34 #define PRT(format, args...) printf("%s:%d() "format, \
35 __FUNCTION__, __LINE__, ##args)
36 #define TC_PRT(format, args...) PRT(format"\n", ##args)
38 GMainLoop *main_loop = NULL;
39 static int timeout_status = 0;
40 #define DEFAULT_CALL_ID 1
41 /*Change this number with Testing SIM*/
42 #define TEST_NUMBER "9986008917"
49 tc_table_t tc_table[] = {
50 /*Telephony Application*/
51 {"bluetooth_telephony_init", 70},
52 {"bluetooth_telephony_deinit", 71},
53 {"Indicate Outgoing call", 72},
54 {"Indicate Incoming call", 73},
55 {"Speaker to Headphone", 74},
56 {"Headphone to Speaker ", 75},
57 {"Call End/Release", 76},
59 {"bluetooth_telephony_call_remote_ringing", 78},
63 {"Is SCO channel connected", 82},
64 {"Voice Recognition Start", 83},
65 {"Voice Recognition Stop", 84},
67 /* -----------------------------------------*/
73 #define tc_result(success, tc_index) \
74 TC_PRT("Test case [%d - %s] %s", tc_table[tc_index].tc_code, \
75 tc_table[tc_index].tc_name, \
76 ((success == TC_PASS) ? "Success" : "Failed"));
78 void tc_usage_print(void)
82 while (tc_table[i].tc_name) {
83 if (tc_table[i].tc_code != 0x00ff) {
84 TC_PRT("Key %d : usage %s", tc_table[i].tc_code,
87 TC_PRT("Key %d : usage %s\n\n", 0x00ff,
95 void telephony_event_handler(int event, void *data, void *user_data)
97 telephony_event_param_t *bt_event;
103 TC_PRT("AG event : [0x%04x]", event);
106 case BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL:
107 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_ANSWER_CALL");
108 bluetooth_telephony_call_answered(DEFAULT_CALL_ID, TRUE);
111 case BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL:
112 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_RELEASE_CALL");
113 bluetooth_telephony_call_end(DEFAULT_CALL_ID);
116 case BLUETOOTH_EVENT_TELEPHONY_REJECT_CALL:
117 bluetooth_telephony_call_end(DEFAULT_CALL_ID);
120 case BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL:
121 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_0_RELEASE_ALL_HELD_CALL");
124 case BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL:
125 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_1_RELEASE_ALL_ACTIVE_CALL");
128 case BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL:
129 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_3_MERGE_CALL");
132 case BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL:
133 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_2_ACTIVE_HELD_CALL");
136 case BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF:
137 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_SEND_DTMF");
140 case BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER:
141 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_CHLD_4_EXPLICIT_CALL_TRANSFER");
144 case BLUETOOTH_EVENT_TELEPHONY_NREC_CHANGED: {
146 TC_PRT("BLUETOOTH_EVENT_TELEPHONY_NREC_CHANGED");
147 nrec = bt_event->param_data;
148 TC_PRT("NREC status = [%d]", *nrec);
157 int test_input_callback(void *data)
159 int test_id = (int)data;
164 g_main_loop_quit(main_loop);
168 bluetooth_telephony_init(telephony_event_handler, NULL);
171 bluetooth_telephony_deinit();
175 bluetooth_telephony_indicate_outgoing_call(
176 TEST_NUMBER, DEFAULT_CALL_ID, TRUE);
179 bluetooth_telephony_indicate_incoming_call(
183 bluetooth_telephony_audio_open();
186 bluetooth_telephony_audio_close();
189 bluetooth_telephony_call_end(DEFAULT_CALL_ID);
192 bluetooth_telephony_call_held(DEFAULT_CALL_ID);
195 bluetooth_telephony_call_remote_ringing(
199 TC_PRT("bluetooth_telephony_call_swapped \n");
202 bluetooth_telephony_call_answered(
203 DEFAULT_CALL_ID, FALSE);
206 bluetooth_telephony_call_answered(
207 DEFAULT_CALL_ID, TRUE);
213 state = bluetooth_telephony_is_sco_connected();
215 TC_PRT("State = %d \n", state);
222 TC_PRT("**********************\n");
223 TC_PRT(" PLEASE SPEAK \n");
224 TC_PRT("**********************\n");
226 ret = bluetooth_telephony_start_voice_recognition();
228 if (ret == BLUETOOTH_TELEPHONY_ERROR_NONE) {
229 TC_PRT("No error\n");
230 bluetooth_telephony_audio_open();
236 TC_PRT("Rcognition finished \n");
237 bluetooth_telephony_audio_close();
238 bluetooth_telephony_stop_voice_recognition();
244 gboolean status = FALSE;
246 ret = bluetooth_telephony_is_nrec_enabled(&status);
248 if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
249 TC_PRT("Error getting NREC Status\n");
251 TC_PRT("NREC status = %d\n", status);
264 TC_PRT("bluetooth framework TC startup");
266 if (!g_thread_supported()) {
270 dbus_g_thread_init();
273 main_loop = g_main_loop_new(NULL, FALSE);
278 TC_PRT("bluetooth framework TC cleanup");
279 if (main_loop != NULL) {
280 g_main_loop_unref(main_loop);
284 int timeout_callback(void *data)
286 TC_PRT("timeout callback");
289 g_main_loop_quit(main_loop);
294 static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond ,
299 unsigned int len = 0;
301 memset(buf, 0, sizeof(buf));
303 if (g_io_channel_read(chan, buf, sizeof(buf), &len) !=
306 printf("IO Channel read error");
316 g_idle_add(test_input_callback, (void *)test_id);
326 key_io = g_io_channel_unix_new(fileno(stdin));
328 g_io_add_watch(key_io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
330 g_io_channel_unref(key_io);
333 g_main_loop_run(main_loop);