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/tx_power_service_server.h" 24 #include "tx_power_service_server_test.h" 25 #include "mock_att_server.h" 26 27 static int8_t tx_power_level = 100; 28 29 TEST_GROUP(TX_POWER_SERVICE_SERVER){ 30 att_service_handler_t * service; 31 uint16_t con_handle; 32 uint16_t tx_power_level_value_handle; 33 34 void setup(void){ 35 // setup database 36 att_set_db(profile_data); 37 tx_power_level_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(0, 0xffff, ORG_BLUETOOTH_CHARACTERISTIC_TX_POWER_LEVEL); 38 39 // setup tx power service 40 tx_power_service_server_init(tx_power_level); 41 42 service = mock_att_server_get_service(); 43 con_handle = 0x00; 44 } 45 46 void teardown(){ 47 mock_deinit(); 48 } 49 }; 50 51 TEST(TX_POWER_SERVICE_SERVER, lookup_attribute_handles){ 52 CHECK(tx_power_level_value_handle != 0); 53 } 54 55 56 TEST(TX_POWER_SERVICE_SERVER, read_tx_power_level_value){ 57 uint8_t response[1]; 58 uint16_t response_len; 59 60 // invalid attribute handle 61 response_len = mock_att_service_read_callback(con_handle, 0xffff, 0xffff, response, sizeof(response)); 62 CHECK_EQUAL(0, response_len); 63 64 response_len = mock_att_service_read_callback(con_handle, tx_power_level_value_handle, 0, response, sizeof(response)); 65 CHECK_EQUAL(1, response_len); 66 } 67 68 69 int main (int argc, const char * argv[]){ 70 return CommandLineTestRunner::RunAllTests(argc, argv); 71 } 72