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 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NONE);
127 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
129 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NO_NETWORK_SERVICE);
130 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
132 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_AG_FAILURE);
133 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
135 ag_info->slc->is_cme_enabled = TRUE;
137 ret = _bt_ag_send_response(ag_info, HFP_STATE_MNGR_ERR_NO_NETWORK_SERVICE);
138 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
140 __bt_destroy_ag_info(ag_info);
143 TEST(BluetoothAGAgent_test, _bt_hfp_call_hold_request) {
144 const char *cmd = "AT+CHLD";
145 bt_ag_info_t* ag_info = __bt_create_ag_info();
147 _bt_hfp_call_hold_request(cmd, ag_info);
149 __bt_destroy_ag_info(ag_info);
152 TEST(BluetoothAGAgent_test, _bt_hfp_key_press_request) {
153 const char *cmd = "AT+CKPD";
154 bt_ag_info_t* ag_info = __bt_create_ag_info();
156 _bt_hfp_key_press_request(cmd, ag_info);
158 __bt_destroy_ag_info(ag_info);
161 TEST(BluetoothAGAgent_test, _bt_hfp_terminate_call_request) {
162 bt_ag_info_t* ag_info = __bt_create_ag_info();
164 _bt_hfp_terminate_call_request(ag_info);
166 __bt_destroy_ag_info(ag_info);
169 TEST(BluetoothAGAgent_test, _bt_hfp_answer_call_request) {
170 bt_ag_info_t* ag_info = __bt_create_ag_info();
172 _bt_hfp_answer_call_request(ag_info);
174 __bt_destroy_ag_info(ag_info);
177 TEST(BluetoothAGAgent_test, _bt_hfp_update_event_request) {
178 bt_ag_info_t* ag_info = __bt_create_ag_info();
180 _bt_hfp_update_event_request(0, ag_info);
182 _bt_hfp_update_event_request(1, ag_info);
184 __bt_destroy_ag_info(ag_info);
187 TEST(BluetoothAGAgent_test, _bt_hfp_response_and_hold_request) {
188 bt_ag_info_t* ag_info = __bt_create_ag_info();
190 _bt_hfp_response_and_hold_request(ag_info);
192 __bt_destroy_ag_info(ag_info);
195 TEST(BluetoothAGAgent_test, _bt_hfp_last_dialed_number_request) {
196 bt_ag_info_t* ag_info = __bt_create_ag_info();
198 _bt_hfp_last_dialed_number_request(ag_info);
200 __bt_destroy_ag_info(ag_info);
203 TEST(BluetoothAGAgent_test, _bt_hfp_dial_number_request) {
204 bt_ag_info_t* ag_info = __bt_create_ag_info();
205 const char *number1 = "#31#";
206 const char *number2 = "*31#";
207 const char *number3 = ">123";
208 const char *number4 = "0123456789";
210 _bt_hfp_dial_number_request(number1, ag_info);
212 _bt_hfp_dial_number_request(number2, ag_info);
214 _bt_hfp_dial_number_request(number3, ag_info);
216 _bt_hfp_dial_number_request(number4, ag_info);
218 __bt_destroy_ag_info(ag_info);
221 TEST(BluetoothAGAgent_test, _bt_hfp_channel_dtmf_request) {
222 bt_ag_info_t* ag_info = __bt_create_ag_info();
223 const char tone = '1';
225 _bt_hfp_channel_dtmf_request(tone, ag_info);
227 __bt_destroy_ag_info(ag_info);
230 TEST(BluetoothAGAgent_test, _bt_hfp_subscriber_number_request) {
231 bt_ag_info_t* ag_info = __bt_create_ag_info();
233 _bt_hfp_subscriber_number_request(ag_info);
235 __bt_destroy_ag_info(ag_info);
238 TEST(BluetoothAGAgent_test, _bt_hfp_get_operator_selection_request) {
239 bt_ag_info_t* ag_info = __bt_create_ag_info();
241 _bt_hfp_get_operator_selection_request(ag_info);
243 __bt_destroy_ag_info(ag_info);
246 TEST(BluetoothAGAgent_test, _bt_hfp_noise_red_and_echo_cancel_request) {
247 bt_ag_info_t* ag_info = __bt_create_ag_info();
249 _bt_hfp_noise_red_and_echo_cancel_request(TRUE, ag_info);
251 _bt_hfp_noise_red_and_echo_cancel_request(FALSE, ag_info);
253 __bt_destroy_ag_info(ag_info);
256 TEST(BluetoothAGAgent_test, _bt_hfp_voice_dial_request) {
257 bt_ag_info_t* ag_info = __bt_create_ag_info();
259 _bt_hfp_voice_dial_request(TRUE, ag_info);
261 _bt_hfp_voice_dial_request(FALSE, ag_info);
263 __bt_destroy_ag_info(ag_info);
266 TEST(BluetoothAGAgent_test, _bt_hfp_set_indicators) {
267 bt_ag_info_t* ag_info = __bt_create_ag_info();
269 const char *cmd = "AT+BIA=call";
271 _bt_hfp_set_indicators(cmd, ag_info);
273 __bt_destroy_ag_info(ag_info);
276 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory_status) {
277 bt_ag_info_t* ag_info = __bt_create_ag_info();
279 _bt_hfp_select_phonebook_memory_status(ag_info);
281 __bt_destroy_ag_info(ag_info);
284 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory_list) {
285 bt_ag_info_t* ag_info = __bt_create_ag_info();
287 _bt_hfp_select_phonebook_memory_list(ag_info);
289 __bt_destroy_ag_info(ag_info);
292 TEST(BluetoothAGAgent_test, _bt_hfp_select_phonebook_memory) {
293 bt_ag_info_t* ag_info = __bt_create_ag_info();
294 const char *pb_path = "user";
296 _bt_hfp_select_phonebook_memory(ag_info, pb_path);
298 __bt_destroy_ag_info(ag_info);
301 TEST(BluetoothAGAgent_test, _bt_hfp_read_phonebook_entries_list) {
302 bt_ag_info_t* ag_info = __bt_create_ag_info();
304 _bt_hfp_read_phonebook_entries_list(ag_info);
306 __bt_destroy_ag_info(ag_info);
309 TEST(BluetoothAGAgent_test, _bt_hfp_read_phonebook_entries) {
310 bt_ag_info_t* ag_info = __bt_create_ag_info();
311 const char *cmd = "AT+CPBR=1,4";
313 _bt_hfp_read_phonebook_entries(ag_info, cmd);
315 __bt_destroy_ag_info(ag_info);
318 TEST(BluetoothAGAgent_test, _bt_hfp_find_phonebook_entries_status) {
319 bt_ag_info_t* ag_info = __bt_create_ag_info();
321 _bt_hfp_find_phonebook_entries_status(ag_info);
323 __bt_destroy_ag_info(ag_info);
326 TEST(BluetoothAGAgent_test, _bt_hfp_find_phonebook_entries) {
327 bt_ag_info_t* ag_info = __bt_create_ag_info();
328 const char *cmd = "AT+CPBR=1,4";
330 _bt_hfp_find_phonebook_entries(ag_info, cmd);
332 __bt_destroy_ag_info(ag_info);
335 TEST(BluetoothAGAgent_test, _bt_hfp_get_character_set) {
336 bt_ag_info_t* ag_info = __bt_create_ag_info();
338 _bt_hfp_get_character_set(ag_info);
340 __bt_destroy_ag_info(ag_info);
343 TEST(BluetoothAGAgent_test, _bt_hfp_list_supported_character) {
344 bt_ag_info_t* ag_info = __bt_create_ag_info();
346 _bt_hfp_list_supported_character(ag_info);
348 __bt_destroy_ag_info(ag_info);
351 TEST(BluetoothAGAgent_test, _bt_hfp_set_character_set) {
352 bt_ag_info_t* ag_info = __bt_create_ag_info();
353 const char *cmd = "\"UTF-8\"";
355 _bt_hfp_set_character_set(ag_info, cmd);
357 __bt_destroy_ag_info(ag_info);
360 TEST(BluetoothAGAgent_test, _bt_hfp_get_battery_property) {
361 bt_ag_info_t* ag_info = __bt_create_ag_info();
363 _bt_hfp_get_battery_property(ag_info);
365 __bt_destroy_ag_info(ag_info);
368 TEST(BluetoothAGAgent_test, _bt_hfp_signal_quality_reply) {
369 bt_ag_info_t* ag_info = __bt_create_ag_info();
371 _bt_hfp_signal_quality_reply(1, 1, ag_info);
373 __bt_destroy_ag_info(ag_info);
376 TEST(BluetoothAGAgent_test, _bt_hfp_battery_property_reply) {
377 bt_ag_info_t* ag_info = __bt_create_ag_info();
379 _bt_hfp_battery_property_reply(ag_info, 1, 1);
381 __bt_destroy_ag_info(ag_info);
384 TEST(BluetoothAGAgent_test, _bt_hfp_operator_reply) {
385 bt_ag_info_t* ag_info = __bt_create_ag_info();
387 _bt_hfp_operator_reply("Tizen", ag_info);
389 __bt_destroy_ag_info(ag_info);
392 TEST(BluetoothAGAgent_test, _bt_ag_agent_dial_num) {
393 bt_ag_info_t* ag_info = __bt_create_ag_info();
394 int ret = BT_HFP_AGENT_ERROR_NONE;
396 ret = _bt_ag_agent_dial_num("01012345678", 0);
397 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
399 __bt_destroy_ag_info(ag_info);
402 TEST(BluetoothAGAgent_test, _bt_ag_agent_dial_last_num) {
403 bt_ag_info_t* ag_info = __bt_create_ag_info();
404 int ret = BT_HFP_AGENT_ERROR_NONE;
406 ret = _bt_ag_agent_dial_last_num(ag_info);
407 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
409 __bt_destroy_ag_info(ag_info);
412 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_signal_quality) {
413 bt_ag_info_t* ag_info = __bt_create_ag_info();
414 gboolean ret = FALSE;
416 ret = _bt_ag_agent_get_signal_quality(ag_info);
417 ASSERT_TRUE(ret == TRUE);
419 __bt_destroy_ag_info(ag_info);
422 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_battery_status) {
423 bt_ag_info_t* ag_info = __bt_create_ag_info();
424 gboolean ret = FALSE;
426 ret = _bt_ag_agent_get_battery_status(ag_info);
427 ASSERT_TRUE(ret == TRUE);
429 __bt_destroy_ag_info(ag_info);
432 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_operator_name) {
433 bt_ag_info_t* ag_info = __bt_create_ag_info();
434 gboolean ret = FALSE;
436 ret = _bt_ag_agent_get_operator_name(ag_info);
437 ASSERT_TRUE(ret == TRUE);
439 __bt_destroy_ag_info(ag_info);
442 TEST(BluetoothAGAgent_test, _bt_hfp_agent_nrec_status) {
443 bt_ag_info_t* ag_info = __bt_create_ag_info();
444 gboolean ret = FALSE;
446 ret = _bt_hfp_agent_nrec_status(TRUE, ag_info);
447 ASSERT_TRUE(ret == TRUE);
449 ret = _bt_hfp_agent_nrec_status(FALSE, ag_info);
450 ASSERT_TRUE(ret == TRUE);
452 __bt_destroy_ag_info(ag_info);
455 TEST(BluetoothAGAgent_test, _bt_ag_agent_voice_dial) {
456 bt_ag_info_t* ag_info = __bt_create_ag_info();
457 gboolean ret = FALSE;
459 ret = _bt_ag_agent_voice_dial(FALSE);
460 ASSERT_TRUE(ret == TRUE);
462 __bt_destroy_ag_info(ag_info);
465 TEST(BluetoothAGAgent_test, _bt_list_current_calls) {
466 bt_ag_info_t* ag_info = __bt_create_ag_info();
468 _bt_list_current_calls(ag_info);
470 __bt_destroy_ag_info(ag_info);
473 TEST(BluetoothAGAgent_test, _bt_get_activity_status) {
474 bt_ag_info_t* ag_info = __bt_create_ag_info();
476 _bt_get_activity_status(ag_info);
478 __bt_destroy_ag_info(ag_info);
481 TEST(BluetoothAGAgent_test, _bt_hfp_set_property_name) {
482 const char *property1 = "OperatorNameChanged";
483 const char *property2 = "SubscriberNumberChanged";
484 const char *operator_name = "Tizen";
487 ret = _bt_hfp_set_property_name(property1, operator_name);
488 ASSERT_TRUE(ret == 1);
490 ret = _bt_hfp_set_property_name(property2, operator_name);
491 ASSERT_TRUE(ret == 1);
494 TEST(BluetoothAGAgent_test, _bt_hfp_get_imei_number_reply) {
495 bt_ag_info_t* ag_info = __bt_create_ag_info();
497 _bt_hfp_get_imei_number_reply("1234", ag_info);
499 __bt_destroy_ag_info(ag_info);
502 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_info_reply) {
503 bt_ag_info_t* ag_info = __bt_create_ag_info();
505 _bt_hfp_get_model_info_reply("Tizen", ag_info);
507 __bt_destroy_ag_info(ag_info);
510 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer_reply) {
511 bt_ag_info_t* ag_info = __bt_create_ag_info();
513 _bt_hfp_get_device_manufacturer_reply("Tizen", ag_info);
515 __bt_destroy_ag_info(ag_info);
518 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_info_reply) {
519 bt_ag_info_t* ag_info = __bt_create_ag_info();
521 _bt_hfp_get_revision_info_reply("5.0", ag_info);
523 __bt_destroy_ag_info(ag_info);
526 TEST(BluetoothAGAgent_test, _bt_hfp_device_disconnected) {
527 bt_ag_info_t* ag_info = __bt_create_ag_info();
529 _bt_hfp_device_disconnected(ag_info);
531 __bt_destroy_ag_info(ag_info);
534 TEST(BluetoothAGAgent_test, _bt_hfp_get_equipment_identity) {
535 bt_ag_info_t* ag_info = __bt_create_ag_info();
536 const char *cmd1 = "AT+CGSN=?";
537 const char *cmd2 = "AT+CGSN";
538 int ret = BT_HFP_AGENT_ERROR_NONE;
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 ret = _bt_hfp_get_model_information(ag_info, cmd1);
556 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
558 ret = _bt_hfp_get_model_information(ag_info, cmd2);
559 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
561 __bt_destroy_ag_info(ag_info);
564 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer) {
565 bt_ag_info_t* ag_info = __bt_create_ag_info();
566 const char *cmd1 = "AT+CGMI=?";
567 const char *cmd2 = "AT+CGMI";
568 int ret = BT_HFP_AGENT_ERROR_NONE;
570 ret = _bt_hfp_get_device_manufacturer(ag_info, cmd1);
571 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
573 ret = _bt_hfp_get_device_manufacturer(ag_info, cmd2);
574 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
576 __bt_destroy_ag_info(ag_info);
579 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi) {
580 bt_ag_info_t* ag_info = __bt_create_ag_info();
581 const char *cmd1 = "AT+IMSI=?";
582 const char *cmd2 = "AT+IMSI";
583 int ret = BT_HFP_AGENT_ERROR_NONE;
585 ret = _bt_hfp_get_imsi(ag_info, cmd1);
586 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
588 ret = _bt_hfp_get_imsi(ag_info, cmd2);
589 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
591 __bt_destroy_ag_info(ag_info);
594 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status) {
595 bt_ag_info_t* ag_info = __bt_create_ag_info();
596 const char *cmd1 = "AT+IMSI=?";
597 const char *cmd2 = "AT+IMSI";
598 const char *cmd3 = "AT+IMSI?";
599 int ret = BT_HFP_AGENT_ERROR_NONE;
601 ret = _bt_hfp_get_creg_status(ag_info, cmd1);
602 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
604 ret = _bt_hfp_get_creg_status(ag_info, cmd2);
605 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
607 ret = _bt_hfp_get_creg_status(ag_info, cmd3);
608 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
610 __bt_destroy_ag_info(ag_info);
613 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_information) {
614 bt_ag_info_t* ag_info = __bt_create_ag_info();
615 const char *cmd1 = "AT+CGMR=?";
616 const char *cmd2 = "AT+CGMR";
617 int ret = BT_HFP_AGENT_ERROR_NONE;
619 ret = _bt_hfp_get_revision_information(ag_info, cmd1);
620 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
622 ret = _bt_hfp_get_revision_information(ag_info, cmd2);
623 ASSERT_TRUE(ret == BT_HFP_AGENT_ERROR_NONE);
625 __bt_destroy_ag_info(ag_info);
628 TEST(BluetoothAGAgent_test, _bt_hfp_get_equipment_identity_req) {
629 bt_ag_info_t* ag_info = __bt_create_ag_info();
631 _bt_hfp_get_equipment_identity_req(ag_info);
633 __bt_destroy_ag_info(ag_info);
636 TEST(BluetoothAGAgent_test, _bt_hfp_initialize_telephony_manager) {
637 uint32_t ag_features = BT_AG_FEATURE_EC_AND_NR |
638 BT_AG_FEATURE_REJECT_CALL |
639 BT_AG_FEATURE_ENHANCED_CALL_STATUS |
640 BT_AG_FEATURE_THREE_WAY_CALL |
641 BT_AG_FEATURE_EXTENDED_ERROR_RESULT_CODES |
642 BT_AG_FEATURE_CODEC_NEGOTIATION;
644 _bt_hfp_initialize_telephony_manager(ag_features);
646 _bt_hfp_deinitialize_telephony_manager();
649 TEST(BluetoothAGAgent_test, _bt_hfp_get_model_info_req) {
650 bt_ag_info_t* ag_info = __bt_create_ag_info();
652 _bt_hfp_get_model_info_req(ag_info);
654 __bt_destroy_ag_info(ag_info);
657 TEST(BluetoothAGAgent_test, _bt_hfp_get_device_manufacturer_req) {
658 bt_ag_info_t* ag_info = __bt_create_ag_info();
660 _bt_hfp_get_device_manufacturer_req(ag_info);
662 __bt_destroy_ag_info(ag_info);
665 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi_req) {
666 bt_ag_info_t* ag_info = __bt_create_ag_info();
668 _bt_hfp_get_imsi_req(ag_info);
670 __bt_destroy_ag_info(ag_info);
673 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status_req) {
674 bt_ag_info_t* ag_info = __bt_create_ag_info();
676 _bt_hfp_get_creg_status_req(ag_info);
678 __bt_destroy_ag_info(ag_info);
681 TEST(BluetoothAGAgent_test, _bt_hfp_get_revision_info_req) {
682 bt_ag_info_t* ag_info = __bt_create_ag_info();
684 _bt_hfp_get_revision_info_req(ag_info);
686 __bt_destroy_ag_info(ag_info);
689 TEST(BluetoothAGAgent_test, _bt_hfp_is_call_exist) {
690 gboolean ret = FALSE;
692 ret = _bt_hfp_is_call_exist();
695 TEST(BluetoothAGAgent_test, _bt_hfp_release_all_calls_by_sender) {
696 const char *sender = "sender";
698 _bt_hfp_release_all_calls_by_sender(sender);
701 TEST(BluetoothAGAgent_test, _bt_hfp_get_imsi_reply) {
702 bt_ag_info_t* ag_info = __bt_create_ag_info();
704 _bt_hfp_get_imsi_reply(NULL, NULL, NULL, ag_info);
706 _bt_hfp_get_imsi_reply("mmc", "mnc", "msin", ag_info);
708 __bt_destroy_ag_info(ag_info);
711 TEST(BluetoothAGAgent_test, _bt_hfp_get_creg_status_reply) {
712 bt_ag_info_t* ag_info = __bt_create_ag_info();
714 _bt_hfp_get_creg_status_reply(1, 0, ag_info);
716 __bt_destroy_ag_info(ag_info);
719 TEST(BluetoothAGAgent_test, _bt_hfp_vendor_cmd_request) {
720 bt_ag_info_t* ag_info = __bt_create_ag_info();
721 const char *cmd = "AT+VND";
723 _bt_hfp_vendor_cmd_request(cmd, ag_info);
725 __bt_destroy_ag_info(ag_info);
728 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_model_name) {
729 bt_ag_info_t* ag_info = __bt_create_ag_info();
731 _bt_ag_agent_get_model_name(ag_info);
733 __bt_destroy_ag_info(ag_info);
736 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_manufacturer_name) {
737 bt_ag_info_t* ag_info = __bt_create_ag_info();
739 _bt_ag_agent_get_manufacturer_name(ag_info);
741 __bt_destroy_ag_info(ag_info);
744 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_imsi) {
745 bt_ag_info_t* ag_info = __bt_create_ag_info();
747 _bt_ag_agent_get_imsi(ag_info);
749 __bt_destroy_ag_info(ag_info);
752 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_creg_status) {
753 bt_ag_info_t* ag_info = __bt_create_ag_info();
755 _bt_ag_agent_get_creg_status(ag_info);
757 __bt_destroy_ag_info(ag_info);
760 TEST(BluetoothAGAgent_test, _bt_ag_agent_get_revision_information) {
761 bt_ag_info_t* ag_info = __bt_create_ag_info();
763 _bt_ag_agent_get_revision_information(ag_info);
765 __bt_destroy_ag_info(ag_info);
768 #ifdef TIZEN_FEATURE_BT_MEDIA_ENHANCE
769 TEST(BluetoothAGAgent_test, _bt_ag_agent_check_transport_state) {
770 bt_ag_info_t* ag_info = __bt_create_ag_info();
772 _bt_ag_agent_check_transport_state(ag_info);
774 __bt_destroy_ag_info(ag_info);
778 /* Functions for hid-agent */
779 TEST(BluetoothHIDAgent_test, _bt_hid_disconnect_profile) {
780 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
782 /* Negative test case : no device is connected */
783 ret = _bt_hid_disconnect_profile();
784 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INTERNAL);
787 TEST(BluetoothHIDAgent_test, _bt_hid_set_profile_state) {
788 _bt_hid_set_profile_state(BT_HID_STATE_CONNECTING);
790 _bt_hid_set_profile_state(BT_HID_STATE_CONNECTED);
792 _bt_hid_set_profile_state(BT_HID_STATE_UNAVAILABLE);
795 TEST(BluetoothHIDAgent_test, _bt_hid_get_profile_state) {
796 bt_hid_state_t state;
798 state = _bt_hid_get_profile_state();
799 ASSERT_TRUE(state >= BT_HID_STATE_UNAVAILABLE && state <= BT_HID_STATE_DISCONNECTING);
802 TEST(BluetoothHIDAgent_test, _bt_hid_register_application) {
803 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
805 /* Negative test case */
806 ret = _bt_hid_register_application(TRUE, NULL);
807 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INVALID_PARAM);
809 ret = _bt_hid_register_application(TRUE, "Sender");
810 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
812 /* Negative test case */
813 ret = _bt_hid_register_application(TRUE, "Sender");
814 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_ALREADY_EXIST);
816 ret = _bt_hid_register_application(FALSE, "Sender");
817 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
819 /* Negative test case */
820 ret = _bt_hid_register_application(FALSE, "Sender");
821 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NOT_AVAILABLE);
824 TEST(BluetoothHIDAgent_test, _bt_hid_get_sender_list) {
825 const GSList *senders;
826 bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE;
828 ret = _bt_hid_register_application(TRUE, "Sender");
829 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
831 senders = _bt_hid_get_sender_list();
832 ASSERT_TRUE(senders == NULL);
834 ret = _bt_hid_register_application(FALSE, "Sender");
835 ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE);
838 /* Functions for ipsp-agent */
839 TEST(BluetoothIPSPAgent_test, _bt_ipsp_register_dbus) {
840 gboolean ret = FALSE;
842 ret = _bt_ipsp_register_dbus();
843 ASSERT_TRUE(ret == TRUE);
846 TEST(BluetoothIPSPAgent_test, _bt_ipsp_unregister_dbus) {
847 _bt_ipsp_unregister_dbus();
850 TEST(BluetoothIPSPAgent_test, _bt_ipsp_gdbus_deinit_proxys) {
851 _bt_ipsp_gdbus_deinit_proxys();
854 /* Functions for map-agent */
855 static message_info_t* __bt_create_msg_info(void)
857 message_info_t *bt_msg_info = g_new0(message_info_t, 1);
859 bt_msg_info->handle = g_strdup("1");
860 bt_msg_info->subject = g_strdup("subject");
861 bt_msg_info->datetime = g_strdup("datetime");
862 bt_msg_info->sender_name = g_strdup("sender_name");
863 bt_msg_info->sender_addressing = g_strdup("sender_addressing");
864 bt_msg_info->replyto_addressing = g_strdup("replyto_addressing");
865 bt_msg_info->recipient_name = g_strdup("recipient_name");
866 bt_msg_info->recipient_addressing = g_strdup("recipient_addressing");
867 bt_msg_info->type = g_strdup("type");
868 bt_msg_info->reception_status = g_strdup("reception_status");
869 bt_msg_info->size = g_strdup("size");
870 bt_msg_info->attachment_size = g_strdup("attachment_size");
875 TEST(BluetoothMAPAgent_test, _bt_mns_client_event_notify) {
876 _bt_mns_client_event_notify("MessageShift", 0,
877 "TELECOM/MSG/DELETED", "/opt/usr", "EMAIL");
881 TEST(BluetoothMAPAgent_test, _bt_update_id) {
884 /* Negative test case */
885 ret = _bt_update_id(0, -1, -1);
886 ASSERT_TRUE(ret == -1);
889 TEST(BluetoothMAPAgent_test, _bt_validate_msg_data) {
890 gboolean ret = FALSE;
891 message_info_t *bt_msg_info = NULL;
893 bt_msg_info = __bt_create_msg_info();
894 ASSERT_TRUE(bt_msg_info == NULL);
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 = NULL;
909 bt_msg_info = __bt_create_msg_info();
910 ASSERT_TRUE(bt_msg_info == NULL);
912 _bt_message_info_free(bt_msg_info);
915 TEST(BluetoothMAPAgent_test, _get_msg_timestamp) {
918 struct timeval tv = {0, };
919 char msg_datetime[16] = {0, };
921 gettimeofday(&tv, NULL);
922 cur_time = tv.tv_sec;
924 _get_msg_timestamp(&cur_time, msg_datetime);
927 TEST(BluetoothMAPAgent_test, _bt_add_id) {
930 map_id = _bt_add_id(-1, BT_MAP_ID_EMAIL);
931 ASSERT_TRUE(map_id == 1);
934 TEST(BluetoothMAPAgent_test, _bt_validate_uid) {
937 map_id = _bt_validate_uid(-1, BT_MAP_ID_EMAIL);
938 ASSERT_TRUE(map_id == 0);
941 TEST(BluetoothMAPAgent_test, is_mns_connected) {
942 gboolean ret = FALSE;
944 /* Negative test case */
945 ret = is_mns_connected();
946 ASSERT_TRUE(ret == FALSE);
949 TEST(BluetoothMAPAgent_test, _bt_verify_read_status) {
950 gboolean ret = FALSE;
951 message_info_t *bt_msg_info = NULL;
953 bt_msg_info = __bt_create_msg_info();
954 ASSERT_TRUE(bt_msg_info == NULL);
956 ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_ALL);
957 _bt_message_info_free(bt_msg_info);
958 ASSERT_TRUE(ret == TRUE);
960 bt_msg_info = __bt_create_msg_info();
961 ASSERT_TRUE(bt_msg_info == NULL);
963 ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_READ);
964 _bt_message_info_free(bt_msg_info);
965 ASSERT_TRUE(ret == FALSE);
968 TEST(BluetoothMAPAgent_test, _bt_verify_sender) {
969 gboolean ret = FALSE;
970 message_info_t *bt_msg_info = NULL;
972 bt_msg_info = __bt_create_msg_info();
973 ASSERT_TRUE(bt_msg_info == NULL);
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();
981 ASSERT_TRUE(bt_msg_info == NULL);
983 ret = _bt_verify_sender(bt_msg_info, "*");
984 _bt_message_info_free(bt_msg_info);
985 ASSERT_TRUE(ret == TRUE);
987 bt_msg_info = __bt_create_msg_info();
988 ASSERT_TRUE(bt_msg_info == NULL);
990 ret = _bt_verify_sender(bt_msg_info, "sender");
991 _bt_message_info_free(bt_msg_info);
992 ASSERT_TRUE(ret == TRUE);
994 bt_msg_info = __bt_create_msg_info();
995 ASSERT_TRUE(bt_msg_info == NULL);
997 /* Negative test case */
998 ret = _bt_verify_sender(bt_msg_info, "negative");
999 _bt_message_info_free(bt_msg_info);
1000 ASSERT_TRUE(ret == FALSE);
1003 TEST(BluetoothMAPAgent_test, _bt_verify_receiver) {
1004 gboolean ret = FALSE;
1005 message_info_t *bt_msg_info = NULL;
1007 bt_msg_info = __bt_create_msg_info();
1008 ASSERT_TRUE(bt_msg_info == NULL);
1010 /* Negative test case */
1011 ret = _bt_verify_receiver(bt_msg_info, NULL);
1012 _bt_message_info_free(bt_msg_info);
1013 ASSERT_TRUE(ret == TRUE);
1015 bt_msg_info = __bt_create_msg_info();
1016 ASSERT_TRUE(bt_msg_info == NULL);
1018 ret = _bt_verify_receiver(bt_msg_info, "*");
1019 _bt_message_info_free(bt_msg_info);
1020 ASSERT_TRUE(ret == TRUE);
1022 bt_msg_info = __bt_create_msg_info();
1023 ASSERT_TRUE(bt_msg_info == NULL);
1025 ret = _bt_verify_receiver(bt_msg_info, "receiver");
1026 _bt_message_info_free(bt_msg_info);
1027 ASSERT_TRUE(ret == TRUE);
1029 bt_msg_info = __bt_create_msg_info();
1030 ASSERT_TRUE(bt_msg_info == NULL);
1032 /* Negative test case */
1033 ret = _bt_verify_receiver(bt_msg_info, "negative");
1034 _bt_message_info_free(bt_msg_info);
1035 ASSERT_TRUE(ret == FALSE);
1038 TEST(BluetoothMAPAgent_test, _bt_verify_time) {
1039 gboolean ret = FALSE;
1040 message_info_t *bt_msg_info = NULL;
1041 map_msg_filter_t filter = { 0, };
1043 bt_msg_info = __bt_create_msg_info();
1044 ASSERT_TRUE(bt_msg_info == NULL);
1046 ret = _bt_verify_time(bt_msg_info, &filter);
1047 _bt_message_info_free(bt_msg_info);
1048 ASSERT_TRUE(ret == FALSE);
1051 TEST(BluetoothMAPAgent_test, _bt_filter_priority) {
1052 gboolean ret = FALSE;
1053 message_info_t *bt_msg_info = NULL;
1054 map_msg_filter_t filter = { 0, };
1056 bt_msg_info = __bt_create_msg_info();
1057 ASSERT_TRUE(bt_msg_info == NULL);
1059 ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_ALL);
1060 _bt_message_info_free(bt_msg_info);
1061 ASSERT_TRUE(ret == TRUE);
1063 bt_msg_info = __bt_create_msg_info();
1064 ASSERT_TRUE(bt_msg_info == NULL);
1066 ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_HIGH);
1067 _bt_message_info_free(bt_msg_info);
1068 ASSERT_TRUE(ret == FALSE);
1071 TEST(BluetoothMAPAgent_test, _bt_map_start_email_service) {
1072 gboolean ret = FALSE;
1074 ret = _bt_map_start_email_service();
1075 ASSERT_TRUE(ret == TRUE);
1077 /* Negative test case */
1078 ret = _bt_map_start_email_service();
1079 ASSERT_TRUE(ret == FALSE);
1082 TEST(BluetoothMAPAgent_test, _bt_map_stop_email_service) {
1083 gboolean ret = FALSE;
1085 ret = _bt_map_stop_email_service();
1086 ASSERT_TRUE(ret == TRUE);
1088 /* Negative test case */
1089 ret = _bt_map_stop_email_service();
1090 ASSERT_TRUE(ret == FALSE);
1093 TEST(BluetoothMAPAgent_test, _bt_map_email_get_supported_folders) {
1094 gboolean ret = FALSE;
1095 gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, };
1097 ret = _bt_map_email_get_supported_folders(folders_supported);
1098 ASSERT_TRUE(ret == TRUE);
1101 TEST(BluetoothMAPAgent_test, _bt_map_update_mailbox) {
1102 gboolean ret = FALSE;
1104 ret = _bt_map_update_mailbox("/tmp");
1105 ASSERT_TRUE(ret == TRUE);
1108 TEST(BluetoothMAPAgent_test, _bt_map_set_email_read_status) {
1109 gboolean ret = FALSE;
1111 /* Negative test case */
1112 ret = _bt_map_set_email_read_status(-1, 0);
1113 ASSERT_TRUE(ret == FALSE);
1116 TEST(BluetoothMAPAgent_test, _bt_map_set_email_delete_status) {
1117 gboolean ret = FALSE;
1119 /* Negative test case */
1120 ret = _bt_map_set_email_delete_status(-1, 0);
1121 ASSERT_TRUE(ret == FALSE);
1124 TEST(BluetoothMAPAgent_test, _bt_map_get_email_message) {
1125 gboolean ret = FALSE;
1126 gchar *bmseg = NULL;
1128 /* Negative test case */
1129 ret = _bt_map_get_email_message(-1, FALSE, TRUE, TRUE, &bmseg);
1130 ASSERT_TRUE(ret == FALSE);
1133 TEST(BluetoothMAPAgent_test, _bt_map_start_sms_service) {
1134 gboolean ret = FALSE;
1136 ret = _bt_map_start_sms_service();
1137 ASSERT_TRUE(ret == TRUE);
1139 /* Negative test case */
1140 ret = _bt_map_start_sms_service();
1141 ASSERT_TRUE(ret == FALSE);
1144 TEST(BluetoothMAPAgent_test, _bt_map_stop_sms_service) {
1145 gboolean ret = FALSE;
1146 gchar *bmseg = NULL;
1148 _bt_map_stop_sms_service();
1149 ASSERT_TRUE(ret == TRUE);
1151 /* Negative test case */
1152 _bt_map_stop_sms_service();
1153 ASSERT_TRUE(ret == FALSE);
1156 TEST(BluetoothMAPAgent_test, _bt_map_sms_get_supported_folders) {
1157 gboolean ret = FALSE;
1158 gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, };
1160 ret = _bt_map_sms_get_supported_folders(folders_supported);
1161 ASSERT_TRUE(ret == TRUE);
1164 TEST(BluetoothMAPAgent_test, _bt_map_get_sms_message) {
1165 gboolean ret = FALSE;
1166 gchar *bmseg = NULL;
1168 /* Negative test case */
1169 ret = _bt_map_get_sms_message(-1, FALSE, TRUE, TRUE, &bmseg);
1170 ASSERT_TRUE(ret == FALSE);
1173 TEST(BluetoothMAPAgent_test, _bt_map_set_sms_delete_status) {
1174 gboolean ret = FALSE;
1176 /* Negative test case */
1177 ret = _bt_map_set_sms_delete_status(-1, 0);
1178 ASSERT_TRUE(ret == FALSE);
1181 TEST(BluetoothMAPAgent_test, _bt_map_sms_set_read_status) {
1182 gboolean ret = FALSE;
1184 /* Negative test case */
1185 ret = _bt_map_sms_set_read_status(-1, 0);
1186 ASSERT_TRUE(ret == FALSE);
1189 /* Functions for pb-agent */
1190 TEST(BluetoothPBAgent_test, _bluetooth_get_contact_addressbook) {
1191 int ret = PBAP_ADDRESSBOOK_PHONE;
1193 ret = _bluetooth_get_contact_addressbook(1);
1194 ASSERT_TRUE(ret == PBAP_ADDRESSBOOK_PHONE);
1197 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact) {
1200 /* Negative test case */
1201 str = _bluetooth_pb_vcard_contact(0, VCARD_PHOTO, VCARD_FORMAT_2_1);
1202 ASSERT_TRUE(str == NULL);
1204 /* Negative test case */
1205 str = _bluetooth_pb_vcard_contact(1, VCARD_PHOTO, VCARD_FORMAT_3_0);
1206 ASSERT_TRUE(str == NULL);
1209 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact_owner) {
1211 const char *number = "01012345678";
1213 str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_2_1);
1214 ASSERT_TRUE(str != NULL);
1217 str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_3_0);
1218 ASSERT_TRUE(str != NULL);
1222 TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_call) {
1224 const char *attr = "DIALED";
1226 /* Negative test case */
1227 str = _bluetooth_pb_vcard_call(1, VCARD_PHOTO, VCARD_FORMAT_2_1, attr);
1228 ASSERT_TRUE(str == NULL);
1231 TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_person_id) {
1234 /* Negative test case */
1235 str = _bluetooth_pb_fn_from_person_id(1);
1236 ASSERT_TRUE(str == NULL);
1239 TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_person_id) {
1242 /* Negative test case */
1243 str = _bluetooth_pb_name_from_person_id(1);
1244 ASSERT_TRUE(str == NULL);
1247 TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_person_id) {
1250 /* Negative test case */
1251 str = _bluetooth_pb_number_from_person_id(1);
1252 ASSERT_TRUE(str == NULL);
1255 TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_phonelog_id) {
1258 /* Negative test case */
1259 str = _bluetooth_pb_fn_from_phonelog_id(1);
1260 ASSERT_TRUE(str == NULL);
1263 TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_phonelog_id) {
1266 /* Negative test case */
1267 str = _bluetooth_pb_name_from_phonelog_id(1);
1268 ASSERT_TRUE(str == NULL);
1271 TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_phonelog_id) {
1274 /* Negative test case */
1275 str = _bluetooth_pb_number_from_phonelog_id(1);
1276 ASSERT_TRUE(str == NULL);
1279 TEST(BluetoothPBAgent_test, _bluetooth_pb_owner_name) {
1282 /* Negative test case */
1283 name = _bluetooth_pb_owner_name();
1284 ASSERT_TRUE(name != NULL);
1288 TEST(BluetoothPBAgent_test, _bt_is_sim_addressbook) {
1290 const char *address_book = "http://tizen.org/addressbook/sim1";
1292 ret = _bt_is_sim_addressbook(address_book);
1293 ASSERT_TRUE(ret == true);
1296 int main(int argc, char **argv) {
1297 InitGoogleTest(&argc, argv);
1299 return RUN_ALL_TESTS();