3
.\" Copyright (c) 2015, 2020 Kristaps Dzonsons <kristaps@bsd.lv>
5
.\" Permission to use, copy, modify, and distribute this software for any
6
.\" purpose with or without fee is hereby granted, provided that the above
7
.\" copyright notice and this permission notice appear in all copies.
9
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
.Nd regression framework for kcgi
31
.Fa "int (*client)(void *)"
33
.Fa "int (*server)(void *)"
38
.Fa "int (*client)(void *)"
40
.Fa "int (*server)(void *)"
44
Automated testing platform for
46
Allow for emulated CGI or FastCGI environments over a local network
51
callback is invoked with argument
53
within a CGI or FastCGI environment as if it were spawned by a web
54
server, upon which the usual
60
functions are usually used to test behaviour.
63
callback communicates with the server over port 17123.
64
Usually this is orchestrated with
66
The port number is fixed.
68
Both of these callbacks must return zero on failure, non-zero on
71
To compile and link, use
74
.Bd -literal -offset indent
75
% cc `pkg-config --cflags kcgi-regress` -c -o sample.o sample.c
76
% cc -o sample sample.o `pkg-config --libs kcgi-regress`
80
components should use their respective
91
as well, or on some systems,
96
These functions return zero on failure, non-zero on success.
98
The following regression test simply checks that the server responds.
99
Its only check is for operation and HTTP status code (201).
100
.Bd -literal -offset indent
104
#include <curl/curl.h>
107
#include <kcgiregress.h>
114
if (khttp_parse(&r, NULL, 0, NULL, 0, 0) != KCGI_OK)
116
khttp_head(&r, kresps[KRESP_STATUS],
117
"%s", khttps[KHTTP_201]);
118
khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
119
"%s", kmimetypes[KMIME_APP_JSON]);
132
if ((curl = curl_easy_init()) == NULL)
134
curl_easy_setopt(curl, CURLOPT_URL,
135
"http://localhost:17123/index.json");
136
if (curl_easy_perform(curl) != CURLE_OK)
138
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http);
139
curl_easy_cleanup(curl);
140
curl_global_cleanup();
148
return kcgi_regress_cgi
149
(client, NULL, server, NULL) ? 0 : 1;
153
To compile this simple regression test, the
159
libraries and headers are needed, along with further dependencies.
162
.Bd -literal -offset indent
163
% export PKGS="kcgi-regress kcgi-json libcurl"
164
% cc `pkg-config --cflags $PKGS` -c sample.c
165
% cc -o sample sample.o `pkg-config --libs $PKGS`
170
has its configuration recognised by
172
which isn't always the case: sometimes
177
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .