static void test_request(const char *json) { jsmntok_t tokens[32]; int parsed = parse_json( tokens, LGTD_ARRAY_SIZE(tokens), json, strlen(json) ); bool ok; struct lgtd_jsonrpc_request req = TEST_REQUEST_INITIALIZER; struct lgtd_client client = { .io = NULL, .current_request = &req, .json = json }; ok = lgtd_jsonrpc_check_and_extract_request(&req, tokens, parsed, json); if (!ok) { errx(1, "can't parse request"); } lgtd_jsonrpc_check_and_call_set_light_from_hsbk(&client); if (set_light_called) { errx(1, "lgtd_proto_power_off was called"); } reset_client_write_buf(); }
int main(void) { jsmntok_t tokens[32]; const char json[] = ("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": {" "\"target\": \"*\", " "\"hue\": 324.2341514, " "\"saturation\": 0.234, " "\"brightness\": 1.0, " "\"kelvin\": 4200," "\"transition\": 60" "}," "\"id\": \"42\"" "}"); int parsed = parse_json( tokens, LGTD_ARRAY_SIZE(tokens), json, sizeof(json) ); bool ok; struct lgtd_jsonrpc_request req = TEST_REQUEST_INITIALIZER; struct lgtd_client client = { .io = NULL, .current_request = &req, .json = json }; ok = lgtd_jsonrpc_check_and_extract_request(&req, tokens, parsed, json); if (!ok) { errx(1, "can't parse request"); } lgtd_jsonrpc_check_and_call_set_light_from_hsbk(&client); if (!set_light_called) { errx(1, "lgtd_proto_set_light_from_hsbk wasn't called"); } return 0; }