int main(void) { struct lgtd_lifx_gateway gw; uint8_t bulb_addr[LGTD_LIFX_ADDR_LENGTH] = { 5, 4, 3, 2, 1, 0 }; struct lgtd_lifx_bulb *bulb = lgtd_lifx_bulb_open(&gw, bulb_addr); bulb->state.power = LGTD_LIFX_POWER_ON; LGTD_STATS_ADD_AND_UPDATE_PROCTITLE(bulbs_powered_on, 1); lgtd_lifx_bulb_close(bulb); if (!RB_EMPTY(&lgtd_lifx_bulbs_table)) { errx(1, "The bulbs table should be empty!"); } if (LGTD_STATS_GET(bulbs) != 0) { errx(1, "The bulbs counter is %d (expected 0)", LGTD_STATS_GET(bulbs)); } if (LGTD_STATS_GET(bulbs_powered_on) != 0) { errx( 1, "The powered on bulbs counter is %d (expected 0)", LGTD_STATS_GET(bulbs_powered_on) ); } return 0; }
int main(void) { struct lgtd_lifx_bulb bulb = { .state = { .hue = 54321, .brightness = UINT16_MAX, .kelvin = 12345, .dim = 808, .power = LGTD_LIFX_POWER_OFF, .label = "lair", .tags = 0x2a }, .gw = (void *)0xdeaf }; struct lgtd_lifx_light_state new_state = { .hue = 22222, .brightness = UINT16_MAX / 2, .kelvin = 54321, .dim = 303, .power = LGTD_LIFX_POWER_ON, .label = "caverne", .tags = 0xfeed }; lgtd_lifx_bulb_set_light_state(&bulb, &new_state, 2015); if (memcmp(&bulb.state, &new_state, sizeof(new_state))) { errx(1, "new light state incorrectly set"); } if (LGTD_STATS_GET(bulbs_powered_on) != 1) { errx( 1, "unexpected bulbs_powered_on counter value %d (expected 1)", LGTD_STATS_GET(bulbs_powered_on) ); } if (bulb.last_light_state_at != 2015) { errx( 1, "got bulb.last_light_state = %jx (expected 2015)", (uintmax_t)bulb.last_light_state_at ); } if (update_tag_refcouts_call_counts != 1) { errx(1, "lgtd_lifx_gateway_update_tag_refcounts wasn't called"); } lgtd_lifx_bulb_set_light_state(&bulb, &new_state, 2015); if (update_tag_refcouts_call_counts != 2) { errx(1, "lgtd_lifx_gateway_update_tag_refcounts wasn't called"); } if (LGTD_STATS_GET(bulbs_powered_on) != 1) { errx( 1, "unexpected bulbs_powered_on counter value %d (expected 1)", LGTD_STATS_GET(bulbs_powered_on) ); } return 0; }