Skip to content

Commit f17d7f2

Browse files
committed
add more c tests
1 parent 0693040 commit f17d7f2

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

c/include/clib_openiap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,12 @@ void connect_async(struct ClientWrapper *client,
691691
int32_t request_id,
692692
ConnectCallback callback);
693693

694+
int32_t client_get_default_timeout(struct ClientWrapper *client_wrap);
695+
694696
void client_set_default_timeout(struct ClientWrapper *client_wrap, int32_t timeout);
695697

698+
const char *client_get_state(struct ClientWrapper *client_wrap);
699+
696700
void client_set_agent_name(struct ClientWrapper *client_wrap, const char *agent_name);
697701

698702
void client_set_agent_version(struct ClientWrapper *client_wrap, const char *agent_version);

c/test_package/main.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const char *queue_event_callback(struct QueueEventWrapper *event) {
6161
printf("> ");
6262
fflush(stdout);
6363
// No reply
64-
return "{}";
64+
return "{\"status\":\"ok\"}";
6565
}
6666

6767
int main(void) {
@@ -295,6 +295,25 @@ int main(void) {
295295
}
296296
free_register_queue_response(resp);
297297
}
298+
} else if (strcmp(input, "r2") == 0) {
299+
struct QueueMessageRequestWrapper req = {
300+
.queuename = "test2queue",
301+
.striptoken = true,
302+
.data = "{\"message\":\"Test message\"}",
303+
.request_id = 1
304+
};
305+
306+
struct RpcResponseWrapper *response = rpc(client, &req, 5);
307+
if (response == NULL) {
308+
error("RPC test failed: response is NULL.");
309+
} else if (!response->success) {
310+
error("RPC test failed:");
311+
error(response->error);
312+
} else {
313+
info("Received reply:");
314+
info(response->result);
315+
}
316+
free_rpc_response(response);
298317
} else if (strcmp(input, "m") == 0) {
299318
struct QueueMessageRequestWrapper req = {
300319
.queuename = "test2queue",
@@ -352,7 +371,27 @@ int main(void) {
352371
printf("Invoke OpenRPA result: %s\n", resp->result);
353372
}
354373
free_invoke_openrpa_response(resp);
355-
}
374+
}
375+
} else if (strcmp(input, "g") == 0) {
376+
const char *state = client_get_state(client);
377+
if (state != NULL) {
378+
info("State:");
379+
info(state);
380+
} else {
381+
error("Failed to get state.");
382+
}
383+
384+
int32_t timeout = client_get_default_timeout(client);
385+
info("Default timeout:");
386+
printf("%d seconds\n", timeout);
387+
388+
client_set_default_timeout(client, 2);
389+
timeout = client_get_default_timeout(client);
390+
if (timeout == 2) {
391+
info("Default timeout set to 2 seconds.");
392+
} else {
393+
error("Failed to set default timeout.");
394+
}
356395
} else {
357396
printf("Unknown command: '%s'\n", input);
358397
}

0 commit comments

Comments
 (0)