int main(void) { lgtd_lifx_wire_setup(); struct lgtd_lifx_gateway gw; memset(&gw, 0, sizeof(gw)); struct lgtd_lifx_packet_header hdr; memset(&hdr, 0, sizeof(hdr)); struct lgtd_lifx_tag tag = { .label = "test", .sites = LIST_HEAD_INITIALIZER(&tag.sites) }; gw.tags[0] = &tag; gw.tag_ids = LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(0) | LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(42); lgtd_lifx_gateway_deallocate_tag_id(&gw, 0); if (gw.tags[0]) { errx(1, "gw.tags[0] should have been set to NULL"); } if (gw.tag_ids != LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(42)) { errx( 1, "unexpected gw.tag_ids value = %jx (expected %jx)", (uintmax_t)gw.tag_ids, (uintmax_t)LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(42) ); } if (!tagging_decref_called) { errx(1, "lgtd_lifx_tagging_decref should have been called"); } tagging_decref_called = false; lgtd_lifx_gateway_deallocate_tag_id(&gw, 0); if (gw.tags[0]) { errx(1, "gw.tags[0] should be NULL"); } if (gw.tag_ids != LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(42)) { errx( 1, "unexpected gw.tag_ids value = %jx (expected %jx)", (uintmax_t)gw.tag_ids, (uintmax_t)LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(42) ); } if (tagging_decref_called) { errx(1, "lgtd_lifx_tagging_decref shouldn't have been called"); } return 0; }
int main(void) { lgtd_lifx_wire_load_packet_info_map(); struct lgtd_lifx_gateway gw; memset(&gw, 0, sizeof(gw)); struct lgtd_lifx_packet_header hdr; memset(&hdr, 0, sizeof(hdr)); lgtd_lifx_gateway_allocate_tag_id(&gw, 4, "test"); if (!gw.tags[4]) { errx(1, "gw.tag_ids[4] shouldn't be NULL"); } if (strcmp(gw.tags[4]->label, "test")) { errx( 1, "unexpected tag %.*s (expected test)", (int)sizeof(gw.tags[0]->label), gw.tags[4]->label ); } if (gw.tag_ids != LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(4)) { errx( 1, "tag_ids = %jx (expected %jx)", (uintmax_t)gw.tag_ids, (uintmax_t)LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(4) ); } lgtd_lifx_gateway_allocate_tag_id(&gw, 63, "test"); if (!gw.tags[4]) { errx(1, "gw.tag_ids[4] shouldn't be NULL"); } if (strcmp(gw.tags[4]->label, "test")) { errx( 1, "unexpected tag %.*s (expected test)", (int)sizeof(gw.tags[0]->label), gw.tags[4]->label ); } if (!gw.tags[63]) { errx(1, "gw.tag_ids[63] shouldn't be NULL"); } if (strcmp(gw.tags[63]->label, "test")) { errx( 1, "unexpected tag %.*s (expected test)", (int)sizeof(gw.tags[0]->label), gw.tags[4]->label ); } uint64_t expected_tags = LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(4) | LGTD_LIFX_WIRE_TAG_ID_TO_VALUE(63); if (gw.tag_ids != expected_tags) { errx( 1, "tag_ids = %jx (expected %jx)", (uintmax_t)gw.tag_ids, (uintmax_t)expected_tags ); } tagging_incref_called = false; lgtd_lifx_gateway_allocate_tag_id(&gw, 4, "test"); if (!gw.tags[4]) { errx(1, "gw.tag_ids[4] shouldn't be NULL"); } if (strcmp(gw.tags[4]->label, "test")) { errx( 1, "unexpected tag %.*s (expected test)", (int)sizeof(gw.tags[0]->label), gw.tags[4]->label ); } if (!gw.tags[63]) { errx(1, "gw.tag_ids[63] shouldn't be NULL"); } if (strcmp(gw.tags[63]->label, "test")) { errx( 1, "unexpected tag %.*s (expected test)", (int)sizeof(gw.tags[0]->label), gw.tags[4]->label ); } if (gw.tag_ids != expected_tags) { errx( 1, "tag_ids = %jx (expected %jx)", (uintmax_t)gw.tag_ids, (uintmax_t)expected_tags ); } if (tagging_incref_called) { errx(1, "lgtd_lifx_tagging_incref shouldn't have been called"); } return 0; }