mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-21 21:41:13 +00:00
test/gatt_service: device_information
This commit is contained in:
parent
75c13281d4
commit
1da84c0920
@ -53,6 +53,7 @@
|
|||||||
#include "ble/att_server.h"
|
#include "ble/att_server.h"
|
||||||
#include "btstack_util.h"
|
#include "btstack_util.h"
|
||||||
#include "bluetooth_gatt.h"
|
#include "bluetooth_gatt.h"
|
||||||
|
#include "btstack_debug.h"
|
||||||
|
|
||||||
#include "ble/gatt-service/device_information_service_server.h"
|
#include "ble/gatt-service/device_information_service_server.h"
|
||||||
|
|
||||||
@ -117,7 +118,7 @@ void device_information_service_server_init(void){
|
|||||||
uint16_t start_handle;
|
uint16_t start_handle;
|
||||||
uint16_t end_handle;
|
uint16_t end_handle;
|
||||||
int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION, &start_handle, &end_handle);
|
int service_found = gatt_server_get_get_handle_range_for_service_with_uuid16(ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION, &start_handle, &end_handle);
|
||||||
if (!service_found) return;
|
btstack_assert(service_found);
|
||||||
|
|
||||||
// set length for fixed size characateristics
|
// set length for fixed size characateristics
|
||||||
device_information_fields[SYSTEM_ID].data = device_information_system_id;
|
device_information_fields[SYSTEM_ID].data = device_information_system_id;
|
||||||
|
4
test/gatt_service/.gitignore
vendored
4
test/gatt_service/.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
battery_service_test
|
battery_service_test
|
||||||
battery_service_profile.h
|
battery_service_profile.h
|
||||||
|
device_information_service_test
|
||||||
|
device_information_service_profile.h
|
@ -39,7 +39,7 @@ COMMON = \
|
|||||||
|
|
||||||
COMMON_OBJ = $(COMMON:.c=.o)
|
COMMON_OBJ = $(COMMON:.c=.o)
|
||||||
|
|
||||||
all: battery_service_test
|
all: battery_service_test device_information_service_test
|
||||||
|
|
||||||
battery_service_profile.h: battery_service_profile.gatt
|
battery_service_profile.h: battery_service_profile.gatt
|
||||||
python3 ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@
|
python3 ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@
|
||||||
@ -47,11 +47,20 @@ battery_service_profile.h: battery_service_profile.gatt
|
|||||||
battery_service_test: battery_service_profile.h ${COMMON_OBJ} battery_service_test.o
|
battery_service_test: battery_service_profile.h ${COMMON_OBJ} battery_service_test.o
|
||||||
${CC} ${COMMON_OBJ} battery_service_test.o ${CFLAGS} ${LDFLAGS} -o $@
|
${CC} ${COMMON_OBJ} battery_service_test.o ${CFLAGS} ${LDFLAGS} -o $@
|
||||||
|
|
||||||
|
device_information_service_profile.h: device_information_service.gatt
|
||||||
|
python3 ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@
|
||||||
|
|
||||||
|
device_information_service_test: device_information_service_profile.h ${COMMON_OBJ} device_information_service_test.o
|
||||||
|
${CC} ${COMMON_OBJ} device_information_service_test.o ${CFLAGS} ${LDFLAGS} -o $@
|
||||||
|
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
./battery_service_test
|
./battery_service_test
|
||||||
|
./device_information_service_test
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f battery_service_test battery_service_profile.h
|
rm -f battery_service_test battery_service_profile.h
|
||||||
|
rm -f device_information_service_test device_information_service_profile.h
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
rm -rf *.dSYM
|
rm -rf *.dSYM
|
||||||
rm -f *.gcno *.gcda
|
rm -f *.gcno *.gcda
|
||||||
|
@ -28,6 +28,7 @@ static uint8_t battery_level = 100;
|
|||||||
|
|
||||||
TEST_GROUP(BATTERY_SERVICE_SERVER){
|
TEST_GROUP(BATTERY_SERVICE_SERVER){
|
||||||
att_service_handler_t * service;
|
att_service_handler_t * service;
|
||||||
|
uint16_t con_handle;
|
||||||
uint16_t battery_value_handle_value;
|
uint16_t battery_value_handle_value;
|
||||||
uint16_t battery_value_handle_client_configuration;
|
uint16_t battery_value_handle_client_configuration;
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ TEST_GROUP(BATTERY_SERVICE_SERVER){
|
|||||||
battery_service_server_init(battery_level);
|
battery_service_server_init(battery_level);
|
||||||
|
|
||||||
service = mock_att_server_get_service();
|
service = mock_att_server_get_service();
|
||||||
|
con_handle = 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
void teardown(){
|
void teardown(){
|
||||||
@ -55,14 +57,14 @@ TEST(BATTERY_SERVICE_SERVER, lookup_attribute_handles){
|
|||||||
|
|
||||||
TEST(BATTERY_SERVICE_SERVER, set_battery_value){
|
TEST(BATTERY_SERVICE_SERVER, set_battery_value){
|
||||||
// battery_value_handle_client_configuration not set
|
// battery_value_handle_client_configuration not set
|
||||||
mock().expectNCalls(0, "att_server_register_can_send_now_callback");
|
mock().expectNCalls(con_handle, "att_server_register_can_send_now_callback");
|
||||||
battery_service_server_set_battery_value(60);
|
battery_service_server_set_battery_value(60);
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
|
|
||||||
// battery_value_handle_client_configuration set
|
// battery_value_handle_client_configuration set
|
||||||
mock().expectOneCall("att_server_register_can_send_now_callback");
|
mock().expectOneCall("att_server_register_can_send_now_callback");
|
||||||
const uint8_t enable_notify[]= { 0x1, 0x0 };
|
const uint8_t enable_notify[]= { 0x1, 0x0 };
|
||||||
mock_att_service_write_callback(0, battery_value_handle_client_configuration, ATT_TRANSACTION_MODE_NONE, 0, enable_notify, sizeof(enable_notify));
|
mock_att_service_write_callback(con_handle, battery_value_handle_client_configuration, ATT_TRANSACTION_MODE_NONE, 0, enable_notify, sizeof(enable_notify));
|
||||||
battery_service_server_set_battery_value(60);
|
battery_service_server_set_battery_value(60);
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
@ -72,13 +74,13 @@ TEST(BATTERY_SERVICE_SERVER, read_battery_value){
|
|||||||
uint16_t response_len;
|
uint16_t response_len;
|
||||||
|
|
||||||
// invalid attribute handle
|
// invalid attribute handle
|
||||||
response_len = mock_att_service_read_callback(0, 0xffff, 0xffff, response, sizeof(response));
|
response_len = mock_att_service_read_callback(con_handle, 0xffff, 0xffff, response, sizeof(response));
|
||||||
CHECK_EQUAL(0, response_len);
|
CHECK_EQUAL(0, response_len);
|
||||||
|
|
||||||
response_len = mock_att_service_read_callback(0, battery_value_handle_value, 0, response, sizeof(response));
|
response_len = mock_att_service_read_callback(con_handle, battery_value_handle_value, 0, response, sizeof(response));
|
||||||
CHECK_EQUAL(1, response_len);
|
CHECK_EQUAL(1, response_len);
|
||||||
|
|
||||||
response_len = mock_att_service_read_callback(0, battery_value_handle_client_configuration, 0, response, sizeof(response));
|
response_len = mock_att_service_read_callback(con_handle, battery_value_handle_client_configuration, 0, response, sizeof(response));
|
||||||
CHECK_EQUAL(2, response_len);
|
CHECK_EQUAL(2, response_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
// add Battery Service
|
||||||
|
#import <device_information_service.gatt>
|
106
test/gatt_service/device_information_service_test.c
Normal file
106
test/gatt_service/device_information_service_test.c
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
|
||||||
|
// *****************************************************************************
|
||||||
|
//
|
||||||
|
// test battery service
|
||||||
|
//
|
||||||
|
// *****************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "CppUTest/TestHarness.h"
|
||||||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
#include "CppUTestExt/MockSupport.h"
|
||||||
|
|
||||||
|
#include "hci.h"
|
||||||
|
#include "btstack_util.h"
|
||||||
|
#include "bluetooth.h"
|
||||||
|
#include "bluetooth_gatt.h"
|
||||||
|
|
||||||
|
#include "ble/gatt-service/device_information_service_server.h"
|
||||||
|
#include "device_information_service_profile.h"
|
||||||
|
#include "mock_att_server.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t * data;
|
||||||
|
uint16_t len;
|
||||||
|
uint16_t value_handle;
|
||||||
|
} device_information_field_t;
|
||||||
|
|
||||||
|
const uint16_t device_information_characteristic_uuids[] = {
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_MANUFACTURER_NAME_STRING,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_MODEL_NUMBER_STRING,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_SERIAL_NUMBER_STRING,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_HARDWARE_REVISION_STRING,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_FIRMWARE_REVISION_STRING,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_SOFTWARE_REVISION_STRING,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_SYSTEM_ID,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST,
|
||||||
|
ORG_BLUETOOTH_CHARACTERISTIC_PNP_ID
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_GROUP(DEVICE_INFORMATION_SERVICE_SERVER){
|
||||||
|
att_service_handler_t * service;
|
||||||
|
uint16_t con_handle;
|
||||||
|
device_information_field_t device_information_fields[9];
|
||||||
|
|
||||||
|
void setup(void){
|
||||||
|
// setup database
|
||||||
|
att_set_db(profile_data);
|
||||||
|
// setup battery service
|
||||||
|
device_information_service_server_init();
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i=0;i<9;i++){
|
||||||
|
device_information_fields[i].value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(0, 0xffff, device_information_characteristic_uuids[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
device_information_service_server_set_manufacturer_name("manufacturer_name");
|
||||||
|
device_information_service_server_set_model_number("model_number");
|
||||||
|
device_information_service_server_set_serial_number("serial_number");
|
||||||
|
device_information_service_server_set_hardware_revision("hardware_revision");
|
||||||
|
device_information_service_server_set_firmware_revision("firmware_revision");
|
||||||
|
device_information_service_server_set_software_revision("software_revision");
|
||||||
|
|
||||||
|
device_information_service_server_set_system_id(0x01, 0x02);
|
||||||
|
device_information_service_server_set_ieee_regulatory_certification(0x03, 0x04);
|
||||||
|
device_information_service_server_set_pnp_id(0x05, 0x06, 0x07, 0x08);
|
||||||
|
|
||||||
|
service = mock_att_server_get_service();
|
||||||
|
con_handle = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
void teardown(){
|
||||||
|
mock().clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(DEVICE_INFORMATION_SERVICE_SERVER, lookup_attribute_handles){
|
||||||
|
// get characteristic value handles
|
||||||
|
int i;
|
||||||
|
for (i=0;i<9;i++){
|
||||||
|
CHECK(device_information_fields[i].value_handle != 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(DEVICE_INFORMATION_SERVICE_SERVER, read_values){
|
||||||
|
uint8_t response[8];
|
||||||
|
uint16_t response_len;
|
||||||
|
|
||||||
|
// invalid attribute handle
|
||||||
|
response_len = mock_att_service_read_callback(con_handle, 0xffff, 0xffff, response, sizeof(response));
|
||||||
|
CHECK_EQUAL(0, response_len);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
for (i=0;i<9;i++){
|
||||||
|
response_len = mock_att_service_read_callback(con_handle, device_information_fields[i].value_handle, 0, response, sizeof(response));
|
||||||
|
CHECK(response_len > 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (int argc, const char * argv[]){
|
||||||
|
return CommandLineTestRunner::RunAllTests(argc, argv);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user