From ddf0a5c586a9d057e65a5e7551abdf546ddc7216 Mon Sep 17 00:00:00 2001 From: Bhumika-1432006 Date: Sat, 17 Oct 2026 16:33:05 +0530 Subject: [PATCH 1/2] test(app): cover named/opt route helpers and set_session_max_age (closes #390) --- Makefile | 5 + scripts/ci/api-untested-baseline.txt | 9 -- tests/test_app_route_helpers.c | 196 +++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 tests/test_app_route_helpers.c diff --git a/Makefile b/Makefile index b1b4bb4c..1e05933a 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 diff --git a/scripts/ci/api-untested-baseline.txt b/scripts/ci/api-untested-baseline.txt index c3954812..ad755b5d 100644 --- a/scripts/ci/api-untested-baseline.txt +++ b/scripts/ci/api-untested-baseline.txt @@ -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 diff --git a/tests/test_app_route_helpers.c b/tests/test_app_route_helpers.c new file mode 100644 index 00000000..f792c95e --- /dev/null +++ b/tests/test_app_route_helpers.c @@ -0,0 +1,196 @@ +/** + * @file test_app_route_helpers.c + * @brief Smoke tests for uncovered cwist_app_* route helpers (issue #390). + * + * Covers: + * cwist_app_get_named -- named GET route; cwist_url_for finds it. + * cwist_app_put_named -- named PUT route; cwist_url_for finds it. + * cwist_app_patch_named -- named PATCH route; cwist_url_for finds it. + * cwist_app_get_opt -- opt GET route with zeroed opts; no crash. + * cwist_app_post_opt -- opt POST route with zeroed opts; no crash. + * cwist_app_put_opt -- opt PUT route with zeroed opts; no crash. + * cwist_app_patch_opt -- opt PATCH route with zeroed opts; no crash. + * cwist_app_delete_opt -- opt DELETE route with zeroed opts; no crash. + * cwist_app_set_session_max_age -- stored in app; survives NULL app. + * + * None of these start a live server -- they only exercise the registration + * and lookup paths. + */ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include +#include +#include + +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; +} From 9d9589c8ea0935b3bddd5b32e8709b2e2d22ac7b Mon Sep 17 00:00:00 2001 From: Lee Yunjin Date: Sun, 18 Oct 2026 16:03:49 +0900 Subject: [PATCH 2/2] test(app): trim restating comments in route-helper tests --- tests/test_app_route_helpers.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/tests/test_app_route_helpers.c b/tests/test_app_route_helpers.c index f792c95e..180d475f 100644 --- a/tests/test_app_route_helpers.c +++ b/tests/test_app_route_helpers.c @@ -1,20 +1,8 @@ /** * @file test_app_route_helpers.c - * @brief Smoke tests for uncovered cwist_app_* route helpers (issue #390). - * - * Covers: - * cwist_app_get_named -- named GET route; cwist_url_for finds it. - * cwist_app_put_named -- named PUT route; cwist_url_for finds it. - * cwist_app_patch_named -- named PATCH route; cwist_url_for finds it. - * cwist_app_get_opt -- opt GET route with zeroed opts; no crash. - * cwist_app_post_opt -- opt POST route with zeroed opts; no crash. - * cwist_app_put_opt -- opt PUT route with zeroed opts; no crash. - * cwist_app_patch_opt -- opt PATCH route with zeroed opts; no crash. - * cwist_app_delete_opt -- opt DELETE route with zeroed opts; no crash. - * cwist_app_set_session_max_age -- stored in app; survives NULL app. - * - * None of these start a live server -- they only exercise the registration - * and lookup paths. + * @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