ble client: unit test write without response

This commit is contained in:
mila@ringwald.ch 2014-04-18 22:10:13 +00:00
parent 42a267b17d
commit ecedf63ab8
2 changed files with 207 additions and 207 deletions

View File

@ -52,7 +52,9 @@ typedef enum {
WRITE_CHARACTERISTIC_DESCRIPTOR,
WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION,
READ_LONG_CHARACTERISTIC_DESCRIPTOR,
WRITE_LONG_CHARACTERISTIC_DESCRIPTOR
WRITE_LONG_CHARACTERISTIC_DESCRIPTOR,
WRITE_CHARACTERISTIC_VALUE_WITHOUT_RESPONSE
} current_test_t;
current_test_t test = IDLE;
@ -353,7 +355,7 @@ static void handle_le_central_event(le_central_event_t * event){
}
extern "C" int att_write_callback(uint16_t handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size, signature_t * signature){
// printf("gatt client test, att_write_callback mode %u, handle 0x%04x, offset %u, data ", transaction_mode, handle, offset);
printf("gatt client test, att_write_callback mode %u, handle 0x%04x, offset %u, data ", transaction_mode, handle, offset);
hexdump2(buffer, buffer_size);
switch(test){
case WRITE_CHARACTERISTIC_DESCRIPTOR:
@ -364,6 +366,7 @@ extern "C" int att_write_callback(uint16_t handle, uint16_t transaction_mode, ui
result_complete = 1;
break;
case WRITE_CHARACTERISTIC_VALUE:
case WRITE_CHARACTERISTIC_VALUE_WITHOUT_RESPONSE:
CHECK_EQUAL(ATT_TRANSACTION_MODE_NONE, transaction_mode);
CHECK_EQUAL(0, offset);
CHECK_EQUAL_ARRAY((uint8_t *)short_value, buffer, short_value_length);
@ -442,251 +445,247 @@ TEST_GROUP(GATTClient){
}
};
TEST(GATTClient, TestScanning){
le_central_start_scan();
mock_simulate_command_complete(&hci_le_set_scan_enable);
mock_simulate_scan_response();
CHECK(advertisement_received);
}
// TEST(GATTClient, TestScanning){
// le_central_start_scan();
// mock_simulate_command_complete(&hci_le_set_scan_enable);
// mock_simulate_scan_response();
// CHECK(advertisement_received);
// }
TEST(GATTClient, TestDiscoverPrimaryServices){
test = DISCOVER_PRIMARY_SERVICES;
le_central_discover_primary_services(&test_device);
CHECK(result_found);
}
// TEST(GATTClient, TestDiscoverPrimaryServices){
// test = DISCOVER_PRIMARY_SERVICES;
// le_central_discover_primary_services(&test_device);
// CHECK(result_found);
// }
TEST(GATTClient, TestDiscoverPrimaryServicesByUUID16){
test = DISCOVER_PRIMARY_SERVICE_WITH_UUID16;
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
CHECK(result_found);
}
// TEST(GATTClient, TestDiscoverPrimaryServicesByUUID16){
// test = DISCOVER_PRIMARY_SERVICE_WITH_UUID16;
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// CHECK(result_found);
// }
TEST(GATTClient, TestDiscoverPrimaryServicesByUUID128){
test = DISCOVER_PRIMARY_SERVICE_WITH_UUID128;
le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
CHECK(result_found);
}
// TEST(GATTClient, TestDiscoverPrimaryServicesByUUID128){
// test = DISCOVER_PRIMARY_SERVICE_WITH_UUID128;
// le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
// CHECK(result_found);
// }
TEST(GATTClient, TestFindIncludedServicesForServiceWithUUID16){
test = DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID16;
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
CHECK(result_found);
// TEST(GATTClient, TestFindIncludedServicesForServiceWithUUID16){
// test = DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID16;
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// CHECK(result_found);
result_index = 0;
result_found = 0;
le_central_find_included_services_for_service(&test_device, &services[0]);
CHECK(result_found);
}
// result_index = 0;
// result_found = 0;
// le_central_find_included_services_for_service(&test_device, &services[0]);
// CHECK(result_found);
// }
TEST(GATTClient, TestFindIncludedServicesForServiceWithUUID128){
test = DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID128;
le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
CHECK(result_found);
// TEST(GATTClient, TestFindIncludedServicesForServiceWithUUID128){
// test = DISCOVER_INCLUDED_SERVICE_FOR_SERVICE_WITH_UUID128;
// le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
// CHECK(result_found);
result_index = 0;
result_found = 0;
le_central_find_included_services_for_service(&test_device, &services[0]);
CHECK(result_found);
}
// result_index = 0;
// result_found = 0;
// le_central_find_included_services_for_service(&test_device, &services[0]);
// CHECK(result_found);
// }
TEST(GATTClient, TestDiscoverCharacteristicsForService){
test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_WITH_UUID16;
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
CHECK(result_found);
// TEST(GATTClient, TestDiscoverCharacteristicsForService){
// test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_WITH_UUID16;
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// CHECK(result_found);
result_found = 0;
result_index = 0;
le_central_discover_characteristics_for_service(&test_device, &services[0]);
CHECK(result_found);
}
// result_found = 0;
// result_index = 0;
// le_central_discover_characteristics_for_service(&test_device, &services[0]);
// CHECK(result_found);
// }
TEST(GATTClient, TestDiscoverCharacteristicsByUUID16){
test = DISCOVER_CHARACTERISTICS_BY_UUID16;
le_central_discover_characteristics_for_handle_range_by_uuid16(&test_device, 0x30, 0x32, 0xF102);
CHECK(result_found);
}
// TEST(GATTClient, TestDiscoverCharacteristicsByUUID16){
// test = DISCOVER_CHARACTERISTICS_BY_UUID16;
// le_central_discover_characteristics_for_handle_range_by_uuid16(&test_device, 0x30, 0x32, 0xF102);
// CHECK(result_found);
// }
TEST(GATTClient, TestDiscoverCharacteristicsByUUID128){
test = DISCOVER_CHARACTERISTICS_BY_UUID128;
le_central_discover_characteristics_for_handle_range_by_uuid128(&test_device, characteristic_handles[1][0], characteristic_handles[1][1], characteristic_uuids[1]);
CHECK(result_found);
}
// TEST(GATTClient, TestDiscoverCharacteristicsByUUID128){
// test = DISCOVER_CHARACTERISTICS_BY_UUID128;
// le_central_discover_characteristics_for_handle_range_by_uuid128(&test_device, characteristic_handles[1][0], characteristic_handles[1][1], characteristic_uuids[1]);
// CHECK(result_found);
// }
TEST(GATTClient, TestDiscoverCharacteristics4ServiceByUUID128){
test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID;
le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
CHECK(result_found);
// TEST(GATTClient, TestDiscoverCharacteristics4ServiceByUUID128){
// test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID;
// le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
// CHECK(result_found);
result_found = 0;
result_index = 0;
uint8_t characteristic_uuid[] = {0x00, 0x00, 0xF2, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
le_central_discover_characteristics_for_service_by_uuid128(&test_device, &services[0], characteristic_uuid);
CHECK(result_found);
// result_found = 0;
// result_index = 0;
// uint8_t characteristic_uuid[] = {0x00, 0x00, 0xF2, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
// le_central_discover_characteristics_for_service_by_uuid128(&test_device, &services[0], characteristic_uuid);
// CHECK(result_found);
result_found = 0;
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF200);
CHECK(result_found);
// result_found = 0;
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF200);
// CHECK(result_found);
}
// }
TEST(GATTClient, TestDiscoverCharacteristics4ServiceByUUID16){
test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID;
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
CHECK(result_found);
// TEST(GATTClient, TestDiscoverCharacteristics4ServiceByUUID16){
// test = DISCOVER_CHARACTERISTICS_FOR_SERVICE_BY_UUID;
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// CHECK(result_found);
result_found = 0;
result_index = 0;
uint8_t characteristic_uuid[]= { 0x00, 0x00, 0xF1, 0x05, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
le_central_discover_characteristics_for_service_by_uuid128(&test_device, &services[0], characteristic_uuid);
CHECK(result_found);
// result_found = 0;
// result_index = 0;
// uint8_t characteristic_uuid[]= { 0x00, 0x00, 0xF1, 0x05, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
// le_central_discover_characteristics_for_service_by_uuid128(&test_device, &services[0], characteristic_uuid);
// CHECK(result_found);
result_found = 0;
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
CHECK(result_found);
}
// result_found = 0;
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// CHECK(result_found);
// }
TEST(GATTClient, TestDiscoverCharacteristicDescriptor){
test = DISCOVER_CHARACTERISTIC_DESCRIPTORS;
le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
CHECK(result_found);
// TEST(GATTClient, TestDiscoverCharacteristicDescriptor){
// test = DISCOVER_CHARACTERISTIC_DESCRIPTORS;
// le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
// CHECK(result_found);
result_found = 0;
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
CHECK(result_found);
// result_found = 0;
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// CHECK(result_found);
result_found = 0;
result_index = 0;
le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
CHECK(result_found);
CHECK_EQUAL(3, result_index);
CHECK_EQUAL(0x2902, descriptors[0].uuid16);
CHECK_EQUAL(0x2900, descriptors[1].uuid16);
CHECK_EQUAL(0x2901, descriptors[2].uuid16);
}
// result_found = 0;
// result_index = 0;
// le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
// CHECK(result_found);
// CHECK_EQUAL(3, result_index);
// CHECK_EQUAL(0x2902, descriptors[0].uuid16);
// CHECK_EQUAL(0x2900, descriptors[1].uuid16);
// CHECK_EQUAL(0x2901, descriptors[2].uuid16);
// }
TEST(GATTClient, TestReadCharacteristicDescriptor){
test = READ_CHARACTERISTIC_DESCRIPTOR;
le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
// TEST(GATTClient, TestReadCharacteristicDescriptor){
// test = READ_CHARACTERISTIC_DESCRIPTOR;
// le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
result_found = 0;
le_central_read_characteristic_descriptor(&test_device, &descriptors[0]);
CHECK(result_found);
}
// result_found = 0;
// le_central_read_characteristic_descriptor(&test_device, &descriptors[0]);
// CHECK(result_found);
// }
TEST(GATTClient, TestWriteCharacteristicDescriptor){
test = WRITE_CHARACTERISTIC_DESCRIPTOR;
le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
// TEST(GATTClient, TestWriteCharacteristicDescriptor){
// test = WRITE_CHARACTERISTIC_DESCRIPTOR;
// le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
result_found = 0;
le_central_write_characteristic_descriptor(&test_device, &descriptors[0], sizeof(indication), indication);
CHECK(result_found);
}
// result_found = 0;
// le_central_write_characteristic_descriptor(&test_device, &descriptors[0], sizeof(indication), indication);
// CHECK(result_found);
// }
TEST(GATTClient, TestWriteClientCharacteristicConfiguration){
test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION;
le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// TEST(GATTClient, TestWriteClientCharacteristicConfiguration){
// test = WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION;
// le_central_discover_primary_services_by_uuid16(&test_device, 0xF000);
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
result_found = 0;
le_central_write_client_characteristic_configuration(&test_device, &characteristics[0], GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
CHECK(result_found);
}
// result_found = 0;
// le_central_write_client_characteristic_configuration(&test_device, &characteristics[0], GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION);
// CHECK(result_found);
// }
TEST(GATTClient, TestReadLongCharacteristicDescriptor){
test = READ_LONG_CHARACTERISTIC_DESCRIPTOR;
le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF200);
result_index = 0;
le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
CHECK(result_found);
// TEST(GATTClient, TestReadLongCharacteristicDescriptor){
// test = READ_LONG_CHARACTERISTIC_DESCRIPTOR;
// le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF200);
// result_index = 0;
// le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
// CHECK(result_found);
result_found = 0;
le_central_read_long_characteristic_descriptor(&test_device, &descriptors[0]);
CHECK(result_found);
}
// result_found = 0;
// le_central_read_long_characteristic_descriptor(&test_device, &descriptors[0]);
// CHECK(result_found);
// }
TEST(GATTClient, TestWriteLongCharacteristicDescriptor){
test = WRITE_LONG_CHARACTERISTIC_DESCRIPTOR;
le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF200);
result_index = 0;
le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
// TEST(GATTClient, TestWriteLongCharacteristicDescriptor){
// test = WRITE_LONG_CHARACTERISTIC_DESCRIPTOR;
// le_central_discover_primary_services_by_uuid128(&test_device, primary_service_uuid128);
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF200);
// result_index = 0;
// le_central_discover_characteristic_descriptors(&test_device, &characteristics[0]);
result_found = 0;
le_central_write_long_characteristic_descriptor(&test_device, &descriptors[0], sizeof(long_value), (uint8_t *)long_value);
CHECK(result_found);
}
// result_found = 0;
// le_central_write_long_characteristic_descriptor(&test_device, &descriptors[0], sizeof(long_value), (uint8_t *)long_value);
// CHECK(result_found);
// }
TEST(GATTClient, TestReadCharacteristicValue){
test = READ_CHARACTERISTIC_VALUE;
// TEST(GATTClient, TestReadCharacteristicValue){
// test = READ_CHARACTERISTIC_VALUE;
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
result_found = 0;
le_central_read_value_of_characteristic(&test_device, &characteristics[0]);
CHECK(result_found);
}
// result_found = 0;
// le_central_read_value_of_characteristic(&test_device, &characteristics[0]);
// CHECK(result_found);
// }
TEST(GATTClient, TestReadLongCharacteristicValue){
test = READ_LONG_CHARACTERISTIC_VALUE;
// TEST(GATTClient, TestReadLongCharacteristicValue){
// test = READ_LONG_CHARACTERISTIC_VALUE;
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// result_found = 0;
// le_central_read_long_value_of_characteristic(&test_device, &characteristics[0]);
// CHECK(result_found);
// }
// TEST(GATTClient, TestWriteCharacteristicValue){
// test = WRITE_CHARACTERISTIC_VALUE;
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// result_found = 0;
// le_central_write_value_of_characteristic(&test_device, characteristics[0].value_handle, short_value_length, (uint8_t*)short_value);
// CHECK(result_found);
// }
// TEST(GATTClient, TestWriteLongCharacteristicValue){
// test = WRITE_LONG_CHARACTERISTIC_VALUE;
// le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
// result_index = 0;
// le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
// result_found = 0;
// le_central_write_long_value_of_characteristic(&test_device, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value);
// CHECK(result_found);
// }
TEST(GATTClient, TestWriteCharacteristicValueWithoutResponse){
test = WRITE_CHARACTERISTIC_VALUE_WITHOUT_RESPONSE;
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF10D);
result_found = 0;
le_central_read_long_value_of_characteristic(&test_device, &characteristics[0]);
CHECK(result_found);
}
TEST(GATTClient, TestWriteCharacteristicValue){
test = WRITE_CHARACTERISTIC_VALUE;
printf(" test = WRITE_CHARACTERISTIC_VALUE\n");
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
result_found = 0;
le_central_write_value_of_characteristic(&test_device, characteristics[0].value_handle, short_value_length, (uint8_t*)short_value);
CHECK(result_found);
}
TEST(GATTClient, TestWriteLongCharacteristicValue){
test = WRITE_LONG_CHARACTERISTIC_VALUE;
printf(" test = WRITE_LONG_CHARACTERISTIC_VALUE\n");
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
result_found = 0;
le_central_write_long_value_of_characteristic(&test_device, characteristics[0].value_handle, long_value_length, (uint8_t*)long_value);
CHECK(result_found);
}
TEST(GATTClient, TestWriteLongCharacteristicValueWithoutResponse){
test = WRITE_LONG_CHARACTERISTIC_VALUE;
printf(" test = WRITE_LONG_CHARACTERISTIC_VALUE\n");
le_central_discover_primary_services_by_uuid16(&test_device, service_uuid16);
result_index = 0;
le_central_discover_characteristics_for_service_by_uuid16(&test_device, &services[0], 0xF100);
result_found = 0;
le_central_write_value_of_characteristic_without_response(&test_device, characteristics[0].value_handle, short_value_length, (uint8_t*)short_value);
CHECK(result_found);
CHECK(result_complete);
}
/*

View File

@ -96,8 +96,9 @@ int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t l
att_init_connection(&att_connection);
uint8_t response[max_mtu];
uint16_t response_len = att_handle_request(&att_connection, l2cap_get_outgoing_buffer(), len, &response[0]);
att_packet_handler(ATT_DATA_PACKET, 0x40, &response[0], response_len);
if (response_len){
att_packet_handler(ATT_DATA_PACKET, 0x40, &response[0], response_len);
}
return 0;
}