Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
Loading...
Searching...
No Matches
test.h
Go to the documentation of this file.
1
24#ifndef CSILK_TEST_H
25#define CSILK_TEST_H
26
27#include <stdlib.h>
28
29#ifdef TEST_OOM
30
37extern int g_oom_fail_after;
38
45extern int g_oom_count;
46
54static inline void*
55csilk_test_malloc(size_t size)
56{
57 if (g_oom_fail_after >= 0 && g_oom_count >= g_oom_fail_after) {
58 return NULL;
59 }
60 g_oom_count++;
61 return malloc(size);
62}
63
72static inline void*
73csilk_test_calloc(size_t nmemb, size_t size)
74{
75 if (g_oom_fail_after >= 0 && g_oom_count >= g_oom_fail_after) {
76 return NULL;
77 }
78 g_oom_count++;
79 return calloc(nmemb, size);
80}
81
90static inline void*
91csilk_test_realloc(void* ptr, size_t size)
92{
93 if (g_oom_fail_after >= 0 && g_oom_count >= g_oom_fail_after) {
94 return NULL;
95 }
96 g_oom_count++;
97 return realloc(ptr, size);
98}
99
106#define malloc(s) csilk_test_malloc(s)
107#define calloc(n, s) csilk_test_calloc(n, s)
108#define realloc(p, s) csilk_test_realloc(p, s)
111#endif /* TEST_OOM */
112
120csilk_ctx_t* csilk_test_ctx_new(void);
121
124void csilk_test_ctx_free(csilk_ctx_t* c);
125
129void csilk_test_ctx_set_handlers(csilk_ctx_t* c, csilk_handler_t* handlers);
130
135void csilk_test_ctx_set_request(csilk_ctx_t* c, const char* method, const char* path);
136
141void csilk_test_ctx_set_handler_metadata(csilk_ctx_t* c,
142 const char* perm_required,
143 const char* perm_resource);
144
149void csilk_test_ctx_set_body(csilk_ctx_t* c, const char* body, size_t len);
150
155void csilk_test_ctx_add_param(csilk_ctx_t* c, const char* key, const char* value);
156
162int
163csilk_test_ctx_count_response_headers(csilk_ctx_t* c, const char* key, const char* value_contains);
164
167#endif /* CSILK_TEST_H */
void(* csilk_handler_t)(csilk_ctx_t *c)
Function pointer for route handlers and middleware.
Definition csilk.h:120
void csilk_test_ctx_free(csilk_ctx_t *c)
Free a mock context created via csilk_test_ctx_new().
Definition test_utils.c:27
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).
Definition test_utils.c:59
void csilk_test_ctx_set_handlers(csilk_ctx_t *c, csilk_handler_t *handlers)
Set the handler chain for a test context.
Definition test_utils.c:39
void csilk_test_ctx_set_body(csilk_ctx_t *c, const char *body, size_t len)
Manually set the request body for testing.
Definition test_utils.c:79
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.
Definition test_utils.c:47
csilk_ctx_t * csilk_test_ctx_new(void)
Create a new mock context for testing (heap-allocated).
Definition test_utils.c:15
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.
Definition test_utils.c:106
void csilk_test_ctx_add_param(csilk_ctx_t *c, const char *key, const char *value)
Manually add a path parameter for testing.
Definition test_utils.c:91