Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
test.h File Reference
#include <stdlib.h>
Include dependency graph for test.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Context Test Helpers

Helpers to create and manipulate opaque csilk_ctx_t objects in unit tests.

csilk_ctx_t * csilk_test_ctx_new (void)
 Create a new mock context for testing (heap-allocated).
 
void csilk_test_ctx_free (csilk_ctx_t *c)
 Free a mock context created via csilk_test_ctx_new().
 
void csilk_test_ctx_set_handlers (csilk_ctx_t *c, csilk_handler_t *handlers)
 Set the handler chain for a test context.
 
void csilk_test_ctx_set_request (csilk_ctx_t *c, const char *method, const char *path)
 Manually set the request method and path for testing.
 
void csilk_test_ctx_set_handler_metadata (csilk_ctx_t *c, const char *perm_required, const char *perm_resource)
 Manually set metadata for the current handler (mocking matched route).
 
void csilk_test_ctx_set_body (csilk_ctx_t *c, const char *body, size_t len)
 Manually set the request body for testing.
 
void csilk_test_ctx_add_param (csilk_ctx_t *c, const char *key, const char *value)
 Manually add a path parameter for testing.
 
int csilk_test_ctx_count_response_headers (csilk_ctx_t *c, const char *key, const char *value_contains)
 Count response headers with a given key and optional value substring.
 

Function Documentation

◆ csilk_test_ctx_add_param()

void csilk_test_ctx_add_param ( csilk_ctx_t *  c,
const char *  key,
const char *  value 
)

Manually add a path parameter for testing.

Parameters
cThe request context.
keyParameter name. Copied.
valueParameter value. Copied.

◆ csilk_test_ctx_count_response_headers()

int csilk_test_ctx_count_response_headers ( csilk_ctx_t *  c,
const char *  key,
const char *  value_contains 
)

Count response headers with a given key and optional value substring.

Parameters
cThe request context.
keyHeader key to look up.
value_containsOptional substring to match in the value.
Returns
Number of matching headers.

◆ csilk_test_ctx_free()

void csilk_test_ctx_free ( csilk_ctx_t *  c)

Free a mock context created via csilk_test_ctx_new().

Parameters
cThe context to free.

◆ csilk_test_ctx_new()

csilk_ctx_t * csilk_test_ctx_new ( void  )

Create a new mock context for testing (heap-allocated).

Returns
Pointer to new context, or NULL on failure.

◆ csilk_test_ctx_set_body()

void csilk_test_ctx_set_body ( csilk_ctx_t *  c,
const char *  body,
size_t  len 
)

Manually set the request body for testing.

Parameters
cThe request context.
bodyThe raw request body string. Not copied.
lenLength of the body.

◆ csilk_test_ctx_set_handler_metadata()

void csilk_test_ctx_set_handler_metadata ( csilk_ctx_t *  c,
const char *  perm_required,
const char *  perm_resource 
)

Manually set metadata for the current handler (mocking matched route).

Parameters
cThe request context.
perm_requiredPermission string. Not copied.
perm_resourceResource pattern. Not copied.

◆ csilk_test_ctx_set_handlers()

void csilk_test_ctx_set_handlers ( csilk_ctx_t *  c,
csilk_handler_t handlers 
)

Set the handler chain for a test context.

Parameters
cThe request context.
handlersNULL-terminated array of handler functions.

◆ csilk_test_ctx_set_request()

void csilk_test_ctx_set_request ( csilk_ctx_t *  c,
const char *  method,
const char *  path 
)

Manually set the request method and path for testing.

Parameters
cThe request context.
methodHTTP method string (e.g. "GET"). Not copied.
pathDecoded URL path string. Not copied.