Skip to content

Commit

Permalink
Add test and update example
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Jan 24, 2025
1 parent 746e2b0 commit 7c7a5d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 15 additions & 6 deletions examples/unix/c11/z_querier.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2024 ZettaScale Technology
// Copyright (c) 2025 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
Expand All @@ -11,9 +11,9 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>

#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <zenoh-pico.h>

Expand All @@ -25,9 +25,11 @@ int main(int argc, char **argv) {
const char *clocator = NULL;
const char *llocator = NULL;
const char *value = NULL;
int n = INT_MAX;
int timeout_ms = 0;

int opt;
while ((opt = getopt(argc, argv, "s:e:m:v:l:")) != -1) {
while ((opt = getopt(argc, argv, "s:e:m:v:l:n:t:")) != -1) {
switch (opt) {
case 's':
selector = optarg;
Expand All @@ -44,8 +46,15 @@ int main(int argc, char **argv) {
case 'v':
value = optarg;
break;
case 'n':
n = atoi(optarg);
break;
case 't':
timeout_ms = atoi(optarg);
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'v' || optopt == 'l' ||
optopt == 'n' || optopt == 't') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down Expand Up @@ -99,7 +108,7 @@ int main(int argc, char **argv) {

z_querier_options_t opts;
z_querier_options_default(&opts);
// TODO(sashacmc): opts.timeout_ms = timeout_ms;
opts.timeout_ms = timeout_ms;

if (z_declare_querier(z_loan(s), &querier, z_loan(keyexpr), &opts) < 0) {
printf("Unable to declare Querier for key expression!\n");
Expand All @@ -108,7 +117,7 @@ int main(int argc, char **argv) {

printf("Press CTRL-C to quit...\n");
char buf[256];
for (int idx = 0; 1; ++idx) {
for (int idx = 0; idx != n; ++idx) {
z_sleep_s(1);
sprintf(buf, "[%4d] %s", idx, value ? value : "");
printf("Querying '%s' with payload '%s'...\n", selector, buf);
Expand Down
4 changes: 4 additions & 0 deletions tests/memory_leak.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ def query_and_queryable(query_cmd, queryable_cmd):
print("*** Query & queryable attachment test ***")
if query_and_queryable('z_get_attachment -v Something', 'z_queryable_attachment -n 1') == 1:
EXIT_STATUS = 1
# Test querier and queryable examples
print("*** Querier & queryable test ***")
if query_and_queryable('z_querier -n 1', 'z_queryable -n 1') == 1:
EXIT_STATUS = 1
# Test liveliness query
print("*** Get liveliness test ***")
if query_and_queryable('z_get_liveliness', 'z_liveliness -t 3') == 1:
Expand Down

0 comments on commit 7c7a5d8

Please sign in to comment.