diff options
Diffstat (limited to 'TC')
44 files changed, 8693 insertions, 0 deletions
diff --git a/TC/READAME.txt b/TC/READAME.txt new file mode 100644 index 0000000..f0edad5 --- /dev/null +++ b/TC/READAME.txt @@ -0,0 +1,5 @@ +Before run DTS of bluetooth, BT should be disabled. +This DTS needs another target and it must be set as the following: + 1) BT is activated. + 2) BT is discoverable. + 3) BT name is set as "dts_test". diff --git a/TC/_export_env.sh b/TC/_export_env.sh new file mode 100755 index 0000000..ac8f4a1 --- /dev/null +++ b/TC/_export_env.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_HOST_PATH # tetware root path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target # tetware target path +#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator # tetware simulator path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/_export_target_env.sh b/TC/_export_target_env.sh new file mode 100755 index 0000000..c693f83 --- /dev/null +++ b/TC/_export_target_env.sh @@ -0,0 +1,8 @@ +#!/bin/sh +. ./config +export TET_INSTALL_PATH=$TET_INSTALL_TARGET_PATH # path to path +export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-target +#export TET_TARGET_PATH=$TET_INSTALL_PATH/tetware-simulator # tetware simulator path +export PATH=$TET_TARGET_PATH/bin:$PATH +export LD_LIBRARY_PATH=$TET_TARGET_PATH/lib/tet3:$LD_LIBRARY_PATH +export TET_ROOT=$TET_TARGET_PATH diff --git a/TC/build.sh b/TC/build.sh new file mode 100755 index 0000000..72aad6c --- /dev/null +++ b/TC/build.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/build-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -c -p ./ +tcc -b -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/clean.sh b/TC/clean.sh new file mode 100755 index 0000000..29743e0 --- /dev/null +++ b/TC/clean.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +. ./_export_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +RESULT_DIR=results + +tcc -c -p ./ # executing tcc, with clean option (-c) +rm -r $RESULT_DIR +rm -r tet_tmp_dir +rm testcase/tet_captured diff --git a/TC/config b/TC/config new file mode 100644 index 0000000..bdfec87 --- /dev/null +++ b/TC/config @@ -0,0 +1,4 @@ +PKG_NAME=capi-network-bluetooth +TET_INSTALL_HOST_PATH=/var/tmp/dts_fw/TC/TETware +TET_INSTALL_TARGET_PATH=/opt/home/$PKG_NAME/TETware + diff --git a/TC/execute.sh b/TC/execute.sh new file mode 100755 index 0000000..0fe02e2 --- /dev/null +++ b/TC/execute.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +. ./_export_target_env.sh # setting environment variables + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT diff --git a/TC/push.sh b/TC/push.sh new file mode 100755 index 0000000..5eb9510 --- /dev/null +++ b/TC/push.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +. ./config + +TC_PATH=/opt/home/$PKG_NAME + +echo $TC_PATH + +sdb shell "mkdir -p $TC_PATH" + +sdb push . $TC_PATH + + diff --git a/TC/run.sh b/TC/run.sh new file mode 100755 index 0000000..cec5778 --- /dev/null +++ b/TC/run.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +source ./_export_target_env.sh + +export TET_SUITE_ROOT=`pwd` +FILE_NAME_EXTENSION=`date +%s` + +RESULT_DIR=results +HTML_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.html +JOURNAL_RESULT=$RESULT_DIR/exec-tar-result-$FILE_NAME_EXTENSION.journal + +mkdir -p $RESULT_DIR + +tcc -e -j $JOURNAL_RESULT -p ./ +grw -c 7 -f chtml -o $HTML_RESULT $JOURNAL_RESULT 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..c3d5dd0 --- /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_audio_negative +/testcase/utc_network_bluetooth_audio_positive +/testcase/utc_network_bluetooth_device_positive +/testcase/utc_network_bluetooth_device_negative +/testcase/utc_network_bluetooth_device_discovery_positive +/testcase/utc_network_bluetooth_device_discovery_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_avrcp_negative +/testcase/utc_network_bluetooth_avrcp_positive +/testcase/utc_network_bluetooth_common_negative +/testcase/utc_network_bluetooth_common_positive
\ No newline at end of file diff --git a/TC/testcase/utc_network_bluetooth_adapter_negative.c b/TC/testcase/utc_network_bluetooth_adapter_negative.c new file mode 100755 index 0000000..a7e2750 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_adapter_negative.c @@ -0,0 +1,429 @@ +/* + * 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_set_connectable_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_add_white_list_n(void); +static void utc_network_bluetooth_adapter_clear_white_list_n(void); +static void utc_network_bluetooth_adapter_remove_white_list_n(void); +static void utc_network_bluetooth_adapter_set_connectable_n(void); +static void utc_network_bluetooth_adapter_get_connectable_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); +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_n(void); +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_unset_le_state_changed_cb_n(void); +static void utc_network_bluetooth_adapter_le_enable_n(void); +static void utc_network_bluetooth_adapter_get_le_state_n(void); +static void utc_network_bluetooth_adapter_le_disable_n(void); + +void adapter_state_changed_cb_for_adapter_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_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_set_connectable_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_adapter_le_disable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_add_white_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_remove_white_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_clear_white_list_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_connectable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_deinitialize_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_connectable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_enable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_connectable_changed_cb_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}, + {utc_network_bluetooth_adapter_set_le_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_le_state_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_le_enable_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_le_state_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_set_connectable_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_connectable_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_connectable_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_set_connectable_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) +{ + int dur = 10; + int ret = bt_adapter_get_visibility(NULL, &dur); + + dts_check_eq("bt_adapter_get_visibility", 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(). + */ +static void utc_network_bluetooth_adapter_set_name_n(void) +{ + int ret = bt_adapter_set_name(NULL); + dts_check_eq("bt_adapter_set_name", 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(). + */ +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_le_add_white_list + */ +static void utc_network_bluetooth_adapter_add_white_list_n(void) +{ + int ret = bt_adapter_le_add_white_list(NULL); + dts_check_eq("bt_adapter_le_add_white_list", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_clear_white_list + */ +static void utc_network_bluetooth_adapter_clear_white_list_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_clear_white_list(); + dts_check_eq("bt_adapter_clear_white_list", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is not enabled."); +} + +/** + * @brief Negative test case of bt_adapter_le_add_white_list + */ +static void utc_network_bluetooth_adapter_remove_white_list_n(void) +{ + int ret = bt_adapter_le_remove_white_list(NULL); + dts_check_eq("bt_adapter_le_remove_white_list", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_get_connectable + */ +static void utc_network_bluetooth_adapter_get_connectable_n(void) +{ + int ret = bt_adapter_get_connectable(NULL); + dts_check_eq("bt_adapter_get_connectable", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +/** + * @brief Negative test case of bt_adapter_set_connectable + */ +static void utc_network_bluetooth_adapter_set_connectable_n(void) +{ + int ret = bt_adapter_set_connectable(NULL); + dts_check_eq("bt_adapter_set_connectable", ret, BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + +/** + * @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."); +} + +/** + * @brief Negative test case of bt_adapter_unset_connectable_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_connectable_changed_cb(); + dts_check_eq("bt_adapter_unset_connectable_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "bt_adapter_unset_connectable_changed_cb() failed."); +} + +/** + * @brief Negative test case of bt_adapter_le_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_set_state_changed_cb(NULL, NULL); + dts_check_eq("bt_adapter_le_set_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when parameter is NULL."); +} + +static void utc_network_bluetooth_adapter_le_enable_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_enable(); + dts_check_eq("bt_adapter_le_enable", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned."); +} + +static void utc_network_bluetooth_adapter_le_disable_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_disable(); + dts_check_eq("bt_adapter_disable", ret, BT_ERROR_NOT_ENABLED, + "BT_ERROR_NOT_ENABLED must be returned when BT is disabled"); +} + +static void utc_network_bluetooth_adapter_get_le_state_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_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."); +} + +static void utc_network_bluetooth_adapter_unset_le_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_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"); +} diff --git a/TC/testcase/utc_network_bluetooth_adapter_positive.c b/TC/testcase/utc_network_bluetooth_adapter_positive.c new file mode 100755 index 0000000..6ad6815 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_adapter_positive.c @@ -0,0 +1,796 @@ +/* + * 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> + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +static void startup(void); +static void cleanup(void); +char *remote_address; +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_set_connectable_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_add_white_list_p(void); +static void utc_network_bluetooth_adapter_remove_white_list_p(void); +static void utc_network_bluetooth_adapter_clear_white_list_p(void); +static void utc_network_bluetooth_adapter_set_connectable_p(void); +static void utc_network_bluetooth_adapter_get_connectable_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); +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_p(void); +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_p(void); +static void utc_network_bluetooth_adapter_le_enable_p(void); +static void utc_network_bluetooth_adapter_get_le_state_p(void); +static void utc_network_bluetooth_adapter_le_disable_p(void); +static void utc_network_bluetooth_adapter_unset_le_state_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); +void adapter_connectable_changed_cb_for_adpater_p(int result, + bool connectable, 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_connectable_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_get_connectable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_connectable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_connectable_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_le_enable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_add_white_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_remove_white_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_clear_white_list_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_set_le_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_unset_le_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_get_le_state_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_le_disable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_adapter_disable_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + fclose(fp); + return 0; + } + } + return -1; +} + +static void startup(void) +{ + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* 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 adapter_le_state_changed_cb_for_adapter_p(int result, + bt_adapter_le_state_e adapter_le_state, + void *user_data) +{ + if (user_data != NULL && !strcmp((char *)user_data, "enable")) { + if (adapter_le_state == BT_ADAPTER_LE_ENABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT LE was enabled."); + callback_result = true; + } else { + tet_printf("Callback: BT LE was not enabled."); + } + + if (mainloop) + g_main_loop_quit(mainloop); + } else if (user_data != NULL && !strcmp((char *)user_data, "disable")) { + if (adapter_le_state == BT_ADAPTER_LE_DISABLED && result == BT_ERROR_NONE) { + tet_printf("Callback: BT LEwas disabled."); + callback_result = true; + } else { + tet_printf("Callback: BT LE 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); +} + +void adapter_connectable_changed_cb_for_adpater_p(int result, bool connectable, + void *user_data) +{ + tet_printf("adapter_connectable_changed_cb_for_adapter_p was called."); + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Connectable Changed"); + tet_printf("%s", connectable ? "Connectable" : "Non-connectable"); + callback_result = true; + } else { + tet_printf("Callback: adapter_connectable_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."); +} + +static void utc_network_bluetooth_adapter_set_connectable_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_set_connectable_changed_cb( + adapter_connectable_changed_cb_for_adpater_p, NULL); + dts_check_eq("bt_adapter_set_connectable_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_set_connectable_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_le_add_white_list + */ +static void utc_network_bluetooth_adapter_add_white_list_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_le_add_white_list(remote_address); + dts_check_eq("bt_adapter_le_add_white_list", ret, BT_ERROR_NONE, + "bt_adapter_le_add_white_list() failed."); +} + +/** + * @brief Positive test case of bt_adapter_le_clear_white_list + */ +static void utc_network_bluetooth_adapter_clear_white_list_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_le_clear_white_list(); + dts_check_eq("bt_adapter_le_clear_white_list", ret, BT_ERROR_NONE, + "bt_adapter_le_clear_white_list() failed."); +} + +/** + * @brief Positive test case of bt_adapter_le_remove_white_list + */ +static void utc_network_bluetooth_adapter_remove_white_list_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_adapter_le_remove_white_list(remote_address); + dts_check_eq("bt_adapter_le_remove_white_list", ret, BT_ERROR_NONE, + "bt_adapter_le_remove_white_list() failed."); +} + +/** + * @brief Positive test case of bt_adapter_get_connectable + */ +static void utc_network_bluetooth_adapter_get_connectable_p(void) +{ + int ret = BT_ERROR_NONE; + bool connectable = false; + ret = bt_adapter_get_connectable(&connectable); + dts_check_eq("bt_adapter_get_connectable", ret, BT_ERROR_NONE, + "bt_adapter_get_connectable() failed."); +} + +/** + * @brief Positive test case of bt_adapter_set_connectable + */ +static void utc_network_bluetooth_adapter_set_connectable_p(void) +{ + int ret = BT_ERROR_NONE; + bool connectable = false; + int timeout_id = 0; + callback_result = false; + + ret = bt_adapter_get_connectable(&connectable); + ret = bt_adapter_set_connectable(!connectable); + if (ret == BT_ERROR_NONE) { + tet_printf("adapter_connectable_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_adapter_set_connectable", ret, BT_ERROR_NONE, + "bt_adapter_set_connectable() 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."); +} + +/** + * @brief Positive test case of bt_adapter_unset_connectable_changed_cb() + */ +static void utc_network_bluetooth_adapter_unset_connectable_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_unset_connectable_changed_cb(); + dts_check_eq("bt_adapter_unset_connectable_changed_cb", ret, + BT_ERROR_NONE, + "bt_adapter_unset_connectable_changed_cb() failed."); +} + +/** + * @brief Positive test case of bt_adapter_le_set_state_changed_cb() + */ +static void utc_network_bluetooth_adapter_set_le_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_set_state_changed_cb( + adapter_le_state_changed_cb_for_adapter_p, NULL); + dts_check_eq("bt_adapter_le_set_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_set_state_le_state_changed_cb failed."); +} + +static void utc_network_bluetooth_adapter_le_enable_p(void) +{ + int timeout_id = 0; + callback_result = false; + bt_error_e ret = BT_ERROR_NONE; + + if (bt_adapter_le_set_state_changed_cb(adapter_le_state_changed_cb_for_adapter_p, "enable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_le_enable", + "bt_adapter_le_set_state_changed_cb() failed."); + } + + ret = bt_adapter_le_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_le_enable", "bt_adapter_le_enable() failed."); + bt_adapter_le_unset_state_changed_cb(); + return; + } + + tet_printf("callback_result: %d", callback_result); + bt_adapter_le_unset_state_changed_cb(); + dts_check_eq("bt_adapter_le_enable", callback_result, true, + "BT LE was not enabled."); +} + +static void utc_network_bluetooth_adapter_le_disable_p(void) +{ + callback_result = false; + int timeout_id = 0; + + if (bt_adapter_le_set_state_changed_cb(adapter_le_state_changed_cb_for_adapter_p, "disable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_le_disable", + "bt_adapter_le_set_state_changed_cb() failed."); + } + + if (bt_adapter_le_disable() == BT_ERROR_NONE) { + tet_printf("bt_adapter_le_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_le_unset_state_changed_cb(); + dts_check_eq("bt_adapter_le_disable", callback_result, true, + "BT LE was not disabled"); + } else { + dts_fail("bt_adapter_le_disable", "bt_adapter_le_disable() failed"); + } +} + +static void utc_network_bluetooth_adapter_get_le_state_p(void) +{ + bt_adapter_le_state_e adapter_le_state = BT_ADAPTER_LE_DISABLED; + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_get_state(&adapter_le_state); + if (ret == BT_ERROR_NONE && adapter_le_state == BT_ADAPTER_LE_ENABLED) { + dts_pass("bt_adapter_le_get_state", + "bt_adapter_le_get_state() succeeded."); + } else { + dts_fail("bt_adapter_le_get_state", + "bt_adapter_le_get_state() failed."); + } +} + +static void utc_network_bluetooth_adapter_unset_le_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_adapter_le_unset_state_changed_cb(); + dts_check_eq("bt_adapter_le_unset_state_changed_cb", ret, BT_ERROR_NONE, + "bt_adapter_unset_state_le_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 100755 index 0000000..438b166 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_audio_negative.c @@ -0,0 +1,383 @@ +/* + * 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_set_vendor_cmd_cb_n(void); +static void utc_network_bluetooth_ag_unset_vendor_cmd_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); +static void utc_network_bluetooth_ag_set_dtmf_transmitted_cb_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_set_vendor_cmd_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_ag_set_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}, + {utc_network_bluetooth_ag_unset_vendor_cmd_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}, + {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_set_dtmf_transmitted_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_ag_unset_multi_call_handling_event_cb() + */ +static void utc_network_bluetooth_ag_unset_multi_call_handling_event_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_deinitialize(); + ret = bt_ag_unset_multi_call_handling_event_cb(); + dts_check_eq("bt_ag_unset_multi_call_handling_event_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + +/** + * @brief Negative test case of bt_ag_unset_dtmf_transmitted_cb() + */ +static void utc_network_bluetooth_ag_unset_dtmf_transmitted_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_deinitialize(); + ret = bt_ag_unset_dtmf_transmitted_cb(); + dts_check_eq("bt_ag_unset_dtmf_transmitted_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + +/** + * @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; + const char *phone_number = "9663868998"; + + ret = bt_call_list_add(NULL, call_id, BT_AG_CALL_STATE_INCOMING, phone_number); + 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 100755 index 0000000..d1fffbc --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_audio_positive.c @@ -0,0 +1,666 @@ +/* + * utc_network_bluetooth_audio_positive.c + * + * Created on: 19-Sep-2013 + * Author: mrinal.m + */ + +#include <tet_api.h> +#include <bluetooth.h> +#include <glib.h> + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +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 *remote_address; +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_set_vendor_cmd_cb_p(void); +static void utc_network_bluetooth_ag_unset_vendor_cmd_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_set_vendor_cmd_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_unset_vendor_cmd_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_is_sco_opened_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_ag_close_sco_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_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}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_HEADSET") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + fclose(fp); + return 0; + } + } + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* 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) +{ + +} + +void vendor_cmd_event_cb_for_ag_p(char *cmd, void *user_data) +{ + tet_printf("Callback : vendor_cmd_cb was called."); + tet_printf("Vendor Command[%s]", cmd); +} + +/** + * @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; + ret = bt_audio_disconnect(remote_address, BT_AUDIO_PROFILE_TYPE_HSP_HFP); + 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; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + 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 = 1; + + 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; + const char *phone_number = "9663868998"; + + ret = bt_call_list_create(&handle); + ret = bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + + 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; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + 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; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + 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; + const char *phone_number = "9663868998"; + + handle = g_malloc0(sizeof(bt_call_list_h)); + bt_call_list_add(handle, 1, BT_AG_CALL_STATE_ACTIVE, phone_number); + ret = bt_call_list_add(handle, call_id, BT_AG_CALL_STATE_INCOMING, phone_number); + dts_check_eq("bt_call_list_add", ret, BT_ERROR_NONE, + "bt_call_list_add() 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..a62c7b4 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_avrcp_negative.c @@ -0,0 +1,174 @@ +/* + * 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 100755 index 0000000..79e0688 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_avrcp_positive.c @@ -0,0 +1,398 @@ +/* + * 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..4d2eb6e --- /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 100755 index 0000000..bf775cf --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_common_positive.c @@ -0,0 +1,122 @@ +/* + * 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..48b22d3 --- /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, + 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_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 100755 index 0000000..76caf9f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_discovery_positive.c @@ -0,0 +1,262 @@ +/* + * 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 100755 index 0000000..9915c99 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_negative.c @@ -0,0 +1,300 @@ +/* + * 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); +static void utc_network_bluetooth_device_get_rssi_strength_n(void); +static void utc_network_bluetooth_device_disable_rssi_monitor_n(void); +static void utc_network_bluetooth_device_enable_rssi_monitor_n(void); +static void utc_network_bluetooth_device_unset_rssi_alert_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_get_rssi_strength_n, NEGATIVE_TC_IDX }, + {utc_network_bluetooth_device_enable_rssi_monitor_n, NEGATIVE_TC_IDX }, + {utc_network_bluetooth_device_disable_rssi_monitor_n, NEGATIVE_TC_IDX }, + {utc_network_bluetooth_device_unset_rssi_alert_cb_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; + + ret = bt_deinitialize(); + + 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 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 100755 index 0000000..1ee789e --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_device_positive.c @@ -0,0 +1,694 @@ +/* + * 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> + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +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; +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); +static void utc_network_bluetooth_device_get_rssi_strength_p(void); +static void utc_network_bluetooth_device_disable_rssi_monitor_p(void); +static void utc_network_bluetooth_device_enable_rssi_monitor_p(void); +static void utc_network_bluetooth_device_unset_rssi_alert_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); +void device_get_rssi_strength_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_dbm, void *user_data); +static void device_rssi_enabled_cb(const char *address, + bt_device_connection_link_type_e link_type, + int rssi_enabled, void *user_data); +static void device_rssi_alert_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_alert_type, int rssi_alert_dbm, void *user_data); + +struct tet_testlist tet_testlist[] = { + { utc_network_bluetooth_device_set_bonded_cb_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_bonded_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_unset_authorization_state_changed_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_get_rssi_strength_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_enable_rssi_monitor_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_disable_rssi_monitor_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_unset_rssi_alert_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_set_unbonded_cb_p, POSITIVE_TC_IDX }, + { utc_network_bluetooth_device_cancel_bonding_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 }, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + target_address = strdup(token); + fclose(fp); + return 0; + } + } + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* 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); + } else + tet_printf("Callback: address of unbonded device is NULL!"); + + if ((remote_address != NULL) && \ + !strcmp(remote_address, target_address)) { + if (result == BT_ERROR_NONE) { + tet_printf("Callback: Unbonding succeeded"); + callback_result = true; + } else { + tet_printf("Callback: Unbonding failed"); + } + } + + 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); + } + } + } +} + +void device_get_rssi_strength_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_dbm, void *user_data) +{ + tet_printf("Callback:Rssi_strength_cb is called."); + tet_printf("RSSI Strength: [Address %s][Link Type %d][RSSI dBm %d]", + bt_address, link_type, rssi_dbm); +} + +static void device_rssi_enabled_cb(const char *address, + bt_device_connection_link_type_e link_type, + int rssi_enabled, void *user_data) +{ + tet_printf("Callback:Rssi_enabled_cb is called."); + tet_printf("RSSI Enabled: %s %d %d", address, link_type, rssi_enabled); +} + +static void device_rssi_alert_cb(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_alert_type, int rssi_alert_dbm, void *user_data) +{ + tet_printf("Callback:rssi_alert_cb is called."); + tet_printf("RSSI Alert: [Address:%s LinkType:%d][RSSI Alert Type:%d dBm:%d]", + bt_address, link_type, rssi_alert_type, rssi_alert_dbm); +} + +/** + * @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) { + tet_printf("bt_device_set_bond_created_cb was called"); + } + + 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", ret, BT_ERROR_NONE, + "bt_device_create_bond() 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", ret, BT_ERROR_NONE, + "bt_device_set_authorization() 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", ret, BT_ERROR_NONE, + "bt_device_destroy_bond() 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 100755 index 0000000..e15467d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_gatt_negative.c @@ -0,0 +1,298 @@ +/* + * 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); +static void utc_network_bluetooth_gatt_connect_n(void); +static void utc_network_bluetooth_gatt_disconnect_n(void); +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_n(void); +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_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_set_gatt_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_connect_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_disconnect_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}, + {utc_network_bluetooth_unset_gatt_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_gatt_unset_characteristic_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_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); + 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(); + dts_check_eq("bt_gatt_unset_characteristic_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} + + +/** + * @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."); +} + +static void utc_network_bluetooth_gatt_connect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_connect(NULL, false); + dts_check_eq("bt_gatt_connect", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address is NULL."); + +} + +static void utc_network_bluetooth_gatt_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_disconnect(NULL); + dts_check_eq("bt_gatt_connect", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address is NULL."); + +} + +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_connection_state_changed_cb(NULL, NULL); + dts_check_eq("bt_gatt_set_connection_state_changed_cb", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when address is NULL."); +} + +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_deinitialize(); + ret = bt_gatt_unset_connection_state_changed_cb(); + dts_check_eq("bt_gatt_unset_connection_state_changed_cb", ret, + BT_ERROR_NOT_INITIALIZED, + "BT_ERROR_NOT_INITIALIZED must be returned when BT is not initialized."); +} diff --git a/TC/testcase/utc_network_bluetooth_gatt_positive.c b/TC/testcase/utc_network_bluetooth_gatt_positive.c new file mode 100755 index 0000000..b45ecca --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_gatt_positive.c @@ -0,0 +1,405 @@ +/* + * 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> + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +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 *remote_address; +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); +static void utc_network_bluetooth_gatt_connect_p(void); +static void utc_network_bluetooth_gatt_disconnect_p(void); +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_p(void); +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_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); +void adapter_le_state_changed_cb_for_gatt_p(int result, bt_adapter_le_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); +void gatt_connection_state_changed_cb(int result, bool connected, + const char *remote_address, 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_set_gatt_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_gatt_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_unset_gatt_connection_state_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}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_LE") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + return 0; + } + } + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* 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"); + } + + if (bt_adapter_le_set_state_changed_cb(adapter_le_state_changed_cb_for_gatt_p, "enable") != BT_ERROR_NONE) { + dts_fail("bt_adapter_le_enable", + "bt_adapter_le_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."); + tet_printf("bt_adapter_le_enable() was called."); + ret = bt_adapter_le_enable(); + if (ret == BT_ERROR_NONE) { + tet_printf("bt_adapter_le_enable() succeeded."); + timeout_id = g_timeout_add(60000, timeout_func, mainloop); + g_main_loop_run(mainloop); + g_source_remove(timeout_id); + } + else { + tet_printf("DTS may fail because bt_adapter_le_enable failed"); + bt_adapter_le_unset_state_changed_cb(); + } + } else if (ret == BT_ERROR_NOT_ENABLED) { + tet_printf("Bluetooth adapter is not 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_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) +{ + +} +void adapter_le_state_changed_cb_for_gatt_p(int result, bt_adapter_le_state_e adapter_le__state, void* user_data) +{ + +} + +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) +{ + +} + +void gatt_connection_state_changed_cb(int result, bool connected, + const char *remote_address, void *user_data) +{ + tet_printf("bt_gatt_connection_state_changed_cb : %d", result); + if (connected) + tet_printf("LE Connected"); + else + tet_printf("LE Disconnected"); +} + +/** + * @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; + + ret = bt_gatt_foreach_primary_services(remote_address, 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_gatt_attribute_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_gatt_attribute_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_gatt_attribute_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_gatt_attribute_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_gatt_attribute_h gatt_serv; + gatt_serv = g_malloc0(sizeof(bt_gatt_attribute_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; + + ret = bt_gatt_set_characteristic_changed_cb(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; + + ret = bt_gatt_unset_characteristic_changed_cb(); + 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_gatt_attribute_h gatt_charac; + gatt_charac = g_malloc0(sizeof(bt_gatt_attribute_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_gatt_attribute_h gatt_charac; + gatt_charac = g_malloc0(sizeof(bt_gatt_attribute_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_gatt_attribute_h gatt_origin; + bt_gatt_attribute_h gatt_clone; + gatt_origin = g_malloc0(sizeof(bt_gatt_attribute_h)); + gatt_clone = g_malloc0(sizeof(bt_gatt_attribute_h)); + + ret = bt_gatt_clone_attribute_handle(&gatt_clone, 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_gatt_attribute_h gatt_handle; + gatt_handle = g_malloc0(sizeof(bt_gatt_attribute_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."); +} + +static void utc_network_bluetooth_gatt_connect_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_connect(remote_address, false); + dts_check_eq("bt_gatt_connect", ret, BT_ERROR_NONE, + "bt_gatt_connect() failed."); + +} + +static void utc_network_bluetooth_gatt_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_gatt_disconnect(remote_address); + dts_check_eq("bt_gatt_connect", ret, BT_ERROR_NONE, + "bt_gatt_connect() failed."); + +} + +static void utc_network_bluetooth_set_gatt_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_set_connection_state_changed_cb(gatt_connection_state_changed_cb, NULL); + dts_check_eq("bt_gatt_set_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_set_connection_state_changed_cb() failed."); +} + +static void utc_network_bluetooth_unset_gatt_connection_state_changed_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_gatt_unset_connection_state_changed_cb(); + dts_check_eq("bt_gatt_unset_connection_state_changed_cb", ret, BT_ERROR_NONE, + "bt_gatt_unset_connection_state_changed_cb() 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..d157a1f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hdp_negative.c @@ -0,0 +1,201 @@ +/* + * 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_set_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_connect_to_source_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_set_data_received_cb_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_disconnect_n, NEGATIVE_TC_IDX }, + { utc_network_bluetooth_hdp_unregister_sink_app_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) +{ + +} + + +/** + * @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 is returned when cb parameters are 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 is returned when cb parameters are NULL"); +} + + +/** + * @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 100755 index 0000000..b99e6f5 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hdp_positive.c @@ -0,0 +1,242 @@ +/* + * 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; + +const char *appid = "/org/bluez/health_app_2"; +const char *remote_adr = "00:22:58:07:77:BB"; + +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_set_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_set_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_connect_to_source_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_send_data_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unset_data_received_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hdp_unregister_sink_app_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_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_hdp_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + +} + +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 = "00:22:58:07:77:BB"; + + ret = bt_hdp_disconnect(remote_adr, 0); + 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; + + 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; + + 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; + + 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 100755 index 0000000..e8cb5f8 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hid_negative.c @@ -0,0 +1,142 @@ +/* + * 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_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_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) +{ + +} +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_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_initialize(NULL, NULL); + dts_check_eq("bt_hid_host_initialize", ret, + BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when callback parameter is NULL."); +} + + +static void utc_network_bluetooth_hid_host_connect_n(void) +{ + int ret = BT_ERROR_NONE; + + ret = bt_hid_host_initialize(host_connection_state_changed_cb_for_hid_p, NULL); + + 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 100755 index 0000000..95e7db1 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_hid_positive.c @@ -0,0 +1,159 @@ +/* + * 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_connect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_disconnect_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_hid_host_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_hid_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_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) +{ + +} + + +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 100755 index 0000000..77ecc79 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-client_negative.c @@ -0,0 +1,136 @@ +/* + * 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_add_file_n(void); +static void utc_network_bluetooth_opp_client_push_files_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_add_file_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_push_files_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(); + bt_opp_client_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_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_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"); +} + + 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 100755 index 0000000..b50baea --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-client_positive.c @@ -0,0 +1,260 @@ +/* + * 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 <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <tet_api.h> +#include <bluetooth.h> +#include <stdlib.h> +#include <stdbool.h> +#include <glib.h> + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" +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; + +char *remote_address; + +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_add_file_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}, + {utc_network_bluetooth_opp_client_clear_files_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_opp_client_deinitialize_p, POSITIVE_TC_IDX}, + {NULL, 0}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + remote_address = strdup(token); + fclose(fp); + return 0; + } + } + return -1; +} + +static void startup(void) +{ + int ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* 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_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_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; + int fd = 0; + const char *file = "/tmp/a.txt"; + + if (access("/tmp/a.txt", F_OK) < 0) { + fd = open("/tmp/a.txt", O_RDWR|O_CREAT,0666); + write(fd, "hey", 3); + } + + ret = bt_opp_client_add_file(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(remote_address, push_responded_cb_for_opp_client_p, + push_progress_cb_for_opp_client_p, push_finished_cb_for_opp_client_p, NULL); + + dts_check_eq("bt_opp_client_push_files", ret, + BT_ERROR_NONE, "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 100755 index 0000000..a7d911d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-server_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 void startup(void); +static void cleanup(void); + +static GMainLoop *mainloop; +const char *dest = "/tmp"; + +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_accept_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); +void transfer_progress_cb_for_opp_server(const char *file, long long size, + int percent, void *user_data); +void transfer_finished_cb_for_opp_server(int result, const char *file, + long long size, void *user_data); +void push_requested_cb_for_opp_server(const char *file, int size, 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_set_destination_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_opp_server_accept_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; +} + +void push_requested_cb_for_opp_server(const char *file, int size, + void *user_data) +{ + +} + +void transfer_progress_cb_for_opp_server(const char *file, long long size, + int percent, void *user_data) +{ + +} + +void transfer_finished_cb_for_opp_server(int result, const char *file, + long long size, void *user_data) +{ + +} + +/** + * @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_initialize", ret, BT_ERROR_INVALID_PARAMETER, + "BT_ERROR_INVALID_PARAMETER must be returned when destination parameter is NULL"); +} + + +static void utc_network_bluetooth_opp_server_accept_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_opp_server_accept(transfer_progress_cb_for_opp_server, + transfer_finished_cb_for_opp_server, NULL, NULL, NULL); + dts_check_eq("bt_opp_server_accept", ret, BT_ERROR_INVALID_PARAMETER, + "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_initialize(dest, push_requested_cb_for_opp_server_p, + NULL); + + 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 100755 index 0000000..39efb77 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_opp-server_positive.c @@ -0,0 +1,224 @@ +/* + * 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; +const char *dest = "/tmp"; + +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); +void transfer_finished_cb_for_opp_server_p(int result, const char *file, + long long size, void *user_data); +void transfer_progress_cb_for_opp_server_p(int result, const char *file, + long long size, 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_set_destination_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_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_opp_server_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_opp_server_p(int result, + bt_adapter_state_e adapter_state, void *user_data) +{ + +} + + +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 transfer_progress_cb_for_opp_server_p(int result, const char *file, + long long size, void *user_data) +{ + +} + +void transfer_finished_cb_for_opp_server_p(int result, const char *file, + long long size, 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); + + if (ret != BT_ERROR_RESOURCE_BUSY) { + dts_check_eq("bt_opp_server_initialize", ret, BT_ERROR_NONE, + "bt_opp_server_initialize() failed"); + } else { + dts_check_eq("bt_opp_server_initialize", ret, BT_ERROR_RESOURCE_BUSY, + "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 = 0; + const char *name = "abc"; + ret = bt_opp_server_accept(transfer_progress_cb_for_opp_server_p, + transfer_finished_cb_for_opp_server_p, 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..ec9db0c --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_pan_negative.c @@ -0,0 +1,166 @@ +/* + * 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_nap_disconnect_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_nap_disconnect_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_nap_disconnect() + */ +static void utc_network_bluetooth_nap_disconnect_n(void) +{ + int ret = BT_ERROR_NONE; + ret = bt_nap_disconnect(NULL); + dts_check_eq("bt_nap_disconnect", ret, BT_ERROR_INVALID_PARAMETER, + "bt_nap_disconnect() 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 100755 index 0000000..4526508 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_pan_positive.c @@ -0,0 +1,265 @@ +/* + * 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_nap_disconnect_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_nap_disconnect_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_nap_disconnect() +*/ +static void utc_network_bluetooth_nap_disconnect_p(void) +{ + int ret = BT_ERROR_NONE; + const char *remote_address = "00:00:00:00:00:00"; + ret = bt_nap_disconnect(remote_address); + dts_check_eq("bt_nap_disconnect", ret, BT_ERROR_NONE, + "bt_nap_disconnect() 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..ce4dd7d --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_service_search_negative.c @@ -0,0 +1,179 @@ +/* + * 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 100755 index 0000000..b0c5e70 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_service_search_positive.c @@ -0,0 +1,406 @@ +/* + * 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> + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" +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; +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}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + target_address = strdup(token); + fclose(fp); + return 0; + } + } + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* 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; + int ret = BT_ERROR_NONE; + + if (discovery_result != true) { + tet_printf("bt_device_start_service_search failed."); + } + + callback_result = false; + ret = bt_device_start_service_search(target_address); + if (ret == 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", ret, BT_ERROR_NONE, + "bt_device_start_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; + int ret = BT_ERROR_NONE; + + if (discovery_result != true) { + tet_printf("t_device_cancel_service_search failed."); + } + + callback_result = false; + if (bt_device_start_service_search(target_address) != BT_ERROR_NONE) { + tet_printf("t_device_start_service_search failed."); + + } else { + tet_printf("bt_device_cancel_service_search", + "bt_device_start_service_search() succeeded."); + } + + ret = bt_device_cancel_service_search(); + if (ret == 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", ret, BT_ERROR_NONE, + "bt_device_cancel_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..dea118f --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_socket_negative.c @@ -0,0 +1,268 @@ +/* + * 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_create_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_connection_state_changed_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_listen_and_accept_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_data_received_cb_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_connect_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_send_data_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_disconnect_rfcomm_n, NEGATIVE_TC_IDX}, + {utc_network_bluetooth_socket_destroy_rfcomm_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(NULL); + dts_check_eq("bt_socket_listen_and_accept_rfcomm", ret, + BT_ERROR_NOT_ENABLED, + "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 = "00:02:79:AC:7D:FD"; + 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 100755 index 0000000..acaf2f9 --- /dev/null +++ b/TC/testcase/utc_network_bluetooth_socket_positive.c @@ -0,0 +1,477 @@ +/* + * 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> + +#define CONFIG_FILE_PATH "/opt/home/capi-network-bluetooth/tetware.conf" + +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; +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_create_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_connection_state_changed_cb_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_listen_and_accept_rfcomm_p, POSITIVE_TC_IDX}, + {utc_network_bluetooth_socket_set_data_received_cb_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_destroy_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}, +}; + +int get_value_from_file(void) +{ + FILE *fp; + char *token; + char buf[100]; + + fp = fopen(CONFIG_FILE_PATH, "r"); + if (fp == NULL) { + tet_printf("Default configuration is used\n"); + return -1; + } + while (fgets(buf, sizeof(buf), fp)) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + + token = strrchr(buf, '\n'); + if (token == NULL) { + tet_printf("g_conf is too long\n"); + break; + } + *token = '\0'; + + token = strtok(buf, "="); + if (token == NULL) { + continue; + } + if (strcasecmp(token, "BT_ADDR_MOBILE") == 0) { + token = strtok(NULL, "="); + target_address = strdup(token); + fclose(fp); + return 0; + } + } + return -1; +} + +static void startup(void) +{ + bt_error_e ret = BT_ERROR_NONE; + int timeout_id = 0; + + if(get_value_from_file() == -1) { + tet_printf("Failed to read."); + } + + /* 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) { + dts_check_eq("bt_socket_connect_rfcomm", ret, BT_ERROR_NONE, + "bt_socket_connect_rfcomm() failed."); + 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"); + } +} + +/** + * @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"; + int socket_fd = 1; + 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."); +} diff --git a/TC/tet_scen b/TC/tet_scen new file mode 100755 index 0000000..03f029a --- /dev/null +++ b/TC/tet_scen @@ -0,0 +1,7 @@ +all + ^TEST +##### Scenarios for TEST ##### + +# Test scenario +TEST + :include:/testcase/tslist diff --git a/TC/tetbuild.cfg b/TC/tetbuild.cfg new file mode 100644 index 0000000..f7eda55 --- /dev/null +++ b/TC/tetbuild.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option for build operation checking +TET_BUILD_TOOL=make # build with using make command +TET_BUILD_FILE=-f Makefile # execution file (Makefile) for build +TET_API_COMPLIANT=True # use TET API in Test Case ? +TET_PASS_TC_NAME=True # report passed TC name in Journal file? diff --git a/TC/tetclean.cfg b/TC/tetclean.cfg new file mode 100644 index 0000000..02d7030 --- /dev/null +++ b/TC/tetclean.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capture option +TET_CLEAN_TOOL= make clean # clean tool +TET_CLEAN_FILE= Makefile # file for clean +TET_API_COMPLIANT=True # TET API useage +TET_PASS_TC_NAME=True # showing name , passed TC diff --git a/TC/tetexec.cfg b/TC/tetexec.cfg new file mode 100644 index 0000000..ef3e452 --- /dev/null +++ b/TC/tetexec.cfg @@ -0,0 +1,5 @@ +TET_OUTPUT_CAPTURE=True # capturing execution or not +TET_EXEC_TOOL= # ex) exec : execution tool set up/ Optional +TET_EXEC_FILE= # ex) exectool : execution file/ Optional +TET_API_COMPLIANT=True # Test case or Tool usesTET API? +TET_PASS_TC_NAME=True # showing Passed TC name ? diff --git a/TC/tetware.conf b/TC/tetware.conf new file mode 100644 index 0000000..4d0c237 --- /dev/null +++ b/TC/tetware.conf @@ -0,0 +1,5 @@ +BT_ADDR_HEADSET=00:21:19:14:29:52 +BT_ADDR_MOBILE=E4:32:CB:41:1D:7A +BT_ADDR_HDP=00:22:58:07:77:BB +BT_ADDR_LE=E4:32:CB:41:1F:A6 + |