xref: /btstack/test/gatt-service-client/device_information_service_client_test.cpp (revision f0ffc42b698678cc25e84949a34fe343a8c5e8e8)
14902524cSMatthias Ringwald 
24902524cSMatthias Ringwald // *****************************************************************************
34902524cSMatthias Ringwald //
44902524cSMatthias Ringwald // test Battery Service Client
54902524cSMatthias Ringwald //
64902524cSMatthias Ringwald // *****************************************************************************
74902524cSMatthias Ringwald 
84902524cSMatthias Ringwald 
94902524cSMatthias Ringwald #include <stdint.h>
104902524cSMatthias Ringwald #include <stdio.h>
114902524cSMatthias Ringwald #include <stdlib.h>
124902524cSMatthias Ringwald #include <string.h>
134902524cSMatthias Ringwald 
144902524cSMatthias Ringwald #include "CppUTest/TestHarness.h"
154902524cSMatthias Ringwald #include "CppUTest/CommandLineTestRunner.h"
164902524cSMatthias Ringwald #include "CppUTestExt/MockSupport.h"
174902524cSMatthias Ringwald 
184902524cSMatthias Ringwald #include "bluetooth.h"
194902524cSMatthias Ringwald #include "bluetooth_gatt.h"
204902524cSMatthias Ringwald #include "btstack_debug.h"
214902524cSMatthias Ringwald #include "btstack_event.h"
224902524cSMatthias Ringwald #include "btstack_memory.h"
234902524cSMatthias Ringwald #include "btstack_util.h"
244902524cSMatthias Ringwald #include "hci.h"
254902524cSMatthias Ringwald 
264902524cSMatthias Ringwald #include "ble/gatt-service/device_information_service_client.h"
274902524cSMatthias Ringwald #include "mock_gatt_client.h"
284902524cSMatthias Ringwald 
294902524cSMatthias Ringwald static const hci_con_handle_t con_handle = 0x01;
304902524cSMatthias Ringwald static bool connected;
314902524cSMatthias Ringwald 
324902524cSMatthias Ringwald // temp btstack run loop mock
334902524cSMatthias Ringwald 
344902524cSMatthias Ringwald static btstack_timer_source_t * btstack_timer = NULL;
354902524cSMatthias Ringwald 
364902524cSMatthias Ringwald static bool manufacturer_name = false;
374902524cSMatthias Ringwald static bool model_number = false;
384902524cSMatthias Ringwald static bool serial_number = false;
394902524cSMatthias Ringwald static bool hardware_revision = false;
404902524cSMatthias Ringwald static bool firmware_revision = false;
414902524cSMatthias Ringwald static bool software_revision = false;
424902524cSMatthias Ringwald static bool system_id = false;
434902524cSMatthias Ringwald static bool ieee_regulatory_certification = false;
444902524cSMatthias Ringwald static bool pnp_id = false;
454902524cSMatthias Ringwald 
464902524cSMatthias Ringwald static bool mock_wrong_hci_event_packet_type = false;
474902524cSMatthias Ringwald 
484902524cSMatthias Ringwald extern "C" void device_information_service_client_set_invalid_state(void);
494902524cSMatthias Ringwald 
btstack_run_lopo_deinit(void)504902524cSMatthias Ringwald void btstack_run_lopo_deinit(void){
514902524cSMatthias Ringwald         btstack_timer = NULL;
524902524cSMatthias Ringwald }
534902524cSMatthias Ringwald 
btstack_run_loop_add_timer(btstack_timer_source_t * timer)544902524cSMatthias Ringwald void btstack_run_loop_add_timer(btstack_timer_source_t * timer){
554902524cSMatthias Ringwald     btstack_timer = timer;
564902524cSMatthias Ringwald }
574902524cSMatthias Ringwald 
btstack_run_loop_remove_timer(btstack_timer_source_t * timer)584902524cSMatthias Ringwald int btstack_run_loop_remove_timer(btstack_timer_source_t * timer){
594902524cSMatthias Ringwald     btstack_timer = NULL;
604902524cSMatthias Ringwald     return 1;
614902524cSMatthias Ringwald }
624902524cSMatthias Ringwald 
btstack_run_loop_set_timer(btstack_timer_source_t * timer,uint32_t timeout_in_ms)634902524cSMatthias Ringwald void btstack_run_loop_set_timer(btstack_timer_source_t * timer, uint32_t timeout_in_ms){
644902524cSMatthias Ringwald }
654902524cSMatthias Ringwald 
btstack_run_loop_set_timer_handler(btstack_timer_source_t * timer,void (* process)(btstack_timer_source_t * _timer))664902524cSMatthias Ringwald void btstack_run_loop_set_timer_handler(btstack_timer_source_t * timer, void (*process)(btstack_timer_source_t * _timer)){
674902524cSMatthias Ringwald     timer->process = process;
684902524cSMatthias Ringwald }
694902524cSMatthias Ringwald 
btstack_run_loop_set_timer_context(btstack_timer_source_t * timer,void * context)704902524cSMatthias Ringwald void btstack_run_loop_set_timer_context(btstack_timer_source_t * timer, void * context){
714902524cSMatthias Ringwald     timer->context = context;
724902524cSMatthias Ringwald }
734902524cSMatthias Ringwald 
btstack_run_loop_get_timer_context(btstack_timer_source_t * timer)744902524cSMatthias Ringwald void * btstack_run_loop_get_timer_context(btstack_timer_source_t * timer){
754902524cSMatthias Ringwald     return timer->context;
764902524cSMatthias Ringwald }
774902524cSMatthias Ringwald 
mock_btstack_run_loop_trigger_timer(void)784902524cSMatthias Ringwald void mock_btstack_run_loop_trigger_timer(void){
794902524cSMatthias Ringwald     btstack_assert(btstack_timer != NULL);
804902524cSMatthias Ringwald     (*btstack_timer->process)(btstack_timer);
814902524cSMatthias Ringwald }
824902524cSMatthias Ringwald 
834902524cSMatthias Ringwald // simulate  btstack_memory_battery_service_client_get
844902524cSMatthias Ringwald 
854902524cSMatthias Ringwald static bool mock_btstack_memory_battery_service_client_no_memory;
864902524cSMatthias Ringwald static battery_service_client_t * mock_btstack_memory_battery_service_client_last_alloc;
874902524cSMatthias Ringwald 
btstack_memory_init(void)884902524cSMatthias Ringwald void btstack_memory_init(void){
894902524cSMatthias Ringwald     mock_btstack_memory_battery_service_client_no_memory = false;
904902524cSMatthias Ringwald     mock_btstack_memory_battery_service_client_last_alloc = NULL;
914902524cSMatthias Ringwald }
924902524cSMatthias Ringwald 
mock_btstack_memory_battery_service_client_simulate_no_memory(void)934902524cSMatthias Ringwald void mock_btstack_memory_battery_service_client_simulate_no_memory(void){
944902524cSMatthias Ringwald     mock_btstack_memory_battery_service_client_no_memory = true;
954902524cSMatthias Ringwald }
964902524cSMatthias Ringwald 
mock_btstack_memory_battery_service_client_get_last_alloc(void)974902524cSMatthias Ringwald battery_service_client_t * mock_btstack_memory_battery_service_client_get_last_alloc(void){
984902524cSMatthias Ringwald     btstack_assert(mock_btstack_memory_battery_service_client_last_alloc != NULL);
994902524cSMatthias Ringwald     return mock_btstack_memory_battery_service_client_last_alloc;
1004902524cSMatthias Ringwald }
1014902524cSMatthias Ringwald 
btstack_memory_battery_service_client_get(void)1024902524cSMatthias Ringwald battery_service_client_t * btstack_memory_battery_service_client_get(void){
1034902524cSMatthias Ringwald     if (mock_btstack_memory_battery_service_client_no_memory){
1044902524cSMatthias Ringwald         return NULL;
1054902524cSMatthias Ringwald     }
1064902524cSMatthias Ringwald     mock_btstack_memory_battery_service_client_last_alloc =  (battery_service_client_t *) malloc(sizeof(battery_service_client_t));
1074902524cSMatthias Ringwald     memset(mock_btstack_memory_battery_service_client_last_alloc, 0, sizeof(battery_service_client_t));
1084902524cSMatthias Ringwald     return mock_btstack_memory_battery_service_client_last_alloc;
1094902524cSMatthias Ringwald }
1104902524cSMatthias Ringwald 
btstack_memory_battery_service_client_free(battery_service_client_t * battery_service_client)1114902524cSMatthias Ringwald void btstack_memory_battery_service_client_free(battery_service_client_t *battery_service_client){
1124902524cSMatthias Ringwald     free(battery_service_client);
1134902524cSMatthias Ringwald }
1144902524cSMatthias Ringwald 
gatt_client_event_handler(uint8_t packet_type,uint16_t channel,uint8_t * packet,uint16_t size)1154902524cSMatthias Ringwald static void gatt_client_event_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
1164902524cSMatthias Ringwald     UNUSED(packet_type);
1174902524cSMatthias Ringwald     UNUSED(channel);
1184902524cSMatthias Ringwald     UNUSED(size);
1194902524cSMatthias Ringwald 
1204902524cSMatthias Ringwald     uint8_t status;
1214902524cSMatthias Ringwald     // uint8_t att_status;
1224902524cSMatthias Ringwald 
1234902524cSMatthias Ringwald     if (hci_event_packet_get_type(packet) != HCI_EVENT_GATTSERVICE_META){
1244902524cSMatthias Ringwald         return;
1254902524cSMatthias Ringwald     }
1264902524cSMatthias Ringwald 
1274902524cSMatthias Ringwald     switch (hci_event_gattservice_meta_get_subevent_code(packet)){
1284902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_DONE:
1294902524cSMatthias Ringwald             status = gattservice_subevent_device_information_done_get_att_status(packet);
1304902524cSMatthias Ringwald             switch (status){
1314902524cSMatthias Ringwald                 case ATT_ERROR_SUCCESS:
1324902524cSMatthias Ringwald                     connected = true;
1334902524cSMatthias Ringwald                     break;
1344902524cSMatthias Ringwald                 default:
1354902524cSMatthias Ringwald                     connected = false;
1364902524cSMatthias Ringwald                     break;
1374902524cSMatthias Ringwald             }
1384902524cSMatthias Ringwald             break;
1394902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MANUFACTURER_NAME:
1404902524cSMatthias Ringwald             manufacturer_name = true;
1414902524cSMatthias Ringwald             break;
1424902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MODEL_NUMBER:
1434902524cSMatthias Ringwald             model_number = true;
1444902524cSMatthias Ringwald             break;
1454902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SERIAL_NUMBER:
1464902524cSMatthias Ringwald             serial_number = true;
1474902524cSMatthias Ringwald             break;
1484902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_HARDWARE_REVISION:
1494902524cSMatthias Ringwald             hardware_revision = true;
1504902524cSMatthias Ringwald             break;
1514902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_FIRMWARE_REVISION:
1524902524cSMatthias Ringwald             firmware_revision = true;
1534902524cSMatthias Ringwald             break;
1544902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SOFTWARE_REVISION:
1554902524cSMatthias Ringwald             software_revision = true;
1564902524cSMatthias Ringwald             break;
1574902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SYSTEM_ID:
1584902524cSMatthias Ringwald             system_id = true;
1594902524cSMatthias Ringwald             break;
1604902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_IEEE_REGULATORY_CERTIFICATION:
1614902524cSMatthias Ringwald             ieee_regulatory_certification = true;
1624902524cSMatthias Ringwald             break;
1634902524cSMatthias Ringwald         case GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_PNP_ID:
1644902524cSMatthias Ringwald             pnp_id = true;
1654902524cSMatthias Ringwald             break;
1664902524cSMatthias Ringwald 
1674902524cSMatthias Ringwald         default:
1684902524cSMatthias Ringwald             break;
1694902524cSMatthias Ringwald     }
1704902524cSMatthias Ringwald }
1714902524cSMatthias Ringwald 
TEST_GROUP(DEVICE_INFORMATION_SERVICE_CLIENT)1724902524cSMatthias Ringwald TEST_GROUP(DEVICE_INFORMATION_SERVICE_CLIENT){
1734902524cSMatthias Ringwald     mock_gatt_client_service_t * service;
1744902524cSMatthias Ringwald     mock_gatt_client_characteristic_t * characteristic;
1754902524cSMatthias Ringwald 
1764902524cSMatthias Ringwald     void setup(void){
1774902524cSMatthias Ringwald         mock_wrong_hci_event_packet_type = false;
1784902524cSMatthias Ringwald         manufacturer_name = false;
1794902524cSMatthias Ringwald         model_number = false;
1804902524cSMatthias Ringwald         serial_number = false;
1814902524cSMatthias Ringwald         hardware_revision = false;
1824902524cSMatthias Ringwald         firmware_revision = false;
1834902524cSMatthias Ringwald         software_revision = false;
1844902524cSMatthias Ringwald         system_id = false;
1854902524cSMatthias Ringwald         ieee_regulatory_certification = false;
1864902524cSMatthias Ringwald         pnp_id = false;
1874902524cSMatthias Ringwald 
1884902524cSMatthias Ringwald         device_information_service_client_init();
1894902524cSMatthias Ringwald         mock_gatt_client_reset();
1904902524cSMatthias Ringwald     }
1914902524cSMatthias Ringwald 
1924902524cSMatthias Ringwald     void setup_service(bool add_characteristic){
1934902524cSMatthias Ringwald         uint8_t buffer[] = {0x01, 0x02};
1944902524cSMatthias Ringwald         service = mock_gatt_client_add_primary_service_uuid16(ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION);
1954902524cSMatthias Ringwald 
1964902524cSMatthias Ringwald         if (!add_characteristic) return;
1974902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_MANUFACTURER_NAME_STRING, ATT_PROPERTY_READ);
1984902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, buffer, sizeof(buffer));
1994902524cSMatthias Ringwald     }
2004902524cSMatthias Ringwald 
2014902524cSMatthias Ringwald     void setup_full_service(void){
2024902524cSMatthias Ringwald         static uint8_t buffer[] = {0x01, 0x02};
2034902524cSMatthias Ringwald         static uint8_t system_id_buffer[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
2044902524cSMatthias Ringwald         static uint8_t ieee_buffer[]  = {0x01, 0x02, 0x03, 0x04};
2054902524cSMatthias Ringwald         static uint8_t pnp_id_buffer[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
2064902524cSMatthias Ringwald 
2074902524cSMatthias Ringwald         service = mock_gatt_client_add_primary_service_uuid16(ORG_BLUETOOTH_SERVICE_DEVICE_INFORMATION);
2084902524cSMatthias Ringwald 
2094902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_MANUFACTURER_NAME_STRING, ATT_PROPERTY_READ);
2104902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, buffer, sizeof(buffer));
2114902524cSMatthias Ringwald 
2124902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_MODEL_NUMBER_STRING     , ATT_PROPERTY_READ);
2134902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, buffer, sizeof(buffer));
2144902524cSMatthias Ringwald 
2154902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_SERIAL_NUMBER_STRING    , ATT_PROPERTY_READ);
2164902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, buffer, sizeof(buffer));
2174902524cSMatthias Ringwald 
2184902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_HARDWARE_REVISION_STRING, ATT_PROPERTY_READ);
2194902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, buffer, sizeof(buffer));
2204902524cSMatthias Ringwald 
2214902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_FIRMWARE_REVISION_STRING, ATT_PROPERTY_READ);
2224902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, buffer, sizeof(buffer));
2234902524cSMatthias Ringwald 
2244902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_SOFTWARE_REVISION_STRING, ATT_PROPERTY_READ);
2254902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, buffer, sizeof(buffer));
2264902524cSMatthias Ringwald 
2274902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_SYSTEM_ID, ATT_PROPERTY_READ);
2284902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, system_id_buffer, sizeof(system_id_buffer));
2294902524cSMatthias Ringwald 
2304902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST, ATT_PROPERTY_READ);
2314902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, ieee_buffer, sizeof(ieee_buffer));
2324902524cSMatthias Ringwald 
2334902524cSMatthias Ringwald         characteristic = mock_gatt_client_add_characteristic_uuid16(ORG_BLUETOOTH_CHARACTERISTIC_PNP_ID, ATT_PROPERTY_READ);
2344902524cSMatthias Ringwald         mock_gatt_client_set_characteristic_value(characteristic, pnp_id_buffer, sizeof(pnp_id_buffer));
2354902524cSMatthias Ringwald     }
2364902524cSMatthias Ringwald 
2374902524cSMatthias Ringwald     void teardown(void){
2384902524cSMatthias Ringwald         device_information_service_client_deinit();
2394902524cSMatthias Ringwald     }
2404902524cSMatthias Ringwald };
2414902524cSMatthias Ringwald 
2424902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,double_query)2434902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, double_query){
2444902524cSMatthias Ringwald     uint8_t status;
2454902524cSMatthias Ringwald 
2464902524cSMatthias Ringwald     status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
2474902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
2484902524cSMatthias Ringwald 
2494902524cSMatthias Ringwald     status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
2504902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_COMMAND_DISALLOWED, status);
251*f0ffc42bSMilanka Ringwald 
252*f0ffc42bSMilanka Ringwald     status = device_information_service_client_query(HCI_CON_HANDLE_INVALID, &gatt_client_event_handler);
253*f0ffc42bSMilanka Ringwald     CHECK_EQUAL(ERROR_CODE_COMMAND_DISALLOWED, status);
2544902524cSMatthias Ringwald }
2554902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,query_no_service)2564902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, query_no_service){
2574902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
2584902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
2594902524cSMatthias Ringwald 
2604902524cSMatthias Ringwald     mock_gatt_client_run();
2614902524cSMatthias Ringwald     CHECK_EQUAL(false, connected);
2624902524cSMatthias Ringwald }
2634902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,query_service_no_caharacteristic)2644902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, query_service_no_caharacteristic){
2654902524cSMatthias Ringwald     setup_service(false);
2664902524cSMatthias Ringwald 
2674902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
2684902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
2694902524cSMatthias Ringwald 
2704902524cSMatthias Ringwald     mock_gatt_client_run();
2714902524cSMatthias Ringwald     CHECK_EQUAL(false, connected);
2724902524cSMatthias Ringwald }
2734902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,query_service_att_error)2744902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, query_service_att_error){
2754902524cSMatthias Ringwald     setup_service(false);
2764902524cSMatthias Ringwald     mock_gatt_client_set_att_error_discover_primary_services();
2774902524cSMatthias Ringwald 
2784902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
2794902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
2804902524cSMatthias Ringwald 
2814902524cSMatthias Ringwald     mock_gatt_client_run();
2824902524cSMatthias Ringwald     CHECK_EQUAL(false, connected);
2834902524cSMatthias Ringwald }
2844902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,query_service_one_chr)2854902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, query_service_one_chr){
2864902524cSMatthias Ringwald     setup_service(true);
2874902524cSMatthias Ringwald 
2884902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
2894902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
2904902524cSMatthias Ringwald 
2914902524cSMatthias Ringwald     mock_gatt_client_run();
2924902524cSMatthias Ringwald     CHECK_EQUAL(true, connected);
2934902524cSMatthias Ringwald }
2944902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,query_service_one_chr_att_error)2954902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, query_service_one_chr_att_error){
2964902524cSMatthias Ringwald     setup_service(true);
2974902524cSMatthias Ringwald     mock_gatt_client_set_att_error_read_value_characteristics();
2984902524cSMatthias Ringwald     // mock_gatt_client_dump_services();
2994902524cSMatthias Ringwald 
3004902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
3014902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
3024902524cSMatthias Ringwald 
3034902524cSMatthias Ringwald     mock_gatt_client_run();
3044902524cSMatthias Ringwald     CHECK_EQUAL(true, connected);
3054902524cSMatthias Ringwald }
3064902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,query_service_full_setup_no_error)3074902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, query_service_full_setup_no_error){
3084902524cSMatthias Ringwald     setup_full_service();
3094902524cSMatthias Ringwald 
3104902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
3114902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
3124902524cSMatthias Ringwald 
3134902524cSMatthias Ringwald     mock_gatt_client_run();
3144902524cSMatthias Ringwald     CHECK_EQUAL(true, connected);
3154902524cSMatthias Ringwald 
3164902524cSMatthias Ringwald     CHECK_EQUAL(true, manufacturer_name);
3174902524cSMatthias Ringwald     CHECK_EQUAL(true, model_number);
3184902524cSMatthias Ringwald     CHECK_EQUAL(true, serial_number);
3194902524cSMatthias Ringwald     CHECK_EQUAL(true, hardware_revision);
3204902524cSMatthias Ringwald     CHECK_EQUAL(true, firmware_revision);
3214902524cSMatthias Ringwald     CHECK_EQUAL(true, software_revision);
3224902524cSMatthias Ringwald 
3234902524cSMatthias Ringwald     CHECK_EQUAL(true, system_id);
3244902524cSMatthias Ringwald     CHECK_EQUAL(true, ieee_regulatory_certification);
3254902524cSMatthias Ringwald     CHECK_EQUAL(true, pnp_id);
3264902524cSMatthias Ringwald }
3274902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,unhandled_gatt_event_when_connected)3284902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, unhandled_gatt_event_when_connected){
3294902524cSMatthias Ringwald     setup_service(true);
3304902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
3314902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
3324902524cSMatthias Ringwald     mock_gatt_client_run();
3334902524cSMatthias Ringwald     CHECK_EQUAL(true, connected);
3344902524cSMatthias Ringwald 
3354902524cSMatthias Ringwald     mock_gatt_client_emit_dummy_event();
3364902524cSMatthias Ringwald     CHECK_EQUAL(true, connected);
3374902524cSMatthias Ringwald }
3384902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,unhandled_gatt_event_when_not_connected)3394902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, unhandled_gatt_event_when_not_connected){
3404902524cSMatthias Ringwald     setup_service(true);
3414902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
3424902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
3434902524cSMatthias Ringwald 
3444902524cSMatthias Ringwald     CHECK_EQUAL(false, connected);
3454902524cSMatthias Ringwald 
3464902524cSMatthias Ringwald     mock_gatt_client_emit_dummy_event();
3474902524cSMatthias Ringwald     CHECK_EQUAL(false, connected);
3484902524cSMatthias Ringwald 
3494902524cSMatthias Ringwald     mock_gatt_client_run();
3504902524cSMatthias Ringwald     CHECK_EQUAL(true, connected);
3514902524cSMatthias Ringwald }
3524902524cSMatthias Ringwald 
3534902524cSMatthias Ringwald 
TEST(DEVICE_INFORMATION_SERVICE_CLIENT,client_in_wrong_state)3544902524cSMatthias Ringwald TEST(DEVICE_INFORMATION_SERVICE_CLIENT, client_in_wrong_state){
3554902524cSMatthias Ringwald     setup_service(true);
3564902524cSMatthias Ringwald     uint8_t status = device_information_service_client_query(con_handle, &gatt_client_event_handler);
3574902524cSMatthias Ringwald     CHECK_EQUAL(ERROR_CODE_SUCCESS, status);
3584902524cSMatthias Ringwald 
3594902524cSMatthias Ringwald     device_information_service_client_set_invalid_state();
3604902524cSMatthias Ringwald     mock_gatt_client_run();
3614902524cSMatthias Ringwald     CHECK_EQUAL(false, connected);
3624902524cSMatthias Ringwald }
3634902524cSMatthias Ringwald 
main(int argc,const char * argv[])3644902524cSMatthias Ringwald int main (int argc, const char * argv[]){
3654902524cSMatthias Ringwald     return CommandLineTestRunner::RunAllTests(argc, argv);
3664902524cSMatthias Ringwald }
367