From fc2bd11fa29e1de7e9c19427d1e3fb74257bae52 Mon Sep 17 00:00:00 2001 From: Amit Purwar Date: Fri, 31 Jul 2020 15:43:37 +0530 Subject: [PATCH] Add Gtest testcase for Network feature of Mesh framework Change-Id: Ie21a980f5bd246921e6d8a576932d11187e4f591 Signed-off-by: Amit Purwar --- tests/unittest/mock/bluetooth-mock.c | 163 +++ tests/unittest/tct-bluetooth-core_mobile.h | 160 +++ .../unittest/utc_bluetooth_mesh_network_negative.c | 1432 +++++++++++++++++++ .../unittest/utc_bluetooth_mesh_network_positive.c | 1499 ++++++++++++++++++++ 4 files changed, 3254 insertions(+) create mode 100644 tests/unittest/utc_bluetooth_mesh_network_negative.c create mode 100644 tests/unittest/utc_bluetooth_mesh_network_positive.c diff --git a/tests/unittest/mock/bluetooth-mock.c b/tests/unittest/mock/bluetooth-mock.c index df900d8..e529896 100644 --- a/tests/unittest/mock/bluetooth-mock.c +++ b/tests/unittest/mock/bluetooth-mock.c @@ -15,6 +15,7 @@ #include #include #include +#include #ifndef API #define API __attribute__ ((visibility("default"))) @@ -31,6 +32,7 @@ static guint g_scan_resp_data[BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX] = {0x04, 0x static bluetooth_cb_func_ptr adapter_event_cb; static bluetooth_cb_func_ptr le_adapter_event_cb; +static mesh_cb_func_ptr bt_mesh_event_proxy_cb; static gboolean __adapter_event_cb(gpointer user_data) { @@ -48,6 +50,16 @@ static gboolean __adapter_le_event_cb(gpointer user_data) return FALSE; } +static gboolean __mesh_event_cb(gpointer user_data) +{ + mesh_event_param_t *bt_event = (mesh_event_param_t *)user_data; + + bt_mesh_event_proxy_cb(bt_event->event, bt_event, NULL); + g_free(bt_event->param_data); + g_free(bt_event); + return FALSE; +} + API int system_info_get_platform_bool(const char *key, bool *value) { *value = true; @@ -758,3 +770,154 @@ API int bluetooth_obex_server_deinit_without_agent(void) { return BLUETOOTH_ERROR_NONE; } + +API int bluetooth_mesh_init(mesh_cb_func_ptr callback_ptr, void *user_data) +{ + bt_mesh_event_proxy_cb = callback_ptr; + + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_create(const char *net_name, bluetooth_mesh_node_t *node, + uint16_t total_models, bluetooth_mesh_model_t **models, + bluetooth_mesh_network_t *network) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_load(const char *token, + bluetooth_mesh_network_t *network) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_set_name(bluetooth_mesh_network_t *network) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_add_netkey(bluetooth_mesh_network_t *network, + uint16_t *netkey_idx) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_get_all_netkey(bluetooth_mesh_network_t *network, + GPtrArray **netkeys) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_update_netkey(bluetooth_mesh_network_t *network, + uint16_t netkey_idx) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_delete_netkey(bluetooth_mesh_network_t *network, + uint16_t netkey_idx) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_add_appkey(bluetooth_mesh_network_t *network, + uint16_t netkey_index, uint16_t *appkey_index) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_netkey_get_all_appkey(bluetooth_mesh_network_t *network, + uint16_t netkey_idx,GPtrArray **appkeys) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_update_appkey(bluetooth_mesh_network_t *network, + uint16_t netkey_index, uint16_t appkey_index) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network, + uint16_t netkey_index, uint16_t appkey_index) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_get_all_nodes(bluetooth_mesh_network_t *network, + GPtrArray **nodes) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_create_group(bluetooth_mesh_network_t *network, + bool is_virtual, uint16_t grp_addr, bluetooth_mesh_network_group_info_t *info) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_get_all_groups(bluetooth_mesh_network_t *network, + GPtrArray **groups) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_scan(bluetooth_mesh_network_t *network, + bluetooth_mesh_scan_param_t *scan_param) +{ + bluetooth_event_param_t *bt_event = NULL; + bluetooth_mesh_scan_result_t *scan_result = NULL; + + scan_result = g_malloc0(sizeof(bluetooth_mesh_scan_result_t)); + scan_result->rssi = 45; + memcpy(scan_result->dev_uuid, g_uuid1, BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH); + + bt_event = g_malloc0(sizeof(bluetooth_event_param_t)); + bt_event->event = BLUETOOTH_EVENT_MESH_SCAN_RESULT; + bt_event->result = BLUETOOTH_ERROR_NONE; + bt_event->param_data = scan_result; + + g_timeout_add(500, __mesh_event_cb, bt_event); + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_cancel_scan(bluetooth_mesh_network_t *network) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_provision_device(bluetooth_mesh_provisioning_request_t *req) +{ + bluetooth_event_param_t *bt_event = NULL; + bluetooth_mesh_provisioning_result_t *prov_result = NULL; + + prov_result = g_malloc0(sizeof(bluetooth_mesh_provisioning_result_t)); + memcpy(prov_result->net_uuid, req->net_uuid, BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH); + memcpy(prov_result->dev_uuid, req->dev_uuid, BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH); + + bt_event = g_malloc0(sizeof(bluetooth_event_param_t)); + bt_event->event = BLUETOOTH_EVENT_MESH_PROVISIONING_FINISHED; + bt_event->result = BLUETOOTH_ERROR_NONE; + bt_event->param_data = prov_result; + + g_timeout_add(500, __mesh_event_cb, bt_event); + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_authentication_reply(int auth_type, + const char *auth_val, gboolean reply) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_set_capabilities(bluetooth_mesh_network_t *network, + bluetooth_mesh_provisioner_caps_t *caps) +{ + return BLUETOOTH_ERROR_NONE; +} + +API int bluetooth_mesh_network_remove_group(bluetooth_mesh_network_t *network, + bluetooth_mesh_network_group_info_t *req) +{ + return BLUETOOTH_ERROR_NONE; +} diff --git a/tests/unittest/tct-bluetooth-core_mobile.h b/tests/unittest/tct-bluetooth-core_mobile.h index dbcdae8..a7cdc2f 100644 --- a/tests/unittest/tct-bluetooth-core_mobile.h +++ b/tests/unittest/tct-bluetooth-core_mobile.h @@ -505,6 +505,89 @@ extern int utc_bluetooth_bt_avrcp_control_get_track_info_n(void); extern int utc_bluetooth_bt_avrcp_control_free_track_info_n(void); extern int utc_bluetooth_bt_device_create_bond_p(void); extern int utc_bluetooth_bt_device_destroy_bond_p(void); +extern void utc_bluetooth_mesh_network_positive_startup(void); +extern void utc_bluetooth_mesh_network_positive_cleanup(void); +extern int utc_bluetooth_bt_mesh_initialize_p(void); +extern int utc_bluetooth_bt_mesh_deinitialize_p(void); +extern int utc_bluetooth_bt_mesh_create_node_p(void); +extern int utc_bluetooth_bt_mesh_node_destroy_p(void); +extern int utc_bluetooth_bt_mesh_node_create_element_p(void); +extern int utc_bluetooth_bt_mesh_element_create_model_p(void); +extern int utc_bluetooth_bt_mesh_node_get_network_p(void); +extern int utc_bluetooth_bt_mesh_model_get_id_p(void); +extern int utc_bluetooth_bt_mesh_model_destroy_p(void); +extern int utc_bluetooth_bt_mesh_model_get_element_p(void); +extern int utc_bluetooth_bt_mesh_element_destroy_p(void); +extern int utc_bluetooth_bt_mesh_element_get_node_p(void); +extern int utc_bluetooth_bt_mesh_node_foreach_element_p(void); +extern int utc_bluetooth_bt_mesh_element_foreach_models_p(void); +extern int utc_bluetooth_bt_mesh_network_create_p(void); +extern int utc_bluetooth_bt_mesh_network_load_p(void); +extern int utc_bluetooth_bt_mesh_network_set_name_p(void); +extern int utc_bluetooth_bt_mesh_network_get_name_p(void); +extern int utc_bluetooth_bt_mesh_network_add_netkey_p(void); +extern int utc_bluetooth_bt_mesh_network_foreach_netkeys_p(void); +extern int utc_bluetooth_bt_mesh_netkey_get_index_p(void); +extern int utc_bluetooth_bt_mesh_netkey_update_p(void); +extern int utc_bluetooth_bt_mesh_netkey_delete_p(void); +extern int utc_bluetooth_bt_mesh_netkey_add_appkey_p(void); +extern int utc_bluetooth_bt_mesh_netkey_foreach_appkeys_p(void); +extern int utc_bluetooth_bt_mesh_appkey_get_index_p(void); +extern int utc_bluetooth_bt_mesh_appkey_update_p(void); +extern int utc_bluetooth_bt_mesh_appkey_delete_p(void); +extern int utc_bluetooth_bt_mesh_network_foreach_devices_p(void); +extern int utc_bluetooth_bt_mesh_network_create_group_p(void); +extern int utc_bluetooth_bt_mesh_network_create_virtual_group_p(void); +extern int utc_bluetooth_bt_mesh_network_remove_group_p(void); +extern int utc_bluetooth_bt_mesh_network_foreach_groups_p(void); +extern int utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_p(void); +extern int utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_p(void); +extern int utc_bluetooth_bt_mesh_network_provision_device_p(void); +extern int utc_bluetooth_bt_mesh_authentication_set_request_cb_p(void); +extern int utc_bluetooth_bt_mesh_authentication_reply_p(void); +extern int utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_p(void); +extern void utc_bluetooth_mesh_network_negative_startup(void); +extern void utc_bluetooth_mesh_network_negative_cleanup(void); +extern int utc_bluetooth_bt_mesh_deinitialize_n(void); +extern int utc_bluetooth_bt_mesh_create_node_n(void); +extern int utc_bluetooth_bt_mesh_node_destroy_n(void); +extern int utc_bluetooth_bt_mesh_node_create_element_n(void); +extern int utc_bluetooth_bt_mesh_node_get_network_n(void); +extern int utc_bluetooth_bt_mesh_element_create_model_n(void); +extern int utc_bluetooth_bt_mesh_model_get_id_n(void); +extern int utc_bluetooth_bt_mesh_model_destroy_n(void); +extern int utc_bluetooth_bt_mesh_model_get_element_n(void); +extern int utc_bluetooth_bt_mesh_element_destroy_n(void); +extern int utc_bluetooth_bt_mesh_element_get_node_n(void); +extern int utc_bluetooth_bt_mesh_node_foreach_element_n(void); +extern int utc_bluetooth_bt_mesh_element_foreach_models_n(void); +extern int utc_bluetooth_bt_mesh_network_create_n(void); +extern int utc_bluetooth_bt_mesh_network_load_n(void); +extern int utc_bluetooth_bt_mesh_network_set_name_n(void); +extern int utc_bluetooth_bt_mesh_network_get_name_n(void); +extern int utc_bluetooth_bt_mesh_network_add_netkey_n(void); +extern int utc_bluetooth_bt_mesh_network_foreach_netkeys_n(void); +extern int utc_bluetooth_bt_mesh_netkey_get_index_n(void); +extern int utc_bluetooth_bt_mesh_netkey_update_n(void); +extern int utc_bluetooth_bt_mesh_netkey_delete_n(void); +extern int utc_bluetooth_bt_mesh_netkey_add_appkey_n(void); +extern int utc_bluetooth_bt_mesh_netkey_foreach_appkeys_n(void); +extern int utc_bluetooth_bt_mesh_appkey_get_index_n(void); +extern int utc_bluetooth_bt_mesh_appkey_update_n(void); +extern int utc_bluetooth_bt_mesh_appkey_delete_n(void); +extern int utc_bluetooth_bt_mesh_network_foreach_devices_n(void); +extern int utc_bluetooth_bt_mesh_network_create_group_n(void); +extern int utc_bluetooth_bt_mesh_network_create_virtual_group_n(void); +extern int utc_bluetooth_bt_mesh_network_remove_group_n(void); +extern int utc_bluetooth_bt_mesh_network_foreach_groups_n(void); +extern int utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_n(void); +extern int utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_n(void); +extern int utc_bluetooth_bt_mesh_network_provision_device_n(void); +extern int utc_bluetooth_bt_mesh_authentication_set_request_cb_n(void); +extern int utc_bluetooth_bt_mesh_authentication_reply_n(void); +extern int utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_n(void); + + testcase tc_array[] = { {"utc_bluetooth_bt_deinitialize_n",utc_bluetooth_bt_deinitialize_n,utc_bluetooth_adapter_negative_startup,utc_bluetooth_adapter_negative_cleanup}, @@ -940,6 +1023,83 @@ testcase tc_array[] = { {"utc_bluetooth_bt_avrcp_control_free_track_info_n",utc_bluetooth_bt_avrcp_control_free_track_info_n,utc_bluetooth_avrcp_control_negative_startup,utc_bluetooth_avrcp_control_negative_cleanup}, {"utc_bluetooth_bt_device_create_bond_p",utc_bluetooth_bt_device_create_bond_p,utc_bluetooth_device_positive_startup,utc_bluetooth_device_positive_cleanup}, {"utc_bluetooth_bt_device_destroy_bond_p",utc_bluetooth_bt_device_destroy_bond_p,utc_bluetooth_device_positive_startup,utc_bluetooth_device_positive_cleanup}, + {"utc_bluetooth_bt_mesh_initialize_p", utc_bluetooth_bt_mesh_initialize_p, utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_deinitialize_p",utc_bluetooth_bt_mesh_deinitialize_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_create_node_p",utc_bluetooth_bt_mesh_create_node_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_node_destroy_p",utc_bluetooth_bt_mesh_node_destroy_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_node_create_element_p",utc_bluetooth_bt_mesh_node_create_element_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_node_get_network_p",utc_bluetooth_bt_mesh_node_get_network_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_element_create_model_p",utc_bluetooth_bt_mesh_element_create_model_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_model_get_id_p",utc_bluetooth_bt_mesh_model_get_id_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_model_destroy_p",utc_bluetooth_bt_mesh_model_destroy_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_model_get_element_p",utc_bluetooth_bt_mesh_model_get_element_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_element_destroy_p",utc_bluetooth_bt_mesh_element_destroy_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_element_get_node_p",utc_bluetooth_bt_mesh_element_get_node_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_node_foreach_element_p",utc_bluetooth_bt_mesh_node_foreach_element_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_element_foreach_models_p",utc_bluetooth_bt_mesh_element_foreach_models_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_create_p",utc_bluetooth_bt_mesh_network_create_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_load_p",utc_bluetooth_bt_mesh_network_load_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_set_name_p",utc_bluetooth_bt_mesh_network_set_name_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_get_name_p",utc_bluetooth_bt_mesh_network_get_name_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_add_netkey_p",utc_bluetooth_bt_mesh_network_add_netkey_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_foreach_netkeys_p",utc_bluetooth_bt_mesh_network_foreach_netkeys_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_get_index_p",utc_bluetooth_bt_mesh_netkey_get_index_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_update_p",utc_bluetooth_bt_mesh_netkey_update_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_delete_p",utc_bluetooth_bt_mesh_netkey_delete_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_add_appkey_p",utc_bluetooth_bt_mesh_netkey_add_appkey_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_foreach_appkeys_p",utc_bluetooth_bt_mesh_netkey_foreach_appkeys_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_appkey_get_index_p",utc_bluetooth_bt_mesh_appkey_get_index_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_appkey_update_p",utc_bluetooth_bt_mesh_appkey_update_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_appkey_delete_p",utc_bluetooth_bt_mesh_appkey_delete_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_foreach_devices_p",utc_bluetooth_bt_mesh_network_foreach_devices_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_create_group_p",utc_bluetooth_bt_mesh_network_create_group_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_create_virtual_group_p",utc_bluetooth_bt_mesh_network_create_virtual_group_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_remove_group_p",utc_bluetooth_bt_mesh_network_remove_group_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_foreach_groups_p",utc_bluetooth_bt_mesh_network_foreach_groups_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_p",utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_p",utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_provision_device_p",utc_bluetooth_bt_mesh_network_provision_device_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_authentication_set_request_cb_p",utc_bluetooth_bt_mesh_authentication_set_request_cb_p,utc_bluetooth_mesh_network_positive_startup, utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_authentication_reply_p",utc_bluetooth_bt_mesh_authentication_reply_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_p",utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_p,utc_bluetooth_mesh_network_positive_startup,utc_bluetooth_mesh_network_positive_cleanup}, + {"utc_bluetooth_bt_mesh_deinitialize_n",utc_bluetooth_bt_mesh_deinitialize_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_create_node_n",utc_bluetooth_bt_mesh_create_node_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_node_destroy_n",utc_bluetooth_bt_mesh_node_destroy_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_node_create_element_n",utc_bluetooth_bt_mesh_node_create_element_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_node_get_network_n",utc_bluetooth_bt_mesh_node_get_network_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_element_create_model_n",utc_bluetooth_bt_mesh_element_create_model_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_model_get_id_n",utc_bluetooth_bt_mesh_model_get_id_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_model_destroy_n",utc_bluetooth_bt_mesh_model_destroy_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_model_get_element_n",utc_bluetooth_bt_mesh_model_get_element_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_element_destroy_n",utc_bluetooth_bt_mesh_element_destroy_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_element_get_node_n",utc_bluetooth_bt_mesh_element_get_node_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_node_foreach_element_n",utc_bluetooth_bt_mesh_node_foreach_element_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_element_foreach_models_n",utc_bluetooth_bt_mesh_element_foreach_models_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_create_n",utc_bluetooth_bt_mesh_network_create_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_load_n",utc_bluetooth_bt_mesh_network_load_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_set_name_n",utc_bluetooth_bt_mesh_network_set_name_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_get_name_n",utc_bluetooth_bt_mesh_network_get_name_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_add_netkey_n",utc_bluetooth_bt_mesh_network_add_netkey_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_foreach_netkeys_n",utc_bluetooth_bt_mesh_network_foreach_netkeys_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_get_index_n",utc_bluetooth_bt_mesh_netkey_get_index_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_update_n",utc_bluetooth_bt_mesh_netkey_update_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_delete_n",utc_bluetooth_bt_mesh_netkey_delete_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_add_appkey_n",utc_bluetooth_bt_mesh_netkey_add_appkey_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_netkey_foreach_appkeys_n",utc_bluetooth_bt_mesh_netkey_foreach_appkeys_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_appkey_get_index_n",utc_bluetooth_bt_mesh_appkey_get_index_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_appkey_update_n",utc_bluetooth_bt_mesh_appkey_update_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_appkey_delete_n",utc_bluetooth_bt_mesh_appkey_delete_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_foreach_devices_n",utc_bluetooth_bt_mesh_network_foreach_devices_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_create_group_n",utc_bluetooth_bt_mesh_network_create_group_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_create_virtual_group_n",utc_bluetooth_bt_mesh_network_create_virtual_group_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_remove_group_n",utc_bluetooth_bt_mesh_network_remove_group_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_foreach_groups_n",utc_bluetooth_bt_mesh_network_foreach_groups_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_n",utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_n",utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_provision_device_n",utc_bluetooth_bt_mesh_network_provision_device_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_authentication_set_request_cb_n",utc_bluetooth_bt_mesh_authentication_set_request_cb_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_authentication_reply_n",utc_bluetooth_bt_mesh_authentication_reply_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, + {"utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_n",utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_n,utc_bluetooth_mesh_network_negative_startup,utc_bluetooth_mesh_network_negative_cleanup}, {NULL, NULL} }; diff --git a/tests/unittest/utc_bluetooth_mesh_network_negative.c b/tests/unittest/utc_bluetooth_mesh_network_negative.c new file mode 100644 index 0000000..3cbf03e --- /dev/null +++ b/tests/unittest/utc_bluetooth_mesh_network_negative.c @@ -0,0 +1,1432 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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 "assert_local.h" +#include +#include "bluetooth_internal.h" +#include +#include +#include +#include +#include +#include "bluetooth_private.h" + +static int startup_flag = BT_ERROR_NONE; +static GMainLoop *mainloop = NULL; +static int ret = BT_ERROR_NONE; +static bool bt_supported = false; +static bool mesh_supported = false; + + +static bool __bt_mesh_node_foreach_elem_cb(int result, bt_mesh_node_h node, int total, + bt_mesh_element_h element, int elem_index, uint16_t element_addr, void *user_data) +{ + return true; +} + +static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total, + bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data) +{ + return true; +} + +static bool __bt_mesh_network_netkey_info_cb(int result, bt_mesh_network_h network, int total, + bt_mesh_netkey_h netkey, uint16_t netkey_index, void *user_data) +{ + return true; +} + +static void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_network_h network, + bt_mesh_scanning_state_e state, bt_mesh_scan_result_s *scan_res, void *user_data) +{ + if (mainloop) + g_main_loop_quit(mainloop); +} + +static void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network, + const char* dev_uuid, void* user_data) +{ + if (mainloop) + g_main_loop_quit(mainloop); +} + +static void wait_for_async() +{ + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); +} + +void utc_bluetooth_mesh_network_negative_startup(void) +{ + bt_supported = false; + system_info_get_platform_bool("http://tizen.org/feature/network.bluetooth", &bt_supported); + + if (bt_supported) { + startup_flag = BT_ERROR_NONE; + mesh_supported = false; + _bt_check_supported_feature(BT_FEATURE_MESH, &mesh_supported); + + if (mesh_supported) { + ret = bt_mesh_initialize(); + if (BT_ERROR_NONE != ret) { + fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__); + fprintf(stderr, "bt_mesh_initialize failed (code: %d)\n", ret); + startup_flag = ret; + return; + } + } + } +} + +void utc_bluetooth_mesh_network_negative_cleanup(void) +{ + if (mesh_supported) + bt_mesh_deinitialize(); + + + if (bt_supported) + bt_deinitialize(); +} + + +int utc_bluetooth_bt_mesh_deinitialize_n(void) +{ + int ret = BT_ERROR_NONE; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_deinitialize(); + + ret = bt_mesh_deinitialize(); + assert_eq(ret, BT_ERROR_NOT_INITIALIZED); + } else { + ret = bt_mesh_deinitialize(); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_create_node_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h local_node = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_deinitialize(); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &local_node); + assert_eq(ret, BT_ERROR_NOT_INITIALIZED); + } else { + ret = bt_mesh_node_create(&features, &local_node); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_destroy_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_h local_node = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_node_destroy(local_node); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_node_destroy(local_node); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_create_element_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_node_create_element(node_h, &elem_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_node_create_element(node_h, &elem_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_get_network_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_network_h net_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + + ret = bt_mesh_node_create_element(node_h, &elem_h); + + ret = bt_mesh_node_get_network(NULL, &net_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_node_get_network(node_h, &net_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_create_model_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_element_h elem_h1 = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + ret = bt_mesh_node_create_element(node_h, &elem_h1); + + mod_id.model_id = BT_MESH_MODEL_ID_CFG_SRV; + mod_id.company_id = 0xFFFF; + + ret = bt_mesh_element_create_model(elem_h1, &mod_id, &model_h); + assert_eq(ret, BT_ERROR_OPERATION_FAILED); + } else { + ret = bt_mesh_element_create_model(elem_h1, &mod_id, &model_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_model_get_id_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s)); + model_h = NULL; + + ret = bt_mesh_model_get_id(model_h, &mod_id); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_model_get_id(model_h, &mod_id); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_model_destroy_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s)); + model_h = NULL; + + ret = bt_mesh_model_destroy(model_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_model_destroy(model_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_model_get_element_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + elem_h = NULL; + ret = bt_mesh_model_get_element(model_h, &elem_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_model_get_element(model_h, &elem_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_destroy_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + ret = bt_mesh_deinitialize(); + ret = bt_mesh_element_destroy(elem_h); + assert_eq(ret, BT_ERROR_NOT_INITIALIZED); + } else { + ret = bt_mesh_element_destroy(elem_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_get_node_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + elem_h = NULL; + ret = bt_mesh_element_get_node(elem_h, &node_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_element_get_node(elem_h, &node_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_foreach_element_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + ret = bt_mesh_node_foreach_element(node_h, NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_foreach_models_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h element_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &element_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(element_h, &mod_id, &model_h); + + ret = bt_mesh_element_foreach_models(element_h, NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_create_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_load_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_load(NULL, &network); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_load(NULL, &network); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_set_name_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_set_name(network, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_set_name(network, network_name); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_get_name_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_get_name(network, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_get_name(network, &network_name); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_add_netkey_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h n_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_add_netkey(NULL, &n_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_add_netkey(network, &n_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_foreach_netkeys_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h n_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &n_h); + + ret = bt_mesh_network_foreach_netkeys(NULL, __bt_mesh_network_netkey_info_cb, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_foreach_netkeys(network, __bt_mesh_network_netkey_info_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_netkey_get_index_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + uint16_t indx = 0xFFFF; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_get_index(NULL, &indx); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_netkey_get_index(netkey_h, &indx); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_netkey_update_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_update(NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_netkey_update(netkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_netkey_delete_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_delete(NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_netkey_delete(netkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_netkey_add_appkey_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_add_appkey(NULL, &appkey_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_netkey_foreach_appkeys_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_foreach_appkeys(netkey_h, NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_netkey_foreach_appkeys(netkey_h, NULL, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_appkey_get_index_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + uint16_t index = 0xFFFF; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_appkey_get_index(NULL, &index); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_appkey_get_index(appkey_h, &index); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_appkey_update_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_appkey_update(NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_appkey_update(appkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_appkey_delete_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_appkey_delete(NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_appkey_delete(appkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_foreach_devices_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_network_foreach_devices(network, NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_foreach_devices(network, NULL, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_create_group_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + uint16_t group_addr = 0xc001; + bt_mesh_group_h group_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_network_create_group(NULL, group_addr, &group_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_create_virtual_group_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_network_create_virtual_group(NULL, &group_h); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_create_virtual_group(network, &group_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_remove_group_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_remove_group(NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_remove_group(group_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_foreach_groups_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_foreach_groups(network, NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_foreach_groups(network, NULL, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + bt_mesh_scan_params_s scan_params; + + memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s)); + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params, + NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + + } else { + ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params, + NULL, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + bt_mesh_scan_params_s scan_params; + + memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s)); + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params, + __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL); + wait_for_async(); + + ret = bt_mesh_stop_unprovisioned_device_scan(NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + + } else { + ret = bt_mesh_stop_unprovisioned_device_scan(network); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_provision_device_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + char *dev_uuid = "abababababababababababababababab"; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_provision_device(network, dev_uuid, NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_provision_device(network, dev_uuid, NULL, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_authentication_set_request_cb_n(void) +{ + int ret = BT_ERROR_NONE; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_authentication_set_request_cb(NULL, NULL); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_authentication_set_request_cb(NULL, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_authentication_reply_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + char *dev_uuid = "abababababababababababababababab"; + static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY; + char* value = "authentication_reply"; + bool auth_reply = TRUE; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + ret = bt_mesh_network_provision_device(network, dev_uuid, + __bt_mesh_network_device_provision_cb, NULL); + wait_for_async(); + + ret = bt_mesh_authentication_reply(request_type, NULL, auth_reply); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_n(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + bt_mesh_provisioner_capabilities_s capabilities; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + capabilities.public_oob = FALSE; + capabilities.static_oob = FALSE; + capabilities.out_oob = BT_MESH_OUT_OOB_METHOD_BLINK; + capabilities.in_oob = BT_MESH_IN_OOB_METHOD_PUSH; + + ret = bt_mesh_network_set_provisioning_capabilities(NULL, &capabilities); + assert_eq(ret, BT_ERROR_INVALID_PARAMETER); + } else { + ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} diff --git a/tests/unittest/utc_bluetooth_mesh_network_positive.c b/tests/unittest/utc_bluetooth_mesh_network_positive.c new file mode 100644 index 0000000..25ea4ac --- /dev/null +++ b/tests/unittest/utc_bluetooth_mesh_network_positive.c @@ -0,0 +1,1499 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * 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 "assert_local.h" +#include +#include "bluetooth_internal.h" +#include +#include +#include +#include +#include +#include "bluetooth_private.h" + +static int startup_flag = BT_ERROR_NONE; +static GMainLoop *mainloop = NULL; +static int ret = BT_ERROR_NONE; +static bool bt_supported = false; +static bool mesh_supported = false; + +static bool __bt_mesh_elem_foreach_model_cb(int result, bt_mesh_element_h element, int total, + bt_mesh_model_h model, bt_mesh_model_id_s *model_id, void *user_data) +{ + return true; +} + +static bool __bt_mesh_node_foreach_elem_cb(int result, bt_mesh_node_h node, int total, + bt_mesh_element_h element, int elem_index, uint16_t element_addr, void *user_data) +{ + return true; +} + +static bool __bt_mesh_network_netkey_info_cb(int result, bt_mesh_network_h network, int total, + bt_mesh_netkey_h netkey, uint16_t netkey_index, void *user_data) +{ + return true; +} + +static bool __bt_mesh_appkey_info_cb(int result, bt_mesh_network_h network, int total, bt_mesh_netkey_h netkey, + bt_mesh_appkey_h appkey, uint16_t appkey_index, void *user_data) +{ + return true; +} + +static bool __bt_mesh_network_device_info_cb(int result, bt_mesh_network_h network, int total, + const char *dev_uuid, uint16_t primary_unicast, void *user_data) +{ + return true; +} + +static bool __bt_mesh_network_group_info_cb(int result, bt_mesh_network_h network, int total, + bt_mesh_group_h group, void *user_data) +{ + return true; +} + +static void __bt_mesh_network_scan_unprovisioned_device_result_cb(int result, bt_mesh_network_h network, + bt_mesh_scanning_state_e state, bt_mesh_scan_result_s *scan_res, void *user_data) +{ + if (mainloop) + g_main_loop_quit(mainloop); +} + +static void __bt_mesh_network_device_provision_cb(int result, bt_mesh_network_h network, + const char* dev_uuid, void* user_data) +{ + if (mainloop) + g_main_loop_quit(mainloop); +} + +static void __bt_mesh_authentication_request_cb(int result, bt_mesh_authentication_type_e auth_type, + char *auth_value, void *user_data) +{ + if (mainloop) + g_main_loop_quit(mainloop); +} + +static void wait_for_async() +{ + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); +} + +void utc_bluetooth_mesh_network_positive_startup(void) +{ + bt_supported = false; + system_info_get_platform_bool("http://tizen.org/feature/network.bluetooth", &bt_supported); + + if (bt_supported) { + startup_flag = BT_ERROR_NONE; + mesh_supported = false; + _bt_check_supported_feature(BT_FEATURE_MESH, &mesh_supported); + + if (mesh_supported) { + ret = bt_mesh_initialize(); + if (BT_ERROR_NONE != ret) { + fprintf(stderr, "Startup error at %s:%d\n", __FILE__, __LINE__); + fprintf(stderr, "bt_mesh_initialize failed (code: %d)\n", ret); + startup_flag = ret; + return; + } + } + } +} + +void utc_bluetooth_mesh_network_positive_cleanup(void) +{ + if (mesh_supported) + bt_mesh_deinitialize(); + + + if (bt_supported) + bt_deinitialize(); +} + +int utc_bluetooth_bt_mesh_initialize_p(void) +{ + int ret = BT_ERROR_NONE; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_deinitialize(); + + ret = bt_mesh_initialize(); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_initialize(); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_deinitialize_p(void) +{ + int ret = BT_ERROR_NONE; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_deinitialize(); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_deinitialize(); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_create_node_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h local_node = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &local_node); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_node_create(&features, &local_node); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_destroy_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h local_node = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &local_node); + + ret = bt_mesh_node_destroy(local_node); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_node_destroy(local_node); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_create_element_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + + ret = bt_mesh_node_create_element(node_h, &elem_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_node_create_element(node_h, &elem_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_get_network_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_network_h net_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + + ret = bt_mesh_node_create_element(node_h, &elem_h); + + ret = bt_mesh_node_get_network(node_h, &net_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_node_get_network(node_h, &net_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_create_model_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_model_get_id_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + memset(&mod_id, 0x00, sizeof(bt_mesh_model_id_s)); + + ret = bt_mesh_model_get_id(model_h, &mod_id); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_model_get_id(model_h, &mod_id); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_model_destroy_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + ret = bt_mesh_model_destroy(model_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_model_destroy(model_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_model_get_element_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + elem_h = NULL; + ret = bt_mesh_model_get_element(model_h, &elem_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_model_get_element(model_h, &elem_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_destroy_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + ret = bt_mesh_element_destroy(elem_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_element_destroy(elem_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_get_node_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + ret = bt_mesh_element_get_node(elem_h, &node_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_element_get_node(elem_h, &node_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_node_foreach_element_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_node_foreach_element(node_h, __bt_mesh_node_foreach_elem_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_element_foreach_models_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h element_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &element_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(element_h, &mod_id, &model_h); + + ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_element_foreach_models(element_h, __bt_mesh_elem_foreach_model_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_create_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_load_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_load(token, &network); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_load(token, &network); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_set_name_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_set_name(network, network_name); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_set_name(network, network_name); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_get_name_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_get_name(network, &network_name); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_get_name(network, &network_name); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_add_netkey_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h n_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + + ret = bt_mesh_network_add_netkey(network, &n_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_add_netkey(network, &n_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_network_foreach_netkeys_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h n_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &n_h); + + ret = bt_mesh_network_foreach_netkeys(network, __bt_mesh_network_netkey_info_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_foreach_netkeys(network, __bt_mesh_network_netkey_info_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_netkey_get_index_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + uint16_t indx = 0xFFFF; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_get_index(netkey_h, &indx); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_netkey_get_index(netkey_h, &indx); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_netkey_update_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_update(netkey_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_netkey_update(netkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_netkey_delete_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_delete(netkey_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_netkey_delete(netkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_netkey_add_appkey_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_netkey_foreach_appkeys_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_netkey_foreach_appkeys(netkey_h, __bt_mesh_appkey_info_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + +int utc_bluetooth_bt_mesh_appkey_get_index_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + uint16_t index = 0xFFFF; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_appkey_get_index(appkey_h, &index); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_appkey_get_index(appkey_h, &index); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_appkey_update_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_appkey_update(appkey_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_appkey_update(appkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_appkey_delete_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_appkey_delete(appkey_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_appkey_delete(appkey_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_foreach_devices_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_foreach_devices(network, __bt_mesh_network_device_info_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_create_group_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + uint16_t group_addr = 0xc001; + bt_mesh_group_h group_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_create_virtual_group_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + + ret = bt_mesh_network_create_virtual_group(network, &group_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_create_virtual_group(network, &group_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_remove_group_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_remove_group(group_h); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_remove_group(group_h); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_foreach_groups_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_foreach_groups(network, __bt_mesh_network_group_info_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_foreach_groups(network, __bt_mesh_network_group_info_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_unprovisioned_device_scan_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + bt_mesh_scan_params_s scan_params; + + memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s)); + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params, + __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + wait_for_async(); + + } else { + ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params, + __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_stop_unprovisioned_device_scan_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + bt_mesh_scan_params_s scan_params; + + memset(&scan_params, 0x00, sizeof(bt_mesh_scan_params_s)); + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_unprovisioned_device_scan(network, &scan_params, + __bt_mesh_network_scan_unprovisioned_device_result_cb, NULL); + wait_for_async(); + + ret = bt_mesh_stop_unprovisioned_device_scan(network); + assert_eq(ret, BT_ERROR_NONE); + + } else { + ret = bt_mesh_stop_unprovisioned_device_scan(network); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_provision_device_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + char *dev_uuid = "abababababababababababababababab"; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + ret = bt_mesh_network_provision_device(network, dev_uuid, + __bt_mesh_network_device_provision_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + + wait_for_async(); + + } else { + ret = bt_mesh_network_provision_device(network, dev_uuid, + __bt_mesh_network_device_provision_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_authentication_set_request_cb_p(void) +{ + int ret = BT_ERROR_NONE; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + ret = bt_mesh_authentication_set_request_cb(__bt_mesh_authentication_request_cb, NULL); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_authentication_set_request_cb(__bt_mesh_authentication_request_cb, NULL); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_authentication_reply_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + char *dev_uuid = "abababababababababababababababab"; + static bt_mesh_authentication_type_e request_type = BT_MESH_AUTH_ALPHANUMERIC_DISPLAY; + char* value = "authentication_reply"; + bool auth_reply = TRUE; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + ret = bt_mesh_network_provision_device(network, dev_uuid, + __bt_mesh_network_device_provision_cb, NULL); + wait_for_async(); + + ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_authentication_reply(request_type, (const char*)value, auth_reply); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + + +int utc_bluetooth_bt_mesh_network_set_provisioning_capabilities_p(void) +{ + int ret = BT_ERROR_NONE; + bt_mesh_node_features_s features; + bt_mesh_node_h node_h = NULL; + bt_mesh_element_h elem_h = NULL; + bt_mesh_model_h model_h = NULL; + bt_mesh_model_id_s mod_id; + char *network_name = "test-mesh"; + char *token; + bt_mesh_network_h network; + bt_mesh_netkey_h netkey_h; + bt_mesh_appkey_h appkey_h; + bt_mesh_group_h group_h; + uint16_t group_addr = 0xc001; + bt_mesh_provisioner_capabilities_s capabilities; + + if (mesh_supported) { + assert_eq(startup_flag, BT_ERROR_NONE); + + features.features = BT_MESH_FEATURE_RELAY; + features.features |= BT_MESH_FEATURE_LOWPOWER; + ret = bt_mesh_node_create(&features, &node_h); + ret = bt_mesh_node_create_element(node_h, &elem_h); + + mod_id.model_id = BT_MESH_MODEL_ID_GEN_LEVEL_SRV; + mod_id.company_id = 0xFFFF; + ret = bt_mesh_element_create_model(elem_h, &mod_id, &model_h); + ret = bt_mesh_network_create(node_h, (const char*)network_name, &network, &token); + ret = bt_mesh_network_add_netkey(network, &netkey_h); + ret = bt_mesh_netkey_add_appkey(netkey_h, &appkey_h); + ret = bt_mesh_network_create_group(network, group_addr, &group_h); + + capabilities.public_oob = FALSE; + capabilities.static_oob = FALSE; + capabilities.out_oob = BT_MESH_OUT_OOB_METHOD_BLINK; + capabilities.in_oob = BT_MESH_IN_OOB_METHOD_PUSH; + + ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities); + assert_eq(ret, BT_ERROR_NONE); + } else { + ret = bt_mesh_network_set_provisioning_capabilities(network, &capabilities); + assert_eq(ret, BT_ERROR_NOT_SUPPORTED); + } + + return 0; +} + -- 2.7.4