test/gatt-service-client: add tests

This commit is contained in:
Milanka Ringwald 2024-04-17 12:32:51 +02:00
parent 500d8180fa
commit 8182555f6b
2 changed files with 38 additions and 21 deletions

View File

@ -153,6 +153,7 @@ TEST(ANCS_CLIENT, ignored_events){
// default hci event
uint8_t some_other_event[] = { 0, 0};
mock_hci_emit_event(some_other_event, sizeof(some_other_event));
// default hci le subevent
uint8_t some_le_event[] = { HCI_EVENT_LE_META, 1, 0};
mock_hci_emit_event(some_le_event, sizeof(some_le_event));
@ -166,6 +167,10 @@ TEST(ANCS_CLIENT, ignored_events){
mock_hci_emit_disconnection_complete(ancs_con_handle+1,0);
// disconnected different handle
mock_hci_emit_disconnection_complete(ancs_con_handle,0);
// some hci gap meta subevent
uint8_t some_gap_meta_event[] = { HCI_EVENT_META_GAP, 1, HCI_SUBEVENT_LE_CONNECTION_COMPLETE + 1};
mock_hci_emit_event(some_gap_meta_event, sizeof(some_gap_meta_event));
}
TEST(ANCS_CLIENT, connect_no_service){
@ -178,19 +183,6 @@ TEST(ANCS_CLIENT, connect_unexpected_event_during_service_disc){
mock_gatt_client_emit_dummy_event();
}
TEST(ANCS_CLIENT, connect_unexpected_events){
setup_service(true, true);
connect();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
}
TEST(ANCS_CLIENT, connect){
setup_service(true, true);
connect();
@ -280,6 +272,27 @@ TEST(ANCS_CLIENT, notifications_invalid_parser){
mock_gatt_client_send_notification(ancs_data_source_characteristic, data, sizeof(data));
}
TEST(ANCS_CLIENT, connect_unexpected_events){
printf("connect_unexpected_events\n");
setup_service(true, true);
connect();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
}
TEST(ANCS_CLIENT, connect_unexpected_events_in_idle_state){
printf("connect_unexpected_events\n");
connect();
mock_gatt_client_run_once();
mock_gatt_client_emit_dummy_event();
}
int main (int argc, const char * argv[]){
return CommandLineTestRunner::RunAllTests(argc, argv);
}

View File

@ -524,24 +524,28 @@ TEST(BATTERY_SERVICE_CLIENT, mixed_poll_and_notify_battery_value){
CHECK_EQUAL(true, connected);
}
TEST(BATTERY_SERVICE_CLIENT, disconnect){
TEST(BATTERY_SERVICE_CLIENT, hci_disconnect_event){
setup_service(true, true);
connect();
CHECK_EQUAL(true, connected);
uint8_t status;
// send unexpected event
mock_hci_emit_connection_encrypted(con_handle, 0);
mock_hci_emit_disconnection_complete(con_handle, 0);
status = battery_service_client_disconnect(battery_service_cid);
uint8_t status = battery_service_client_disconnect(battery_service_cid);
CHECK_EQUAL(ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, status);
// send event with wrong con handle
mock_hci_emit_disconnection_complete(HCI_CON_HANDLE_INVALID, 0);
}
TEST(BATTERY_SERVICE_CLIENT, ignored_events){
setup_service(true, true);
connect();
CHECK_EQUAL(true, connected);
// unexpected event
mock_hci_emit_connection_encrypted(con_handle, 0);
// event with wrong con handle
mock_hci_emit_disconnection_complete(HCI_CON_HANDLE_INVALID, 0);
}
int main (int argc, const char * argv[]){
return CommandLineTestRunner::RunAllTests(argc, argv);