From f9e4ac4b1e6b4b1760ed722c29c6a66e5e76fa82 Mon Sep 17 00:00:00 2001 From: DoHyun Pyun Date: Mon, 2 Jul 2018 14:00:05 +0900 Subject: [PATCH] Add the testcases for each agent Change-Id: Ibe466c29753154387d32586d0306c1aad1e5ac0d Signed-off-by: DoHyun Pyun --- unittest/CMakeLists.txt | 5 + unittest/bluetooth-agent_test.cpp | 568 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 557 insertions(+), 16 deletions(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index c18abc1..9645718 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -23,8 +23,13 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(/usr/include/glib-2.0) INCLUDE_DIRECTORIES(/usr/include/dlog) INCLUDE_DIRECTORIES(/usr/include/vconf) +INCLUDE_DIRECTORIES(/usr/include/gio-unix-2.0) INCLUDE_DIRECTORIES(/usr/lib/glib-2.0/include/) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ag-agent) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/hid-agent) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ipsp-agent) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/map-agent) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/pb-agent) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") diff --git a/unittest/bluetooth-agent_test.cpp b/unittest/bluetooth-agent_test.cpp index f669110..6a02e02 100644 --- a/unittest/bluetooth-agent_test.cpp +++ b/unittest/bluetooth-agent_test.cpp @@ -24,11 +24,27 @@ #include #include #include +#include /* ag-agent header files */ #include "bluetooth-ag-agent.h" #include "bluetooth-ag-handler.h" +/* hid-agent header files */ +#include "bluetooth-hid-agent.h" +#include "bluetooth-hid-manager.h" + +/* ipsp-agent header files */ +#include "bluetooth-ipsp-agent.h" + +/* map-agent header files */ +#include "bluetooth_map_agent.h" +#include "bluetooth_map_email.h" +#include "bluetooth_map_sms.h" + +/* pb-agent header files */ +#include "bluetooth_pb_vcard.h" + using ::testing::EmptyTestEventListener; using ::testing::InitGoogleTest; using ::testing::Test; @@ -40,6 +56,24 @@ using ::testing::UnitTest; static GMainLoop *mainloop = NULL; + +static gboolean timeout_func(gpointer data) +{ + g_main_loop_quit((GMainLoop *)data); + return FALSE; +} + +static void wait_for_async(void) +{ + int timeout_id = 0; + mainloop = g_main_loop_new(NULL, FALSE); + + timeout_id = g_timeout_add(2000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); +} + +/* Functions for ag-agent */ static bt_ag_info_t* __bt_create_ag_info(void) { bt_ag_info_t *bt_ag_info = g_new0(bt_ag_info_t, 1); @@ -73,22 +107,6 @@ static void __bt_destroy_ag_info(bt_ag_info_t *ag_info) g_free(ag_info); } -static gboolean timeout_func(gpointer data) -{ - g_main_loop_quit((GMainLoop *)data); - return FALSE; -} - -static void wait_for_async(void) -{ - int timeout_id = 0; - mainloop = g_main_loop_new(NULL, FALSE); - - timeout_id = g_timeout_add(2000, timeout_func, mainloop); - g_main_loop_run(mainloop); - g_source_remove(timeout_id); -} - TEST(BluetoothAGAgent_test, _bt_ag_slconn_complete) { bt_ag_info_t* ag_info = __bt_create_ag_info(); @@ -757,6 +775,524 @@ TEST(BluetoothAGAgent_test, _bt_ag_agent_check_transport_state) { } #endif +/* Functions for hid-agent */ +TEST(BluetoothHIDAgent_test, _bt_hid_disconnect_profile) { + bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE; + + /* Negative test case : no device is connected */ + ret = _bt_hid_disconnect_profile(); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INTERNAL); +} + +TEST(BluetoothHIDAgent_test, _bt_hid_set_profile_state) { + _bt_hid_set_profile_state(BT_HID_STATE_CONNECTING); + + _bt_hid_set_profile_state(BT_HID_STATE_CONNECTED); + + _bt_hid_set_profile_state(BT_HID_STATE_UNAVAILABLE); +} + +TEST(BluetoothHIDAgent_test, _bt_hid_get_profile_state) { + bt_hid_state_t state; + + state = _bt_hid_get_profile_state(); + ASSERT_TRUE(state >= BT_HID_STATE_UNAVAILABLE && state <= BT_HID_STATE_DISCONNECTING); +} + +TEST(BluetoothHIDAgent_test, _bt_hid_register_application) { + bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE; + + /* Negative test case */ + ret = _bt_hid_register_application(TRUE, NULL); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_INVALID_PARAM); + + ret = _bt_hid_register_application(TRUE, "Sender"); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE); + + /* Negative test case */ + ret = _bt_hid_register_application(TRUE, "Sender"); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_ALREADY_EXIST); + + ret = _bt_hid_register_application(FALSE, "Sender"); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE); + + /* Negative test case */ + ret = _bt_hid_register_application(FALSE, "Sender"); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NOT_AVAILABLE); +} + +TEST(BluetoothHIDAgent_test, _bt_hid_get_sender_list) { + const GSList *senders; + bt_hid_agent_error_t ret = BT_HID_AGENT_ERROR_NONE; + + ret = _bt_hid_register_application(TRUE, "Sender"); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE); + + senders = _bt_hid_get_sender_list(); + ASSERT_TRUE(senders == NULL); + + ret = _bt_hid_register_application(FALSE, "Sender"); + ASSERT_TRUE(ret == BT_HID_AGENT_ERROR_NONE); +} + +/* Functions for ipsp-agent */ +TEST(BluetoothIPSPAgent_test, _bt_ipsp_register_dbus) { + gboolean ret = FALSE; + + ret = _bt_ipsp_register_dbus(); + ASSERT_TRUE(ret == TRUE); +} + +TEST(BluetoothIPSPAgent_test, _bt_ipsp_unregister_dbus) { + _bt_ipsp_unregister_dbus(); +} + +TEST(BluetoothIPSPAgent_test, _bt_ipsp_gdbus_deinit_proxys) { + _bt_ipsp_gdbus_deinit_proxys(); +} + +/* Functions for map-agent */ +static message_info_t* __bt_create_msg_info(void) +{ + message_info_t *bt_msg_info = g_new0(message_info_t, 1); + + bt_msg_info->handle = g_strdup("1"); + bt_msg_info->subject = g_strdup("subject"); + bt_msg_info->datetime = g_strdup("datetime"); + bt_msg_info->sender_name = g_strdup("sender_name"); + bt_msg_info->sender_addressing = g_strdup("sender_addressing"); + bt_msg_info->replyto_addressing = g_strdup("replyto_addressing"); + bt_msg_info->recipient_name = g_strdup("recipient_name"); + bt_msg_info->recipient_addressing = g_strdup("recipient_addressing"); + bt_msg_info->type = g_strdup("type"); + bt_msg_info->reception_status = g_strdup("reception_status"); + bt_msg_info->size = g_strdup("size"); + bt_msg_info->attachment_size = g_strdup("attachment_size"); + + return bt_msg_info; +} + +TEST(BluetoothMAPAgent_test, _bt_mns_client_event_notify) { + _bt_mns_client_event_notify("MessageShift", 0, + "TELECOM/MSG/DELETED", "/opt/usr", "EMAIL"); + +} + +TEST(BluetoothMAPAgent_test, _bt_update_id) { + int ret = 0; + + /* Negative test case */ + ret = _bt_update_id(0, -1, -1); + ASSERT_TRUE(ret == -1); +} + +TEST(BluetoothMAPAgent_test, _bt_validate_msg_data) { + gboolean ret = FALSE; + message_info_t *bt_msg_info = NULL; + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + /* Negative test case */ + ret = _bt_validate_msg_data(NULL); + ASSERT_TRUE(ret == FALSE); + + ret = _bt_validate_msg_data(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + _bt_message_info_free(bt_msg_info); +} + +TEST(BluetoothMAPAgent_test, _bt_message_info_free) { + message_info_t *bt_msg_info = NULL; + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + _bt_message_info_free(bt_msg_info); +} + +TEST(BluetoothMAPAgent_test, _get_msg_timestamp) { + time_t cur_time = 0; + struct tm new_time; + struct timeval tv = {0, }; + char msg_datetime[16] = {0, }; + + gettimeofday(&tv, NULL); + cur_time = tv.tv_sec; + + _get_msg_timestamp(&cur_time, msg_datetime); +} + +TEST(BluetoothMAPAgent_test, _bt_add_id) { + guint64 map_id; + + map_id = _bt_add_id(-1, BT_MAP_ID_EMAIL); + ASSERT_TRUE(map_id == 1); +} + +TEST(BluetoothMAPAgent_test, _bt_validate_uid) { + guint64 map_id; + + map_id = _bt_validate_uid(-1, BT_MAP_ID_EMAIL); + ASSERT_TRUE(map_id == 0); +} + +TEST(BluetoothMAPAgent_test, is_mns_connected) { + gboolean ret = FALSE; + + /* Negative test case */ + ret = is_mns_connected(); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_verify_read_status) { + gboolean ret = FALSE; + message_info_t *bt_msg_info = NULL; + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_ALL); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_verify_read_status(bt_msg_info, FILTER_READ_STATUS_READ); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_verify_sender) { + gboolean ret = FALSE; + message_info_t *bt_msg_info = NULL; + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + /* Negative test case */ + ret = _bt_verify_sender(bt_msg_info, NULL); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_verify_sender(bt_msg_info, "*"); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_verify_sender(bt_msg_info, "sender"); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + /* Negative test case */ + ret = _bt_verify_sender(bt_msg_info, "negative"); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_verify_receiver) { + gboolean ret = FALSE; + message_info_t *bt_msg_info = NULL; + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + /* Negative test case */ + ret = _bt_verify_receiver(bt_msg_info, NULL); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_verify_receiver(bt_msg_info, "*"); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_verify_receiver(bt_msg_info, "receiver"); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + /* Negative test case */ + ret = _bt_verify_receiver(bt_msg_info, "negative"); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_verify_time) { + gboolean ret = FALSE; + message_info_t *bt_msg_info = NULL; + map_msg_filter_t filter = { 0, }; + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_verify_time(bt_msg_info, &filter); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_filter_priority) { + gboolean ret = FALSE; + message_info_t *bt_msg_info = NULL; + map_msg_filter_t filter = { 0, }; + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_ALL); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == TRUE); + + bt_msg_info = __bt_create_msg_info(); + ASSERT_TRUE(bt_msg_info == NULL); + + ret = _bt_filter_priority(bt_msg_info, FILTER_PRIORITY_HIGH); + _bt_message_info_free(bt_msg_info); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_start_email_service) { + gboolean ret = FALSE; + + ret = _bt_map_start_email_service(); + ASSERT_TRUE(ret == TRUE); + + /* Negative test case */ + ret = _bt_map_start_email_service(); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_stop_email_service) { + gboolean ret = FALSE; + + ret = _bt_map_stop_email_service(); + ASSERT_TRUE(ret == TRUE); + + /* Negative test case */ + ret = _bt_map_stop_email_service(); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_email_get_supported_folders) { + gboolean ret = FALSE; + gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, }; + + ret = _bt_map_email_get_supported_folders(folders_supported); + ASSERT_TRUE(ret == TRUE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_update_mailbox) { + gboolean ret = FALSE; + + ret = _bt_map_update_mailbox("/tmp"); + ASSERT_TRUE(ret == TRUE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_set_email_read_status) { + gboolean ret = FALSE; + + /* Negative test case */ + ret = _bt_map_set_email_read_status(-1, 0); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_set_email_delete_status) { + gboolean ret = FALSE; + + /* Negative test case */ + ret = _bt_map_set_email_delete_status(-1, 0); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_get_email_message) { + gboolean ret = FALSE; + gchar *bmseg = NULL; + + /* Negative test case */ + ret = _bt_map_get_email_message(-1, FALSE, TRUE, TRUE, &bmseg); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_start_sms_service) { + gboolean ret = FALSE; + + ret = _bt_map_start_sms_service(); + ASSERT_TRUE(ret == TRUE); + + /* Negative test case */ + ret = _bt_map_start_sms_service(); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_stop_sms_service) { + gboolean ret = FALSE; + gchar *bmseg = NULL; + + _bt_map_stop_sms_service(); + ASSERT_TRUE(ret == TRUE); + + /* Negative test case */ + _bt_map_stop_sms_service(); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_sms_get_supported_folders) { + gboolean ret = FALSE; + gboolean folders_supported[FOLDER_COUNT][MSG_TYPES] = { {FALSE, FALSE}, }; + + ret = _bt_map_sms_get_supported_folders(folders_supported); + ASSERT_TRUE(ret == TRUE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_get_sms_message) { + gboolean ret = FALSE; + gchar *bmseg = NULL; + + /* Negative test case */ + ret = _bt_map_get_sms_message(-1, FALSE, TRUE, TRUE, &bmseg); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_set_sms_delete_status) { + gboolean ret = FALSE; + + /* Negative test case */ + ret = _bt_map_set_sms_delete_status(-1, 0); + ASSERT_TRUE(ret == FALSE); +} + +TEST(BluetoothMAPAgent_test, _bt_map_sms_set_read_status) { + gboolean ret = FALSE; + + /* Negative test case */ + ret = _bt_map_sms_set_read_status(-1, 0); + ASSERT_TRUE(ret == FALSE); +} + +/* Functions for pb-agent */ +TEST(BluetoothPBAgent_test, _bluetooth_get_contact_addressbook) { + int ret = PBAP_ADDRESSBOOK_PHONE; + + ret = _bluetooth_get_contact_addressbook(1); + ASSERT_TRUE(ret == PBAP_ADDRESSBOOK_PHONE); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact) { + gchar *str = NULL; + + /* Negative test case */ + str = _bluetooth_pb_vcard_contact(0, VCARD_PHOTO, VCARD_FORMAT_2_1); + ASSERT_TRUE(str == NULL); + + /* Negative test case */ + str = _bluetooth_pb_vcard_contact(1, VCARD_PHOTO, VCARD_FORMAT_3_0); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_contact_owner) { + gchar *str = NULL; + const char *number = "01012345678"; + + str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_2_1); + ASSERT_TRUE(str != NULL); + g_free(str); + + str = _bluetooth_pb_vcard_contact_owner(number, VCARD_PHOTO, VCARD_FORMAT_3_0); + ASSERT_TRUE(str != NULL); + g_free(str); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_vcard_call) { + gchar *str = NULL; + const char *attr = "DIALED"; + + /* Negative test case */ + str = _bluetooth_pb_vcard_call(1, VCARD_PHOTO, VCARD_FORMAT_2_1, attr); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_person_id) { + gchar *str = NULL; + + /* Negative test case */ + str = _bluetooth_pb_fn_from_person_id(1); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_person_id) { + gchar *str = NULL; + + /* Negative test case */ + str = _bluetooth_pb_name_from_person_id(1); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_person_id) { + gchar *str = NULL; + + /* Negative test case */ + str = _bluetooth_pb_number_from_person_id(1); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_fn_from_phonelog_id) { + gchar *str = NULL; + + /* Negative test case */ + str = _bluetooth_pb_fn_from_phonelog_id(1); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_name_from_phonelog_id) { + gchar *str = NULL; + + /* Negative test case */ + str = _bluetooth_pb_name_from_phonelog_id(1); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_number_from_phonelog_id) { + gchar *str = NULL; + + /* Negative test case */ + str = _bluetooth_pb_number_from_phonelog_id(1); + ASSERT_TRUE(str == NULL); +} + +TEST(BluetoothPBAgent_test, _bluetooth_pb_owner_name) { + gchar *name = NULL; + + /* Negative test case */ + name = _bluetooth_pb_owner_name(); + ASSERT_TRUE(name != NULL); + g_free(name); +} + +TEST(BluetoothPBAgent_test, _bt_is_sim_addressbook) { + bool ret = true; + const char *address_book = "http://tizen.org/addressbook/sim1"; + + ret = _bt_is_sim_addressbook(address_book); + ASSERT_TRUE(ret == true); +} + int main(int argc, char **argv) { InitGoogleTest(&argc, argv); -- 2.7.4