diff options
Diffstat (limited to 'TC/testcase')
30 files changed, 7573 insertions, 0 deletions
diff --git a/TC/testcase/Makefile b/TC/testcase/Makefile new file mode 100644 index 0000000..7d86802 --- /dev/null +++ b/TC/testcase/Makefile @@ -0,0 +1,24 @@ +CC ?= gcc + +C_FILES = $(shell ls *.c) + +PKGS = capi-network-bluetooth glib-2.0 + +LDFLAGS = `pkg-config --libs $(PKGS)` +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s + +CFLAGS = -I. `pkg-config --cflags $(PKGS)` +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +TCS := $(shell ls -1 *.c | cut -d. -f1) + +all: $(TCS) + +%: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TCS) diff --git a/TC/testcase/tslist b/TC/testcase/tslist new file mode 100644 index 0000000..39a8464 --- /dev/null +++ b/TC/testcase/tslist @@ -0,0 +1,28 @@ +/testcase/utc_network_bluetooth_adapter_positive +/testcase/utc_network_bluetooth_adapter_negative +/testcase/utc_network_bluetooth_device_discovery_positive +/testcase/utc_network_bluetooth_device_discovery_negative +/testcase/utc_network_bluetooth_device_positive +/testcase/utc_network_bluetooth_device_negative +/testcase/utc_network_bluetooth_service_search_positive +/testcase/utc_network_bluetooth_service_search_negative +/testcase/utc_network_bluetooth_socket_positive +/testcase/utc_network_bluetooth_socket_negative +/testcase/utc_network_bluetooth_gatt_negative +/testcase/utc_network_bluetooth_gatt_positive +/testcase/utc_network_bluetooth_hid_negative +/testcase/utc_network_bluetooth_hid_positive +/testcase/utc_network_bluetooth_hdp_negative +/testcase/utc_network_bluetooth_hdp_positive +/testcase/utc_network_bluetooth_opp-server_negative +/testcase/utc_network_bluetooth_opp-server_positive +/testcase/utc_network_bluetooth_opp-client_negative +/testcase/utc_network_bluetooth_opp-client_positive +/testcase/utc_network_bluetooth_pan_negative +/testcase/utc_network_bluetooth_pan_positive +/testcase/utc_network_bluetooth_audio_negative +/testcase/utc_network_bluetooth_audio_positive +/testcase/utc_network_bluetooth_avrcp_negative +/testcase/utc_network_bluetooth_avrcp_positive +/testcase/utc_network_bluetooth_common_negative +/testcase/utc_network_bluetooth_common_positive diff --git a/TC/testcase/utc_network_bluetooth_adapter_negative.c b/TC/testcase/utc_network_bluetooth_adapter_negative.c new file mode 100644 index 0000000..06fdea7 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_adapter_negative.c @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> +#include <time.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); +bt_adapter_visibility_mode_e adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE; +char adapter_name[128] = "dts_test"; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_deinitialize_n(void); +static void utc_network_bluetooth_adapter_set_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_set_name_changed_cb_n(void); +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_n(void); +static void utc_network_bluetooth_adapter_enable_n(void); +static void utc_network_bluetooth_adapter_get_state_n(void); +static void utc_network_bluetooth_adapter_get_address_n(void); +static void utc_network_bluetooth_adapter_set_name_n(void); +static void utc_network_bluetooth_adapter_get_name_n(void); +static void utc_network_bluetooth_adapter_set_visibility_n(void); +static void utc_network_bluetooth_adapter_get_visibility_n(void); +static void utc_network_bluetooth_adapter_disable_n(void); +static void utc_network_bluetooth_adapter_unset_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_unset_name_changed_cb_n(void); +static void utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_n(void); + +void adapter_state_changed_cb_for_adapter_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void adapter_state_changed_cb_for_adapter_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void adapter_name_changed_cb_for_adapter_n(char *device_name, void *user_data); +void adapter_visibility_mode_changed_cb_for_adpater_n(int result, + bt_adapter_visibility_mode_e visibility_mode, + void *user_data); +void device_discovery_state_changed_cb_for_adapter_n(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_device_info_s *device_info, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_adapter_disable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_state_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_address_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_name_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_visibility_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_deinitialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_enable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_name_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + /* start of TC */ + tet_printf("TC start."); + bt_initialize(); +} + +static void cleanup(void) +{ + /* end of TC */ + tet_printf("TC end"); +} + +/** + * @brief Negative test case of bt_deinitialize() + */ +static void utc_network_bluetooth_deinitialize_n(void) +{ + int ret = bt_deinitialize(); + + if (ret == BT_ERROR_NONE) { + ret = bt_deinitialize(); + dts_check_eq("bt_deinitialize", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); + } else { + dts_fail("bt_deinitialize", "bt_deinitialize() failed."); + } +} + +/** + * @brief Negative test case of bt_adapter_disable() + */ +static void utc_network_bluetooth_adapter_disable_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_disable(); + dts_check_eq("bt_adapter_disable", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is disabled"); +} + +/** + * @brief Negative test case of bt_adapter_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_state_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_name_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_name_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_name_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_visibility_mode_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_visibility_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_visibility_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_get_state() + */ +static void utc_network_bluetooth_adapter_get_state_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_get_state(NULL); + dts_check_eq("bt_adapter_get_state", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_get_address(). + */ +static void utc_network_bluetooth_adapter_get_address_n(void) +{ + char *address = NULL; + int ret = bt_adapter_get_address(&address); + + dts_check_eq("bt_adapter_get_address", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_get_name(). + */ +static void utc_network_bluetooth_adapter_get_name_n(void) +{ + char *name = NULL; + int ret = bt_adapter_get_name(&name); + + dts_check_eq("bt_adapter_get_name", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_get_visibility(). + */ +static void utc_network_bluetooth_adapter_get_visibility_n(void) +{ + bt_adapter_visibility_mode_e mode = + BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; + int dur = 10; + int ret = bt_adapter_get_visibility(&mode, &dur); + + dts_check_eq("bt_adapter_get_visibility", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_set_name(). + */ +static void utc_network_bluetooth_adapter_set_name_n(void) +{ + int ret = bt_adapter_set_name(adapter_name); + + dts_check_eq("bt_adapter_set_name", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_set_visibility(). + */ +static void utc_network_bluetooth_adapter_set_visibility_n(void) +{ + int ret = bt_adapter_set_visibility(adapter_visibility_mode, 180); + + dts_check_eq("bt_adapter_set_visibility", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_unset_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_unset_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_adapter_unset_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_name_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_name_changed_cb(); + dts_check_eq("bt_adapter_unset_name_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_adapter_unset_visibility_mode_changed_cb() + */ +static void +utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_visibility_mode_changed_cb(); + dts_check_eq("bt_adapter_unset_visibility_mode_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_adapter_enable() + */ +static void utc_network_bluetooth_adapter_enable_n(void) +{ + bt_error_e ret = bt_adapter_enable(); + dts_check_eq("bt_adapter_enable", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); +} diff --git a/TC/testcase/utc_network_bluetooth_adapter_positive.c b/TC/testcase/utc_network_bluetooth_adapter_positive.c new file mode 100644 index 0000000..28168a3 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_adapter_positive.c @@ -0,0 +1,499 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> +#include <time.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); +static GMainLoop *mainloop; +static bool callback_result = false; +bt_adapter_visibility_mode_e adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE; +char adapter_name[128] = "dts_test"; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_initialize_p(void); +static void utc_network_bluetooth_deinitialize_p(void); +static void utc_network_bluetooth_adapter_set_state_changed_cb_p(void); +static void utc_network_bluetooth_adapter_set_name_changed_cb_p(void); +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_p(void); +static void utc_network_bluetooth_adapter_enable_p(void); +static void utc_network_bluetooth_adapter_get_state_p(void); +static void utc_network_bluetooth_adapter_get_address_p(void); +static void utc_network_bluetooth_adapter_set_name_p(void); +static void utc_network_bluetooth_adapter_get_name_p(void); +static void utc_network_bluetooth_adapter_set_visibility_p(void); +static void utc_network_bluetooth_adapter_get_visibility_p(void); +static void utc_network_bluetooth_adapter_disable_p(void); +static void utc_network_bluetooth_adapter_unset_state_changed_cb_p(void); +static void utc_network_bluetooth_adapter_unset_name_changed_cb_p(void); +static void utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_p(void); + +void adapter_state_changed_cb_for_adapter_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void adapter_state_changed_cb_for_adapter_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void adapter_name_changed_cb_for_adapter_p(char *device_name, void *user_data); +void adapter_visibility_mode_changed_cb_for_adpater_p(int result, + bt_adapter_visibility_mode_e visibility_mode, + void *user_data); +void device_discovery_state_changed_cb_for_adapter_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_device_info_s *device_info, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_enable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_address_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_name_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_name_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_name_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_visibility_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_visibility_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_disable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + /* start of TC */ + tet_printf("TC start."); + mainloop = g_main_loop_new(NULL, FALSE); +} + +static void cleanup(void) +{ + /* end of TC */ + tet_printf("TC end"); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_adapter_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "enable")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + callback_result = true; + } else { + tet_printf("Callback: BT was not enabled."); + } + + if (mainloop) + g_main_loop_quit(mainloop); + } else if (user_data != NULL && !strcmp((char *)user_data, "disable")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled."); + callback_result = true; + } else { + tet_printf("Callback: BT was not disabled."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_adapter_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_device_info_s *device_info, + void *user_data) +{ + tet_printf("bt_adapter_device_discovery_state_changed_cb was called"); + + if (user_data != NULL && !strcmp((char *)user_data, "enable")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb_for_adapter_p was called \ + and device discovery ends."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void adapter_name_changed_cb_for_adapter_p(char *device_name, void *user_data) +{ + tet_printf("bt_adapter_name_changed_cb_for_adapter_p was called: %s", + (char *)device_name); + + if (user_data != NULL && !strcmp((char *)user_data, "set_name")) { + if (!strcmp(device_name, adapter_name)) + callback_result = true; + } + + if (mainloop) + g_main_loop_quit(mainloop); + +} + +void adapter_visibility_mode_changed_cb_for_adpater_p(int result, + bt_adapter_visibility_mode_e visibility_mode, + void *user_data) +{ + tet_printf("bt_adapter_visibility_mode_changed_cb was called: %d", visibility_mode); + + if (user_data != NULL && !strcmp((char *)user_data, "set_visibility")) { + if (result == BT_ERROR_NONE) { + if (visibility_mode == adapter_visibility_mode) { + callback_result = true; + } else { + tet_printf("Callback: adapter_visibility_mode_changed_cb_for_adpater_p() was called but visibility mode is not same."); + tet_printf("Callback: actual visibility mode : %d", visibility_mode); + callback_result = false; + } + } else { + tet_printf("\n Callback: adapter_visibility_mode_changed_cb_for_adpater_p() was called but failed."); + callback_result = false; + } + } + + if (mainloop) + g_main_loop_quit(mainloop); +} + +/** + * @brief Positive test case of bt_initialize() + */ +static void utc_network_bluetooth_initialize_p(void) +{ + int ret = bt_initialize(); + dts_check_eq("bt_initialize", ret, BT_ERROR_NONE, + "bt_initialize() failed."); +} + +/** + * @brief Positive test case of bt_deinitialize() + */ +static void utc_network_bluetooth_deinitialize_p(void) +{ + int ret = bt_deinitialize(); + dts_check_eq("bt_deinitialize", ret, + BT_ERROR_NONE, "bt_deinitialize() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_adapter_p, NULL); + dts_check_eq("bt_adapter_set_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_set_state_changed_cb failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_name_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + ret = bt_adapter_set_name_changed_cb(adapter_name_changed_cb_for_adapter_p, NULL); + if (ret == BT_ERROR_NONE) { + timeout_id = g_timeout_add(10000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + dts_check_eq("bt_adapter_set_name_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_set_name_changed_cb failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_visibility_mode_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_visibility_mode_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + ret = bt_adapter_set_visibility_mode_changed_cb(adapter_visibility_mode_changed_cb_for_adpater_p, NULL); + if (ret == BT_ERROR_NONE) { + timeout_id = g_timeout_add(10000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + dts_check_eq("bt_adapter_set_visibility_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_set_visibility_mode_changed_cb failed."); +} + +/** + * @brief Positive test case of bt_adapter_enable() + */ +static void utc_network_bluetooth_adapter_enable_p(void) +{ + int timeout_id = 0; + callback_result = false; + bt_error_e ret = BT_ERROR_NONE; + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_adapter_p, "enable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_enable", + "bt_adapter_set_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_ALREADY_DONE) { + callback_result = true; + } else { + dts_fail("bt_adapter_enable", "bt_adapter_enable() failed."); + bt_adapter_unset_state_changed_cb(); + return; + } + + tet_printf("callback_result: %d", callback_result); + bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_enable", callback_result, true, + "BT was not enabled."); +} + +/** + * @brief Positive test case of bt_adapter_get_state() + */ +static void utc_network_bluetooth_adapter_get_state_p(void) +{ + bt_adapter_state_e adapter_state = BT_ADAPTER_DISABLED; + int ret = BT_ERROR_NONE; + + ret = bt_adapter_get_state(&adapter_state); + if (ret == BT_ERROR_NONE && adapter_state == BT_ADAPTER_ENABLED) { + dts_pass("bt_adapter_get_state", + "bt_adapter_get_state() succeeded."); + } else { + dts_fail("bt_adapter_get_state", + "bt_adapter_get_state() failed."); + } +} + +/** + * @brief Positive test case of bt_adapter_get_address(). + */ +static void utc_network_bluetooth_adapter_get_address_p(void) +{ + char *address = NULL; + int ret = bt_adapter_get_address(&address); + + if (address != NULL) + tet_printf("device address: %s", address); + + dts_check_eq("bt_adapter_get_address", ret, BT_ERROR_NONE, + "bt_adapter_get_address() failed."); +} + +/** + * @brief Positive test case of bt_adapter_get_name(). + */ +static void utc_network_bluetooth_adapter_get_name_p(void) +{ + char *name = NULL; + int ret = bt_adapter_get_name(&name); + + if (name != NULL) + tet_printf("device name : %s", name); + + memset(adapter_name, 0x00, sizeof(adapter_name)); + g_strlcpy(adapter_name, name, sizeof(adapter_name)); + + dts_check_eq("bt_adapter_get_name", ret, BT_ERROR_NONE, + "bt_adapter_get_name() failed."); +} + +/** + * @brief Positive test case of bt_adapter_get_visibility(). + */ +static void utc_network_bluetooth_adapter_get_visibility_p(void) +{ + bt_adapter_visibility_mode_e mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; + int dur = 1; + int ret = bt_adapter_get_visibility(&mode, &dur); + + tet_printf("visibility mode : %d", mode); + if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) { + adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE; + } else if (mode == BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE) { + adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; + } else + adapter_visibility_mode = BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE; + + dts_check_eq("bt_adapter_get_visibility", ret, BT_ERROR_NONE, + "bt_adapter_get_visibility() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_name(). + */ +static void utc_network_bluetooth_adapter_set_name_p(void) +{ + int timeout_id = 0; + char name[128] = ""; + + snprintf(name, 128, "%s_1", adapter_name); + strncpy(adapter_name, name, 128); + + if (bt_adapter_set_name_changed_cb(adapter_name_changed_cb_for_adapter_p, "set_name") != BT_ERROR_NONE) { + dts_fail("bt_adapter_set_name", + "bt_adapter_set_name_changed_cb() failed."); + } + + if (bt_adapter_set_name(adapter_name) == BT_ERROR_NONE) { + tet_printf("adapter_name_changed_cb_for_adapter_p() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_name_changed_cb(); + dts_check_eq("bt_adapter_set_name", callback_result, true, + "The local adapter name was not set."); + } else { + dts_fail("bt_adapter_set_name", "bt_adapter_set_name() failed"); + } +} + +/** + * @brief Positive test case of bt_adapter_set_visibility(). + */ +static void utc_network_bluetooth_adapter_set_visibility_p(void) +{ + callback_result = false; + int timeout = 0; + int timeout_id = 0; + + if (bt_adapter_set_visibility_mode_changed_cb(adapter_visibility_mode_changed_cb_for_adpater_p, "set_visibility") != BT_ERROR_NONE) { + dts_fail("bt_adapter_set_visibility", + "bt_adapter_set_visibility_mode_changed_cb() failed."); + } + + tet_printf("set visibility mode: %d", adapter_visibility_mode); + if (adapter_visibility_mode == BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE) { + timeout = 90; + tet_printf("set timeout: %d", timeout); + } + + if (bt_adapter_set_visibility(adapter_visibility_mode, timeout) == BT_ERROR_NONE) { + tet_printf("bt_adapter_visibility_changed_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_visibility_mode_changed_cb(); + dts_check_eq("bt_adapter_set_visibility", callback_result, true, + "The visibility of BT was not set."); + } else { + dts_fail("bt_adapter_set_visibility", + "bt_adapter_set_visibility() failed"); + } +} + +/** + * @brief Positive test case of bt_adapter_disable() + */ +static void utc_network_bluetooth_adapter_disable_p(void) +{ + callback_result = false; + int timeout_id = 0; + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_adapter_p, "disable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_disable", + "bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_disable() == BT_ERROR_NONE) { + tet_printf("bt_adapter_state_changed_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_disable", callback_result, true, + "BT was not disabled"); + } else { + dts_fail("bt_adapter_disable", "bt_adapter_disable() failed"); + } +} + +/** + * @brief Positive test case of bt_adapter_unset_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_state_changed_cb(); + dts_check_eq("bt_adapter_unset_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_unset_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_unset_name_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_name_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_name_changed_cb(); + dts_check_eq("bt_adapter_unset_name_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_unset_name_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_unset_visibility_mode_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_visibility_mode_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_visibility_mode_changed_cb(); + dts_check_eq("bt_adapter_unset_visibility_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_unset_visibility_mode_changed_cb() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_audio_negative.c b/TC/testcase/utc_network_bluetooth_audio_negative.c new file mode 100644 index 0000000..63c29d9 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_audio_negative.c @@ -0,0 +1,362 @@ +/* + * utc_network_bluetooth_audio_negative.c + * + * Created on: 19-Sep-2013 + * Author: mrinal.m + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_audio_connect_n(void); +static void utc_network_bluetooth_audio_disconnect_n(void); +static void utc_network_bluetooth_audio_set_connection_n(void); +static void utc_network_bluetooth_ag_get_speaker_gain_n(void); +static void utc_network_bluetooth_ag_is_nrec_enabled_n(void); +static void utc_network_bluetooth_ag_set_microphone_gain_changed_n(void); +static void utc_network_bluetooth_ag_set_speaker_gain_changed_n(void); +static void utc_network_bluetooth_ag_is_sco_opened_n(void); +static void utc_network_bluetooth_ag_set_sco_state_changed_n(void); +static void utc_network_bluetooth_ag_notify_call_event_n(void); +static void utc_network_bluetooth_ag_notify_call_list_n(void); +static void utc_network_bluetooth_ag_set_call_handling_event_cb_n(void); +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_n(void); +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_n(void); +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_n(void); +static void utc_network_bluetooth_ag_call_list_destroy_n(void); +static void utc_network_bluetooth_ag_call_list_reset_n(void); +static void utc_network_bluetooth_ag_call_list_add_n(void); + +void adapter_state_changed_cb_for_audio_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_audio_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_audio_disconnect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_audio_set_connection_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_get_speaker_gain_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_nrec_enabled_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_microphone_gain_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_speaker_gain_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_sco_opened_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_sco_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_event_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_call_handling_event_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_multi_call_handling_event_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_destroy_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_reset_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_add_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_audio_initialize() != BT_ERROR_NONE) + tet_printf("bt_audio_initialize failed"); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_audio_negative, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_audio_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_audio_connect() + */ +static void utc_network_bluetooth_audio_connect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_connect(NULL, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + dts_check_eq("bt_audio_connect", ret, + BT_ERROR_INVALID_PARAMETER, "bt_audio_connect() failed."); +} + +/** + * @brief Negative test case of bt_audio_disconnect() + */ +static void utc_network_bluetooth_audio_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_disconnect(NULL, BT_AUDIO_PROFILE_TYPE_A2DP); + dts_check_eq("bt_audio_disconnect", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_audio_disconnect() failed."); +} + +/** + * @brief Negative test case of bt_audio_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_audio_set_connection_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_audio_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_audio_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_audio_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_get_speaker_gain() + */ +static void utc_network_bluetooth_ag_get_speaker_gain_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_get_speaker_gain(NULL); + dts_check_eq("bt_ag_get_speaker_gain", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_get_speaker_gain() failed."); +} + +/** + * @brief Negative test case of bt_ag_is_nrec_enabled() + */ +static void utc_network_bluetooth_ag_is_nrec_enabled_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_is_nrec_enabled(NULL); + dts_check_eq("bt_ag_is_nrec_enabled", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_is_nrec_enabled() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_microphone_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_microphone_gain_changed_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_microphone_gain_changed_cb(NULL, NULL); + dts_check_eq("bt_ag_set_microphone_gain_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_microphone_gain_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_speaker_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_speaker_gain_changed_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_speaker_gain_changed_cb(NULL, NULL); + dts_check_eq("bt_ag_set_speaker_gain_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_speaker_gain_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_is_sco_opened() + */ +static void utc_network_bluetooth_ag_is_sco_opened_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_is_sco_opened(NULL); + dts_check_eq("bt_ag_is_sco_opened", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_is_sco_opened() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_sco_state_changed_cb() + */ +static void utc_network_bluetooth_ag_set_sco_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_sco_state_changed_cb(NULL, NULL); + dts_check_eq("bt_ag_set_sco_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_sco_state_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_notify_call_event() + */ +static void utc_network_bluetooth_ag_notify_call_event_n(void) +{ + int ret = BT_ERROR_NONE; + unsigned int call_id = 0; + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_INCOMING, call_id, NULL); + dts_check_eq("bt_ag_notify_call_event", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_notify_call_event() failed."); +} + +/** + * @brief Negative test case of bt_ag_notify_call_list() + */ +static void utc_network_bluetooth_ag_notify_call_list_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_notify_call_list(NULL); + dts_check_eq("bt_ag_notify_call_list", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_notify_call_list() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_call_handling_event_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_call_handling_event_cb(NULL, NULL); + dts_check_eq("bt_ag_set_call_handling_event_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_call_handling_event_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_multi_call_handling_event_cb(NULL, NULL); + dts_check_eq("bt_ag_set_multi_call_handling_event_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_multi_call_handling_event_cb() failed."); +} + +/** + * @brief Negative test case of bt_ag_set_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_dtmf_transmitted_cb(NULL, NULL); + dts_check_eq("bt_ag_set_dtmf_transmitted_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_ag_set_dtmf_transmitted_cb() failed."); +} + +/** + * @brief Negative test case of bt_call_list_create() + */ +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_n(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + handle = g_malloc0(sizeof(bt_call_list_h)); + ret = bt_call_list_create(handle); + dts_check_eq("bt_call_list_create", ret, BT_ERROR_NONE, + "bt_call_list_create() failed."); +} + +/** + * @brief Negative test case of bt_call_list_destroy() + */ +static void utc_network_bluetooth_ag_call_list_destroy_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_call_list_destroy(NULL); + dts_check_eq("bt_call_list_destroy", ret, BT_ERROR_INVALID_PARAMETER, + "bt_call_list_destroy() failed."); +} + +/** + * @brief Negative test case of bt_call_list_reset() + */ +static void utc_network_bluetooth_ag_call_list_reset_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_call_list_reset(NULL); + dts_check_eq("bt_call_list_reset", ret, BT_ERROR_INVALID_PARAMETER, + "bt_call_list_reset() failed."); +} + +/** + * @brief Negative test case of bt_call_list_add() + */ +static void utc_network_bluetooth_ag_call_list_add_n(void) +{ + int ret = BT_ERROR_NONE; + unsigned int call_id = 0; + + ret = bt_call_list_add(NULL, call_id, BT_AG_CALL_STATE_INCOMING); + dts_check_eq("bt_call_list_add", ret, BT_ERROR_INVALID_PARAMETER, + "bt_call_list_add() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_audio_positive.c b/TC/testcase/utc_network_bluetooth_audio_positive.c new file mode 100644 index 0000000..1f7c6a5 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_audio_positive.c @@ -0,0 +1,618 @@ +/* + * utc_network_bluetooth_audio_positive.c + * + * Created on: 19-Sep-2013 + * Author: mrinal.m + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +char target_address[18] = ""; +static GMainLoop *mainloop; + +static void utc_network_bluetooth_audio_initialize_p(void); +static void utc_network_bluetooth_audio_deinitialize_p(void); +static void utc_network_bluetooth_audio_connect_p(void); +static void utc_network_bluetooth_audio_disconnect_p(void); +static void utc_network_bluetooth_audio_set_connection_p(void); +static void utc_network_bluetooth_audio_unset_connection_p(void); +static void utc_network_bluetooth_ag_notify_speaker_gain_p(void); +static void utc_network_bluetooth_ag_get_speaker_gain_p(void); +static void utc_network_bluetooth_ag_is_nrec_enabled_p(void); +static void utc_network_bluetooth_ag_set_microphone_gain_changed_p(void); +static void utc_network_bluetooth_ag_unset_microphone_gain_changed_p(void); +static void utc_network_bluetooth_ag_set_speaker_gain_changed_p(void); +static void utc_network_bluetooth_ag_unset_speaker_gain_changed_p(void); +static void utc_network_bluetooth_ag_open_sco_p(void); +static void utc_network_bluetooth_ag_close_sco_p(void); +static void utc_network_bluetooth_ag_is_sco_opened_p(void); +static void utc_network_bluetooth_ag_set_sco_state_changed_p(void); +static void utc_network_bluetooth_ag_unset_sco_state_changed_p(void); +static void utc_network_bluetooth_ag_notify_call_event_p(void); +static void utc_network_bluetooth_ag_notify_call_list_p(void); +static void utc_network_bluetooth_ag_notify_voice_recognition_state_p(void); +static void utc_network_bluetooth_ag_set_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_unset_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_p(void); +static void utc_network_bluetooth_ag_set_dtmf_transmitted_cb_p(void); +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_p(void); +static void utc_network_bluetooth_ag_call_list_create_p(void); +static void utc_network_bluetooth_ag_call_list_destroy_p(void); +static void utc_network_bluetooth_ag_call_list_reset_p(void); +static void utc_network_bluetooth_ag_call_list_add_p(void); +static void utc_network_bluetooth_ag_ca2dp_set_content_protection_p(void); + +void connection_state_changed_cb_for_audio_p(int result, bool connected, + const char *remote_address, + bt_audio_profile_type_e type, + void *user_data); +void dtmf_transmitted_cb_for_ag_p(const char *dtmf, void *user_data); +void multi_call_handling_event_cb_for_ag_p(bt_ag_multi_call_handling_event_e event, void *user_data); +void call_handling_event_cb_for_ag_p(bt_ag_call_handling_event_e event, + unsigned int call_id, void *user_data); +void sco_state_changed_cb_for_ag_p(int result, bool opened, void *user_data); +void speaker_gain_changed_cb_for_ag_p(int gain, void *user_data); +void microphone_gain_changed_cb_for_ag_p(int gain, void *user_data); +void adapter_state_changed_cb_for_audio_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); + +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_audio_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_set_connection_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_open_sco_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_microphone_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_speaker_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_speaker_gain_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_get_speaker_gain_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_nrec_enabled_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_microphone_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_speaker_gain_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_sco_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_sco_opened_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_event_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_call_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_notify_voice_recognition_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_multi_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_dtmf_transmitted_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_close_sco_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_sco_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_create_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_destroy_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_reset_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_call_list_add_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_ca2dp_set_content_protection_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_unset_connection_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_audio_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + tet_printf("TC start."); + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_audio_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ + +void adapter_state_changed_cb_for_audio_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +void connection_state_changed_cb_for_audio_p(int result, bool connected, + const char *remote_address, + bt_audio_profile_type_e type, + void *user_data) +{ + +} + +void microphone_gain_changed_cb_for_ag_p(int gain, void *user_data) +{ + +} + +void speaker_gain_changed_cb_for_ag_p(int gain, void *user_data) +{ + +} + +void sco_state_changed_cb_for_ag_p(int result, bool opened, void *user_data) +{ + +} + +void call_handling_event_cb_for_ag_p(bt_ag_call_handling_event_e event, + unsigned int call_id, void *user_data) +{ + +} + +void multi_call_handling_event_cb_for_ag_p(bt_ag_multi_call_handling_event_e event, void *user_data) +{ + +} + +void dtmf_transmitted_cb_for_ag_p(const char *dtmf, void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_audio_initialize() + */ +static void utc_network_bluetooth_audio_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_initialize(); + dts_check_eq("bt_audio_initialize", ret, BT_ERROR_NONE, + "bt_audio_initialize() failed. %x", ret); + +} + +/** + * @brief Positive test case of bt_audio_connect() + */ +static void utc_network_bluetooth_audio_connect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:23:78:AB:C4:20"; + ret = bt_audio_connect(remote_address, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + dts_check_eq("bt_audio_connect", ret, BT_ERROR_NONE, + "bt_audio_connect() failed. %x", ret); +} + +/** + * @brief Positive test case of bt_audio_disconnect() + */ +static void utc_network_bluetooth_audio_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:23:78:AB:C4:20"; + ret = bt_audio_disconnect(remote_address, BT_AUDIO_PROFILE_TYPE_A2DP); + dts_check_eq("bt_audio_disconnect", ret, BT_ERROR_NONE, + "bt_audio_disconnect() failed. %x", ret); +} + +/** + * @brief Positive test case of bt_audio_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_audio_set_connection_p(void) +{ + int ret = BT_ERROR_NONE; + ret = + bt_audio_set_connection_state_changed_cb + (connection_state_changed_cb_for_audio_p, NULL); + dts_check_eq("bt_audio_set_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_audio_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_audio_unset_connection_state_changed_cb() + */ +static void utc_network_bluetooth_audio_unset_connection_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_audio_unset_connection_state_changed_cb(); + dts_check_eq("bt_audio_set_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_audio_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_ag_notify_speaker_gain() + */ +static void utc_network_bluetooth_ag_notify_speaker_gain_p(void) +{ + int ret = BT_ERROR_NONE; + int gain = 10; + ret = bt_ag_notify_speaker_gain(gain); + dts_check_eq("bt_ag_notify_speaker_gain", ret, BT_ERROR_NONE, + "bt_ag_notify_speaker_gain() failed.%x", ret); +} + +/** + * @brief Positive test case of bt_ag_get_speaker_gain() + */ +static void utc_network_bluetooth_ag_get_speaker_gain_p(void) +{ + int ret = BT_ERROR_NONE; + int gain = 0; + ret = bt_ag_get_speaker_gain(&gain); + dts_check_eq("bt_ag_get_speaker_gain", ret, BT_ERROR_NONE, + "bt_ag_get_speaker_gain() failed."); + +} + +/** + * @brief Positive test case of bt_ag_is_nrec_enabled() + */ +static void utc_network_bluetooth_ag_is_nrec_enabled_p(void) +{ + int ret = BT_ERROR_NONE; + bool enabled = 1; + ret = bt_ag_is_nrec_enabled(&enabled); + dts_check_eq("bt_ag_is_nrec_enabled", ret, BT_ERROR_NONE, + "bt_ag_is_nrec_enabled() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_microphone_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_microphone_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_microphone_gain_changed_cb(microphone_gain_changed_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_microphone_gain_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_set_microphone_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_microphone_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_unset_microphone_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_microphone_gain_changed_cb(); + dts_check_eq("bt_ag_unset_microphone_gain_changed_cb", ret, + BT_ERROR_NONE, + "bt_ag_unset_microphone_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_speaker_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_set_speaker_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_speaker_gain_changed_cb(speaker_gain_changed_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_speaker_gain_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_set_speaker_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_speaker_gain_changed_cb() + */ +static void utc_network_bluetooth_ag_unset_speaker_gain_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_speaker_gain_changed_cb(); + dts_check_eq("bt_ag_unset_speaker_gain_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_speaker_gain_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_open_sco() + */ +static void utc_network_bluetooth_ag_open_sco_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_open_sco(); + dts_check_eq("bt_ag_open_sco", ret, BT_ERROR_NONE, + "bt_ag_open_sco() failed."); + +} + +/** + * @brief Positive test case of bt_ag_close_sco() + */ +static void utc_network_bluetooth_ag_close_sco_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_close_sco(); + dts_check_eq("bt_ag_close_sco", ret, BT_ERROR_NONE, + "bt_ag_close_sco() failed."); + +} + +/** + * @brief Positive test case of bt_ag_is_sco_opened() + */ +static void utc_network_bluetooth_ag_is_sco_opened_p(void) +{ + int ret = BT_ERROR_NONE; + bool opened = 1; + ret = bt_ag_is_sco_opened(&opened); + dts_check_eq("bt_ag_is_sco_opened", ret, BT_ERROR_NONE, + "bt_ag_is_sco_opened() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_sco_state_changed_cb() + */ +static void utc_network_bluetooth_ag_set_sco_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_sco_state_changed_cb(sco_state_changed_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_sco_state_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_set_sco_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_sco_state_changed_cb() + */ +static void utc_network_bluetooth_ag_unset_sco_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_sco_state_changed_cb(); + dts_check_eq("bt_ag_unset_sco_state_changed_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_sco_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_notify_call_event() + */ +static void utc_network_bluetooth_ag_notify_call_event_p(void) +{ + int ret = BT_ERROR_NONE; + const char *phone_number = "9663868998"; + unsigned int call_id = 0; + ret = bt_ag_notify_call_event(BT_AG_CALL_EVENT_INCOMING, + call_id, phone_number); + dts_check_eq("bt_ag_notify_call_event", ret, BT_ERROR_NONE, + "bt_ag_notify_call_event() failed."); + +} + +/** + * @brief Positive test case of bt_ag_notify_call_list() + */ +static void utc_network_bluetooth_ag_notify_call_list_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE); + ret = bt_ag_notify_call_list(handle); + dts_check_eq("bt_ag_notify_call_list", ret, BT_ERROR_NONE, + "bt_ag_notify_call_list() failed."); + +} + +/** + * @brief Positive test case of bt_ag_notify_voice_recognition_state() + */ +static void utc_network_bluetooth_ag_notify_voice_recognition_state_p(void) +{ + int ret = BT_ERROR_NONE; + bool state = true; + + ret = bt_ag_notify_voice_recognition_state(state); + dts_check_eq("bt_ag_notify_voice_recognition_state", ret, BT_ERROR_NONE, + "bt_ag_notify_voice_recognition_state() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_call_handling_event_cb(call_handling_event_cb_for_ag_p, + NULL); + dts_check_eq("bt_ag_set_call_handling_event_cb", ret, BT_ERROR_NONE, + "bt_ag_set_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_unset_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_call_handling_event_cb(); + dts_check_eq("bt_ag_unset_call_handling_event_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_set_multi_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_multi_call_handling_event_cb(multi_call_handling_event_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_multi_call_handling_event_cb", ret, + BT_ERROR_NONE, + "bt_ag_set_multi_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_multi_call_handling_event_cb(); + dts_check_eq("bt_ag_unset_multi_call_handling_event_cb", ret, + BT_ERROR_NONE, + "bt_ag_unset_multi_call_handling_event_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_set_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_set_dtmf_transmitted_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_set_dtmf_transmitted_cb(dtmf_transmitted_cb_for_ag_p, NULL); + dts_check_eq("bt_ag_set_dtmf_transmitted_cb", ret, BT_ERROR_NONE, + "bt_ag_set_dtmf_transmitted_cb() failed."); + +} + +/** + * @brief Positive test case of bt_ag_unset_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_ag_unset_dtmf_transmitted_cb(); + dts_check_eq("bt_ag_unset_dtmf_transmitted_cb", ret, BT_ERROR_NONE, + "bt_ag_unset_dtmf_transmitted_cb() failed."); + +} + +/** + * @brief Positive test case of bt_call_list_create() + */ +static void utc_network_bluetooth_ag_call_list_create_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE); + ret = bt_call_list_create(&handle); + dts_check_eq("bt_call_list_create", ret, BT_ERROR_NONE, + "bt_call_list_create() failed."); +} + +/** + * @brief Positive test case of bt_call_list_destroy() + */ +static void utc_network_bluetooth_ag_call_list_destroy_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE); + ret = bt_call_list_destroy(handle); + dts_check_eq("bt_call_list_destroy", ret, BT_ERROR_NONE, + "bt_call_list_destroy() failed."); +} + +/** + * @brief Positive test case of bt_call_list_reset() + */ +static void utc_network_bluetooth_ag_call_list_reset_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h handle; + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE); + ret = bt_call_list_reset(handle); + dts_check_eq("bt_call_list_reset", ret, BT_ERROR_NONE, + "bt_call_list_reset() failed."); +} + +/** + * @brief Positive test case of bt_call_list_add() + */ +static void utc_network_bluetooth_ag_call_list_add_p(void) +{ + int ret = BT_ERROR_NONE; + unsigned int call_id = 0; + bt_call_list_h handle; + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE); + ret = bt_call_list_add(handle, call_id, BT_AG_CALL_STATE_INCOMING); + dts_check_eq("bt_call_list_add", ret, BT_ERROR_NONE, + "bt_call_list_add() failed."); +} + +/** + * @brief Positive test case of bt_a2dp_set_content_protection() + */ +static void utc_network_bluetooth_ag_ca2dp_set_content_protection_p(void) +{ + int ret = BT_ERROR_NONE; + bool status = true; + ret = bt_a2dp_set_content_protection(status); + dts_check_eq("bt_a2dp_set_content_protection", ret, BT_ERROR_NONE, + "bt_a2dp_set_content_protection() failed."); +} + +/** + * @brief Positive test case of bt_audio_deinitialize() + */ +static void utc_network_bluetooth_audio_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_audio_deinitialize(); + dts_check_eq("bt_audio_deinitialize", ret, BT_ERROR_NONE, + "bt_audio_deinitialize() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_avrcp_negative.c b/TC/testcase/utc_network_bluetooth_avrcp_negative.c new file mode 100644 index 0000000..d418475 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_avrcp_negative.c @@ -0,0 +1,171 @@ +/* + * utc_network_bluetooth_avrcp_negative.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include <tet_api.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +const char target_name[128] = "dts_test"; +char target_address[18] = ""; + +static GMainLoop *mainloop; + +static void utc_network_bluetooth_audio_initialize_n(void); +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_n(void); +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_n(void); +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_n(void); +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_n(void); + +void adapter_state_changed_cb_for_avrcp_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_audio_initialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_equalizer_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_repeat_mode_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_shuffle_mode_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_scan_mode_changed_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_avrcp_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Negative test case of bt_avrcp_target_initialize() + */ + +void adapter_state_changed_cb_for_avrcp_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +static void utc_network_bluetooth_audio_initialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_initialize(NULL, NULL); + dts_check_eq("bt_avrcp_target_initialize", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_target_initialize() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_equalizer_state_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_equalizer_state_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_equalizer_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_equalizer_state_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_repeat_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_repeat_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_repeat_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_repeat_mode_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_shuffle_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_shuffle_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_shuffle_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_shuffle_mode_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_avrcp_set_scan_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_scan_mode_changed_cb(NULL, NULL); + dts_check_eq("bt_avrcp_set_scan_mode_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_avrcp_set_scan_mode_changed_cb() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_avrcp_positive.c b/TC/testcase/utc_network_bluetooth_avrcp_positive.c new file mode 100644 index 0000000..dab7f7e --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_avrcp_positive.c @@ -0,0 +1,387 @@ +/* + * utc_network_bluetooth_avrcp_positive.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include <tet_api.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +void target_connection_state_changed_cb_for_avrcp_p(bool connected, + const char *remote_address, + void *user_data); +void equalizer_state_changed_cb_for_avrcp_p(bt_avrcp_equalizer_state_e equalizer, void *user_data); +void repeat_mode_changed_cb_for_avrcp_p(bt_avrcp_repeat_mode_e repeat, + void *user_data); +void shuffle_mode_changed_cb_for_avrcp_p(bt_avrcp_shuffle_mode_e shuffle, + void *user_data); +void scan_mode_changed_cb_for_avrcp_p(bt_avrcp_scan_mode_e scan, + void *user_data); + +static void utc_network_bluetooth_avrcp_targe_initialize_p(void); +static void utc_network_bluetooth_avrcp_target_deinitialize_p(void); +static void utc_network_bluetooth_avrcp_target_notify_equalizer_state_p(void); +static void utc_network_bluetooth_avrcp_target_notify_repeat_mode_p(void); +static void utc_network_bluetooth_avrcp_target_notify_shuffle_mode_p(void); +static void utc_network_bluetooth_avrcp_target_notify_scan_mode_p(void); +static void utc_network_bluetooth_avrcp_target_notify_player_state_p(void); +static void utc_network_bluetooth_avrcp_target_notify_position_p(void); +static void utc_network_bluetooth_avrcp_target_notify_track_p(void); +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_equalizer_state_changed_p(void); +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_repeat_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_shuffle_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_p(void); +static void utc_network_bluetooth_avrcp_unset_scan_mode_changed_p(void); + +void adapter_state_changed_cb_for_avrcp_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_avrcp_targe_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_equalizer_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_repeat_mode_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_shuffle_mode_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_scan_mode_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_player_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_position_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_notify_track_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_equalizer_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_equalizer_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_repeat_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_repeat_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_shuffle_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_shuffle_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_set_scan_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_unset_scan_mode_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_avrcp_target_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_avrcp_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ + +void adapter_state_changed_cb_for_avrcp_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +void target_connection_state_changed_cb_for_avrcp_p(bool connected, + const char *remote_address, + void *user_data) +{ + +} + +void equalizer_state_changed_cb_for_avrcp_p(bt_avrcp_equalizer_state_e equalizer, void *user_data) +{ + +} + +void repeat_mode_changed_cb_for_avrcp_p(bt_avrcp_repeat_mode_e repeat, + void *user_data) +{ + +} + +void shuffle_mode_changed_cb_for_avrcp_p(bt_avrcp_shuffle_mode_e shuffle, + void *user_data) +{ + +} + +void scan_mode_changed_cb_for_avrcp_p(bt_avrcp_scan_mode_e scan, + void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_avrcp_target_initialize() + */ +static void utc_network_bluetooth_avrcp_targe_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_initialize(target_connection_state_changed_cb_for_avrcp_p, NULL); + dts_check_eq("bt_avrcp_target_initialize", ret, BT_ERROR_NONE, + "bt_avrcp_target_initialize() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_deinitialize() + */ +static void utc_network_bluetooth_avrcp_target_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_deinitialize(); + dts_check_eq("bt_avrcp_target_deinitialize", ret, BT_ERROR_NONE, + "bt_avrcp_target_deinitialize() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_equalizer_state() + */ +static void utc_network_bluetooth_avrcp_target_notify_equalizer_state_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_equalizer_state(BT_AVRCP_EQUALIZER_STATE_ON); + dts_check_eq("bt_avrcp_target_notify_equalizer_state", ret, + BT_ERROR_NONE, + "bt_avrcp_target_notify_equalizer_state() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_repeat_mode() + */ +static void utc_network_bluetooth_avrcp_target_notify_repeat_mode_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_repeat_mode(BT_AVRCP_REPEAT_MODE_ALL_TRACK); + dts_check_eq("bt_avrcp_target_notify_repeat_mode", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_repeat_mode() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_shuffle_mode() + */ +static void utc_network_bluetooth_avrcp_target_notify_shuffle_mode_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_shuffle_mode(BT_AVRCP_SHUFFLE_MODE_ALL_TRACK); + dts_check_eq("bt_avrcp_target_notify_shuffle_mode", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_shuffle_mode() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_scan_mode() + */ +static void utc_network_bluetooth_avrcp_target_notify_scan_mode_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_scan_mode(BT_AVRCP_SCAN_MODE_ALL_TRACK); + dts_check_eq("bt_avrcp_target_notify_scan_mode", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_scan_mode() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_player_state() + */ +static void utc_network_bluetooth_avrcp_target_notify_player_state_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_player_state(BT_AVRCP_PLAYER_STATE_PLAYING); + dts_check_eq("bt_avrcp_target_notify_player_state", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_player_state() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_position() + */ +static void utc_network_bluetooth_avrcp_target_notify_position_p(void) +{ + int ret = BT_ERROR_NONE; + unsigned int position = 0; + ret = bt_avrcp_target_notify_position(position); + dts_check_eq("bt_avrcp_target_notify_position", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_position() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_target_notify_track() + */ +static void utc_network_bluetooth_avrcp_target_notify_track_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_target_notify_track("title", "artist", "album", "genre", 5, 20, 2); + dts_check_eq("bt_avrcp_target_notify_track", ret, BT_ERROR_NONE, + "bt_avrcp_target_notify_track() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_set_equalizer_state_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_equalizer_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_equalizer_state_changed_cb(equalizer_state_changed_cb_for_avrcp_p, NULL); + dts_check_eq("bt_avrcp_set_equalizer_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_avrcp_set_equalizer_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_unset_equalizer_state_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_equalizer_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_equalizer_state_changed_cb(); + dts_check_eq("bt_avrcp_unset_equalizer_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_avrcp_unset_equalizer_state_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_set_repeat_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_repeat_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_repeat_mode_changed_cb(repeat_mode_changed_cb_for_avrcp_p, NULL); + dts_check_eq("bt_avrcp_set_repeat_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_set_repeat_mode_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_unset_repeat_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_repeat_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_repeat_mode_changed_cb(); + dts_check_eq("bt_avrcp_unset_repeat_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_avrcp_unset_repeat_mode_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_avrcp_set_shuffle_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_shuffle_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_shuffle_mode_changed_cb(shuffle_mode_changed_cb_for_avrcp_p, NULL); + dts_check_eq("bt_avrcp_set_shuffle_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_set_shuffle_mode_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_unset_shuffle_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_shuffle_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_shuffle_mode_changed_cb(); + dts_check_eq("bt_avrcp_unset_shuffle_mode_changed_cb", ret, + BT_ERROR_NONE, + "bt_avrcp_unset_shuffle_mode_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_set_scan_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_set_scan_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_set_scan_mode_changed_cb(scan_mode_changed_cb_for_avrcp_p, NULL); + dts_check_eq("bt_avrcp_set_scan_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_set_scan_mode_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_avrcp_unset_scan_mode_changed_cb() + */ +static void utc_network_bluetooth_avrcp_unset_scan_mode_changed_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_avrcp_unset_scan_mode_changed_cb(); + dts_check_eq("bt_avrcp_unset_scan_mode_changed_cb", ret, BT_ERROR_NONE, + "bt_avrcp_unset_scan_mode_changed_cb() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_common_negative.c b/TC/testcase/utc_network_bluetooth_common_negative.c new file mode 100644 index 0000000..507d7f5 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_common_negative.c @@ -0,0 +1,84 @@ +/* + * utc_network_bluetooth_common_negative.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include <tet_api.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; +void adapter_state_changed_cb_for_common_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_common_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_common_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} diff --git a/TC/testcase/utc_network_bluetooth_common_positive.c b/TC/testcase/utc_network_bluetooth_common_positive.c new file mode 100644 index 0000000..c694655 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_common_positive.c @@ -0,0 +1,119 @@ +/* + * utc_network_bluetooth_common_positive.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include <tet_api.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +void adapter_state_changed_cb_for_common_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +static void utc_network_bluetooth_bt_initialize_p(void); +static void utc_network_bluetooth_bt_deinitialize_p(void); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_bt_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_bt_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_common_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_common_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_initialize() + */ +static void utc_network_bluetooth_bt_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_initialize(); + dts_check_eq("bt_initialize", ret, BT_ERROR_NONE, + "bt_initialize() failed."); + +} + +/** + * @brief Positive test case of bt_deinitialize() + */ +static void utc_network_bluetooth_bt_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_deinitialize(); + dts_check_eq("bt_deinitialize", ret, BT_ERROR_NONE, + "bt_deinitialize() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_device_discovery_negative.c b/TC/testcase/utc_network_bluetooth_device_discovery_negative.c new file mode 100644 index 0000000..b5b422f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_discovery_negative.c @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static GMainLoop *mainloop; +gboolean timeout_func(gpointer data); + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_discovery_cancel_n(void); +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_n(void); +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_n(void); +static void utc_network_bluetooth_device_discovery_start_n(void); +static void utc_network_bluetooth_device_discovery_get_status_n(void); + +void adapter_state_changed_cb_for_discovery_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_device_discovery_cancel_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_set_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_get_status_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_start_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_unset_state_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_discovery_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end"); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_discovery_n(int result, + state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && + result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + *@brief Negative test case of bt_adapter_stop_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_cancel_n(void) +{ + int ret = bt_adapter_stop_device_discovery(); + + dts_check_eq("bt_adapter_stop_device_discovery", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + *@brief Negative test case of bt_adapter_unset_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (bt_deinitialize() != BT_ERROR_NONE) { + dts_fail("bt_adapter_unset_device_discovery_state_changed_cb", + "bt_deinitialize() failed."); + } + ret = bt_adapter_unset_device_discovery_state_changed_cb(); + dts_check_eq("bt_adapter_unset_device_discovery_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + *@brief Negative test case of bt_adapter_set_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_device_discovery_state_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_device_discovery_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + *@brief Negative test case of bt_adapter_start_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_start_n(void) +{ + bt_error_e ret = BT_ERROR_NONE; + + ret = bt_adapter_start_device_discovery();; + dts_check_eq("bt_adapter_start_device_discovery", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + *@brief Negative test case of bt_adapter_is_discovering() + */ +static void utc_network_bluetooth_device_discovery_get_status_n(void) +{ + bt_error_e ret = BT_ERROR_NONE; + bool status = false; + + ret = bt_adapter_is_discovering(&status); + dts_check_eq("bt_adapter_is_discovering", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_device_discovery_positive.c b/TC/testcase/utc_network_bluetooth_device_discovery_positive.c new file mode 100644 index 0000000..0cd0fe4 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_discovery_positive.c @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static GMainLoop *mainloop; +static bool callback_result = false; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_discovery_get_status_p(void); +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_p(void); +static void utc_network_bluetooth_device_discovery_start_p(void); +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_p(void); +static void utc_network_bluetooth_device_discovery_cancel_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_discovery_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void device_discovery_state_changed_cb_for_discovery_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_device_discovery_get_status_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_set_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_start_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_unset_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_discovery_cancel_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_discovery_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf + ("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + tet_printf("TC end"); + bt_deinitialize(); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_discovery_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && + result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + } else { + tet_printf("Callback: bt_adapter_state_changed_cb() was \ + called but bt_adapter_enable() failed."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_discovery_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data) +{ + tet_printf("Callback: device_discovery_state_changed_cb_for_discovery_p is called"); + + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were found"); + tet_printf("Callback: Device name is %s", discovery_info->remote_name); + tet_printf("Callback: Service class: %x", discovery_info->bt_class.major_service_class_mask); + if (user_data != NULL && !strcmp((char *)user_data, "start")) { + callback_result = true; + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished"); + if (user_data != NULL) { + if (!strcmp((char *)user_data, "start") && callback_result == false) { + tet_printf("You need a discoverable device"); + tet_printf("utc_network_bluetooth_device_discovery_start_p and \ + utc_network_bluetooth_device_discovery_cancel_p will fail"); + } else if (!strcmp((char *)user_data, "cancel")) { + if (result == BT_ERROR_CANCELLED) { + callback_result = true; + } + } + } + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Positive test case of bt_adapter_is_discovering() + */ +static void utc_network_bluetooth_device_discovery_get_status_p(void) +{ + bt_error_e ret = BT_ERROR_NONE; + bool status = false; + + ret = bt_adapter_is_discovering(&status); + dts_check_eq("bt_adapter_is_discovering", ret, BT_ERROR_NONE, + "bt_adapter_is_discovering() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_set_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_discovery_p, "start"); + dts_check_eq("bt_adapter_set_device_discovery_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_set_device_discovery_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_start_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_start_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + ret = bt_adapter_start_device_discovery(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_device_discovery_state_changed_cb_for_discovery_p() will be called."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_adapter_start_device_discovery", + callback_result, true, + "Callback was called but failed."); + } else { + dts_fail("bt_adapter_start_device_discovery", + "bt_adapter_start_device_discovery() failed."); + } +} + +/** + * @brief Positive test case of bt_adapter_unset_device_discovery_state_changed_cb() + */ +static void utc_network_bluetooth_device_discovery_unset_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_device_discovery_state_changed_cb(); + dts_check_eq("bt_adapter_unset_device_discovery_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_device_discovery_uset_state_changed_cb() failed"); +} + +/** + * @brief Positive test case of bt_adapter_stop_device_discovery() + */ +static void utc_network_bluetooth_device_discovery_cancel_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + if (bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_discovery_p, "cancel") != BT_ERROR_NONE) { + dts_fail("bt_adapter_stop_device_discovery", + "bt_adapter_set_device_discovery_state_changed_cb() failed"); + } + + ret = bt_adapter_stop_device_discovery(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_device_discovery_state_changed_cb_for_discovery_p() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_adapter_unset_device_discovery_state_changed_cb(); + dts_check_eq("bt_adapter_stop_device_discovery", + callback_result, true, + "Callback was called but failed"); + } else { + dts_fail("bt_adapter_stop_device_discovery", + "bt_adapter_stop_device_discovery() failed"); + } + +} diff --git a/TC/testcase/utc_network_bluetooth_device_negative.c b/TC/testcase/utc_network_bluetooth_device_negative.c new file mode 100644 index 0000000..f1e7d42 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_negative.c @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +gboolean timeout_func(gpointer data); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_set_bonded_cb_n(void); +static void utc_network_bluetooth_device_set_unbonded_cb_n(void); +static void utc_network_bluetooth_device_set_authorization_state_changed_cb_n(void); +static void utc_network_bluetooth_device_cancel_bonding_n(void); +static void utc_network_bluetooth_device_bond_n(void); +static void utc_network_bluetooth_device_foreach_bonded_device_n(void); +static void utc_network_bluetooth_device_set_alias_n(void); +static void utc_network_bluetooth_device_set_authorization_n(void); +static void utc_network_bluetooth_device_unbond_n(void); +static void utc_network_bluetooth_device_unset_bonded_cb_n(void); +static void utc_network_bluetooth_device_unset_unbonded_cb_n(void); +static void utc_network_bluetooth_device_unset_authorization_state_changed_cb_n(void); + +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_device_set_bonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_unbonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_authorization_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_bond_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_cancel_bonding_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_unbond_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_foreach_bonded_device_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_alias_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_set_authorization_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_bonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_unbonded_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_authorization_state_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_device_negative, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_device_set_bond_created_cb() + */ +static void utc_network_bluetooth_device_set_bonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_bond_created_cb(NULL, NULL); + dts_check_eq("bt_device_set_bond_created_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_set_unbonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_bond_destroyed_cb(NULL, NULL); + dts_check_eq("bt_device_set_bond_destroyed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_authorization_changed_cb() + */ +static void +utc_network_bluetooth_device_set_authorization_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_authorization_changed_cb(NULL, NULL); + dts_check_eq("bt_device_set_authorization_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_unset_bond_created_cb() + */ +static void utc_network_bluetooth_device_unset_bonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (bt_deinitialize() != BT_ERROR_NONE) { + dts_fail("bt_device_unset_bond_created_cb", + "bt_deinitialize() failed."); + } + + ret = bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_unset_bond_created_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + + /** + * @brief Negative test case of bt_device_unset_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_unset_unbonded_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_unset_bond_destroyed_cb(); + dts_check_eq("bt_device_unset_bond_destroyed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_device_unset_authorization_changed_cb() + */ +static void +utc_network_bluetooth_device_unset_authorization_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_unset_authorization_changed_cb(); + dts_check_eq("bt_device_unset_authorization_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + + /** + * @brief Negative test case of bt_device_create_bond() + */ +static void utc_network_bluetooth_device_bond_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_create_bond(NULL); + dts_check_eq("bt_device_create_bond", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + + /** + * @brief Negative test case of bt_device_cancel_bonding() + */ +static void utc_network_bluetooth_device_cancel_bonding_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_cancel_bonding(); + dts_check_eq("bt_device_cancel_bonding", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_device_destroy_bond() + */ +static void utc_network_bluetooth_device_unbond_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_destroy_bond(NULL); + dts_check_eq("bt_device_destroy_bond", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL"); +} + +/** + * @brief Negative test case of bt_adapter_foreach_bonded_device() + */ +static void utc_network_bluetooth_device_foreach_bonded_device_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_foreach_bonded_device(NULL, NULL); + dts_check_eq("bt_adapter_foreach_bonded_device", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_alias() + */ +static void utc_network_bluetooth_device_set_alias_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_alias(NULL, "dts_alias"); + dts_check_eq("bt_device_set_alias", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_set_authorization() + */ +static void utc_network_bluetooth_device_set_authorization_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_authorization(NULL, BT_DEVICE_AUTHORIZED); + dts_check_eq("bt_device_set_authorization", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address parameter is NULL"); +} diff --git a/TC/testcase/utc_network_bluetooth_device_positive.c b/TC/testcase/utc_network_bluetooth_device_positive.c new file mode 100644 index 0000000..0a43e2d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_positive.c @@ -0,0 +1,610 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +static bool callback_result = false; +char target_name[128] = "dts_test"; +char target_address[18] = ""; +bt_device_info_s *device_info = NULL; +bool discovery_result = false; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_device_set_bonded_cb_p(void); +static void utc_network_bluetooth_device_set_unbonded_cb_p(void); +static void utc_network_bluetooth_device_set_authorization_state_changed_cb_p(void); +static void utc_network_bluetooth_device_cancel_bonding_p(void); +static void utc_network_bluetooth_device_bond_p(void); +static void utc_network_bluetooth_device_foreach_bonded_device_p(void); +static void utc_network_bluetooth_device_set_alias_p(void); +static void utc_network_bluetooth_device_set_authorization_p(void); +static void utc_network_bluetooth_device_unbond_p(void); +static void utc_network_bluetooth_device_unset_bonded_cb_p(void); +static void utc_network_bluetooth_device_unset_unbonded_cb_p(void); +static void utc_network_bluetooth_device_unset_authorization_state_changed_cb_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_device_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void device_discovery_state_changed_cb_for_device_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data); +void device_bonded_cb(int result, bt_device_info_s *device_info, + void *user_data); +void device_unbonded_cb(int result, char *remote_address, void *user_data); +void device_authorization_state_changed_cb(bt_device_authorization_e authorization_state, + char *remote_address, + void *user_data); +bool bonded_device_cb_for_device_p(bt_device_info_s *dev_info, + void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_device_set_bonded_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_bonded_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_cancel_bonding_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_bond_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_foreach_bonded_device_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_set_alias_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_set_authorization_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_set_authorization_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_authorization_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_set_unbonded_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_unbond_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_device_unset_unbonded_cb_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + callback_result = false; + discovery_result = false; + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_device_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_device_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_device_discovery_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + + tet_printf("BT was enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_state_changed_cb() failed."); + } + + if (bt_adapter_unset_device_discovery_state_changed_cb() != + BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + tet_printf("TC start."); +} + +static void cleanup(void) +{ + /* end of TC */ + if (device_info != NULL) + free(device_info); + + bt_deinitialize(); + tet_printf("TC end"); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_device_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_device_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data) +{ + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished. DTS will be started."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were founded (%s)", discovery_info->remote_name); + if (discovery_info->remote_name != NULL && !strcmp(discovery_info->remote_name, target_name)) { + discovery_result = true; + tet_printf("Callback: dts_test device was found."); + strncpy(target_address, discovery_info->remote_address, 18); + tet_printf("Callback: device address: [%s]", discovery_info->remote_address); + if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) { + tet_printf("Callback: Device discovery will be stopped"); + } + } + } + } +} + +void device_bonded_cb(int result, bt_device_info_s * device_info, + void *user_data) +{ + int i = 0; + + tet_printf("Callback: bt_device_bond_created_cb() was called."); + if (result == BT_ERROR_TIMED_OUT) + tet_printf("result is BT_ERROR_TIMEOUT"); + else if (result == BT_ERROR_CANCELLED) + tet_printf("result is BT_ERROR_CANCELLED"); + else if (result == BT_ERROR_AUTH_FAILED) + tet_printf("result is BT_ERROR_AUTH_FAILED"); + else if (result == BT_ERROR_OPERATION_FAILED) + tet_printf("result is BT_ERROR_OPERATION_FAILED"); + else if (result == BT_ERROR_AUTH_REJECTED) + tet_printf("result is BT_ERROR_AUTH_REJECTED"); + else if (result == BT_ERROR_REMOTE_DEVICE_NOT_FOUND) + tet_printf("result is BT_ERROR_REMOTE_DEVICE_NOT_FOUND"); + else if (result == BT_ERROR_NONE) + tet_printf("result is BT_ERROR_NONE"); + else + tet_printf("result is unknown: %s", + _bt_convert_error_to_string(result)); + + /* in case of bt_device_cancel_bonding() */ + if (user_data != NULL && !strcmp((char *)user_data, "cancel")) { + if (result == BT_ERROR_CANCELLED) { + tet_printf("Callback: Cancellation of bonding succeeded"); + callback_result = true; + } else { + tet_printf("Callback: Cancellation of bonding failed"); + } + } /* in case of bt_device_create_bond() */ + else if (user_data != NULL && !strcmp((char *)user_data, "bond")) { + if (device_info == NULL) { + tet_printf("Callback data is NULL"); + + if (result == BT_ERROR_CANCELLED) + tet_printf("No user input in the peer device"); + + if (mainloop) + g_main_loop_quit(mainloop); + + return; + } + + if (device_info->remote_name != NULL && !strcmp(device_info->remote_name, target_name)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Bonding succeeded"); + tet_printf("Callback: serivce count : %d", device_info->service_count); + callback_result = true; + for (i = 0; i < device_info->service_count; i++) { + tet_printf("Callback: service list[%d] - %s", i + 1, device_info->service_uuid[i]); + } + } else { + tet_printf("Callback: Bonding failed"); + } + } + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +void device_unbonded_cb(int result, char *remote_address, void *user_data) +{ + tet_printf("Callback: bt_device_bond_destroyed_cb() was called."); + tet_printf("Callback: target address"); + if (target_address != NULL) { + tet_printf("device address: %s", target_address); + } else + tet_printf("Callback: target address is NULL!"); + + tet_printf("Callback: address of unbonded device"); + if (remote_address != NULL) { + tet_printf("device address: %s", remote_address); + if (!strcmp(remote_address, target_address)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Unbonding succeeded"); + callback_result = true; + } else { + tet_printf("Callback: Unbonding failed"); + } + } + } else + tet_printf("Callback: address of unbonded device is NULL!"); + + + if (mainloop) { + g_main_loop_quit(mainloop); + } + +} + +void device_authorization_state_changed_cb(bt_device_authorization_e + authorization_state, char *address, + void *user_data) +{ + if (authorization_state == BT_DEVICE_AUTHORIZED) { + if (address != NULL && !strcmp(address, target_address)) { + callback_result = true; + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } else { + if (address != NULL && !strcmp(address, target_address)) { + callback_result = true; + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +/** + * @brief Positive test case of bt_device_set_bond_created_cb() + */ +static void utc_network_bluetooth_device_set_bonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_set_bond_created_cb(device_bonded_cb, "cancel"); + dts_check_eq("bt_device_set_bond_created_cb", ret, BT_ERROR_NONE, + "bt_device_set_bond_created_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_set_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_set_unbonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_set_bond_destroyed_cb(device_unbonded_cb, NULL); + dts_check_eq("bt_device_set_bond_destroyed_cb", ret, BT_ERROR_NONE, + "bt_device_set_bond_destroyed_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_set_authorization_changed_cb() + */ +static void +utc_network_bluetooth_device_set_authorization_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_set_authorization_changed_cb(device_authorization_state_changed_cb, NULL); + dts_check_eq("bt_device_set_authorization_changed_cb", ret, + BT_ERROR_NONE, + "bt_device_set_authorization_changed_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_cancel_bonding() + */ +static void utc_network_bluetooth_device_cancel_bonding_p(void) +{ + int ret = BT_ERROR_NONE; + callback_result = false; + int timeout_id = 0; + + if (bt_device_set_bond_created_cb(device_bonded_cb, "cancel") != + BT_ERROR_NONE) { + dts_fail("bt_device_cancel_bonding", + "bt_device_set_bond_created_cb() failed"); + } + + /* bond device */ + ret = bt_device_create_bond(target_address); + if (ret != BT_ERROR_NONE) { + dts_fail("bt_device_cancel_bonding", + "bt_device_create_bond failed"); + } + tet_printf("bt_device_create_bond() was called"); + + /* cancel bonding */ + ret = bt_device_cancel_bonding(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_cancel_bonding() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_cancel_bonding", callback_result, true, + "Failed"); + } else { + bt_device_unset_bond_created_cb(); + dts_fail("bt_device_cancel_bonding", + "bt_device_cancel_bonding() failed"); + } +} + +/** + * @brief Positive test case of bt_device_unset_bond_created_cb() + */ +static void utc_network_bluetooth_device_unset_bonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_unset_bond_created_cb", ret, BT_ERROR_NONE, + "bt_device_unset_bond_created_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_create_bond() + */ +static void utc_network_bluetooth_device_bond_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + /* bond device */ + ret = bt_device_set_bond_created_cb(device_bonded_cb, "bond"); + if (ret != BT_ERROR_NONE) { + dts_fail("bt_device_create_bond", + "bt_device_set_bond_created_cb() failed"); + } + + ret = bt_device_create_bond(target_address); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_bond_created_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + bt_device_unset_bond_created_cb(); + dts_check_eq("bt_device_create_bond", callback_result, true, + "Failed"); + } else { + bt_device_unset_bond_created_cb(); + dts_fail("bt_device_create_bond", + "bt_device_create_bond() failed"); + } +} + +bool bonded_device_cb_for_device_p(bt_device_info_s * dev_info, void *user_data) +{ + int i = 0; + device_info = (bt_device_info_s *) malloc(sizeof(bt_device_info_s)); + if (device_info == NULL) { + tet_printf("Callback: Memory allocation failed");; + } else if (dev_info != NULL) { + device_info->remote_address = strdup(dev_info->remote_address); + tet_printf("device address : %s", device_info->remote_address); + device_info->remote_name = strdup(dev_info->remote_name); + tet_printf("device name : %s", device_info->remote_name); + device_info->bt_class.major_device_class = dev_info->bt_class.major_device_class; + tet_printf("major clasee : %2.2X", device_info->bt_class.major_device_class); + device_info->bt_class.minor_device_class = dev_info->bt_class.minor_device_class; + tet_printf("minor clasee : %2.2X", device_info->bt_class.minor_device_class); + device_info->bt_class.major_service_class_mask = dev_info->bt_class.major_service_class_mask; + tet_printf("service clasee : %2.2X", device_info->bt_class.major_service_class_mask); + device_info->service_count = dev_info->service_count; + tet_printf("service count : %d", device_info->service_count); + if (device_info->service_count > 0) { + device_info->service_uuid = (char **)malloc(sizeof(char *) * device_info->service_count); + if (device_info->service_uuid == NULL) { + tet_printf("Failed to allocate memory"); + } else { + if (dev_info->service_uuid == NULL) { + tet_printf("service_list is NULL"); + } else { + tet_printf("Copy service list"); + for (i = 0; i < device_info->service_count; i++) { + device_info->service_uuid[i] = strdup(dev_info->service_uuid[i]); + tet_printf("Callback: service list[%d] - %s", i + 1, device_info->service_uuid[i]); + } + } + } + } else + device_info->service_uuid = NULL; + + device_info->is_bonded = dev_info->is_bonded; + tet_printf("is_bonded : %d", device_info->is_bonded); + device_info->is_connected = dev_info->is_connected; + tet_printf("is_connected : %d", device_info->is_connected); + tet_printf("Callback: device_info was selected."); + } + + return false; +} + +/** + * @brief Positive test case of bt_adapter_foreach_bonded_device() + */ +static void utc_network_bluetooth_device_foreach_bonded_device_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_foreach_bonded_device(bonded_device_cb_for_device_p, NULL); + if (ret == BT_ERROR_NONE) { + dts_pass("bt_adapter_foreach_bonded_device", + "bt_adapter_foreach_bonded_device pass"); + } else { + dts_fail("bt_adapter_foreach_bonded_device", + "bt_adapter_foreach_bonded_device() failed"); + } +} + +/** + * @brief Positive test case of bt_device_set_alias() + */ +static void utc_network_bluetooth_device_set_alias_p(void) +{ + int ret = BT_ERROR_NONE; + + if (device_info == NULL) { + tet_printf("No device to alias"); + dts_fail("bt_device_set_alias", "bt_device_set_alias() failed"); + return; + } + + ret = bt_device_set_alias(device_info->remote_address, "dts_alias"); + dts_check_eq("bt_device_set_alias", ret, BT_ERROR_NONE, + "bt_device_set_alias() failed"); +} + +/** + * @brief Positive test case of bt_device_set_authorization() + */ +static void utc_network_bluetooth_device_set_authorization_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + callback_result = false; + + ret = bt_device_set_authorization(target_address, BT_DEVICE_AUTHORIZED); + if (ret == BT_ERROR_NONE) { + tet_printf("device_authorization_state_changed_cb will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_set_authorization", callback_result, + true, "Callback was called but failed"); + callback_result = false; + } else { + dts_fail("bt_device_set_authorization", + "bt_device_set_authorization() failed"); + } +} + +/** + * @brief Positive test case of bt_device_destroy_bond() + */ +static void utc_network_bluetooth_device_unbond_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + callback_result = false; + + tet_printf("bt_device_destroy_bond() will start"); + ret = bt_device_destroy_bond(target_address); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_device_unbond_cb() will be called"); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_destroy_bond", callback_result, true, + "Failed"); + } else { + dts_fail("bt_device_destroy_bond", + "bt_device_destroy_bond() failed"); + } +} + +/** + * @brief Positive test case of bt_device_unset_bond_destroyed_cb() + */ +static void utc_network_bluetooth_device_unset_unbonded_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_unset_bond_destroyed_cb(); + dts_check_eq("bt_device_unset_bond_destroyed_cb", ret, BT_ERROR_NONE, + "bt_device_unset_bond_destroyed_cb() failed"); +} + +/** + * @brief Positive test case of bt_device_unset_authorization_changed_cb() + */ +static void utc_network_bluetooth_device_unset_authorization_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + /* Normal operation test */ + ret = bt_device_unset_authorization_changed_cb(); + dts_check_eq("bt_device_unset_authorization_changed_cb", ret, + BT_ERROR_NONE, + "bt_device_unset_authorization_changed_cb() failed"); +} diff --git a/TC/testcase/utc_network_bluetooth_gatt_negative.c b/TC/testcase/utc_network_bluetooth_gatt_negative.c new file mode 100644 index 0000000..c58bdcf --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_gatt_negative.c @@ -0,0 +1,238 @@ +/* + * utc_network_bluetooth_gatt_negative.c + * + * Created on: 23-Sep-2013 + * Author: shagun.garg + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_gatt_foreach_primary_services_n(void); +static void utc_network_bluetooth_gatt_discover_characteristics_n(void); +static void utc_network_bluetooth_gatt_get_service_uuid_n(void); +static void utc_network_bluetooth_gatt_foreach_included_services_n(void); +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_n(void); +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_n(void); +static void utc_network_bluetooth_gatt_get_characteristic_declaration_n(void); +static void utc_network_bluetooth_gatt_set_characteristic_value_n(void); +static void utc_network_bluetooth_gatt_clone_attribute_handle_n(void); +static void utc_network_bluetooth_gatt_destroy_attribute_handle_n(void); + +void adapter_state_changed_cb_for_gatt_n(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_gatt_foreach_primary_services_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_discover_characteristics_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_service_uuid_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_foreach_included_services_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_unset_characteristic_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_characteristic_declaration_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_value_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_clone_attribute_handle_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_destroy_attribute_handle_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_gatt_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_gatt_n(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_gatt_foreach_primary_services() + */ +static void utc_network_bluetooth_gatt_foreach_primary_services_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_foreach_primary_services(NULL, NULL, NULL); + dts_check_eq("bt_gatt_foreach_primary_services", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_discover_characteristics() + */ +static void utc_network_bluetooth_gatt_discover_characteristics_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_discover_characteristics(NULL, NULL, NULL); + dts_check_eq("bt_gatt_discover_characteristics", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_get_service_uuid() + */ +static void utc_network_bluetooth_gatt_get_service_uuid_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_get_service_uuid(NULL, NULL); + dts_check_eq("bt_gatt_get_service_uuid", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service parameter is NULL."); +} + +/** + * @brief Negative test case of bt_gatt_foreach_included_services() + */ +static void utc_network_bluetooth_gatt_foreach_included_services_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_foreach_included_services(NULL, NULL, NULL); + dts_check_eq("bt_socket_unset_connection_state_changed_cb", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_set_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_characteristic_changed_cb(NULL, NULL, NULL); + dts_check_eq("bt_gatt_set_characteristic_changed_cb", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service and callback parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_unset_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_unset_characteristic_changed_cb(NULL); + dts_check_eq("bt_gatt_unset_characteristic_changed_cb", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when service parameter is NULL."); +} + +/** + * @brief Negative test case of bt_gatt_get_characteristic_declaration() + */ +static void utc_network_bluetooth_gatt_get_characteristic_declaration_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_get_characteristic_declaration(NULL, NULL, NULL, 0); + dts_check_eq("bt_gatt_get_characteristic_declaration", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when characteristic parameter is NULL."); +} + +/** + * @brief Negative test case of bt_gatt_set_characteristic_value() + */ +static void utc_network_bluetooth_gatt_set_characteristic_value_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_characteristic_value(NULL, NULL, -1); + dts_check_eq("bt_socket_connect_rfcomm", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when characteristic and value parameters are NULL."); +} + +/** + * @brief Negative test case of bt_gatt_clone_attribute_handle() + */ +static void utc_network_bluetooth_gatt_clone_attribute_handle_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_clone_attribute_handle(NULL, NULL); + dts_check_eq("bt_gatt_clone_attribute_handle", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when origin parameter is NULL."); +} + +/** + * @brief Negative test case of bt_gatt_destroy_attribute_handle() + */ +static void utc_network_bluetooth_gatt_destroy_attribute_handle_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_destroy_attribute_handle(NULL); + dts_check_eq("bt_gatt_destroy_attribute_handle", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when handle parameter is NULL."); +} diff --git a/TC/testcase/utc_network_bluetooth_gatt_positive.c b/TC/testcase/utc_network_bluetooth_gatt_positive.c new file mode 100644 index 0000000..5df118c --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_gatt_positive.c @@ -0,0 +1,282 @@ +/* + * utc_network_bluetooth_gatt_positive.c + * + * Created on: 23-Sep-2013 + * Author: shagun.garg + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +const char target_name[128] = "dts_test"; +char target_address[18] = ""; + +static GMainLoop *mainloop; + +static void utc_network_bluetooth_gatt_foreach_primary_services_p(void); +static void utc_network_bluetooth_gatt_discover_characteristics_p(void); + +static void utc_network_bluetooth_gatt_get_service_uuid_p(void); +static void utc_network_bluetooth_gatt_foreach_included_services_p(void); +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_p(void); +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_p(void); +static void utc_network_bluetooth_gatt_get_characteristic_declaration_p(void); +static void utc_network_bluetooth_gatt_set_characteristic_value_p(void); +static void utc_network_bluetooth_gatt_clone_attribute_handle_p(void); +static void utc_network_bluetooth_gatt_destroy_attribute_handle_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_gatt_p(int result, bt_adapter_state_e adapter_state, void *user_data); + +bool primary_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data); +bool included_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data); +bool characteristics_discovered_cb_for_gatt_p(int result, int index, int total, bt_gatt_attribute_h characteristic, + void *user_data); +void characteristics_changed_cb_for_gatt_p(bt_gatt_attribute_h characteristic, unsigned char *value, int value_length, + void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_gatt_foreach_primary_services_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_discover_characteristics_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_service_uuid_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_foreach_included_services_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_unset_characteristic_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_get_characteristic_declaration_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_set_characteristic_value_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_clone_attribute_handle_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_destroy_attribute_handle_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + tet_printf("TC start."); + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_gatt_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_gatt_p(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +bool primary_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data) +{ + return false; +} + +bool characteristics_discovered_cb_for_gatt_p(int result, int index, int total, bt_gatt_attribute_h characteristic, + void *user_data) +{ + return false; +} + +bool included_service_cb_for_gatt_p(bt_gatt_attribute_h service, void *user_data) +{ + return false; +} + +void characteristics_changed_cb_for_gatt_p(bt_gatt_attribute_h characteristic, unsigned char *value, int value_length, + void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_gatt_foreach_primary_services() + */ +static void utc_network_bluetooth_gatt_foreach_primary_services_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_addr = "dts_addr"; + + ret = bt_gatt_foreach_primary_services(remote_addr, primary_service_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_foreach_primary_services", ret, BT_ERROR_NONE, "bt_gatt_foreach_primary_services() failed."); +} + +/** + * @brief Positive test case of bt_gatt_discover_characteristics() + */ +static void utc_network_bluetooth_gatt_discover_characteristics_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_call_list_h)); + + ret = bt_gatt_discover_characteristics(gatt_serv, characteristics_discovered_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_discover_characteristics", ret, BT_ERROR_NONE, "bt_gatt_discover_characteristics() failed."); +} + +/** + * @brief Positive test case of bt_gatt_get_service_uuid() + */ +static void utc_network_bluetooth_gatt_get_service_uuid_p(void) +{ + int ret = BT_ERROR_NONE; + char *uid = "dts_uid"; + bt_call_list_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_call_list_h)); + + ret = bt_gatt_get_service_uuid(gatt_serv, &uid); + dts_check_eq("bt_gatt_get_service_uuid", ret, BT_ERROR_NONE, "bt_gatt_get_service_uuid() failed."); +} + +/** + * @brief Positive test case of bt_gatt_foreach_included_services() + */ +static void utc_network_bluetooth_gatt_foreach_included_services_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_call_list_h)); + ret = bt_gatt_foreach_included_services(gatt_serv, included_service_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_foreach_included_services", ret, BT_ERROR_NONE, "bt_gatt_foreach_included_services() failed."); +} + +/** + * @brief Positive test case of bt_gatt_set_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_set_characteristic_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_call_list_h)); + ret = bt_gatt_set_characteristic_changed_cb(gatt_serv, characteristics_changed_cb_for_gatt_p, NULL); + dts_check_eq("bt_gatt_set_characteristic_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_set_characteristic_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_gatt_unset_characteristic_changed_cb() + */ +static void utc_network_bluetooth_gatt_unset_characteristic_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_call_list_h)); + ret = bt_gatt_unset_characteristic_changed_cb(gatt_serv); + dts_check_eq("bt_gatt_unset_characteristic_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_unset_characteristic_changed_cb() failed."); + +} + +/** + * @brief Positive test case of bt_gatt_get_characteristic_declaration() + */ +static void utc_network_bluetooth_gatt_get_characteristic_declaration_p(void) +{ + int ret = BT_ERROR_NONE; + char **uid = "dts_uid"; + unsigned char **val = "dts_value"; + int l = 1; + bt_call_list_h gatt_charac; + gatt_charac = g_malloc0(sizeof(bt_call_list_h)); + ret = bt_gatt_get_characteristic_declaration(gatt_charac, uid, val, &l); + dts_check_eq("bt_gatt_get_characteristic_declaration", ret, BT_ERROR_NONE, + "gatt_get_characteristic_declaration() failed."); +} + +/** + * @brief Positive test case of bt_gatt_set_characteristic_value() + */ +static void utc_network_bluetooth_gatt_set_characteristic_value_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h gatt_charac; + gatt_charac = g_malloc0(sizeof(bt_call_list_h)); + const unsigned char *gatt_value = "dts_value"; + ret = bt_gatt_set_characteristic_value(gatt_charac, gatt_value, strlen("dts_value")); + dts_check_eq("bt_gatt_set_characteristic_value", ret, BT_ERROR_NONE, "bt_gatt_set_characteristic_value() failed."); +} + +/** + * @brief Positive test case of bt_gatt_clone_attribute_handle() + */ +static void utc_network_bluetooth_gatt_clone_attribute_handle_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h gatt_origin; + gatt_origin = g_malloc0(sizeof(bt_call_list_h)); + + ret = bt_gatt_clone_attribute_handle(NULL, gatt_origin); + dts_check_eq("bt_gatt_clone_attribute_handle", ret, BT_ERROR_NONE, "bt_gatt_clone_attribute_handle() failed."); +} + +/** + * @brief Positive test case of bt_gatt_destroy_attribute_handle() + */ +static void utc_network_bluetooth_gatt_destroy_attribute_handle_p(void) +{ + int ret = BT_ERROR_NONE; + bt_call_list_h gatt_handle; + gatt_handle = g_malloc0(sizeof(bt_call_list_h)); + + ret = bt_gatt_destroy_attribute_handle(gatt_handle); + dts_check_eq("bt_gatt_destroy_attribute_handle", ret, BT_ERROR_NONE, "bt_gatt_destroy_attribute_handle() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_hdp_negative.c b/TC/testcase/utc_network_bluetooth_hdp_negative.c new file mode 100644 index 0000000..4313d0b --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hdp_negative.c @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_hdp_register_sink_app_n(void); +static void utc_network_bluetooth_hdp_unregister_sink_app_n(void); +static void utc_network_bluetooth_hdp_connect_to_source_n(void); +static void utc_network_bluetooth_hdp_disconnect_n(void); +static void utc_network_bluetooth_hdp_send_data_n(void); +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_hdp_unset_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_hdp_set_data_received_cb_n(void); +static void utc_network_bluetooth_hdp_unset_data_received_cb_n(void); + +void adapter_state_changed_cb_for_hdp_n(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_hdp_register_sink_app_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unregister_sink_app_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_connect_to_source_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_disconnect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_send_data_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_set_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_set_data_received_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_data_received_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hdp_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_hdp_n(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_hdp_set_data_received_cb() + */ +static void utc_network_bluetooth_hdp_set_data_received_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_data_received_cb(NULL, NULL); + dts_check_eq("bt_hdp_set_data_received_cb", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_hdp_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_connection_state_changed_cb(NULL, NULL, NULL); + dts_check_eq("bt_hdp_set_connection_state_changed_cb", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameters are NULL"); +} + +/** + * @brief Negative test case of bt_hdp_unset_data_received_cb() + */ +static void utc_network_bluetooth_hdp_unset_data_received_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unset_data_received_cb(); + dts_check_eq("bt_hdp_unset_data_received_cb", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_hdp_unset_connection_state_changed_cb() + */ +static void utc_network_bluetooth_hdp_unset_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unset_connection_state_changed_cb(); + dts_check_eq("bt_hdp_unset_connection_state_changed_cb", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_hdp_disconnect() + */ +static void utc_network_bluetooth_hdp_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_disconnect(NULL, 1); + dts_check_eq("bt_hdp_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address parameter is NULL"); +} + +/** + * @brief Negative test case of bt_hdp_connect_to_source() + */ +static void utc_network_bluetooth_hdp_connect_to_source_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_connect_to_source(NULL, NULL); + dts_check_eq("bt_hdp_connect_to_source", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address and app_id parameter are NULL"); +} + +/** + * @brief Negative test case of bt_hdp_register_sink_app() + */ +static void utc_network_bluetooth_hdp_register_sink_app_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_register_sink_app(1, NULL); + dts_check_eq("bt_hdp_register_sink_app", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when app_id parameter is NULL"); +} + +/** + * @brief Negative test case of bt_hdp_unregister_sink_appe() + */ +static void utc_network_bluetooth_hdp_unregister_sink_app_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unregister_sink_app(NULL); + dts_check_eq("bt_shdp_unregister_sink", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when app_id parameter is NULL"); +} + +/** + * @brief Negative test case of bt_hdp_send_data() + */ +static void utc_network_bluetooth_hdp_send_data_n(void) +{ + int ret = BT_ERROR_NONE; + char *data = "dts_test"; + + ret = bt_hdp_send_data(1, data, sizeof(data)); + dts_check_eq("bt_hdp_send_data", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_hdp_positive.c b/TC/testcase/utc_network_bluetooth_hdp_positive.c new file mode 100644 index 0000000..aa0eaa9 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hdp_positive.c @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_hdp_register_sink_app_p(void); +static void utc_network_bluetooth_hdp_unregister_sink_app_p(void); +static void utc_network_bluetooth_hdp_connect_to_source_p(void); +static void utc_network_bluetooth_hdp_disconnect_p(void); +static void utc_network_bluetooth_hdp_send_data_p(void); +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_p(void); +static void utc_network_bluetooth_hdp_unset_connection_state_changed_cb_p(void); +static void utc_network_bluetooth_hdp_set_data_received_cb_p(void); +static void utc_network_bluetooth_hdp_unset_data_received_cb_p(void); + +void data_received_cb_for_hdp_p(unsigned int channel, const char *data, unsigned int size, void *user_data); +void connected_cb_for_hdp_p(int result, const char *remote_address, const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *user_data); +void disconnected_cb_for_hdp_p(int result, const char *remote_address, unsigned int channel, void *user_data); + +void adapter_state_changed_cb_for_hdp_p(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_hdp_register_sink_app_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unregister_sink_app_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_connect_to_source_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_send_data_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_set_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_set_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_data_received_cb_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hdp_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_hdp_p(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void data_received_cb_for_hdp_p(unsigned int channel, const char *data, unsigned int size, void *user_data) +{ + +} + +void connected_cb_for_hdp_p(int result, const char *remote_address, const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *user_data) +{ + +} + +void disconnected_cb_for_hdp_p(int result, const char *remote_address, unsigned int channel, void *user_data) +{ + +} + +static void utc_network_bluetooth_hdp_set_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_data_received_cb(data_received_cb_for_hdp_p, NULL); + dts_check_eq("bt_hdp_set_data_received_cb", ret, BT_ERROR_NONE, "bt_hdp_set_data_received_cb() failed."); +} + +static void utc_network_bluetooth_hdp_unset_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unset_data_received_cb(); + dts_check_eq("bt_hdp_unset_data_received_cb", ret, BT_ERROR_NONE, "bt_hdp_unset_data_received_cb() failed."); +} + +static void utc_network_bluetooth_hdp_set_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_set_connection_state_changed_cb(connected_cb_for_hdp_p, disconnected_cb_for_hdp_p, NULL); + dts_check_eq("bt_hdp_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_hdp_set_connection_state_changed_cb() failed."); +} + +static void utc_network_bluetooth_hdp_unset_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hdp_unset_connection_state_changed_cb(); + dts_check_eq("bt_hdp_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_hdp_unset_connection_state_changed_cb() failed."); +} + +static void utc_network_bluetooth_hdp_send_data_p(void) +{ + int ret = BT_ERROR_NONE; + char *dts_test = "dts_test"; + + ret = bt_hdp_send_data(1, "dts_test", sizeof(dts_test)); + dts_check_eq("bt_hdp_send_data", ret, BT_ERROR_NONE, "bt_hdp_send_data() failed."); +} + +static void utc_network_bluetooth_hdp_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_adr = ""; + + ret = bt_hdp_disconnect(remote_adr, 1); + dts_check_eq("bt_hdp_disconnect", ret, BT_ERROR_NONE, "bt_hdp_disconnect() failed."); +} + +static void utc_network_bluetooth_hdp_connect_to_source_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_adr = "dts_remote"; + char *appid = "dts_id"; + + ret = bt_hdp_connect_to_source(remote_adr, appid); + dts_check_eq("bt_hdp_connect_to_source", ret, BT_ERROR_NONE, "bt_hdp_connect_to_source() failed."); + +} + +static void utc_network_bluetooth_hdp_unregister_sink_app_p(void) +{ + int ret = BT_ERROR_NONE; + char *appid = "dts_id"; + + ret = bt_hdp_unregister_sink_app(appid); + dts_check_eq("bt_hdp_unregister_sink_app", ret, BT_ERROR_NONE, "bt_hdp_unregister_sink_app() failed."); + +} + +static void utc_network_bluetooth_hdp_register_sink_app_p(void) +{ + int ret = BT_ERROR_NONE; + char *appid = "dts_id"; + + ret = bt_hdp_register_sink_app(1, &appid); + dts_check_eq("bt_hdp_register_sink_app", ret, BT_ERROR_NONE, "bt_hdp_register_sink_app() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_hid_negative.c b/TC/testcase/utc_network_bluetooth_hid_negative.c new file mode 100644 index 0000000..6b99d66 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hid_negative.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_hid_host_initialize_n(void); +static void utc_network_bluetooth_hid_host_deinitialize_n(void); +static void utc_network_bluetooth_hid_host_connect_n(void); +static void utc_network_bluetooth_hid_host_disconnect_n(void); + +void adapter_state_changed_cb_for_hid_n(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_hid_host_initialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_deinitialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_disconnect_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hid_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_hid_n(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +static void utc_network_bluetooth_hid_host_initialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_initialize(NULL, NULL); + dts_check_eq("bt_socket_set_data_received_cb", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL."); +} + +static void utc_network_bluetooth_hid_host_deinitialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_deinitialize(); + dts_check_eq("bt_hid_host_deinitialize", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned."); +} + +static void utc_network_bluetooth_hid_host_connect_n(void) +{ + int ret = BT_ERROR_NONE; + //char* remote_addr="dts_addr"; + + ret = bt_hid_host_connect(NULL); + dts_check_eq("bt_hid_host_connect", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address parameter is NULL."); +} + +static void utc_network_bluetooth_hid_host_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_disconnect(NULL); + dts_check_eq("bt_hid_host_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when remote address parameter is NULL."); +} diff --git a/TC/testcase/utc_network_bluetooth_hid_positive.c b/TC/testcase/utc_network_bluetooth_hid_positive.c new file mode 100644 index 0000000..a06a164 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hid_positive.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_hid_host_initialize_p(void); +static void utc_network_bluetooth_hid_host_deinitialize_p(void); +static void utc_network_bluetooth_hid_host_connect_p(void); +static void utc_network_bluetooth_hid_host_disconnect_p(void); + +void adapter_state_changed_cb_for_hid_p(int result, bt_adapter_state_e adapter_state, void *user_data); +void host_connection_state_changed_cb_for_hid_p(int result, bool connected, const char *remote_address, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_hid_host_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_deinitialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_disconnect_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_hid_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_hid_p(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void host_connection_state_changed_cb_for_hid_p(int result, bool connected, const char *remote_address, void *user_data) +{ + +} + +static void utc_network_bluetooth_hid_host_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_initialize(host_connection_state_changed_cb_for_hid_p, NULL); + dts_check_eq("bt_hid_host_initialize", ret, BT_ERROR_NONE, "bt_hid_host_initialize() failed."); +} + +static void utc_network_bluetooth_hid_host_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_deinitialize(); + dts_check_eq("bt_hid_host_deinitialize", ret, BT_ERROR_NONE, "bt_hid_host_deinitialize() failed."); +} + +static void utc_network_bluetooth_hid_host_connect_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_addr = "dts_addr"; + + ret = bt_hid_host_connect(remote_addr); + dts_check_eq("bt_hid_host_connect", ret, BT_ERROR_NONE, "bt_hid_host_connect() failed."); +} + +static void utc_network_bluetooth_hid_host_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + char *remote_addr = "dts_addr"; + + ret = bt_hid_host_disconnect(remote_addr); + dts_check_eq("bt_hid_host_disconnect", ret, BT_ERROR_NONE, "bt_hid_host_disconnect() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_opp-client_negative.c b/TC/testcase/utc_network_bluetooth_opp-client_negative.c new file mode 100644 index 0000000..67299e9 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-client_negative.c @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_opp_client_initialize_n(void); +static void utc_network_bluetooth_opp_client_deinitialize_n(void); +static void utc_network_bluetooth_opp_client_add_file_n(void); +static void utc_network_bluetooth_opp_client_clear_files_n(void); +static void utc_network_bluetooth_opp_client_push_files_n(void); +static void utc_network_bluetooth_opp_client_cancel_push_n(void); + +void adapter_state_changed_cb_for_opp_client_n(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_client_initialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_deinitialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_add_file_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_clear_files_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_push_files_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_cancel_push_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_client_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_opp_client_n(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +static void utc_network_bluetooth_opp_client_initialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_initialize(); + dts_check_eq("bt_opp_client_initialize", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); +} + +static void utc_network_bluetooth_opp_client_deinitialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_deinitialize(); + dts_check_eq("bt_opp_client_deinitialize", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); + +} + +static void utc_network_bluetooth_opp_client_add_file_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_add_file(NULL); + dts_check_eq("bt_opp_client_add_file", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when file parameter is NULL"); +} + +static void utc_network_bluetooth_opp_client_clear_files_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_clear_files(); + dts_check_eq("bt_opp_client_clear_files", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); + +} + +static void utc_network_bluetooth_opp_client_push_files_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_push_files(NULL, NULL, NULL, NULL, NULL); + dts_check_eq("bt_opp_client_push_files", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameters are NULL"); +} + +static void utc_network_bluetooth_opp_client_cancel_push_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_cancel_push(); + dts_check_eq("bt_opp_client_cancel_push", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); +} diff --git a/TC/testcase/utc_network_bluetooth_opp-client_positive.c b/TC/testcase/utc_network_bluetooth_opp-client_positive.c new file mode 100644 index 0000000..341243d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-client_positive.c @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_opp_client_initialize_p(void); +static void utc_network_bluetooth_opp_client_deinitialize_p(void); +static void utc_network_bluetooth_opp_client_add_file_p(void); +static void utc_network_bluetooth_opp_client_clear_files_p(void); +static void utc_network_bluetooth_opp_client_push_files_p(void); +static void utc_network_bluetooth_opp_client_cancel_push_p(void); + +void push_responded_cb_for_opp_client_p(int result, const char *remote_address, void *user_data); +void push_progress_cb_for_opp_client_p(const char *file, long long size, int percent, void *user_data); +void push_finished_cb_for_opp_client_p(int result, const char *remote_address, void *user_data); +void adapter_state_changed_cb_for_opp_client_p(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_client_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_deinitialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_add_file_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_clear_files_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_push_files_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_cancel_push_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_client_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_opp_client_p(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void push_responded_cb_for_opp_client_p(int result, const char *remote_address, void *user_data) +{ + +} + +void push_progress_cb_for_opp_client_p(const char *file, long long size, int percent, void *user_data) +{ + +} + +void push_finished_cb_for_opp_client_p(int result, const char *remote_address, void *user_data) +{ + +} + +static void utc_network_bluetooth_opp_client_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_initialize(); + dts_check_eq("bt_opp_client_initialize", ret, BT_ERROR_NONE, "bt_opp_client_initialize() failed."); +} + +static void utc_network_bluetooth_opp_client_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_deinitialize(); + dts_check_eq("bt_opp_client_deinitialize", ret, BT_ERROR_NONE, "bt_opp_client_deinitialize() failed."); + +} + +static void utc_network_bluetooth_opp_client_add_file_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_add_file("dts_file"); + dts_check_eq("bt_opp_client_add_file", ret, BT_ERROR_NONE, "bt_opp_client_add_file() failed"); +} + +static void utc_network_bluetooth_opp_client_clear_files_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_clear_files(); + dts_check_eq("bt_opp_client_clear_files", ret, BT_ERROR_NONE, "bt_opp_client_clear_files() failed."); + +} + +static void utc_network_bluetooth_opp_client_push_files_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = + bt_opp_client_push_files(NULL, push_responded_cb_for_opp_client_p, push_progress_cb_for_opp_client_p, + push_finished_cb_for_opp_client_p, NULL); + if (ret == BT_ERROR_NONE) { + dts_pass("bt_opp_client_push_files", "bt_opp_client_push_files pass"); + } else { + dts_fail("bt_opp_client_push_files", "bt_opp_client_push_files() failed"); + } +} + +static void utc_network_bluetooth_opp_client_cancel_push_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_client_cancel_push(); + dts_check_eq("bt_opp_client_cancel_push", ret, BT_ERROR_NONE, "bt_opp_client_cancel_push() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_opp-server_negative.c b/TC/testcase/utc_network_bluetooth_opp-server_negative.c new file mode 100644 index 0000000..d44db06 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-server_negative.c @@ -0,0 +1,174 @@ +/* + * + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_opp_server_initialize_n(void); +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_n(void); +static void utc_network_bluetooth_opp_server_deinitialize_n(void); +static void utc_network_bluetooth_opp_server_accept_n(void); +static void utc_network_bluetooth_opp_server_reject_n(void); +static void utc_network_bluetooth_opp_server_set_destination_n(void); + +void adapter_state_changed_cb_for_opp_server_n(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_server_initialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_initialize_by_connection_request_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_deinitialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_accept_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_reject_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_set_destination_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_server_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_opp_server_n(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if ((user_data != NULL) && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +static void utc_network_bluetooth_opp_server_initialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize(NULL, NULL, NULL); + dts_check_eq("bt_opp_server_initializa", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when destination parameter is NULL"); +} + +static void utc_network_bluetooth_opp_server_deinitialize_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_deinitialize(); + dts_check_eq("bt_opp_server_deinitialize", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); +} + +static void utc_network_bluetooth_opp_server_accept_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_opp_server_accept(NULL, NULL, NULL, NULL, NULL); + dts_check_eq("bt_opp_server_accept", ret, BT_ERROR_NOT_INITIALIZED, "BT_ERROR_NOT_INITIALIZED must be returned."); + +} + +static void utc_network_bluetooth_opp_server_reject_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_reject(); + dts_check_eq("bt_opp_server_reject", ret, BT_ERROR_NOT_INITIALIZED, "BT_ERROR_NOT_INITIALIZED must be returned."); +} + +static void utc_network_bluetooth_opp_server_set_destination_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_set_destination(NULL); + dts_check_eq("bt_opp_server_set_destination", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned destination parameter is NULL"); +} + +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize_by_connection_request(NULL, NULL, NULL); + dts_check_eq("bt_opp_server_initialize_by_connection_request", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned destination parameter is NULL"); + +} diff --git a/TC/testcase/utc_network_bluetooth_opp-server_positive.c b/TC/testcase/utc_network_bluetooth_opp-server_positive.c new file mode 100644 index 0000000..fa93272 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-server_positive.c @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +char dest[18] = ""; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_opp_server_initialize_p(void); +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_p(void); +static void utc_network_bluetooth_opp_server_deinitialize_p(void); +static void utc_network_bluetooth_opp_server_accept_p(void); +static void utc_network_bluetooth_opp_server_reject_p(void); +static void utc_network_bluetooth_opp_server_set_destination_p(void); + +void push_requested_cb_for_opp_server_p(const char *file, int size, void *user_data); +void connection_requested_cb_for_opp_server_p(const char *remote_address, void *user_data); +void adapter_state_changed_cb_for_opp_server_p(int result, bt_adapter_state_e adapter_state, void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_opp_server_initialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_initialize_by_connection_request_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_deinitialize_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_accept_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_reject_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_set_destination_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_opp_server_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +void adapter_state_changed_cb_for_opp_server_p(int result, bt_adapter_state_e adapter_state, void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void push_requested_cb_for_opp_server_p(const char *file, int size, void *user_data) +{ + +} + +void connection_requested_cb_for_opp_server_p(const char *remote_address, void *user_data) +{ + +} + +static void utc_network_bluetooth_opp_server_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize(dest, push_requested_cb_for_opp_server_p, NULL); + dts_check_eq("bt_opp_server_initialize", ret, BT_ERROR_NONE, "bt_opp_server_initialize() failed"); + +} + +static void utc_network_bluetooth_opp_server_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_deinitialize(); + dts_check_eq("bt_opp_server_deinitialize", ret, BT_ERROR_NONE, "bt_opp_server_deinitialize() failed."); +} + +static void utc_network_bluetooth_opp_server_accept_p(void) +{ + int ret = BT_ERROR_NONE; + int tid = 1; + ret = bt_opp_server_accept(NULL, NULL, "dts_name", NULL, &tid); + dts_check_eq("bt_opp_server_accept", ret, BT_ERROR_NONE, "bt_opp_server_accept() failed."); + +} + +static void utc_network_bluetooth_opp_server_reject_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_reject(); + dts_check_eq("bt_opp_server_reject", ret, BT_ERROR_NONE, "bt_opp_server_reject() failed."); +} + +static void utc_network_bluetooth_opp_server_set_destination_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_set_destination(dest); + dts_check_eq("bt_opp_server_set_destination", ret, BT_ERROR_NONE, "bt_opp_server_destination() failed"); +} + +static void utc_network_bluetooth_opp_server_initialize_by_connection_request_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_opp_server_initialize_by_connection_request(dest, connection_requested_cb_for_opp_server_p, NULL); + dts_check_eq("bt_opp_server_initialize_by_connection_request", ret, BT_ERROR_NONE, + "bt_opp_server_initialize_by_connection_request() failed"); + +} diff --git a/TC/testcase/utc_network_bluetooth_pan_negative.c b/TC/testcase/utc_network_bluetooth_pan_negative.c new file mode 100644 index 0000000..a5a0712 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_pan_negative.c @@ -0,0 +1,148 @@ +/* + * utc_network_bluetooth_pan_negative.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include <tet_api.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_nap_set_connection_state_changed_n(void); +static void utc_network_bluetooth_panu_set_connection_state_changed_n(void); +static void utc_network_bluetooth_panu_connect_n(void); +static void utc_network_bluetooth_panu_disconnect_n(void); + +void adapter_state_changed_cb_for_pan_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_nap_set_connection_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_panu_set_connection_state_changed_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_panu_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_panu_disconnect_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_pan_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Negative test case of bt_nap_set_connection_state_changed_cb() + */ + +void adapter_state_changed_cb_for_pan_n(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +static void utc_network_bluetooth_nap_set_connection_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_nap_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_nap_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_nap_set_connection_state_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_panu_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_panu_set_connection_state_changed_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_panu_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_panu_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "bt_panu_set_connection_state_changed_cb() failed."); + +} + +/** + * @brief Negative test case of bt_panu_connect() + */ +static void utc_network_bluetooth_panu_connect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_panu_connect(NULL, BT_PANU_SERVICE_TYPE_NAP); + dts_check_eq("bt_panu_connect", ret, BT_ERROR_INVALID_PARAMETER, + "bt_panu_connect() failed."); + +} + +/** + * @brief Negative test case of bt_panu_disconnect() + */ +static void utc_network_bluetooth_panu_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_panu_disconnect(NULL); + dts_check_eq("bt_panu_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "bt_panu_disconnect() failed."); + +} diff --git a/TC/testcase/utc_network_bluetooth_pan_positive.c b/TC/testcase/utc_network_bluetooth_pan_positive.c new file mode 100644 index 0000000..28d5632 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_pan_positive.c @@ -0,0 +1,237 @@ +/* + * utc_network_bluetooth_pan_positive.c + * + * Created on: 20-Sep-2013 + * Author: mrinal.m + */ + +#include "bluetooth.h" +#include <tet_api.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_nap_activate_p(void); +static void utc_network_bluetooth_nap_deactivate_p(void); +static void utc_network_bluetooth_nap_disconnect_all_p(void); +static void utc_network_bluetooth_nap_set_connection_state_changed_p(void); +static void utc_network_bluetooth_nap_unset_connection_state_changed_p(void); +static void utc_network_bluetooth_panu_set_connection_state_changed_p(void); +static void utc_network_bluetooth_panu_unset_connection_state_changed_p(void); +static void utc_network_bluetooth_panu_connect_p(void); +static void utc_network_bluetooth_panu_disconnect_p(void); + +void connection_state_changed_cb_for_nap_p(bool connected, + const char *remote_address, + const char *interface_name, + void *user_data); +void connection_state_changed_cb_for_panu_p(int result, + bool connected, + const char *remote_address, + bt_panu_service_type_e type, + void *user_data); + +void adapter_state_changed_cb_for_pan_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_nap_activate_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_set_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_unset_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_deactivate_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_nap_disconnect_all_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_set_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_unset_connection_state_changed_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_panu_disconnect_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_pan_p, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_enable() was called."); + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret != BT_ERROR_ALREADY_DONE) { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions +*/ + +void adapter_state_changed_cb_for_pan_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + +} + +void connection_state_changed_cb_for_nap_p(bool connected, + const char *remote_address, + const char *interface_name, + void *user_data) +{ + +} + +void connection_state_changed_cb_for_panu_p(int result, + bool connected, + const char *remote_address, + bt_panu_service_type_e type, + void *user_data) +{ + +} + +/** + * @brief Positive test case of bt_nap_activate() +*/ +static void utc_network_bluetooth_nap_activate_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_activate(); + if (ret != BT_ERROR_ALREADY_DONE) { + dts_check_eq("bt_nap_activate", ret, BT_ERROR_NONE, "bt_nap_activate() failed."); + } else { + dts_check_eq("bt_nap_activate", ret, BT_ERROR_ALREADY_DONE, + "bt_nap_activate() failed."); + } +} + +/** + * @brief Positive test case of bt_nap_deactivate() +*/ +static void utc_network_bluetooth_nap_deactivate_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_deactivate(); + dts_check_eq("bt_nap_deactivate", ret, BT_ERROR_NONE, "bt_nap_deactivate() failed."); +} + +/** + * @brief Positive test case of bt_nap_disconnect_all() + */ +static void utc_network_bluetooth_nap_disconnect_all_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_disconnect_all(); + dts_check_eq("bt_nap_disconnect_all", ret, BT_ERROR_NONE, + "bt_nap_disconnect_all() failed."); +} + +/** + * @brief Positive test case of bt_nap_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_nap_set_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_set_connection_state_changed_cb(connection_state_changed_cb_for_nap_p, NULL); + dts_check_eq("bt_nap_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_nap_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_nap_unset_connection_state_changed_cb() +*/ +static void utc_network_bluetooth_nap_unset_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_unset_connection_state_changed_cb(); + dts_check_eq("bt_nap_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_nap_unset_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_panu_set_connection_state_changed_cb() +*/ +static void utc_network_bluetooth_panu_set_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_panu_set_connection_state_changed_cb(connection_state_changed_cb_for_panu_p, NULL); + dts_check_eq("bt_panu_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_panu_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_panu_unset_connection_state_changed_cb() +*/ +static void utc_network_bluetooth_panu_unset_connection_state_changed_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_panu_unset_connection_state_changed_cb(); + dts_check_eq("bt_panu_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_panu_unset_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_panu_connect() +*/ +static void utc_network_bluetooth_panu_connect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:00:00:00:00:00"; + ret = bt_panu_connect(remote_address, BT_PANU_SERVICE_TYPE_NAP); + dts_check_eq("bt_panu_connect", ret, BT_ERROR_NONE, "bt_panu_connect() failed."); +} + +/** + * @brief Positive test case of bt_panu_disconnect() +*/ +static void utc_network_bluetooth_panu_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:00:00:00:00:00"; + ret = bt_panu_disconnect(remote_address); + dts_check_eq("bt_panu_disconnect", ret, BT_ERROR_NONE, "bt_panu_disconnect() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_service_search_negative.c b/TC/testcase/utc_network_bluetooth_service_search_negative.c new file mode 100644 index 0000000..1e83157 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_service_search_negative.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_service_search_set_cb_n(void); +static void utc_network_bluetooth_service_search_unset_cb_n(void); +static void utc_network_bluetooth_service_search_n(void); +static void utc_network_bluetooth_service_search_cancel_n(void); + +void adapter_state_changed_cb_for_service_search_n(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_service_search_set_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_service_search_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_service_search_cancel_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_service_search_unset_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_service_search_n, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_service_search_n(int result, + bt_adapter_state_e + adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_device_set_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_set_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_set_service_searched_cb(NULL, NULL); + dts_check_eq("bt_device_set_service_searched_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_unset_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_unset_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (bt_deinitialize() != BT_ERROR_NONE) { + dts_fail("bt_device_unset_service_searched_cb", + "bt_deinitialize() failed."); + } + + ret = bt_device_unset_service_searched_cb(); + dts_check_eq("bt_device_unset_service_searched_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_device_start_service_search() + */ +static void utc_network_bluetooth_service_search_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_start_service_search(NULL); + dts_check_eq("bt_device_start_service_search", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL"); +} + +/** + * @brief Negative test case of bt_device_cancel_service_search() + */ +static void utc_network_bluetooth_service_search_cancel_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_cancel_service_search(); + dts_check_eq("bt_device_cancel_service_search", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_service_search_positive.c b/TC/testcase/utc_network_bluetooth_service_search_positive.c new file mode 100644 index 0000000..eab85ed --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_service_search_positive.c @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +char target_name[128] = "dts_test"; +char target_address[18] = ""; +bool callback_result = false; +bool discovery_result = false; +bool bonding_result = false; +static GMainLoop *mainloop; + +static void utc_network_bluetooth_service_search_set_cb_p(void); +static void utc_network_bluetooth_service_search_p(void); +static void utc_network_bluetooth_service_search_cancel_p(void); +static void utc_network_bluetooth_service_search_unset_cb_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_service_search_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void device_discovery_state_changed_cb_for_service_search_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data); +void service_searched_cb_for_service_search_p(int result, + bt_device_sdp_info_s *sdp_info, + void *user_data); +void device_bonded_cb_for_service_search_p(int result, + bt_device_info_s *device_info, + void *user_data); +void device_unbonded_cb(int result, char *remote_address, void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_service_search_set_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_service_search_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_service_search_cancel_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_service_search_unset_cb_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + callback_result = false; + discovery_result = false; + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_service_search_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_service_search_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_device_discovery_state_changed_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + + tet_printf("BT was enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_state_changed_cb() failed."); + } + + if (bt_adapter_unset_device_discovery_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + tet_printf("TC start."); +} + +static void cleanup(void) +{ + /* end of TC */ + int timeout_id = 0; + + /* Destroy a bond */ + bt_device_set_bond_destroyed_cb(device_unbonded_cb, NULL); + if (bt_device_destroy_bond(target_address) == BT_ERROR_NONE) { + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void device_unbonded_cb(int result, char *remote_address, void *user_data) +{ + tet_printf("Callback: bt_device_bond_destroyed_cb() was called."); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + +} + +void adapter_state_changed_cb_for_service_search_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +void device_discovery_state_changed_cb_for_service_search_p(int result, + bt_adapter_device_discovery_state_e + discovery_state, + bt_adapter_device_discovery_info_s + * discovery_info, + void *user_data) +{ + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished. DTS will be started."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were founded (%s)", + discovery_info->remote_name); + if (discovery_info->remote_name != NULL && !strcmp(discovery_info->remote_name, target_name)) { + discovery_result = true; + tet_printf("Callback: dts_test device was found."); + strncpy(target_address, discovery_info->remote_address, 18); + tet_printf("Callback: device address: %s", discovery_info->remote_address); + if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) { + tet_printf("Callback: Device discovery will be stopped"); + } + } + } + } +} + +void service_searched_cb_for_service_search_p(int result, + bt_device_sdp_info_s *sdp_info, + void *user_data) +{ + int i = 0; + + tet_printf("Callback: bt_device_service_searched_cb() was called."); + if (result == BT_ERROR_NONE) { + if (sdp_info != NULL && !strcmp(sdp_info->remote_address, target_address)) { + tet_printf("Callback: Service search succeeded."); + tet_printf("Callback: Service count : %d", sdp_info->service_count); + for (i = 0; i < sdp_info->service_count; i++) { + tet_printf("Callback: uuid[%d] - %s", i + 1, sdp_info->service_uuid[i]); + } + + callback_result = true; + } + } else if (result == BT_ERROR_CANCELLED) { + if (sdp_info != NULL && !strcmp(sdp_info->remote_address, target_address)) { + tet_printf("Callback: Calcellation of service search succeeded."); + callback_result = true; + } + } else { + tet_printf("Callback: Failed."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +void device_bonded_cb_for_service_search_p(int result, + bt_device_info_s *device_info, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (device_info->remote_address != NULL && !strcmp(device_info->remote_address, target_address)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Bonding succeeded"); + bonding_result = true; + } else { + tet_printf("Callback: Bonding failed"); + } + } + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +/** + * @brief Positive test case of bt_device_set_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_set_cb_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + ret = bt_device_set_service_searched_cb(service_searched_cb_for_service_search_p, NULL); + if (ret == BT_ERROR_NONE) { + if (bt_device_set_bond_created_cb(device_bonded_cb_for_service_search_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_device_set_bond_created_cb() failed."); + } + + if (discovery_result == true && bt_device_create_bond(target_address) == BT_ERROR_NONE) { + tet_printf("bt_device_create_bond() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_device_create_bond() failed."); + } + } + + dts_check_eq("bt_device_set_service_searched_cb", ret, BT_ERROR_NONE, + "bt_device_set_service_searched_cb() failed."); +} + +/** + * @brief Positive test case of bt_device_start_service_search() + */ +static void utc_network_bluetooth_service_search_p(void) +{ + int timeout_id = 0; + + if (discovery_result != true) { + dts_fail("bt_device_start_service_search", + "device discovery failed."); + } + + callback_result = false; + if (bt_device_start_service_search(target_address) == BT_ERROR_NONE) { + tet_printf("bt_device_start_service_search() succeeded."); + tet_printf("service_searched_cb_for_service_search_p() will be called."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_start_service_search", callback_result, + true, "Service search failed."); + } else { + dts_fail("bt_device_start_service_search", + "bt_device_start_service_search() failed."); + } +} + +/** + * @brief Positive test case of bt_device_cancel_service_search() + */ +static void utc_network_bluetooth_service_search_cancel_p(void) +{ + int timeout_id = 0; + + if (discovery_result != true) { + dts_fail("bt_device_cancel_service_search", + "device discovery failed."); + } + + callback_result = false; + if (bt_device_start_service_search(target_address) != BT_ERROR_NONE) { + dts_fail("bt_device_cancel_service_search", + "bt_device_start_service_search() failed."); + } else { + tet_printf("bt_device_cancel_service_search", + "bt_device_start_service_search() succeeded."); + } + + if (bt_device_cancel_service_search() == BT_ERROR_NONE) { + tet_printf("bt_device_cancel_service_search() succeeded."); + tet_printf("service_searched_cb_for_service_search_p() will be called."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + dts_check_eq("bt_device_cancel_service_search", callback_result, + true, "Cancellation of service search failed."); + } else { + dts_fail("bt_device_cancel_service_search", + "bt_device_cancel_service_search() failed."); + } +} + +/** + * @brief Positive test case of bt_device_unset_service_searched_cb() + */ +static void utc_network_bluetooth_service_search_unset_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_device_unset_service_searched_cb(); + dts_check_eq("bt_device_unset_service_searched_cb", ret, BT_ERROR_NONE, + "bt_device_set_service_searched_cb() failed."); +} diff --git a/TC/testcase/utc_network_bluetooth_socket_negative.c b/TC/testcase/utc_network_bluetooth_socket_negative.c new file mode 100644 index 0000000..9e3f490 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_socket_negative.c @@ -0,0 +1,266 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +static void utc_network_bluetooth_socket_set_data_received_cb_n(void); +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_socket_unset_data_received_cb_n(void); +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_socket_create_rfcomm_n(void); +static void utc_network_bluetooth_socket_destroy_rfcomm_n(void); +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_n(void); +static void utc_network_bluetooth_socket_connect_rfcomm_n(void); +static void utc_network_bluetooth_socket_disconnect_rfcomm_n(void); +static void utc_network_bluetooth_socket_send_data_n(void); + +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data); +gboolean timeout_func(gpointer data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_socket_set_data_received_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_create_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_destroy_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_listen_and_accept_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_connect_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_disconnect_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_send_data_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_data_received_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_device_negative, "startup") != BT_ERROR_NONE) { + tet_printf("DTS may fail because bt_adapter_set_state_changed_cb() failed"); + } + + tet_printf("bt_adapter_disable() was called."); + ret = bt_adapter_disable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_disable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not enabled."); + } else { + tet_printf("DTS may fail because bt_adapter_disable() failed"); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + tet_printf("TC start"); +} + +static void cleanup(void) +{ + /* end of TC */ + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("Callback: Timeout."); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void adapter_state_changed_cb_for_device_negative(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + tet_printf("Callback: bt_adapter_state_changed_cb was called."); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was disabled. DTS will be started."); + } else { + tet_printf("Callback: BT was not disabled. DTS will be started but DTS may fail."); + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } +} + +/** + * @brief Negative test case of bt_socket_set_data_received_cb() + */ +static void utc_network_bluetooth_socket_set_data_received_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_data_received_cb(NULL, NULL); + dts_check_eq("bt_socket_set_data_received_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_socket_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_socket_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL"); +} + +/** + * @brief Negative test case of bt_socket_unset_data_received_cb() + */ +static void utc_network_bluetooth_socket_unset_data_received_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (bt_deinitialize() != BT_ERROR_NONE) { + dts_fail("bt_socket_unset_data_received_cb", + "bt_deinitialize() failed."); + } + + ret = bt_socket_unset_data_received_cb(); + dts_check_eq("bt_socket_unset_data_received_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_socket_unset_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_unset_connection_state_changed_cb(); + dts_check_eq("bt_socket_unset_connection_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT service is not initialized."); +} + +/** + * @brief Negative test case of bt_socket_create_rfcomm() + */ +static void utc_network_bluetooth_socket_create_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_create_rfcomm(NULL, NULL); + dts_check_eq("bt_socket_create_rfcomm", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when port_uuid parameter is NULL"); +} + +/** + * @brief Negative test case of bt_socket_destroy_rfcomm() + */ +static void utc_network_bluetooth_socket_destroy_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_destroy_rfcomm(-1); + dts_check_eq("bt_socket_listen_and_accept_rfcomm", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when socket_fd is below 0"); +} + +/** + * @brief Negative test case of bt_socket_listen_and_accept_rfcomm() + */ +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_listen_and_accept_rfcomm(1, 1); + dts_check_eq("bt_socket_listen_and_accept_rfcomm", ret, + BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_socket_connect_rfcomm() + */ +static void utc_network_bluetooth_socket_connect_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + char *address = ""; + char *uuid = ""; + + ret = bt_socket_connect_rfcomm(address, uuid); + dts_check_eq("bt_socket_connect_rfcomm", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_socket_disconnect_rfcomm() + */ +static void utc_network_bluetooth_socket_disconnect_rfcomm_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_disconnect_rfcomm(-1); + dts_check_eq("bt_socket_disconnect_rfcomm", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} + +/** + * @brief Negative test case of bt_socket_send_data() + */ +static void utc_network_bluetooth_socket_send_data_n(void) +{ + int ret = BT_ERROR_NONE; + char *data = "dts_test"; + + ret = bt_socket_send_data(1, data, sizeof(data)); + dts_check_eq("bt_socket_send_data", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled"); +} diff --git a/TC/testcase/utc_network_bluetooth_socket_positive.c b/TC/testcase/utc_network_bluetooth_socket_positive.c new file mode 100644 index 0000000..5754b4f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_socket_positive.c @@ -0,0 +1,440 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); + +void (*tet_startup) (void) = startup; +void (*tet_cleanup) (void) = cleanup; + +const char target_name[128] = "dts_test"; +const char *rfcomm_test_uuid_spp = "00001101-0000-1000-8000-00805F9B34FB"; +char target_address[18] = ""; +int socket_fd = 0; +bool callback_result = false; +bool discovery_result = false; +bool bonding_result = false; +bool is_connecting = false; +static GMainLoop *mainloop; + +static void utc_network_bluetooth_socket_set_data_received_cb_p(void); +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_p(void); + +static void utc_network_bluetooth_socket_create_rfcomm_p(void); +static void utc_network_bluetooth_socket_destroy_rfcomm_p(void); +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_p(void); +static void utc_network_bluetooth_socket_connect_rfcomm_p(void); +static void utc_network_bluetooth_socket_disconnect_rfcomm_p(void); +static void utc_network_bluetooth_socket_send_data_p(void); +static void utc_network_bluetooth_socket_unset_data_received_cb_p(void); +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_p(void); + +gboolean timeout_func(gpointer data); +void adapter_state_changed_cb_for_socket_p(int result, + bt_adapter_state_e adapter_state, + void *user_data); +void device_discovery_state_changed_cb_for_socket_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data); +void device_bonded_cb_for_socket_p(int result, bt_device_info_s *device_info, + void *user_data); +void socket_data_received_cb_for_socket_p(bt_socket_received_data_s *data, + void *user_data); +void socket_connection_state_changed_cb_for_socket_p(int result, + bt_socket_connection_state_e connection_state, + bt_socket_connection_s *connection, + void *user_data); +void device_unbonded_cb(int result, char *remote_address, void *user_data); + +struct tet_testlist tet_testlist[] = { + {utc_network_bluetooth_socket_set_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_create_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_listen_and_accept_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_destroy_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_connect_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_send_data_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_disconnect_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_unset_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + /* start of TC */ + tet_printf("TC start."); + callback_result = false; + discovery_result = false; + bonding_result = false; + mainloop = g_main_loop_new(NULL, FALSE); + + bt_initialize(); + + if (bt_adapter_set_state_changed_cb(adapter_state_changed_cb_for_socket_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_state_changed_cb() failed."); + } + + if (bt_adapter_set_device_discovery_state_changed_cb(device_discovery_state_changed_cb_for_socket_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_adapter_set_device_discovery_state_changed_cb() failed."); + } + + if (bt_device_set_bond_created_cb(device_bonded_cb_for_socket_p, "startup") != BT_ERROR_NONE) { + tet_printf("bt_device_set_bond_created_cb() failed."); + } + + ret = bt_adapter_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + + tet_printf("BT was enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else if (ret == BT_ERROR_ALREADY_DONE) { + tet_printf("BT was already enabled. Device discovery will be started"); + if (bt_adapter_start_device_discovery() == BT_ERROR_NONE) { + tet_printf("bt_adapter_start_device_discovery() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_adapter_start_device_discovery() failed."); + } + } else { + tet_printf("DTS may fail because bt_adapter_enable() failed."); + } + + if (discovery_result == true && bt_device_create_bond(target_address) == BT_ERROR_NONE) { + tet_printf("bt_device_create_bond() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + tet_printf("bt_device_create_bond() failed."); + } + + if (bt_adapter_unset_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_state_changed_cb() failed."); + } + + if (bt_adapter_unset_device_discovery_state_changed_cb() != BT_ERROR_NONE) { + tet_printf("bt_adapter_unset_device_discovery_state_changed_cb() failed."); + } + + if (bt_device_unset_bond_created_cb() != BT_ERROR_NONE) { + tet_printf("bt_device_unset_bond_created_cb() failed."); + } + +} + +static void cleanup(void) +{ + /* end of TC */ + int timeout_id = 0; + + /* Destroy a bond */ + bt_device_set_bond_destroyed_cb(device_unbonded_cb, NULL); + if (bt_device_destroy_bond(target_address) == BT_ERROR_NONE) { + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + + bt_deinitialize(); + tet_printf("TC end."); +} + +gboolean timeout_func(gpointer data) +{ + tet_printf("[%s] Callback: Timeout.", __FUNCTION__); + g_main_loop_quit((GMainLoop *) data); + return FALSE; +} + +/** + * @brief Callback funtions + */ +void device_unbonded_cb(int result, char *remote_address, void *user_data) +{ + tet_printf("Callback: bt_device_bond_destroyed_cb() was called."); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + +} + +void adapter_state_changed_cb_for_socket_p(int result, + bt_adapter_state_e adapter_state, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (adapter_state == BT_ADAPTER_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT was enabled."); + bt_adapter_start_device_discovery(); + } else { + tet_printf("Callback: BT was not enabled. DTS will be started but DTS may fail."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +void device_discovery_state_changed_cb_for_socket_p(int result, + bt_adapter_device_discovery_state_e discovery_state, + bt_adapter_device_discovery_info_s *discovery_info, + void *user_data) +{ + tet_printf("Callback: bt_adapter_device_discovery_state_changed_cb() was called"); + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + tet_printf("Callback: Device discovery finished. DTS will be started."); + if (mainloop) { + g_main_loop_quit(mainloop); + } + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) { + tet_printf("Callback: Devices were founded (%s)", discovery_info->remote_name); + if (discovery_info->remote_name != NULL && !strcmp(discovery_info->remote_name, target_name)) { + discovery_result = true; + tet_printf("Callback: dts_test device was found."); + strncpy(target_address, discovery_info->remote_address, 18); + tet_printf("Callback: device address: %s", discovery_info->remote_address); + if (bt_adapter_stop_device_discovery() == BT_ERROR_NONE) { + tet_printf("Callback: Device discovery will be stopped"); + } + } + } + } +} + +void device_bonded_cb_for_socket_p(int result, bt_device_info_s *device_info, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "startup")) { + if (device_info->remote_address != NULL && !strcmp(device_info->remote_address, target_address)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Bonding succeeded"); + bonding_result = true; + } else { + tet_printf("Callback: Bonding failed"); + } + } + } + + if (mainloop) { + g_main_loop_quit(mainloop); + } +} + +void socket_data_received_cb_for_socket_p(bt_socket_received_data_s *data, + void *user_data) +{ +} + +void socket_connection_state_changed_cb_for_socket_p(int result, + bt_socket_connection_state_e connection_state, + bt_socket_connection_s *connection, + void *user_data) +{ + tet_printf("Callback: bt_socket_connection_state_changed_cb() was called"); + if (connection_state == BT_SOCKET_CONNECTED) + tet_printf("Callback: Connected"); + else + tet_printf("Callback: Disconnected"); + + if (connection_state == BT_SOCKET_CONNECTED) { + tet_printf("Callback: [BT_SOCKET_CONNECTED] result = %d", result); + if (result == BT_ERROR_NONE && is_connecting == true) { + callback_result = true; + socket_fd = connection->socket_fd; + tet_printf("Callback: socket_fd = %d", socket_fd); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } else if (connection_state == BT_SOCKET_DISCONNECTED) { + tet_printf("Callback: [BT_SOCKET_DISCONNECTED] result = %d", result); + if (result == BT_ERROR_NONE && is_connecting == false) { + callback_result = true; + socket_fd = connection->socket_fd; + tet_printf("Callback: socket_fd = %d", socket_fd); + + if (mainloop) { + g_main_loop_quit(mainloop); + } + } + } +} + +/** + * @brief Positive test case of bt_socket_set_data_received_cb() + */ +static void utc_network_bluetooth_socket_set_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_data_received_cb(socket_data_received_cb_for_socket_p, NULL); + dts_check_eq("bt_socket_set_data_received_cb", ret, BT_ERROR_NONE, + "bt_socket_set_data_received_cb() failed."); +} + +/** + * @brief Positive test case of bt_socket_set_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_set_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_set_connection_state_changed_cb(socket_connection_state_changed_cb_for_socket_p, NULL); + dts_check_eq("bt_socket_set_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_socket_set_connection_state_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_socket_create_rfcomm() + */ +static void utc_network_bluetooth_socket_create_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_create_rfcomm(rfcomm_test_uuid_spp, &socket_fd); + dts_check_eq("bt_socket_create_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_create_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_listen_and_accept_rfcomm() + */ +static void utc_network_bluetooth_socket_listen_and_accept_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_listen_and_accept_rfcomm(socket_fd, 1); + dts_check_eq("bt_socket_listen_and_accept_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_listen_and_accept_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_destroy_rfcomm() + */ +static void utc_network_bluetooth_socket_destroy_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_destroy_rfcomm(socket_fd); + dts_check_eq("bt_socket_destroy_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_destroy_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_connect_rfcomm() + */ +static void utc_network_bluetooth_socket_connect_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + is_connecting = true; + callback_result = false; + ret = bt_socket_connect_rfcomm(target_address, rfcomm_test_uuid_spp); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_socket_connect_rfcomm() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } else { + dts_fail("bt_socket_connect_rfcomm", + "bt_socket_connect_rfcomm() failed"); + } + dts_check_eq("bt_socket_connect_rfcomm", callback_result, true, + "connecting failed."); +} + +/** + * @brief Positive test case of bt_socket_disconnect_rfcomm() + */ +static void utc_network_bluetooth_socket_disconnect_rfcomm_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_disconnect_rfcomm(socket_fd); + dts_check_eq("bt_socket_disconnect_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_disconnect_rfcomm() failed."); +} + +/** + * @brief Positive test case of bt_socket_send_data() + */ +static void utc_network_bluetooth_socket_send_data_p(void) +{ + int ret = BT_ERROR_NONE; + char *dts_test = "dts_test"; + + ret = bt_socket_send_data(socket_fd, "dts_test", sizeof(dts_test)); + dts_check_eq("bt_socket_send_data", ret, BT_ERROR_NONE, + "bt_socket_send_data() failed."); +} + +/** + * @brief Positive test case of bt_socket_unset_data_received_cb() + */ +static void utc_network_bluetooth_socket_unset_data_received_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_unset_data_received_cb(); + dts_check_eq("bt_socket_unset_data_received_cb", ret, BT_ERROR_NONE, + "bt_socket_unset_data_received_cb() failed."); +} + +/** + * @brief Positive test case of bt_socket_unset_connection_state_changed_cb() + */ +static void utc_network_bluetooth_socket_unset_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_socket_unset_connection_state_changed_cb(); + dts_check_eq("bt_socket_unset_connection_state_changed_cb", ret, + BT_ERROR_NONE, + "bt_socket_unset_connection_state_changed_cb() failed."); +} |