TEST_F(PropertyTest, copy) { { bt_uuid_t uuids[] = { {{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, }}, {{ 0xf0, 0xe1, 0xd2, 0xc3, 0xf4, 0xe5, 0xd6, 0xc7, 0xf8, 0xe9, 0xda, 0xcb, 0xfc, 0xed, 0xde, 0xcf, }}, }; bt_property_t *property0 = property_new_uuids(uuids, sizeof(bt_uuid_t)/sizeof(uuids)); bt_property_t property1; property_copy(&property1, property0); EXPECT_TRUE(property_equals(property0, &property1)); property_free(property0); } }
int widget_timer_quit(WIDGET * Self) { if (Self) { /* do not deallocate child widget! */ if (Self->parent == NULL) { if (Self->data) { WIDGET_TIMER *Timer = Self->data; property_free(&Timer->expression); property_free(&Timer->update); property_free(&Timer->active); free(Self->data); Self->data = NULL; } } } return 0; }
int widget_keypad_quit(WIDGET * Self) { if (Self && Self->data) { WIDGET_KEYPAD *keypad = Self->data; property_free(&keypad->expression); free(Self->data); Self->data = NULL; } return 0; }
TEST_F(PropertyTest, name) { const char *name0 = "My btcore name"; bt_property_t *property = property_new_name(name0); EXPECT_EQ(0, strcmp((char *)name0, (char *)property->val)); EXPECT_EQ(BT_PROPERTY_BDNAME, property->type); EXPECT_EQ((int)sizeof(bt_bdname_t), property->len); const bt_bdname_t *name1 = property_as_name(property); EXPECT_EQ(0, strcmp((char *)name0, (char *)name1->name)); property_free(property); }
TEST_F(PropertyTest, discovery_timeout) { uint32_t timeout0 = 12345; bt_property_t *property = property_new_discovery_timeout(timeout0); EXPECT_EQ(timeout0, *(uint32_t *)property->val); EXPECT_EQ(BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT, property->type); EXPECT_EQ((int)sizeof(uint32_t), property->len); uint32_t timeout1 = property_as_discovery_timeout(property); EXPECT_EQ(timeout0, timeout1); property_free(property); }
TEST_F(PropertyTest, device_type) { bt_device_type_t dt0 = (bt_device_type_t)1; bt_property_t *property = property_new_device_type(dt0); EXPECT_EQ((int)dt0, *(int*)property->val); EXPECT_EQ(BT_PROPERTY_TYPE_OF_DEVICE, property->type); EXPECT_EQ((int)sizeof(bt_device_type_t), property->len); bt_device_type_t dt1 = property_as_device_type(property); EXPECT_EQ(1, (int)dt1); property_free(property); }
TEST_F(PropertyTest, scan_mode) { bt_scan_mode_t mode0 = (bt_scan_mode_t)3; bt_property_t *property = property_new_scan_mode(mode0); EXPECT_EQ(*(int *)property->val, mode0); EXPECT_EQ(BT_PROPERTY_ADAPTER_SCAN_MODE, property->type); EXPECT_EQ((int)sizeof(int), property->len); bt_scan_mode_t mode1 = property_as_scan_mode(property); EXPECT_EQ((int)mode0, (int)mode1); property_free(property); }
TEST_F(PropertyTest, rssi) { int8_t rssi0 = -56; bt_property_t *property = property_new_rssi(rssi0); EXPECT_EQ(*(int8_t *)property->val, rssi0); EXPECT_EQ(BT_PROPERTY_REMOTE_RSSI, property->type); EXPECT_EQ((int)sizeof(int8_t), property->len); int8_t rss1 = property_as_rssi(property); EXPECT_EQ(rssi0, rss1); property_free(property); }
int pa_property_remove(pa_core *c, const char *name) { pa_property *p; pa_assert(c); pa_assert(name); pa_assert(c->properties); if (!(p = pa_hashmap_remove(c->properties, name))) return -1; property_free(p); return 0; }
TEST_F(PropertyTest, device_class) { bt_device_class_t dc0 = {{ 0x01, 0x23, 0x45 }}; bt_property_t *property = property_new_device_class(&dc0); EXPECT_EQ(dc0._[0], ((uint8_t*)property->val)[0]); EXPECT_EQ(dc0._[1], ((uint8_t*)property->val)[1]); EXPECT_EQ(dc0._[2], ((uint8_t*)property->val)[2]); EXPECT_EQ(BT_PROPERTY_CLASS_OF_DEVICE, property->type); EXPECT_EQ((int)sizeof(bt_device_class_t), property->len); const bt_device_class_t *dc1 = property_as_device_class(property); int dc_int = device_class_to_int(dc1); EXPECT_EQ(0x452301, dc_int); property_free(property); }
TEST_F(PropertyTest, addr) { bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; bt_property_t *property = property_new_addr(&addr0); EXPECT_EQ(addr0.address[0], ((uint8_t*)property->val)[0]); EXPECT_EQ(addr0.address[1], ((uint8_t*)property->val)[1]); EXPECT_EQ(addr0.address[2], ((uint8_t*)property->val)[2]); EXPECT_EQ(addr0.address[3], ((uint8_t*)property->val)[3]); EXPECT_EQ(addr0.address[4], ((uint8_t*)property->val)[4]); EXPECT_EQ(addr0.address[5], ((uint8_t*)property->val)[5]); EXPECT_EQ(BT_PROPERTY_BDADDR, property->type); EXPECT_EQ((int)sizeof(bt_bdaddr_t), property->len); const bt_bdaddr_t *addr1 = property_as_addr(property); EXPECT_EQ(addr0.address[0], addr1->address[0]); property_free(property); }
TEST_F(PropertyTest, uuids) { bt_uuid_t uuid0 = { { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, } }; bt_property_t *property = property_new_uuids(&uuid0, 1); EXPECT_EQ(0, strcmp((const char *)uuid0.uu, (char *)property->val)); EXPECT_EQ(BT_PROPERTY_UUIDS, property->type); EXPECT_EQ((int)sizeof(bt_uuid_t), property->len); size_t uuid_cnt1; const bt_uuid_t *uuid1 = property_as_uuids(property, &uuid_cnt1); EXPECT_EQ(0, memcmp(uuid1->uu, uuid1->uu, sizeof(bt_uuid_t))); property_free(property); }
TEST_F(PropertyTest, equals) { { bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; bt_property_t *property0 = property_new_addr(&addr0); bt_device_class_t dc0 = {{ 0x01, 0x23, 0x45 }}; bt_property_t *property1 = property_new_device_class(&dc0); EXPECT_FALSE(property_equals(property0, property1)); property_free(property0); property_free(property1); } { bt_bdaddr_t addr = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; bt_property_t *property0 = property_new_addr(&addr); bt_property_t *property1 = property_new_addr(&addr); EXPECT_TRUE(property_equals(property0, property1)); property_free(property0); property_free(property1); } { bt_bdaddr_t addr0 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0x6}}; bt_property_t *property0 = property_new_addr(&addr0); bt_bdaddr_t addr1 = {{0x1, 0x2, 0x3, 0x4, 0x5, 0xff}}; bt_property_t *property1 = property_new_addr(&addr1); EXPECT_FALSE(property_equals(property0, property1)); property_free(property0); property_free(property1); } { const char *name0 = "My btcore name"; bt_property_t *property0 = property_new_name(name0); const char *name1 = "My btcore name"; bt_property_t *property1 = property_new_name(name1); EXPECT_TRUE(property_equals(property0, property1)); property_free(property0); property_free(property1); } { const char *name0 = "My btcore name"; bt_property_t *property0 = property_new_name(name0); const char *name1 = "My btcore name "; bt_property_t *property1 = property_new_name(name1); EXPECT_FALSE(property_equals(property0, property1)); property_free(property0); property_free(property1); } }
int main(int argc, char** argv) { if (!parse_args(argc, argv)) { usage(argv[0]); } if (bond && discoverable) { fprintf(stderr, "Can only select either bond or discoverable, not both\n"); usage(argv[0]); } if (sco_listen && sco_connect) { fprintf(stderr, "Can only select either sco_listen or sco_connect, not both\n"); usage(argv[0]); } if (!bond && !discover && !discoverable && !up && !get_name && !set_name && !sco_listen && !sco_connect) { fprintf(stderr, "Must specify one command\n"); usage(argv[0]); } if (signal(SIGINT, sig_handler) == SIG_ERR) { fprintf(stderr, "Will be unable to catch signals\n"); } fprintf(stdout, "Bringing up bluetooth adapter\n"); if (!hal_open(callbacks_get_adapter_struct())) { fprintf(stderr, "Unable to open Bluetooth HAL.\n"); return 1; } if (discover) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); fprintf(stdout, "Starting to start discovery\n"); CALL_AND_WAIT(bt_interface->start_discovery(), discovery_state_changed); fprintf(stdout, "Started discovery for %d seconds\n", timeout_in_sec); sleep(timeout_in_sec); fprintf(stdout, "Starting to cancel discovery\n"); CALL_AND_WAIT(bt_interface->cancel_discovery(), discovery_state_changed); fprintf(stdout, "Cancelled discovery after %d seconds\n", timeout_in_sec); } if (discoverable) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); bt_property_t* property = property_new_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); int rc = bt_interface->set_adapter_property(property); fprintf(stdout, "Set rc:%d device as discoverable for %d seconds\n", rc, timeout_in_sec); sleep(timeout_in_sec); property_free(property); } if (bond) { if (bdaddr_is_empty(&bt_remote_bdaddr)) { fprintf(stderr, "Must specify a remote device address [ " "--bdaddr=xx:yy:zz:aa:bb:cc ]\n"); exit(1); } CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); int rc = bt_interface->create_bond( &bt_remote_bdaddr, 0 /* UNKNOWN; Currently not documented :( */); fprintf(stdout, "Started bonding:%d for %d seconds\n", rc, timeout_in_sec); sleep(timeout_in_sec); } if (up) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); fprintf(stdout, "Waiting for %d seconds\n", timeout_in_sec); sleep(timeout_in_sec); } if (get_name) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); int error; CALL_AND_WAIT( error = bt_interface->get_adapter_property(BT_PROPERTY_BDNAME), adapter_properties); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to get adapter property\n"); exit(1); } bt_property_t* property = adapter_get_property(BT_PROPERTY_BDNAME); const bt_bdname_t* name = property_as_name(property); if (name) printf("Queried bluetooth device name:%s\n", name->name); else printf("No name\n"); } if (set_name) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); bt_property_t* property = property_new_name(bd_name); printf("Setting bluetooth device name to:%s\n", bd_name); int error; CALL_AND_WAIT(error = bt_interface->set_adapter_property(property), adapter_properties); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to set adapter property\n"); exit(1); } CALL_AND_WAIT( error = bt_interface->get_adapter_property(BT_PROPERTY_BDNAME), adapter_properties); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to get adapter property\n"); exit(1); } property_free(property); sleep(timeout_in_sec); } const int app_uid = 0; if (sco_listen) { CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); bt_property_t* property = property_new_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE); CALL_AND_WAIT(bt_interface->set_adapter_property(property), adapter_properties); property_free(property); const btsock_interface_t* sock = bt_interface->get_profile_interface(BT_PROFILE_SOCKETS_ID); int rfcomm_fd = INVALID_FD; int error = sock->listen(BTSOCK_RFCOMM, "meow", (const uint8_t*)&HFP_AG_UUID, 0, &rfcomm_fd, 0, app_uid); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to listen for incoming RFCOMM socket: %d\n", error); exit(1); } int sock_fd = INVALID_FD; error = sock->listen(BTSOCK_SCO, NULL, NULL, 5, &sock_fd, 0, app_uid); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to listen for incoming SCO sockets: %d\n", error); exit(1); } fprintf(stdout, "Waiting for incoming SCO connections...\n"); sleep(timeout_in_sec); } if (sco_connect) { if (bdaddr_is_empty(&bt_remote_bdaddr)) { fprintf(stderr, "Must specify a remote device address [ " "--bdaddr=xx:yy:zz:aa:bb:cc ]\n"); exit(1); } CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed); fprintf(stdout, "BT adapter is up\n"); const btsock_interface_t* sock = bt_interface->get_profile_interface(BT_PROFILE_SOCKETS_ID); int rfcomm_fd = INVALID_FD; int error = sock->connect(&bt_remote_bdaddr, BTSOCK_RFCOMM, (const uint8_t*)&HFP_AG_UUID, 0, &rfcomm_fd, 0, app_uid); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to connect to RFCOMM socket: %d.\n", error); exit(1); } WAIT(acl_state_changed); fprintf(stdout, "Establishing SCO connection...\n"); int sock_fd = INVALID_FD; error = sock->connect(&bt_remote_bdaddr, BTSOCK_SCO, NULL, 5, &sock_fd, 0, app_uid); if (error != BT_STATUS_SUCCESS) { fprintf(stderr, "Unable to connect to SCO socket: %d.\n", error); exit(1); } sleep(timeout_in_sec); } CALL_AND_WAIT(bt_interface->disable(), adapter_state_changed); fprintf(stdout, "BT adapter is down\n"); }