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 <gmock/gmock.h>
24 #include <gtest/gtest.h>
29 /* ag-agent header files */
30 #include "bluetooth-ag-agent.h"
31 #include "bluetooth-ag-handler.h"
33 /* hid-agent header files */
34 #include "bluetooth-hid-agent.h"
35 #include "bluetooth-hid-manager.h"
37 /* ipsp-agent header files */
38 #include "bluetooth-ipsp-agent.h"
40 /* map-agent header files */
41 #include "bluetooth_map_agent.h"
42 #include "bluetooth_map_email.h"
43 #include "bluetooth_map_sms.h"
45 /* pb-agent header files */
46 #include "bluetooth_pb_vcard.h"
48 using ::testing::EmptyTestEventListener;
49 using ::testing::InitGoogleTest;
50 using ::testing::Test;
51 using ::testing::TestCase;
52 using ::testing::TestEventListeners;
53 using ::testing::TestInfo;
54 using ::testing::TestPartResult;
55 using ::testing::UnitTest;
57 static GMainLoop *mainloop = NULL;
60 static gboolean timeout_func(gpointer data)
62 g_main_loop_quit((GMainLoop *)data);
66 static void wait_for_async(void)
69 mainloop = g_main_loop_new(NULL, FALSE);
71 timeout_id = g_timeout_add(2000, timeout_func, mainloop);
72 g_main_loop_run(mainloop);
73 g_source_remove(timeout_id);
76 /* Functions for ag-agent */
77 static bt_ag_info_t* __bt_create_ag_info(void)
79 bt_ag_info_t *bt_ag_info = g_new0(bt_ag_info_t, 1);
81 bt_ag_info->rfcomm = NULL;
82 bt_ag_info->slc = NULL;
83 bt_ag_info->hfp_active = TRUE;
84 bt_ag_info->vr_blacklisted = FALSE;
85 bt_ag_info->state = HEADSET_STATE_DISCONNECTED;
86 bt_ag_info->sco_server_started = FALSE;
87 bt_ag_info->path = "dev_00_1C_43_2B_1A_E5";
89 bt_ag_info->remote_addr = g_strdup("00:1C:43:2B:1A:E5");
91 bt_ag_info->slc = g_new0(bt_ag_slconn_t, 1);
92 bt_ag_info->slc->speaker_gain = 15;
93 bt_ag_info->slc->microphone_gain = 15;
94 bt_ag_info->slc->is_nrec = TRUE;
99 static void __bt_destroy_ag_info(bt_ag_info_t *ag_info)
104 g_free(ag_info->remote_addr);
105 g_free(ag_info->slc);
111 TEST(BluetoothAGAgent_test, _bt_ag_slconn_complete) {
112 bt_ag_info_t* ag_info = __bt_create_ag_info();
114 _bt_ag_slconn_complete(ag_info);
116 /* Need to wait 2 sec for invoking callback */
119 __bt_destroy_ag_info(ag_info);
122 TEST(BluetoothAGAgent_test, _bt_ag_send_response) {
123 int ret = BT_HFP_AGENT_ERROR_NONE;
124 bt_ag_info_t* ag_info = __bt_create_ag_info();
126 /* Negative test case : no device is connected */
127 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NONE);
128 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
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 /* Negative test case : no device is connected */
135 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_AG_FAILURE);
136 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
138 ag_info->slc->is_cme_enabled = TRUE;
140 /* Negative test case : no device is connected */
141 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NO_NETWORK_SERVICE);
142 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
144 __bt_destroy_ag_info(ag_info);
147 TEST(BluetoothAGAgent_test, _bt_hfp_call_hold_request) {
148 const char *cmd = "AT+CHLD";
149 bt_ag_info_t* ag_info = __bt_create_ag_info();
151 _bt_hfp_call_hold_request(cmd, ag_info);
153 __bt_destroy_ag_info(ag_info);
156 TEST(BluetoothAGAgent_test, _bt_hfp_key_press_request) {
157 const char *cmd = "AT+CKPD";
158 bt_ag_info_t* ag_info = __bt_create_ag_info();
160 _bt_hfp_key_press_request(cmd, ag_info);
162 __bt_destroy_ag_info(ag_info);
165 TEST(BluetoothAGAgent_test, _bt_hfp_terminate_call_request) {
166 bt_ag_info_t* ag_info = __bt_create_ag_info();
168 _bt_hfp_terminate_call_request(ag_info);
170 __bt_destroy_ag_info(ag_info);
173 TEST(BluetoothAGAgent_test, _bt_hfp_answer_call_request) {
174 bt_ag_info_t* ag_info = __bt_create_ag_info();
176 _bt_hfp_answer_call_request(ag_info);
178 __bt_destroy_ag_info(ag_info);
181 TEST(BluetoothAGAgent_test, _bt_hfp_update_event_request) {
182 bt_ag_info_t* ag_info = __bt_create_ag_info();
184 _bt_hfp_update_event_request(0, ag_info);
186 _bt_hfp_update_event_request(1, ag_info);
188 __bt_destroy_ag_info(ag_info);
191 TEST(BluetoothAGAgent_test, _bt_hfp_response_and_hold_request) {
192 bt_ag_info_t* ag_info = __bt_create_ag_info();
194 _bt_hfp_response_and_hold_request(ag_info);
196 __bt_destroy_ag_info(ag_info);
199 TEST(BluetoothAGAgent_test, _bt_hfp_last_dialed_number_request) {
200 bt_ag_info_t* ag_info = __bt_create_ag_info();
202 _bt_hfp_last_dialed_number_request(ag_info);
204 __bt_destroy_ag_info(ag_info);
207 TEST(BluetoothAGAgent_test, _bt_hfp_dial_number_request) {
208 bt_ag_info_t* ag_info = __bt_create_ag_info();
209 const char *number1 = "#31#";
210 const char *number2 = "*31#";
211 const char *number3 = ">123";
212 const char *number4 = "0123456789";
214 _bt_hfp_dial_number_request(number1, ag_info);
216 _bt_hfp_dial_number_request(number2, ag_info);
218 _bt_hfp_dial_number_request(number3, ag_info);
220 _bt_hfp_dial_number_request(number4, ag_info);
222 __bt_destroy_ag_info(ag_info);
225 TEST(BluetoothAGAgent_test, _bt_hfp_channel_dtmf_request) {
226 bt_ag_info_t* ag_info = __bt_create_ag_info();
227 const char tone = '1';
229 _bt_hfp_channel_dtmf_request(tone, ag_info);
231 __bt_destroy_ag_info(ag_info);
234 TEST(BluetoothAGAgent_test, _bt_hfp_subscriber_number_request) {
235 bt_ag_info_t* ag_info = __bt_create_ag_info();
237 _bt_hfp_subscriber_number_request(ag_info);
239 __bt_destroy_ag_info(ag_info);
242 TEST(BluetoothAGAgent_test, _bt_hfp_get_operator_selection_request) {
243 bt_ag_info_t* ag_info = __bt_create_ag_info();
245 _bt_hfp_get_operator_selection_request(ag_info);
247 __bt_destroy_ag_info(ag_info);
250 TEST(BluetoothAGAgent_test, _bt_hfp_noise_red_and_echo_cancel_request) {
251 bt_ag_info_t* ag_info = __bt_create_ag_info();
253 _bt_hfp_noise_red_and_echo_cancel_request(TRUE, ag_info);
255 _bt_hfp_noise_red_and_echo_cancel_request(FALSE, ag_info);
257 __bt_destroy_ag_info(ag_info);
260 TEST(BluetoothAGAgent_test, _bt_hfp_voice_dial_request) {
261 bt_ag_info_t* ag_info = __bt_create_ag_info();
263 _bt_hfp_voice_dial_request(TRUE, ag_info);
265 _bt_hfp_voice_dial_request(FALSE, ag_info);
267 __bt_destroy_ag_info(ag_info);
270 TEST(BluetoothAGAgent_test, _bt_hfp_set_indicators) {
271 bt_ag_info_t* ag_info = __bt_create_ag_info();
273 const char *cmd = "AT+BIA=call";
275 _bt_hfp_set_indicators(cmd, ag_info);
277 __bt_destroy_ag_info(ag_info);
280 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory_status) {
281 bt_ag_info_t* ag_info = __bt_create_ag_info();
283 _bt_hfp_select_phonebook_memory_status(ag_info);
285 __bt_destroy_ag_info(ag_info);
288 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory_list) {
289 bt_ag_info_t* ag_info = __bt_create_ag_info();
291 _bt_hfp_select_phonebook_memory_list(ag_info);
293 __bt_destroy_ag_info(ag_info);
296 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory) {
297 bt_ag_info_t* ag_info = __bt_create_ag_info();
298 const char *pb_path = "user";
300 _bt_hfp_select_phonebook_memory(ag_info, pb_path);
302 __bt_destroy_ag_info(ag_info);
305 TEST(BluetoothAGAgent_test, _bt_hfp_read_phonebook_entries_list) {
306 bt_ag_info_t* ag_info = __bt_create_ag_info();
308 _bt_hfp_read_phonebook_entries_list(ag_info);
310 __bt_destroy_ag_info(ag_info);
313 TEST(BluetoothAGAgent_test, _bt_hfp_read_phonebook_entries) {
314 bt_ag_info_t* ag_info = __bt_create_ag_info();
315 const char *cmd = "AT+CPBR=1,4";
317 _bt_hfp_read_phonebook_entries(ag_info, cmd);
319 __bt_destroy_ag_info(ag_info);
322 TEST(BluetoothAGAgent_test, _bt_hfp_find_phonebook_entries_status) {
323 bt_ag_info_t* ag_info = __bt_create_ag_info();
325 _bt_hfp_find_phonebook_entries_status(ag_info);
327 __bt_destroy_ag_info(ag_info);
330 TEST(BluetoothAGAgent_test, _bt_hfp_find_phonebook_entries) {
331 bt_ag_info_t* ag_info = __bt_create_ag_info();
332 const char *cmd = "AT+CPBR=1,4";
334 _bt_hfp_find_phonebook_entries(ag_info, cmd);
336 __bt_destroy_ag_info(ag_info);
339 TEST(BluetoothAGAgent_test, _bt_hfp_get_character_set) {
340 bt_ag_info_t* ag_info = __bt_create_ag_info();
342 _bt_hfp_get_character_set(ag_info);
344 __bt_destroy_ag_info(ag_info);
347 TEST(BluetoothAGAgent_test, _bt_hfp_list_supported_character) {
348 bt_ag_info_t* ag_info = __bt_create_ag_info();
350 _bt_hfp_list_supported_character(ag_info);
352 __bt_destroy_ag_info(ag_info);
355 TEST(BluetoothAGAgent_test, _bt_hfp_set_character_set) {
356 bt_ag_info_t* ag_info = __bt_create_ag_info();
357 const char *cmd = "\"UTF-8\"";
359 _bt_hfp_set_character_set(ag_info, cmd);
361 __bt_destroy_ag_info(ag_info);
364 TEST(BluetoothAGAgent_test, _bt_hfp_get_battery_property) {
365 bt_ag_info_t* ag_info = __bt_create_ag_info();
367 _bt_hfp_get_battery_property(ag_info);
369 __bt_destroy_ag_info(ag_info);
372 TEST(BluetoothAGAgent_test, _bt_hfp_signal_quality_reply) {
373 bt_ag_info_t* ag_info = __bt_create_ag_info();
375 _bt_hfp_signal_quality_reply(1, 1, ag_info);
377 __bt_destroy_ag_info(ag_info);
380 TEST(BluetoothAGAgent_test, _bt_hfp_battery_property_reply) {
381 bt_ag_info_t* ag_info = __bt_create_ag_info();
383 _bt_hfp_battery_property_reply(ag_info, 1, 1);
385 __bt_destroy_ag_info(ag_info);
388 TEST(BluetoothAGAgent_test, _bt_hfp_operator_reply) {
389 bt_ag_info_t* ag_info = __bt_create_ag_info();
391 _bt_hfp_operator_reply("Tizen", ag_info);
393 __bt_destroy_ag_info(ag_info);
396 TEST(BluetoothAGAgent_test, _bt_ag_agent_dial_num) {
397 bt_ag_info_t* ag_info = __bt_create_ag_info();
398 int ret = BT_HFP_AGENT_ERROR_NONE;
400 /* Negative test case */
401 ret = _bt_ag_agent_dial_num(NULL, 0);
402 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_INVALID_PARAM);
404 ret = _bt_ag_agent_dial_num("01012345678", 0);
405 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
407 __bt_destroy_ag_info(ag_info);
410 TEST(BluetoothAGAgent_test, _bt_ag_agent_dial_last_num) {
411 bt_ag_info_t* ag_info = __bt_create_ag_info();
412 int ret = BT_HFP_AGENT_ERROR_NONE;
414 /* Negative test case : No contact info */
415 ret = _bt_ag_agent_dial_last_num(ag_info);
416 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
418 __bt_destroy_ag_info(ag_info);
421 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_signal_quality) {
422 bt_ag_info_t* ag_info = __bt_create_ag_info();
423 gboolean ret = FALSE;
425 ret = _bt_ag_agent_get_signal_quality(ag_info);
426 ASSERT_TRUE(ret == TRUE);
428 __bt_destroy_ag_info(ag_info);
431 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_battery_status) {
432 bt_ag_info_t* ag_info = __bt_create_ag_info();
433 gboolean ret = FALSE;
435 ret = _bt_ag_agent_get_battery_status(ag_info);
436 ASSERT_TRUE(ret == TRUE);
438 __bt_destroy_ag_info(ag_info);
441 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_operator_name) {
442 bt_ag_info_t* ag_info = __bt_create_ag_info();
443 gboolean ret = FALSE;
445 ret = _bt_ag_agent_get_operator_name(ag_info);
446 ASSERT_TRUE(ret == TRUE);
448 __bt_destroy_ag_info(ag_info);
451 TEST(BluetoothAGAgent_test, _bt_hfp_agent_nrec_status) {
452 bt_ag_info_t* ag_info = __bt_create_ag_info();
453 gboolean ret = FALSE;
455 ret = _bt_hfp_agent_nrec_status(TRUE, ag_info);
456 ASSERT_TRUE(ret == TRUE);
458 ret = _bt_hfp_agent_nrec_status(FALSE, ag_info);
459 ASSERT_TRUE(ret == TRUE);
461 __bt_destroy_ag_info(ag_info);
464 TEST(BluetoothAGAgent_test, _bt_ag_agent_voice_dial) {
465 bt_ag_info_t* ag_info = __bt_create_ag_info();
466 gboolean ret = FALSE;
468 ret = _bt_ag_agent_voice_dial(FALSE);
469 ASSERT_TRUE(ret == TRUE);
471 __bt_destroy_ag_info(ag_info);
474 TEST(BluetoothAGAgent_test, _bt_list_current_calls) {
475 bt_ag_info_t* ag_info = __bt_create_ag_info();
477 _bt_list_current_calls(ag_info);
479 __bt_destroy_ag_info(ag_info);
482 TEST(BluetoothAGAgent_test, _bt_get_activity_status) {
483 bt_ag_info_t* ag_info = __bt_create_ag_info();
485 _bt_get_activity_status(ag_info);
487 __bt_destroy_ag_info(ag_info);
490 TEST(BluetoothAGAgent_test, _bt_hfp_set_property_name) {
491 const char *property1 = "OperatorNameChanged";
492 const char *property2 = "SubscriberNumberChanged";
493 const char *operator_name = "Tizen";
496 ret = _bt_hfp_set_property_name(property1, operator_name);
497 ASSERT_TRUE(ret == 1);
499 ret = _bt_hfp_set_property_name(property2, operator_name);
500 ASSERT_TRUE(ret == 1);
503 TEST(BluetoothAGAgent_test, _bt_hfp_get_imei_number_reply) {
504 bt_ag_info_t* ag_info = __bt_create_ag_info();
506 _bt_hfp_get_imei_number_reply("1234", ag_info);
508 __bt_destroy_ag_info(ag_info);
511 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_info_reply) {
512 bt_ag_info_t* ag_info = __bt_create_ag_info();
514 _bt_hfp_get_model_info_reply("Tizen", ag_info);
516 __bt_destroy_ag_info(ag_info);
519 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer_reply) {
520 bt_ag_info_t* ag_info = __bt_create_ag_info();
522 _bt_hfp_get_device_manufacturer_reply("Tizen", ag_info);
524 __bt_destroy_ag_info(ag_info);
527 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_info_reply) {
528 bt_ag_info_t* ag_info = __bt_create_ag_info();
530 _bt_hfp_get_revision_info_reply("5.0", ag_info);
532 __bt_destroy_ag_info(ag_info);
535 TEST(BluetoothAGAgent_test, _bt_hfp_device_disconnected) {
536 bt_ag_info_t* ag_info = __bt_create_ag_info();
538 _bt_hfp_device_disconnected(ag_info);
540 __bt_destroy_ag_info(ag_info);
543 TEST(BluetoothAGAgent_test, _bt_hfp_get_equipment_identity) {
544 bt_ag_info_t* ag_info = __bt_create_ag_info();
545 const char *cmd1 = "AT+CGSN=?";
546 const char *cmd2 = "AT+CGSN";
547 int ret = BT_HFP_AGENT_ERROR_NONE;
549 /* Negative test case */
550 ret = _bt_hfp_get_equipment_identity(ag_info, cmd1);
551 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
553 ret = _bt_hfp_get_equipment_identity(ag_info, cmd2);
554 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
556 __bt_destroy_ag_info(ag_info);
559 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_information) {
560 bt_ag_info_t* ag_info = __bt_create_ag_info();
561 const char *cmd1 = "AT+CGMM=?";
562 const char *cmd2 = "AT+CGMM";
563 int ret = BT_HFP_AGENT_ERROR_NONE;
565 /* Negative test case : No device connected */
566 ret = _bt_hfp_get_model_information(ag_info, cmd1);
567 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
569 ret = _bt_hfp_get_model_information(ag_info, cmd2);
570 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
572 __bt_destroy_ag_info(ag_info);
575 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer) {
576 bt_ag_info_t* ag_info = __bt_create_ag_info();
577 const char *cmd1 = "AT+CGMI=?";
578 const char *cmd2 = "AT+CGMI";
579 int ret = BT_HFP_AGENT_ERROR_NONE;
581 /* Negative test case */
582 ret = _bt_hfp_get_device_manufacturer(ag_info, cmd1);
583 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
585 ret = _bt_hfp_get_device_manufacturer(ag_info, cmd2);
586 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
588 __bt_destroy_ag_info(ag_info);
591 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi) {
592 bt_ag_info_t* ag_info = __bt_create_ag_info();
593 const char *cmd1 = "AT+IMSI=?";
594 const char *cmd2 = "AT+IMSI";
595 int ret = BT_HFP_AGENT_ERROR_NONE;
597 ret = _bt_hfp_get_imsi(ag_info, cmd1);
598 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
600 ret = _bt_hfp_get_imsi(ag_info, cmd2);
601 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
603 __bt_destroy_ag_info(ag_info);
606 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status) {
607 bt_ag_info_t* ag_info = __bt_create_ag_info();
608 const char *cmd1 = "AT+IMSI=?";
609 const char *cmd2 = "AT+IMSI";
610 const char *cmd3 = "AT+IMSI?";
611 int ret = BT_HFP_AGENT_ERROR_NONE;
613 ret = _bt_hfp_get_creg_status(ag_info, cmd1);
614 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
616 ret = _bt_hfp_get_creg_status(ag_info, cmd2);
617 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
619 ret = _bt_hfp_get_creg_status(ag_info, cmd3);
620 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
622 __bt_destroy_ag_info(ag_info);
625 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_information) {
626 bt_ag_info_t* ag_info = __bt_create_ag_info();
627 const char *cmd1 = "AT+CGMR=?";
628 const char *cmd2 = "AT+CGMR";
629 int ret = BT_HFP_AGENT_ERROR_NONE;
631 /* Negative test case : No device connected */
632 ret = _bt_hfp_get_revision_information(ag_info, cmd1);
633 ASSERT_TRUE(ret != BT_HFP_AGENT_ERROR_NONE);
635 ret = _bt_hfp_get_revision_information(ag_info, cmd2);
636 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
638 __bt_destroy_ag_info(ag_info);
641 TEST(BluetoothAGAgent_test, _bt_hfp_get_equipment_identity_req) {
642 bt_ag_info_t* ag_info = __bt_create_ag_info();
644 _bt_hfp_get_equipment_identity_req(ag_info);
646 __bt_destroy_ag_info(ag_info);
649 TEST(BluetoothAGAgent_test, _bt_hfp_initialize_telephony_manager) {
650 uint32_t ag_features = BT_AG_FEATURE_EC_AND_NR |
651 BT_AG_FEATURE_REJECT_CALL |
652 BT_AG_FEATURE_ENHANCED_CALL_STATUS |
653 BT_AG_FEATURE_THREE_WAY_CALL |
654 BT_AG_FEATURE_EXTENDED_ERROR_RESULT_CODES |
655 BT_AG_FEATURE_CODEC_NEGOTIATION;
657 _bt_hfp_initialize_telephony_manager(ag_features);
659 _bt_hfp_deinitialize_telephony_manager();
662 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_info_req) {
663 bt_ag_info_t* ag_info = __bt_create_ag_info();
665 _bt_hfp_get_model_info_req(ag_info);
667 __bt_destroy_ag_info(ag_info);
670 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer_req) {
671 bt_ag_info_t* ag_info = __bt_create_ag_info();
673 _bt_hfp_get_device_manufacturer_req(ag_info);
675 __bt_destroy_ag_info(ag_info);
678 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi_req) {
679 bt_ag_info_t* ag_info = __bt_create_ag_info();
681 _bt_hfp_get_imsi_req(ag_info);
683 __bt_destroy_ag_info(ag_info);
686 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status_req) {
687 bt_ag_info_t* ag_info = __bt_create_ag_info();
689 _bt_hfp_get_creg_status_req(ag_info);
691 __bt_destroy_ag_info(ag_info);
694 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_info_req) {
695 bt_ag_info_t* ag_info = __bt_create_ag_info();
697 _bt_hfp_get_revision_info_req(ag_info);
699 __bt_destroy_ag_info(ag_info);
702 TEST(BluetoothAGAgent_test, _bt_hfp_is_call_exist) {
703 gboolean ret = FALSE;
705 ret = _bt_hfp_is_call_exist();
708 TEST(BluetoothAGAgent_test, _bt_hfp_release_all_calls_by_sender) {
709 const char *sender = "sender";
711 _bt_hfp_release_all_calls_by_sender(sender);
714 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi_reply) {
715 bt_ag_info_t* ag_info = __bt_create_ag_info();
717 _bt_hfp_get_imsi_reply(NULL, NULL, NULL, ag_info);
719 _bt_hfp_get_imsi_reply("mmc", "mnc", "msin", ag_info);
721 __bt_destroy_ag_info(ag_info);
724 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status_reply) {
725 bt_ag_info_t* ag_info = __bt_create_ag_info();
727 _bt_hfp_get_creg_status_reply(1, 0, ag_info);
729 __bt_destroy_ag_info(ag_info);
732 TEST(BluetoothAGAgent_test, _bt_hfp_vendor_cmd_request) {
733 bt_ag_info_t* ag_info = __bt_create_ag_info();
734 const char *cmd = "AT+VND";
736 _bt_hfp_vendor_cmd_request(cmd, ag_info);
738 __bt_destroy_ag_info(ag_info);
741 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_model_name) {
742 bt_ag_info_t* ag_info = __bt_create_ag_info();
744 _bt_ag_agent_get_model_name(ag_info);
746 __bt_destroy_ag_info(ag_info);
749 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_manufacturer_name) {
750 bt_ag_info_t* ag_info = __bt_create_ag_info();
752 _bt_ag_agent_get_manufacturer_name(ag_info);
754 __bt_destroy_ag_info(ag_info);
757 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_imsi) {
758 bt_ag_info_t* ag_info = __bt_create_ag_info();
760 _bt_ag_agent_get_imsi(ag_info);
762 __bt_destroy_ag_info(ag_info);
765 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_creg_status) {
766 bt_ag_info_t* ag_info = __bt_create_ag_info();
768 _bt_ag_agent_get_creg_status(ag_info);
770 __bt_destroy_ag_info(ag_info);
773 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_revision_information) {
774 bt_ag_info_t* ag_info = __bt_create_ag_info();
776 _bt_ag_agent_get_revision_information(ag_info);
778 __bt_destroy_ag_info(ag_info);
781 #ifdef TIZEN_FEATURE_BT_MEDIA_ENHANCE
782 TEST(BluetoothAGAgent_test, _bt_ag_agent_check_transport_state) {
783 bt_ag_info_t* ag_info = __bt_create_ag_info();
785 _bt_ag_agent_check_transport_state(ag_info);
787 __bt_destroy_ag_info(ag_info);
791 /* Functions for hid-agent */
792 TEST(BluetoothHIDAgent_test, _bt_hid_disconnect_profile) {
793 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
795 /* Negative test case : no device is connected */
796 ret = _bt_hid_disconnect_profile();
797 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INTERNAL);
800 TEST(BluetoothHIDAgent_test, _bt_hid_set_profile_state) {
801 _bt_hid_set_profile_state(BT_HID_STATE_CONNECTING);
803 _bt_hid_set_profile_state(BT_HID_STATE_CONNECTED);
805 _bt_hid_set_profile_state(BT_HID_STATE_UNAVAILABLE);
808 TEST(BluetoothHIDAgent_test, _bt_hid_get_profile_state) {
809 bt_hid_state_t state;
811 state = _bt_hid_get_profile_state();
812 ASSERT_TRUE(state >= BT_HID_STATE_UNAVAILABLE && state <= BT_HID_STATE_DISCONNECTING);
815 TEST(BluetoothHIDAgent_test, _bt_hid_register_application) {
816 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
818 /* Negative test case */
819 ret = _bt_hid_register_application(TRUE, NULL);
820 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INVALID_PARAM);
822 ret = _bt_hid_register_application(TRUE, "Sender");
823 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
825 /* Negative test case */
826 ret = _bt_hid_register_application(TRUE, "Sender");
827 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_ALREADY_EXIST);
829 ret = _bt_hid_register_application(FALSE, "Sender");
830 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
832 /* Negative test case */
833 ret = _bt_hid_register_application(FALSE, "Sender");
834 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NOT_AVAILABLE);
837 TEST(BluetoothHIDAgent_test, _bt_hid_get_sender_list) {
838 const GSList *senders;
839 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
841 ret = _bt_hid_register_application(TRUE, "Sender");
842 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
844 senders = _bt_hid_get_sender_list();
845 ASSERT_TRUE(senders != NULL);
847 ret = _bt_hid_register_application(FALSE, "Sender");
848 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
851 /* Functions for ipsp-agent */
852 TEST(BluetoothIPSPAgent_test, _bt_ipsp_register_dbus) {
853 gboolean ret = FALSE;
855 ret = _bt_ipsp_register_dbus();
856 ASSERT_TRUE(ret == TRUE);
859 TEST(BluetoothIPSPAgent_test, _bt_ipsp_unregister_dbus) {
860 _bt_ipsp_unregister_dbus();
863 TEST(BluetoothIPSPAgent_test, _bt_ipsp_gdbus_deinit_proxys) {
864 _bt_ipsp_gdbus_deinit_proxys();
867 /* Functions for map-agent */
868 static message_info_t* __bt_create_msg_info(void)
870 message_info_t *bt_msg_info = g_new0(message_info_t, 1);
872 bt_msg_info->handle = g_strdup("1");
873 bt_msg_info->subject = g_strdup("subject");
874 bt_msg_info->datetime = g_strdup("datetime");
875 bt_msg_info->sender_name = g_strdup("sender_name");
876 bt_msg_info->sender_addressing = g_strdup("sender_addressing");
877 bt_msg_info->replyto_addressing = g_strdup("replyto_addressing");
878 bt_msg_info->recipient_name = g_strdup("recipient_name");
879 bt_msg_info->recipient_addressing = g_strdup("recipient_addressing");
880 bt_msg_info->type = g_strdup("type");
881 bt_msg_info->reception_status = g_strdup("reception_status");
882 bt_msg_info->size = g_strdup("size");
883 bt_msg_info->attachment_size = g_strdup("attachment_size");
888 TEST(BluetoothMAPAgent_test, _bt_mns_client_event_notify) {
889 _bt_mns_client_event_notify("MessageShift", 0,
890 "TELECOM/MSG/DELETED", "/opt/usr", "EMAIL");
894 TEST(BluetoothMAPAgent_test, _bt_update_id) {
897 /* Negative test case */
898 ret = _bt_update_id(0, -1, -1);
899 ASSERT_TRUE(ret == -1);
902 TEST(BluetoothMAPAgent_test, _bt_validate_msg_data) {
903 gboolean ret = FALSE;
904 message_info_t *bt_msg_info = __bt_create_msg_info();
906 /* Negative test case */
907 ret = _bt_validate_msg_data(NULL);
908 ASSERT_TRUE(ret == FALSE);
910 ret = _bt_validate_msg_data(bt_msg_info);
911 ASSERT_TRUE(ret == TRUE);
913 _bt_message_info_free(bt_msg_info);
916 TEST(BluetoothMAPAgent_test, _bt_message_info_free) {
917 message_info_t *bt_msg_info = __bt_create_msg_info();
919 _bt_message_info_free(bt_msg_info);
922 TEST(BluetoothMAPAgent_test, _get_msg_timestamp) {
925 struct timeval tv = {0, };
926 char msg_datetime[16] = {0, };
928 gettimeofday(&tv, NULL);
929 cur_time = tv.tv_sec;
931 _get_msg_timestamp(&cur_time, msg_datetime);
934 TEST(BluetoothMAPAgent_test, _bt_add_id) {
937 map_id = _bt_add_id(-1, BT_MAP_ID_EMAIL);
938 ASSERT_TRUE(map_id == 1);
941 TEST(BluetoothMAPAgent_test, _bt_validate_uid) {
944 map_id = _bt_validate_uid(-1, BT_MAP_ID_EMAIL);
945 ASSERT_TRUE(map_id == 1);
948 TEST(BluetoothMAPAgent_test, is_mns_connected) {
949 gboolean ret = FALSE;
951 /* Negative test case */
952 ret = is_mns_connected();
953 ASSERT_TRUE(ret == FALSE);
956 TEST(BluetoothMAPAgent_test, _bt_verify_read_status) {
957 gboolean ret = FALSE;
958 message_info_t *bt_msg_info = __bt_create_msg_info();
960 ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_ALL);
961 _bt_message_info_free(bt_msg_info);
962 ASSERT_TRUE(ret == TRUE);
964 bt_msg_info = __bt_create_msg_info();
966 ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_READ);
967 _bt_message_info_free(bt_msg_info);
968 ASSERT_TRUE(ret == FALSE);
971 TEST(BluetoothMAPAgent_test, _bt_verify_sender) {
972 gboolean ret = FALSE;
973 message_info_t *bt_msg_info = __bt_create_msg_info();
975 /* Negative test case */
976 ret = _bt_verify_sender(bt_msg_info, NULL);
977 _bt_message_info_free(bt_msg_info);
978 ASSERT_TRUE(ret == TRUE);
980 bt_msg_info = __bt_create_msg_info();
982 ret = _bt_verify_sender(bt_msg_info, "*");
983 _bt_message_info_free(bt_msg_info);
984 ASSERT_TRUE(ret == TRUE);
986 bt_msg_info = __bt_create_msg_info();
988 ret = _bt_verify_sender(bt_msg_info, "sender");
989 _bt_message_info_free(bt_msg_info);
990 ASSERT_TRUE(ret == TRUE);
992 bt_msg_info = __bt_create_msg_info();
994 /* Negative test case */
995 ret = _bt_verify_sender(bt_msg_info, "negative");
996 _bt_message_info_free(bt_msg_info);
997 ASSERT_TRUE(ret == FALSE);
1000 TEST(BluetoothMAPAgent_test, _bt_verify_receiver) {
1001 gboolean ret = FALSE;
1002 message_info_t *bt_msg_info = __bt_create_msg_info();
1004 /* Negative test case */
1005 ret = _bt_verify_receiver(bt_msg_info, NULL);
1006 _bt_message_info_free(bt_msg_info);
1007 ASSERT_TRUE(ret == TRUE);
1009 bt_msg_info = __bt_create_msg_info();
1011 ret = _bt_verify_receiver(bt_msg_info, "*");
1012 _bt_message_info_free(bt_msg_info);
1013 ASSERT_TRUE(ret == TRUE);
1015 bt_msg_info = __bt_create_msg_info();
1017 ret = _bt_verify_receiver(bt_msg_info, "receiver");
1018 _bt_message_info_free(bt_msg_info);
1019 ASSERT_TRUE(ret == FALSE);
1021 bt_msg_info = __bt_create_msg_info();
1023 /* Negative test case */
1024 ret = _bt_verify_receiver(bt_msg_info, "negative");
1025 _bt_message_info_free(bt_msg_info);
1026 ASSERT_TRUE(ret == FALSE);
1029 TEST(BluetoothMAPAgent_test, _bt_verify_time) {
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_verify_time(bt_msg_info, &filter);
1035 _bt_message_info_free(bt_msg_info);
1036 ASSERT_TRUE(ret == FALSE);
1039 TEST(BluetoothMAPAgent_test, _bt_filter_priority) {
1040 gboolean ret = FALSE;
1041 map_msg_filter_t filter = { 0, };
1042 message_info_t *bt_msg_info = __bt_create_msg_info();
1044 ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_ALL);
1045 _bt_message_info_free(bt_msg_info);
1046 ASSERT_TRUE(ret == TRUE);
1048 bt_msg_info = __bt_create_msg_info();
1050 ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_HIGH);
1051 _bt_message_info_free(bt_msg_info);
1052 ASSERT_TRUE(ret == FALSE);
1055 TEST(BluetoothMAPAgent_test, _bt_map_start_email_service) {
1056 gboolean ret = FALSE;
1058 /* Negative test case */
1059 ret = _bt_map_start_email_service();
1060 ASSERT_TRUE(ret == FALSE);
1063 TEST(BluetoothMAPAgent_test, _bt_map_stop_email_service) {
1064 gboolean ret = FALSE;
1066 ret = _bt_map_stop_email_service();
1067 ASSERT_TRUE(ret == TRUE);
1070 TEST(BluetoothMAPAgent_test, _bt_map_email_get_supported_folders) {
1071 gboolean ret = FALSE;
1072 gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, };
1074 /* Negative test case */
1075 ret = _bt_map_email_get_supported_folders(folders_supported);
1076 ASSERT_TRUE(ret == FALSE);
1079 TEST(BluetoothMAPAgent_test, _bt_map_update_mailbox) {
1080 gboolean ret = FALSE;
1082 /* Negative test case */
1083 ret = _bt_map_update_mailbox("/tmp");
1084 ASSERT_TRUE(ret == FALSE);
1087 TEST(BluetoothMAPAgent_test, _bt_map_set_email_read_status) {
1088 gboolean ret = FALSE;
1090 /* Negative test case */
1091 ret = _bt_map_set_email_read_status(-1, 0);
1092 ASSERT_TRUE(ret == FALSE);
1095 TEST(BluetoothMAPAgent_test, _bt_map_set_email_delete_status) {
1096 gboolean ret = FALSE;
1098 /* Negative test case */
1099 ret = _bt_map_set_email_delete_status(-1, 0);
1100 ASSERT_TRUE(ret == FALSE);
1103 TEST(BluetoothMAPAgent_test, _bt_map_get_email_message) {
1104 gboolean ret = FALSE;
1105 gchar *bmseg = NULL;
1107 /* Negative test case */
1108 ret = _bt_map_get_email_message(-1, FALSE, TRUE, TRUE, &bmseg);
1109 ASSERT_TRUE(ret == FALSE);
1112 TEST(BluetoothMAPAgent_test, _bt_map_start_sms_service) {
1113 gboolean ret = FALSE;
1115 ret = _bt_map_start_sms_service();
1116 ASSERT_TRUE(ret == TRUE);
1119 TEST(BluetoothMAPAgent_test, _bt_map_stop_sms_service) {
1120 gboolean ret = FALSE;
1121 gchar *bmseg = NULL;
1123 /* Negative test case */
1124 _bt_map_stop_sms_service();
1125 ASSERT_TRUE(ret == FALSE);
1128 TEST(BluetoothMAPAgent_test, _bt_map_sms_get_supported_folders) {
1129 gboolean ret = FALSE;
1130 gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, };
1132 /* Negative test case */
1133 ret = _bt_map_sms_get_supported_folders(folders_supported);
1134 ASSERT_TRUE(ret == FALSE);
1137 TEST(BluetoothMAPAgent_test, _bt_map_get_sms_message) {
1138 gboolean ret = FALSE;
1139 gchar *bmseg = NULL;
1141 /* Negative test case */
1142 ret = _bt_map_get_sms_message(-1, FALSE, TRUE, TRUE, &bmseg);
1143 ASSERT_TRUE(ret == FALSE);
1146 TEST(BluetoothMAPAgent_test, _bt_map_set_sms_delete_status) {
1147 gboolean ret = FALSE;
1149 /* Negative test case */
1150 ret = _bt_map_set_sms_delete_status(-1, 0);
1151 ASSERT_TRUE(ret == FALSE);
1154 TEST(BluetoothMAPAgent_test, _bt_map_sms_set_read_status) {
1155 gboolean ret = FALSE;
1157 /* Negative test case */
1158 ret = _bt_map_sms_set_read_status(-1, 0);
1159 ASSERT_TRUE(ret == FALSE);
1162 /* Functions for pb-agent */
1163 TEST(BluetoothPBAgent_test, _bluetooth_get_contact_addressbook) {
1164 int ret = PBAP_ADDRESSBOOK_PHONE;
1166 ret = _bluetooth_get_contact_addressbook(1);
1167 ASSERT_TRUE(ret == PBAP_ADDRESSBOOK_PHONE);
1170 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact) {
1173 /* Negative test case */
1174 str = _bluetooth_pb_vcard_contact(0, VCARD_PHOTO, VCARD_FORMAT_2_1);
1175 ASSERT_TRUE(str == NULL);
1177 /* Negative test case */
1178 str = _bluetooth_pb_vcard_contact(1, VCARD_PHOTO, VCARD_FORMAT_3_0);
1179 ASSERT_TRUE(str == NULL);
1182 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact_owner) {
1184 const char *number = "01012345678";
1186 str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_2_1);
1187 ASSERT_TRUE(str != NULL);
1190 str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_3_0);
1191 ASSERT_TRUE(str != NULL);
1195 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_call) {
1197 const char *attr = "DIALED";
1199 /* Negative test case */
1200 str = _bluetooth_pb_vcard_call(1, VCARD_PHOTO, VCARD_FORMAT_2_1, NULL);
1201 ASSERT_TRUE(str == NULL);
1203 str = _bluetooth_pb_vcard_call(1, VCARD_PHOTO, VCARD_FORMAT_2_1, attr);
1204 ASSERT_TRUE(str != NULL);
1209 TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_person_id) {
1212 /* Negative test case */
1213 str = _bluetooth_pb_fn_from_person_id(1);
1214 ASSERT_TRUE(str == NULL);
1217 TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_person_id) {
1220 /* Negative test case */
1221 str = _bluetooth_pb_name_from_person_id(1);
1222 ASSERT_TRUE(str == NULL);
1225 TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_person_id) {
1228 /* Negative test case */
1229 str = _bluetooth_pb_number_from_person_id(1);
1230 ASSERT_TRUE(str == NULL);
1233 TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_phonelog_id) {
1236 str = _bluetooth_pb_fn_from_phonelog_id(1);
1237 ASSERT_TRUE(str != NULL);
1242 TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_phonelog_id) {
1245 str = _bluetooth_pb_name_from_phonelog_id(1);
1246 ASSERT_TRUE(str != NULL);
1251 TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_phonelog_id) {
1254 /* Negative test case */
1255 str = _bluetooth_pb_number_from_phonelog_id(1);
1256 ASSERT_TRUE(str == NULL);
1259 TEST(BluetoothPBAgent_test, _bluetooth_pb_owner_name) {
1262 /* Negative test case */
1263 name = _bluetooth_pb_owner_name();
1264 ASSERT_TRUE(name != NULL);
1268 TEST(BluetoothPBAgent_test, _bt_is_sim_addressbook) {
1270 const char *address_book = "http://tizen.org/addressbook/sim1";
1272 ret = _bt_is_sim_addressbook(address_book);
1273 ASSERT_TRUE(ret == true);
1276 int main(int argc, char **argv) {
1277 InitGoogleTest(&argc, argv);
1279 return RUN_ALL_TESTS();