Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ TEST_TARGETS = test_worker_affinity \
test_orm \
test_app_resource_limits \
test_app_named_routes_and_error_handler \
test_app_route_helpers \
test_classic_pool_scaling \
test_reactor_wake \
test_reactor_timer \
Expand Down Expand Up @@ -1093,6 +1094,10 @@ test_app_named_routes_and_error_handler: $(LIB_NAME) tests/test_app_named_routes
$(CC) $(CFLAGS) -o $@ tests/test_app_named_routes_and_error_handler.c $(LIB_NAME) $(LIBS)
./$@

test_app_route_helpers: $(LIB_NAME) tests/test_app_route_helpers.c
$(CC) $(CFLAGS) -o $@ tests/test_app_route_helpers.c $(LIB_NAME) $(LIBS)
./$@

test_classic_pool_scaling: $(LIB_NAME) tests/test_classic_pool_scaling.c
$(CC) $(CFLAGS) -o $@ tests/test_classic_pool_scaling.c $(LIB_NAME) $(LIBS)
./$@ burst
Expand Down
9 changes: 0 additions & 9 deletions scripts/ci/api-untested-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,14 @@
# was added (2026-10-11). This list may only shrink: v3.9.2 works it down to empty.
cwist_accept_socket
cwist_app_configure_bdr
cwist_app_delete_opt
cwist_app_enable_metrics
cwist_app_get_db
cwist_app_get_db_pool
cwist_app_get_named
cwist_app_get_opt
cwist_app_get_redis_pool
cwist_app_http_handler
cwist_app_multiport
cwist_app_patch_named
cwist_app_patch_opt
cwist_app_post_opt
cwist_app_put_named
cwist_app_put_opt
cwist_app_register_error_handler
cwist_app_set_max_memspace
cwist_app_set_session_max_age
cwist_app_set_tls_groups
cwist_app_static_with_cache
cwist_app_use_db
Expand Down
184 changes: 184 additions & 0 deletions tests/test_app_route_helpers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/**
* @file test_app_route_helpers.c
* @brief Smoke tests for the cwist_app_* named/opt route helpers and
* cwist_app_set_session_max_age (issue #390). Registration and lookup
* paths only; no live server is started.
*/
#define _POSIX_C_SOURCE 200809L
#include <cwist/sys/app/app.h>
#include <cwist/sys/app/endpoint_opts.h>
#include <cwist/net/http/session.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>

static void noop_handler(cwist_http_request *req, cwist_http_response *res) {
(void)req;
(void)res;
}

static void test_get_named(void) {
printf("test_app_get_named...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_app_get_named(app, "/articles", "articles_list", noop_handler);

char *url = cwist_url_for(app, "articles_list", NULL);
assert(url != NULL);
assert(strcmp(url, "/articles") == 0);
free(url);

cwist_app_get_named(NULL, "/x", "x", noop_handler);
cwist_app_get_named(app, NULL, "x", noop_handler);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_put_named(void) {
printf("test_app_put_named...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_app_put_named(app, "/articles/:id", "articles_replace", noop_handler);

char *url = cwist_url_for(app, "articles_replace", NULL);
assert(url != NULL);
assert(strstr(url, "/articles") != NULL);
free(url);

cwist_app_put_named(NULL, "/x", "x", noop_handler);
cwist_app_put_named(app, NULL, "x", noop_handler);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_patch_named(void) {
printf("test_app_patch_named...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_app_patch_named(app, "/articles/:id", "articles_update", noop_handler);

char *url = cwist_url_for(app, "articles_update", NULL);
assert(url != NULL);
assert(strstr(url, "/articles") != NULL);
free(url);

cwist_app_patch_named(NULL, "/x", "x", noop_handler);
cwist_app_patch_named(app, NULL, "x", noop_handler);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_get_opt(void) {
printf("test_app_get_opt...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_endpoint_opt_t opts = 0;
cwist_app_get_opt(app, "/data", noop_handler, opts);

cwist_app_get_opt(NULL, "/data", noop_handler, opts);
cwist_app_get_opt(app, NULL, noop_handler, opts);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_post_opt(void) {
printf("test_app_post_opt...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_endpoint_opt_t opts = 0;
cwist_app_post_opt(app, "/data", noop_handler, opts);

cwist_app_post_opt(NULL, "/data", noop_handler, opts);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_put_opt(void) {
printf("test_app_put_opt...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_endpoint_opt_t opts = 0;
cwist_app_put_opt(app, "/data/:id", noop_handler, opts);

cwist_app_put_opt(NULL, "/data/:id", noop_handler, opts);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_patch_opt(void) {
printf("test_app_patch_opt...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_endpoint_opt_t opts = 0;
cwist_app_patch_opt(app, "/data/:id", noop_handler, opts);

cwist_app_patch_opt(NULL, "/data/:id", noop_handler, opts);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_delete_opt(void) {
printf("test_app_delete_opt...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_endpoint_opt_t opts = 0;
cwist_app_delete_opt(app, "/data/:id", noop_handler, opts);

cwist_app_delete_opt(NULL, "/data/:id", noop_handler, opts);

cwist_app_destroy(app);
printf(" OK\n");
}

static void test_set_session_max_age(void) {
printf("test_app_set_session_max_age...\n");

cwist_app *app = cwist_app_create();
assert(app != NULL);

cwist_app_set_session_max_age(app, 3600);
cwist_app_set_session_max_age(app, 0);

/* NULL must not crash. */
cwist_app_set_session_max_age(NULL, 3600);

cwist_app_destroy(app);
printf(" OK\n");
}

int main(void) {
test_get_named();
test_put_named();
test_patch_named();
test_get_opt();
test_post_opt();
test_put_opt();
test_patch_opt();
test_delete_opt();
test_set_session_max_age();
printf("All test_app_route_helpers tests passed.\n");
return 0;
}
Loading