xref: /btstack/test/gatt_service_server/heart_rate_service_server_test.cpp (revision c824d78c0a34df89b57d535abafcc7dacf30bb06)
1 
2 // *****************************************************************************
3 //
4 // test battery service
5 //
6 // *****************************************************************************
7 
8 
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 
14 #include "CppUTest/TestHarness.h"
15 #include "CppUTest/CommandLineTestRunner.h"
16 #include "CppUTestExt/MockSupport.h"
17 
18 #include "hci.h"
19 #include "btstack_util.h"
20 #include "bluetooth.h"
21 #include "bluetooth_gatt.h"
22 
23 #include "ble/gatt-service/heart_rate_service_server.h"
24 #include "heart_rate_service_server_test.h"
25 #include "mock_att_server.h"
26 
27 
28 TEST_GROUP(HEART_RATE_SERVER){
29     att_service_handler_t * service;
30     uint16_t con_handle;
31     heart_rate_service_body_sensor_location_t location;
32     int energy_expended_supported;
33     uint16_t body_sensor_location_value_handle;
34     uint16_t heart_rate_measurement_configuration_handle;
35 
36     void setup(void){
37         // setup database
38         att_set_db(profile_data);
39 
40         body_sensor_location_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(0, 0xFFFF, ORG_BLUETOOTH_CHARACTERISTIC_BODY_SENSOR_LOCATION);
41         heart_rate_measurement_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(0, 0xFFFF, ORG_BLUETOOTH_CHARACTERISTIC_HEART_RATE_MEASUREMENT);
42 
43         energy_expended_supported = 1;
44         location = HEART_RATE_SERVICE_BODY_SENSOR_LOCATION_OTHER;
45 
46         // setup heart rate service
47         heart_rate_service_server_init(location, energy_expended_supported);
48 
49         service = mock_att_server_get_service();
50         con_handle = 0x00;
51     }
52 
53     void teardown(){
54         mock_deinit();
55     }
56 };
57 
58 
59 TEST(HEART_RATE_SERVER, read_callback_test){
60     uint8_t response[2];
61     uint16_t response_len;
62 
63     // invalid attribute handle
64     response_len = mock_att_service_read_callback(con_handle, 0xffff, 0xffff, response, sizeof(response));
65     CHECK_EQUAL(0, response_len);
66 
67     // get location value length (1 byte length)
68     response_len = mock_att_service_read_callback(con_handle, body_sensor_location_value_handle, 0, NULL, 0);
69     CHECK_EQUAL(1, response_len);
70 
71     // get location value (1 byte length)
72     response_len = mock_att_service_read_callback(con_handle, body_sensor_location_value_handle, 0, response, sizeof(response));
73     CHECK_EQUAL(1, response_len);
74 
75     // get rate measurement configuration length (2 byte length)
76     response_len = mock_att_service_read_callback(con_handle, heart_rate_measurement_configuration_handle, 0, NULL, 0);
77     CHECK_EQUAL(2, response_len);
78 
79     // get rate measurement configuration (2 byte length)
80     response_len = mock_att_service_read_callback(con_handle, heart_rate_measurement_configuration_handle, 0, response, sizeof(response));
81     CHECK_EQUAL(2, response_len);
82 }
83 
84 int main (int argc, const char * argv[]){
85     return CommandLineTestRunner::RunAllTests(argc, argv);
86 }
87