2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file bluetooth-agent_test.cpp
20 * @brief Unit-tests setup
23 #include <gtest/gtest.h>
28 /* ag-agent header files */
29 #include "bluetooth-ag-agent.h"
30 #include "bluetooth-ag-handler.h"
32 /* hid-agent header files */
33 #include "bluetooth-hid-agent.h"
34 #include "bluetooth-hid-manager.h"
36 /* ipsp-agent header files */
37 #include "bluetooth-ipsp-agent.h"
39 /* map-agent header files */
40 #include "bluetooth_map_agent.h"
41 #include "bluetooth_map_email.h"
42 #include "bluetooth_map_sms.h"
44 /* pb-agent header files */
45 #include "bluetooth_pb_vcard.h"
47 static GMainLoop *mainloop = NULL;
50 static gboolean timeout_func(gpointer data)
52 g_main_loop_quit((GMainLoop *)data);
56 static void wait_for_async(void)
59 mainloop = g_main_loop_new(NULL, FALSE);
61 timeout_id = g_timeout_add(2000, timeout_func, mainloop);
62 g_main_loop_run(mainloop);
63 g_source_remove(timeout_id);
66 /* Functions for ag-agent */
67 static bt_ag_info_t* __bt_create_ag_info(void)
69 bt_ag_info_t *bt_ag_info = g_new0(bt_ag_info_t, 1);
71 bt_ag_info->rfcomm = NULL;
72 bt_ag_info->slc = NULL;
73 bt_ag_info->hfp_active = TRUE;
74 bt_ag_info->vr_blacklisted = FALSE;
75 bt_ag_info->state = HEADSET_STATE_DISCONNECTED;
76 bt_ag_info->sco_server_started = FALSE;
77 bt_ag_info->path = "dev_00_1C_43_2B_1A_E5";
79 bt_ag_info->remote_addr = g_strdup("00:1C:43:2B:1A:E5");
81 bt_ag_info->slc = g_new0(bt_ag_slconn_t, 1);
82 bt_ag_info->slc->speaker_gain = 15;
83 bt_ag_info->slc->microphone_gain = 15;
84 bt_ag_info->slc->is_nrec = TRUE;
89 static void __bt_destroy_ag_info(bt_ag_info_t *ag_info)
94 g_free(ag_info->remote_addr);
101 TEST(BluetoothAGAgent_test, _bt_ag_slconn_complete) {
102 bt_ag_info_t* ag_info = __bt_create_ag_info();
104 _bt_ag_slconn_complete(ag_info);
106 /* Need to wait 2 sec for invoking callback */
109 __bt_destroy_ag_info(ag_info);
112 TEST(BluetoothAGAgent_test, _bt_ag_send_response) {
113 int ret = BT_HFP_AGENT_ERROR_NONE;
114 bt_ag_info_t* ag_info = __bt_create_ag_info();
116 /* Negative test case : no device is connected */
117 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NONE);
118 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
120 /* Negative test case : no device is connected */
121 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NO_NETWORK_SERVICE);
122 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
124 /* Negative test case : no device is connected */
125 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_AG_FAILURE);
126 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
128 ag_info->slc->is_cme_enabled = TRUE;
130 /* Negative test case : no device is connected */
131 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NO_NETWORK_SERVICE);
132 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
134 __bt_destroy_ag_info(ag_info);
137 TEST(BluetoothAGAgent_test, _bt_hfp_call_hold_request) {
138 const char *cmd = "AT+CHLD";
139 bt_ag_info_t* ag_info = __bt_create_ag_info();
141 _bt_hfp_call_hold_request(cmd, ag_info);
143 __bt_destroy_ag_info(ag_info);
146 TEST(BluetoothAGAgent_test, _bt_hfp_key_press_request) {
147 const char *cmd = "AT+CKPD";
148 bt_ag_info_t* ag_info = __bt_create_ag_info();
150 _bt_hfp_key_press_request(cmd, ag_info);
152 __bt_destroy_ag_info(ag_info);
155 TEST(BluetoothAGAgent_test, _bt_hfp_terminate_call_request) {
156 bt_ag_info_t* ag_info = __bt_create_ag_info();
158 _bt_hfp_terminate_call_request(ag_info);
160 __bt_destroy_ag_info(ag_info);
163 TEST(BluetoothAGAgent_test, _bt_hfp_answer_call_request) {
164 bt_ag_info_t* ag_info = __bt_create_ag_info();
166 _bt_hfp_answer_call_request(ag_info);
168 __bt_destroy_ag_info(ag_info);
171 TEST(BluetoothAGAgent_test, _bt_hfp_update_event_request) {
172 bt_ag_info_t* ag_info = __bt_create_ag_info();
174 _bt_hfp_update_event_request(0, ag_info);
176 _bt_hfp_update_event_request(1, ag_info);
178 __bt_destroy_ag_info(ag_info);
181 TEST(BluetoothAGAgent_test, _bt_hfp_response_and_hold_request) {
182 bt_ag_info_t* ag_info = __bt_create_ag_info();
184 _bt_hfp_response_and_hold_request(ag_info);
186 __bt_destroy_ag_info(ag_info);
189 TEST(BluetoothAGAgent_test, _bt_hfp_last_dialed_number_request) {
190 bt_ag_info_t* ag_info = __bt_create_ag_info();
192 _bt_hfp_last_dialed_number_request(ag_info);
194 __bt_destroy_ag_info(ag_info);
197 TEST(BluetoothAGAgent_test, _bt_hfp_dial_number_request) {
198 bt_ag_info_t* ag_info = __bt_create_ag_info();
199 const char *number1 = "#31#";
200 const char *number2 = "*31#";
201 const char *number3 = ">123";
202 const char *number4 = "0123456789";
204 _bt_hfp_dial_number_request(number1, ag_info);
206 _bt_hfp_dial_number_request(number2, ag_info);
208 _bt_hfp_dial_number_request(number3, ag_info);
210 _bt_hfp_dial_number_request(number4, ag_info);
212 __bt_destroy_ag_info(ag_info);
215 TEST(BluetoothAGAgent_test, _bt_hfp_channel_dtmf_request) {
216 bt_ag_info_t* ag_info = __bt_create_ag_info();
217 const char tone = '1';
219 _bt_hfp_channel_dtmf_request(tone, ag_info);
221 __bt_destroy_ag_info(ag_info);
224 TEST(BluetoothAGAgent_test, _bt_hfp_subscriber_number_request) {
225 bt_ag_info_t* ag_info = __bt_create_ag_info();
227 _bt_hfp_subscriber_number_request(ag_info);
229 __bt_destroy_ag_info(ag_info);
232 TEST(BluetoothAGAgent_test, _bt_hfp_get_operator_selection_request) {
233 bt_ag_info_t* ag_info = __bt_create_ag_info();
235 _bt_hfp_get_operator_selection_request(ag_info);
237 __bt_destroy_ag_info(ag_info);
240 TEST(BluetoothAGAgent_test, _bt_hfp_noise_red_and_echo_cancel_request) {
241 bt_ag_info_t* ag_info = __bt_create_ag_info();
243 _bt_hfp_noise_red_and_echo_cancel_request(TRUE, ag_info);
245 _bt_hfp_noise_red_and_echo_cancel_request(FALSE, ag_info);
247 __bt_destroy_ag_info(ag_info);
250 TEST(BluetoothAGAgent_test, _bt_hfp_voice_dial_request) {
251 bt_ag_info_t* ag_info = __bt_create_ag_info();
253 _bt_hfp_voice_dial_request(TRUE, ag_info);
255 _bt_hfp_voice_dial_request(FALSE, ag_info);
257 __bt_destroy_ag_info(ag_info);
260 TEST(BluetoothAGAgent_test, _bt_hfp_set_indicators) {
261 bt_ag_info_t* ag_info = __bt_create_ag_info();
263 const char *cmd = "AT+BIA=call";
265 _bt_hfp_set_indicators(cmd, ag_info);
267 __bt_destroy_ag_info(ag_info);
270 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory_status) {
271 bt_ag_info_t* ag_info = __bt_create_ag_info();
273 _bt_hfp_select_phonebook_memory_status(ag_info);
275 __bt_destroy_ag_info(ag_info);
278 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory_list) {
279 bt_ag_info_t* ag_info = __bt_create_ag_info();
281 _bt_hfp_select_phonebook_memory_list(ag_info);
283 __bt_destroy_ag_info(ag_info);
286 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory) {
287 bt_ag_info_t* ag_info = __bt_create_ag_info();
288 const char *pb_path = "user";
290 _bt_hfp_select_phonebook_memory(ag_info, pb_path);
292 __bt_destroy_ag_info(ag_info);
295 TEST(BluetoothAGAgent_test, _bt_hfp_read_phonebook_entries_list) {
296 bt_ag_info_t* ag_info = __bt_create_ag_info();
298 _bt_hfp_read_phonebook_entries_list(ag_info);
300 __bt_destroy_ag_info(ag_info);
303 TEST(BluetoothAGAgent_test, _bt_hfp_read_phonebook_entries) {
304 bt_ag_info_t* ag_info = __bt_create_ag_info();
305 const char *cmd = "AT+CPBR=1,4";
307 _bt_hfp_read_phonebook_entries(ag_info, cmd);
309 __bt_destroy_ag_info(ag_info);
312 TEST(BluetoothAGAgent_test, _bt_hfp_find_phonebook_entries_status) {
313 bt_ag_info_t* ag_info = __bt_create_ag_info();
315 _bt_hfp_find_phonebook_entries_status(ag_info);
317 __bt_destroy_ag_info(ag_info);
320 TEST(BluetoothAGAgent_test, _bt_hfp_find_phonebook_entries) {
321 bt_ag_info_t* ag_info = __bt_create_ag_info();
322 const char *cmd = "AT+CPBR=1,4";
324 _bt_hfp_find_phonebook_entries(ag_info, cmd);
326 __bt_destroy_ag_info(ag_info);
329 TEST(BluetoothAGAgent_test, _bt_hfp_get_character_set) {
330 bt_ag_info_t* ag_info = __bt_create_ag_info();
332 _bt_hfp_get_character_set(ag_info);
334 __bt_destroy_ag_info(ag_info);
337 TEST(BluetoothAGAgent_test, _bt_hfp_list_supported_character) {
338 bt_ag_info_t* ag_info = __bt_create_ag_info();
340 _bt_hfp_list_supported_character(ag_info);
342 __bt_destroy_ag_info(ag_info);
345 TEST(BluetoothAGAgent_test, _bt_hfp_set_character_set) {
346 bt_ag_info_t* ag_info = __bt_create_ag_info();
347 const char *cmd = "\"UTF-8\"";
349 _bt_hfp_set_character_set(ag_info, cmd);
351 __bt_destroy_ag_info(ag_info);
354 TEST(BluetoothAGAgent_test, _bt_hfp_get_battery_property) {
355 bt_ag_info_t* ag_info = __bt_create_ag_info();
357 _bt_hfp_get_battery_property(ag_info);
359 __bt_destroy_ag_info(ag_info);
362 TEST(BluetoothAGAgent_test, _bt_hfp_signal_quality_reply) {
363 bt_ag_info_t* ag_info = __bt_create_ag_info();
365 _bt_hfp_signal_quality_reply(1, 1, ag_info);
367 __bt_destroy_ag_info(ag_info);
370 TEST(BluetoothAGAgent_test, _bt_hfp_battery_property_reply) {
371 bt_ag_info_t* ag_info = __bt_create_ag_info();
373 _bt_hfp_battery_property_reply(ag_info, 1, 1);
375 __bt_destroy_ag_info(ag_info);
378 TEST(BluetoothAGAgent_test, _bt_hfp_operator_reply) {
379 bt_ag_info_t* ag_info = __bt_create_ag_info();
381 _bt_hfp_operator_reply("Tizen", ag_info);
383 __bt_destroy_ag_info(ag_info);
386 TEST(BluetoothAGAgent_test, _bt_ag_agent_dial_num) {
387 bt_ag_info_t* ag_info = __bt_create_ag_info();
388 int ret = BT_HFP_AGENT_ERROR_NONE;
390 /* Negative test case */
391 ret = _bt_ag_agent_dial_num(NULL, 0);
392 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_INVALID_PARAM);
394 ret = _bt_ag_agent_dial_num("01012345678", 0);
395 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
397 __bt_destroy_ag_info(ag_info);
400 TEST(BluetoothAGAgent_test, _bt_ag_agent_dial_last_num) {
401 bt_ag_info_t* ag_info = __bt_create_ag_info();
402 int ret = BT_HFP_AGENT_ERROR_NONE;
404 /* Negative test case : No contact info */
405 ret = _bt_ag_agent_dial_last_num(ag_info);
406 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
408 __bt_destroy_ag_info(ag_info);
411 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_signal_quality) {
412 bt_ag_info_t* ag_info = __bt_create_ag_info();
413 gboolean ret = FALSE;
415 ret = _bt_ag_agent_get_signal_quality(ag_info);
416 ASSERT_TRUE(ret == TRUE);
418 __bt_destroy_ag_info(ag_info);
421 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_battery_status) {
422 bt_ag_info_t* ag_info = __bt_create_ag_info();
423 gboolean ret = FALSE;
425 ret = _bt_ag_agent_get_battery_status(ag_info);
426 ASSERT_TRUE(ret == TRUE);
428 __bt_destroy_ag_info(ag_info);
431 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_operator_name) {
432 bt_ag_info_t* ag_info = __bt_create_ag_info();
433 gboolean ret = FALSE;
435 ret = _bt_ag_agent_get_operator_name(ag_info);
436 ASSERT_TRUE(ret == TRUE);
438 __bt_destroy_ag_info(ag_info);
441 TEST(BluetoothAGAgent_test, _bt_hfp_agent_nrec_status) {
442 bt_ag_info_t* ag_info = __bt_create_ag_info();
443 gboolean ret = FALSE;
445 ret = _bt_hfp_agent_nrec_status(TRUE, ag_info);
446 ASSERT_TRUE(ret == TRUE);
448 ret = _bt_hfp_agent_nrec_status(FALSE, ag_info);
449 ASSERT_TRUE(ret == TRUE);
451 __bt_destroy_ag_info(ag_info);
454 TEST(BluetoothAGAgent_test, _bt_ag_agent_voice_dial) {
455 bt_ag_info_t* ag_info = __bt_create_ag_info();
456 gboolean ret = FALSE;
458 ret = _bt_ag_agent_voice_dial(FALSE);
459 ASSERT_TRUE(ret == TRUE);
461 __bt_destroy_ag_info(ag_info);
464 TEST(BluetoothAGAgent_test, _bt_list_current_calls) {
465 bt_ag_info_t* ag_info = __bt_create_ag_info();
467 _bt_list_current_calls(ag_info);
469 __bt_destroy_ag_info(ag_info);
472 TEST(BluetoothAGAgent_test, _bt_get_activity_status) {
473 bt_ag_info_t* ag_info = __bt_create_ag_info();
475 _bt_get_activity_status(ag_info);
477 __bt_destroy_ag_info(ag_info);
480 TEST(BluetoothAGAgent_test, _bt_hfp_set_property_name) {
481 const char *property1 = "OperatorNameChanged";
482 const char *property2 = "SubscriberNumberChanged";
483 const char *operator_name = "Tizen";
486 ret = _bt_hfp_set_property_name(property1, operator_name);
487 ASSERT_TRUE(ret == 1);
489 ret = _bt_hfp_set_property_name(property2, operator_name);
490 ASSERT_TRUE(ret == 1);
493 TEST(BluetoothAGAgent_test, _bt_hfp_get_imei_number_reply) {
494 bt_ag_info_t* ag_info = __bt_create_ag_info();
496 _bt_hfp_get_imei_number_reply("1234", ag_info);
498 __bt_destroy_ag_info(ag_info);
501 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_info_reply) {
502 bt_ag_info_t* ag_info = __bt_create_ag_info();
504 _bt_hfp_get_model_info_reply("Tizen", ag_info);
506 __bt_destroy_ag_info(ag_info);
509 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer_reply) {
510 bt_ag_info_t* ag_info = __bt_create_ag_info();
512 _bt_hfp_get_device_manufacturer_reply("Tizen", ag_info);
514 __bt_destroy_ag_info(ag_info);
517 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_info_reply) {
518 bt_ag_info_t* ag_info = __bt_create_ag_info();
520 _bt_hfp_get_revision_info_reply("5.0", ag_info);
522 __bt_destroy_ag_info(ag_info);
525 TEST(BluetoothAGAgent_test, _bt_hfp_device_disconnected) {
526 bt_ag_info_t* ag_info = __bt_create_ag_info();
528 _bt_hfp_device_disconnected(ag_info);
530 __bt_destroy_ag_info(ag_info);
533 TEST(BluetoothAGAgent_test, _bt_hfp_get_equipment_identity) {
534 bt_ag_info_t* ag_info = __bt_create_ag_info();
535 const char *cmd1 = "AT+CGSN=?";
536 const char *cmd2 = "AT+CGSN";
537 int ret = BT_HFP_AGENT_ERROR_NONE;
539 /* Negative test case */
540 ret = _bt_hfp_get_equipment_identity(ag_info, cmd1);
541 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
543 ret = _bt_hfp_get_equipment_identity(ag_info, cmd2);
544 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
546 __bt_destroy_ag_info(ag_info);
549 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_information) {
550 bt_ag_info_t* ag_info = __bt_create_ag_info();
551 const char *cmd1 = "AT+CGMM=?";
552 const char *cmd2 = "AT+CGMM";
553 int ret = BT_HFP_AGENT_ERROR_NONE;
555 /* Negative test case : No device connected */
556 ret = _bt_hfp_get_model_information(ag_info, cmd1);
557 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
559 ret = _bt_hfp_get_model_information(ag_info, cmd2);
560 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
562 __bt_destroy_ag_info(ag_info);
565 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer) {
566 bt_ag_info_t* ag_info = __bt_create_ag_info();
567 const char *cmd1 = "AT+CGMI=?";
568 const char *cmd2 = "AT+CGMI";
569 int ret = BT_HFP_AGENT_ERROR_NONE;
571 /* Negative test case */
572 ret = _bt_hfp_get_device_manufacturer(ag_info, cmd1);
573 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
575 ret = _bt_hfp_get_device_manufacturer(ag_info, cmd2);
576 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
578 __bt_destroy_ag_info(ag_info);
581 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi) {
582 bt_ag_info_t* ag_info = __bt_create_ag_info();
583 const char *cmd1 = "AT+IMSI=?";
584 const char *cmd2 = "AT+IMSI";
585 int ret = BT_HFP_AGENT_ERROR_NONE;
587 ret = _bt_hfp_get_imsi(ag_info, cmd1);
588 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
590 ret = _bt_hfp_get_imsi(ag_info, cmd2);
591 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
593 __bt_destroy_ag_info(ag_info);
596 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status) {
597 bt_ag_info_t* ag_info = __bt_create_ag_info();
598 const char *cmd1 = "AT+IMSI=?";
599 const char *cmd2 = "AT+IMSI";
600 const char *cmd3 = "AT+IMSI?";
601 int ret = BT_HFP_AGENT_ERROR_NONE;
603 ret = _bt_hfp_get_creg_status(ag_info, cmd1);
604 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
606 ret = _bt_hfp_get_creg_status(ag_info, cmd2);
607 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
609 ret = _bt_hfp_get_creg_status(ag_info, cmd3);
610 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
612 __bt_destroy_ag_info(ag_info);
615 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_information) {
616 bt_ag_info_t* ag_info = __bt_create_ag_info();
617 const char *cmd1 = "AT+CGMR=?";
618 const char *cmd2 = "AT+CGMR";
619 int ret = BT_HFP_AGENT_ERROR_NONE;
621 /* Negative test case : No device connected */
622 ret = _bt_hfp_get_revision_information(ag_info, cmd1);
623 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
625 ret = _bt_hfp_get_revision_information(ag_info, cmd2);
626 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
628 __bt_destroy_ag_info(ag_info);
631 TEST(BluetoothAGAgent_test, _bt_hfp_get_equipment_identity_req) {
632 bt_ag_info_t* ag_info = __bt_create_ag_info();
634 _bt_hfp_get_equipment_identity_req(ag_info);
636 __bt_destroy_ag_info(ag_info);
639 TEST(BluetoothAGAgent_test, _bt_hfp_initialize_telephony_manager) {
640 uint32_t ag_features = BT_AG_FEATURE_EC_AND_NR |
641 BT_AG_FEATURE_REJECT_CALL |
642 BT_AG_FEATURE_ENHANCED_CALL_STATUS |
643 BT_AG_FEATURE_THREE_WAY_CALL |
644 BT_AG_FEATURE_EXTENDED_ERROR_RESULT_CODES |
645 BT_AG_FEATURE_CODEC_NEGOTIATION;
647 _bt_hfp_initialize_telephony_manager(ag_features);
649 _bt_hfp_deinitialize_telephony_manager();
652 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_info_req) {
653 bt_ag_info_t* ag_info = __bt_create_ag_info();
655 _bt_hfp_get_model_info_req(ag_info);
657 __bt_destroy_ag_info(ag_info);
660 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer_req) {
661 bt_ag_info_t* ag_info = __bt_create_ag_info();
663 _bt_hfp_get_device_manufacturer_req(ag_info);
665 __bt_destroy_ag_info(ag_info);
668 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi_req) {
669 bt_ag_info_t* ag_info = __bt_create_ag_info();
671 _bt_hfp_get_imsi_req(ag_info);
673 __bt_destroy_ag_info(ag_info);
676 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status_req) {
677 bt_ag_info_t* ag_info = __bt_create_ag_info();
679 _bt_hfp_get_creg_status_req(ag_info);
681 __bt_destroy_ag_info(ag_info);
684 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_info_req) {
685 bt_ag_info_t* ag_info = __bt_create_ag_info();
687 _bt_hfp_get_revision_info_req(ag_info);
689 __bt_destroy_ag_info(ag_info);
692 TEST(BluetoothAGAgent_test, _bt_hfp_is_call_exist) {
693 gboolean ret = FALSE;
695 ret = _bt_hfp_is_call_exist();
698 TEST(BluetoothAGAgent_test, _bt_hfp_release_all_calls_by_sender) {
699 const char *sender = "sender";
701 _bt_hfp_release_all_calls_by_sender(sender);
704 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi_reply) {
705 bt_ag_info_t* ag_info = __bt_create_ag_info();
707 _bt_hfp_get_imsi_reply(NULL, NULL, NULL, ag_info);
709 _bt_hfp_get_imsi_reply("mmc", "mnc", "msin", ag_info);
711 __bt_destroy_ag_info(ag_info);
714 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status_reply) {
715 bt_ag_info_t* ag_info = __bt_create_ag_info();
717 _bt_hfp_get_creg_status_reply(1, 0, ag_info);
719 __bt_destroy_ag_info(ag_info);
722 TEST(BluetoothAGAgent_test, _bt_hfp_vendor_cmd_request) {
723 bt_ag_info_t* ag_info = __bt_create_ag_info();
724 const char *cmd = "AT+VND";
726 _bt_hfp_vendor_cmd_request(cmd, ag_info);
728 __bt_destroy_ag_info(ag_info);
731 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_model_name) {
732 bt_ag_info_t* ag_info = __bt_create_ag_info();
734 _bt_ag_agent_get_model_name(ag_info);
736 __bt_destroy_ag_info(ag_info);
739 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_manufacturer_name) {
740 bt_ag_info_t* ag_info = __bt_create_ag_info();
742 _bt_ag_agent_get_manufacturer_name(ag_info);
744 __bt_destroy_ag_info(ag_info);
747 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_imsi) {
748 bt_ag_info_t* ag_info = __bt_create_ag_info();
750 _bt_ag_agent_get_imsi(ag_info);
752 __bt_destroy_ag_info(ag_info);
755 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_creg_status) {
756 bt_ag_info_t* ag_info = __bt_create_ag_info();
758 _bt_ag_agent_get_creg_status(ag_info);
760 __bt_destroy_ag_info(ag_info);
763 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_revision_information) {
764 bt_ag_info_t* ag_info = __bt_create_ag_info();
766 _bt_ag_agent_get_revision_information(ag_info);
768 __bt_destroy_ag_info(ag_info);
771 #ifdef TIZEN_FEATURE_BT_MEDIA_ENHANCE
772 TEST(BluetoothAGAgent_test, _bt_ag_agent_check_transport_state) {
773 bt_ag_info_t* ag_info = __bt_create_ag_info();
775 _bt_ag_agent_check_transport_state(ag_info);
777 __bt_destroy_ag_info(ag_info);
781 /* Functions for hid-agent */
782 TEST(BluetoothHIDAgent_test, _bt_hid_disconnect_profile) {
783 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
785 /* Negative test case : no device is connected */
786 ret = _bt_hid_disconnect_profile();
787 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INTERNAL);
790 TEST(BluetoothHIDAgent_test, _bt_hid_set_profile_state) {
791 _bt_hid_set_profile_state(BT_HID_STATE_CONNECTING);
793 _bt_hid_set_profile_state(BT_HID_STATE_CONNECTED);
795 _bt_hid_set_profile_state(BT_HID_STATE_UNAVAILABLE);
798 TEST(BluetoothHIDAgent_test, _bt_hid_get_profile_state) {
799 bt_hid_state_t state;
801 state = _bt_hid_get_profile_state();
802 ASSERT_TRUE(state >= BT_HID_STATE_UNAVAILABLE && state <= BT_HID_STATE_DISCONNECTING);
805 TEST(BluetoothHIDAgent_test, _bt_hid_register_application) {
806 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
808 /* Negative test case */
809 ret = _bt_hid_register_application(TRUE, NULL);
810 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INVALID_PARAM);
812 ret = _bt_hid_register_application(TRUE, "Sender");
813 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
815 /* Negative test case */
816 ret = _bt_hid_register_application(TRUE, "Sender");
817 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_ALREADY_EXIST);
819 ret = _bt_hid_register_application(FALSE, "Sender");
820 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
822 /* Negative test case */
823 ret = _bt_hid_register_application(FALSE, "Sender");
824 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NOT_AVAILABLE);
827 TEST(BluetoothHIDAgent_test, _bt_hid_get_sender_list) {
828 const GSList *senders;
829 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
831 ret = _bt_hid_register_application(TRUE, "Sender");
832 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
834 senders = _bt_hid_get_sender_list();
835 ASSERT_TRUE(senders != NULL);
837 ret = _bt_hid_register_application(FALSE, "Sender");
838 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
841 /* Functions for ipsp-agent */
842 TEST(BluetoothIPSPAgent_test, _bt_ipsp_register_dbus) {
843 gboolean ret = FALSE;
845 ret = _bt_ipsp_register_dbus();
846 ASSERT_TRUE(ret == TRUE);
849 TEST(BluetoothIPSPAgent_test, _bt_ipsp_unregister_dbus) {
850 _bt_ipsp_unregister_dbus();
853 TEST(BluetoothIPSPAgent_test, _bt_ipsp_gdbus_deinit_proxys) {
854 _bt_ipsp_gdbus_deinit_proxys();
857 /* Functions for map-agent */
858 static message_info_t* __bt_create_msg_info(void)
860 message_info_t *bt_msg_info = g_new0(message_info_t, 1);
862 bt_msg_info->handle = g_strdup("1");
863 bt_msg_info->subject = g_strdup("subject");
864 bt_msg_info->datetime = g_strdup("datetime");
865 bt_msg_info->sender_name = g_strdup("sender_name");
866 bt_msg_info->sender_addressing = g_strdup("sender_addressing");
867 bt_msg_info->replyto_addressing = g_strdup("replyto_addressing");
868 bt_msg_info->recipient_name = g_strdup("recipient_name");
869 bt_msg_info->recipient_addressing = g_strdup("recipient_addressing");
870 bt_msg_info->type = g_strdup("type");
871 bt_msg_info->reception_status = g_strdup("reception_status");
872 bt_msg_info->size = g_strdup("size");
873 bt_msg_info->attachment_size = g_strdup("attachment_size");
878 TEST(BluetoothMAPAgent_test, _bt_mns_client_event_notify) {
879 _bt_mns_client_event_notify("MessageShift", 0,
880 "TELECOM/MSG/DELETED", "/opt/usr", "EMAIL");
884 TEST(BluetoothMAPAgent_test, _bt_update_id) {
887 /* Negative test case */
888 ret = _bt_update_id(0, -1, -1);
889 ASSERT_TRUE(ret == -1);
892 TEST(BluetoothMAPAgent_test, _bt_validate_msg_data) {
893 gboolean ret = FALSE;
894 message_info_t *bt_msg_info = __bt_create_msg_info();
896 /* Negative test case */
897 ret = _bt_validate_msg_data(NULL);
898 ASSERT_TRUE(ret == FALSE);
900 ret = _bt_validate_msg_data(bt_msg_info);
901 ASSERT_TRUE(ret == TRUE);
903 _bt_message_info_free(bt_msg_info);
906 TEST(BluetoothMAPAgent_test, _bt_message_info_free) {
907 message_info_t *bt_msg_info = __bt_create_msg_info();
909 _bt_message_info_free(bt_msg_info);
912 TEST(BluetoothMAPAgent_test, _get_msg_timestamp) {
915 struct timeval tv = {0, };
916 char msg_datetime[16] = {0, };
918 gettimeofday(&tv, NULL);
919 cur_time = tv.tv_sec;
921 _get_msg_timestamp(&cur_time, msg_datetime);
924 TEST(BluetoothMAPAgent_test, _bt_add_id) {
927 map_id = _bt_add_id(-1, BT_MAP_ID_EMAIL);
928 ASSERT_TRUE(map_id == 1);
931 TEST(BluetoothMAPAgent_test, _bt_validate_uid) {
934 map_id = _bt_validate_uid(-1, BT_MAP_ID_EMAIL);
935 ASSERT_TRUE(map_id == 1);
938 TEST(BluetoothMAPAgent_test, is_mns_connected) {
939 gboolean ret = FALSE;
941 /* Negative test case */
942 ret = is_mns_connected();
943 ASSERT_TRUE(ret == FALSE);
946 TEST(BluetoothMAPAgent_test, _bt_verify_read_status) {
947 gboolean ret = FALSE;
948 message_info_t *bt_msg_info = __bt_create_msg_info();
950 ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_ALL);
951 _bt_message_info_free(bt_msg_info);
952 ASSERT_TRUE(ret == TRUE);
954 bt_msg_info = __bt_create_msg_info();
956 ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_READ);
957 _bt_message_info_free(bt_msg_info);
958 ASSERT_TRUE(ret == FALSE);
961 TEST(BluetoothMAPAgent_test, _bt_verify_sender) {
962 gboolean ret = FALSE;
963 message_info_t *bt_msg_info = __bt_create_msg_info();
965 /* Negative test case */
966 ret = _bt_verify_sender(bt_msg_info, NULL);
967 _bt_message_info_free(bt_msg_info);
968 ASSERT_TRUE(ret == TRUE);
970 bt_msg_info = __bt_create_msg_info();
972 ret = _bt_verify_sender(bt_msg_info, "*");
973 _bt_message_info_free(bt_msg_info);
974 ASSERT_TRUE(ret == TRUE);
976 bt_msg_info = __bt_create_msg_info();
978 ret = _bt_verify_sender(bt_msg_info, "sender");
979 _bt_message_info_free(bt_msg_info);
980 ASSERT_TRUE(ret == TRUE);
982 bt_msg_info = __bt_create_msg_info();
984 /* Negative test case */
985 ret = _bt_verify_sender(bt_msg_info, "negative");
986 _bt_message_info_free(bt_msg_info);
987 ASSERT_TRUE(ret == FALSE);
990 TEST(BluetoothMAPAgent_test, _bt_verify_receiver) {
991 gboolean ret = FALSE;
992 message_info_t *bt_msg_info = __bt_create_msg_info();
994 /* Negative test case */
995 ret = _bt_verify_receiver(bt_msg_info, NULL);
996 _bt_message_info_free(bt_msg_info);
997 ASSERT_TRUE(ret == TRUE);
999 bt_msg_info = __bt_create_msg_info();
1001 ret = _bt_verify_receiver(bt_msg_info, "*");
1002 _bt_message_info_free(bt_msg_info);
1003 ASSERT_TRUE(ret == TRUE);
1005 bt_msg_info = __bt_create_msg_info();
1007 ret = _bt_verify_receiver(bt_msg_info, "receiver");
1008 _bt_message_info_free(bt_msg_info);
1009 ASSERT_TRUE(ret == FALSE);
1011 bt_msg_info = __bt_create_msg_info();
1013 /* Negative test case */
1014 ret = _bt_verify_receiver(bt_msg_info, "negative");
1015 _bt_message_info_free(bt_msg_info);
1016 ASSERT_TRUE(ret == FALSE);
1019 TEST(BluetoothMAPAgent_test, _bt_verify_time) {
1020 gboolean ret = FALSE;
1021 map_msg_filter_t filter = { 0, };
1022 message_info_t *bt_msg_info = __bt_create_msg_info();
1024 ret = _bt_verify_time(bt_msg_info, &filter);
1025 _bt_message_info_free(bt_msg_info);
1026 ASSERT_TRUE(ret == FALSE);
1029 TEST(BluetoothMAPAgent_test, _bt_filter_priority) {
1030 gboolean ret = FALSE;
1031 map_msg_filter_t filter = { 0, };
1032 message_info_t *bt_msg_info = __bt_create_msg_info();
1034 ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_ALL);
1035 _bt_message_info_free(bt_msg_info);
1036 ASSERT_TRUE(ret == TRUE);
1038 bt_msg_info = __bt_create_msg_info();
1040 ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_HIGH);
1041 _bt_message_info_free(bt_msg_info);
1042 ASSERT_TRUE(ret == FALSE);
1045 TEST(BluetoothMAPAgent_test, _bt_map_start_email_service) {
1046 gboolean ret = FALSE;
1048 /* Negative test case */
1049 ret = _bt_map_start_email_service();
1050 ASSERT_TRUE(ret == FALSE);
1053 TEST(BluetoothMAPAgent_test, _bt_map_stop_email_service) {
1054 gboolean ret = FALSE;
1056 ret = _bt_map_stop_email_service();
1057 ASSERT_TRUE(ret == TRUE);
1060 TEST(BluetoothMAPAgent_test, _bt_map_email_get_supported_folders) {
1061 gboolean ret = FALSE;
1062 gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, };
1064 /* Negative test case */
1065 ret = _bt_map_email_get_supported_folders(folders_supported);
1066 ASSERT_TRUE(ret == FALSE);
1069 TEST(BluetoothMAPAgent_test, _bt_map_update_mailbox) {
1070 gboolean ret = FALSE;
1072 /* Negative test case */
1073 ret = _bt_map_update_mailbox("/tmp");
1074 ASSERT_TRUE(ret == FALSE);
1077 TEST(BluetoothMAPAgent_test, _bt_map_set_email_read_status) {
1078 gboolean ret = FALSE;
1080 /* Negative test case */
1081 ret = _bt_map_set_email_read_status(-1, 0);
1082 ASSERT_TRUE(ret == FALSE);
1085 TEST(BluetoothMAPAgent_test, _bt_map_set_email_delete_status) {
1086 gboolean ret = FALSE;
1088 /* Negative test case */
1089 ret = _bt_map_set_email_delete_status(-1, 0);
1090 ASSERT_TRUE(ret == FALSE);
1093 TEST(BluetoothMAPAgent_test, _bt_map_get_email_message) {
1094 gboolean ret = FALSE;
1095 gchar *bmseg = NULL;
1097 /* Negative test case */
1098 ret = _bt_map_get_email_message(-1, FALSE, TRUE, TRUE, &bmseg);
1099 ASSERT_TRUE(ret == FALSE);
1102 TEST(BluetoothMAPAgent_test, _bt_map_start_sms_service) {
1103 gboolean ret = FALSE;
1105 ret = _bt_map_start_sms_service();
1106 ASSERT_TRUE(ret == TRUE);
1109 TEST(BluetoothMAPAgent_test, _bt_map_stop_sms_service) {
1110 gboolean ret = FALSE;
1111 gchar *bmseg = NULL;
1113 /* Negative test case */
1114 _bt_map_stop_sms_service();
1115 ASSERT_TRUE(ret == FALSE);
1118 TEST(BluetoothMAPAgent_test, _bt_map_sms_get_supported_folders) {
1119 gboolean ret = FALSE;
1120 gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, };
1122 /* Negative test case */
1123 ret = _bt_map_sms_get_supported_folders(folders_supported);
1124 ASSERT_TRUE(ret == FALSE);
1127 TEST(BluetoothMAPAgent_test, _bt_map_get_sms_message) {
1128 gboolean ret = FALSE;
1129 gchar *bmseg = NULL;
1131 /* Negative test case */
1132 ret = _bt_map_get_sms_message(-1, FALSE, TRUE, TRUE, &bmseg);
1133 ASSERT_TRUE(ret == FALSE);
1136 TEST(BluetoothMAPAgent_test, _bt_map_set_sms_delete_status) {
1137 gboolean ret = FALSE;
1139 /* Negative test case */
1140 ret = _bt_map_set_sms_delete_status(-1, 0);
1141 ASSERT_TRUE(ret == FALSE);
1144 TEST(BluetoothMAPAgent_test, _bt_map_sms_set_read_status) {
1145 gboolean ret = FALSE;
1147 /* Negative test case */
1148 ret = _bt_map_sms_set_read_status(-1, 0);
1149 ASSERT_TRUE(ret == FALSE);
1152 /* Functions for pb-agent */
1153 TEST(BluetoothPBAgent_test, _bluetooth_get_contact_addressbook) {
1154 int ret = PBAP_ADDRESSBOOK_PHONE;
1156 ret = _bluetooth_get_contact_addressbook(1);
1157 ASSERT_TRUE(ret == PBAP_ADDRESSBOOK_PHONE);
1160 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact) {
1163 /* Negative test case */
1164 str = _bluetooth_pb_vcard_contact(0, VCARD_PHOTO, VCARD_FORMAT_2_1);
1165 ASSERT_TRUE(str == NULL);
1167 /* Negative test case */
1168 str = _bluetooth_pb_vcard_contact(1, VCARD_PHOTO, VCARD_FORMAT_3_0);
1169 ASSERT_TRUE(str == NULL);
1172 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact_owner) {
1174 const char *number = "01012345678";
1176 str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_2_1);
1177 ASSERT_TRUE(str != NULL);
1180 str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_3_0);
1181 ASSERT_TRUE(str != NULL);
1185 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_call) {
1187 const char *attr = "DIALED";
1189 /* Negative test case */
1190 str = _bluetooth_pb_vcard_call(1, VCARD_PHOTO, VCARD_FORMAT_2_1, NULL);
1191 ASSERT_TRUE(str == NULL);
1193 str = _bluetooth_pb_vcard_call(1, VCARD_PHOTO, VCARD_FORMAT_2_1, attr);
1194 ASSERT_TRUE(str != NULL);
1199 TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_person_id) {
1202 /* Negative test case */
1203 str = _bluetooth_pb_fn_from_person_id(1);
1204 ASSERT_TRUE(str == NULL);
1207 TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_person_id) {
1210 /* Negative test case */
1211 str = _bluetooth_pb_name_from_person_id(1);
1212 ASSERT_TRUE(str == NULL);
1215 TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_person_id) {
1218 /* Negative test case */
1219 str = _bluetooth_pb_number_from_person_id(1);
1220 ASSERT_TRUE(str == NULL);
1223 TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_phonelog_id) {
1226 str = _bluetooth_pb_fn_from_phonelog_id(1);
1227 ASSERT_TRUE(str != NULL);
1232 TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_phonelog_id) {
1235 str = _bluetooth_pb_name_from_phonelog_id(1);
1236 ASSERT_TRUE(str != NULL);
1241 TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_phonelog_id) {
1244 /* Negative test case */
1245 str = _bluetooth_pb_number_from_phonelog_id(1);
1246 ASSERT_TRUE(str == NULL);
1249 TEST(BluetoothPBAgent_test, _bluetooth_pb_owner_name) {
1252 /* Negative test case */
1253 name = _bluetooth_pb_owner_name();
1254 ASSERT_TRUE(name != NULL);
1258 TEST(BluetoothPBAgent_test, _bt_is_sim_addressbook) {
1260 const char *address_book = "http://tizen.org/addressbook/sim1";
1262 ret = _bt_is_sim_addressbook(address_book);
1263 ASSERT_TRUE(ret == true);
1266 int main(int argc, char **argv) {
1267 testing::InitGoogleTest(&argc, argv);
1269 return RUN_ALL_TESTS();