KCGIREGRESS(3)

NAME
kcgiregress, kcgi_regress_cgi, kcgi_regress_fcgi - regression framework for kcgi

LIBRARY
libkcgiregress

SYNOPSIS
#include <kcgiregress.h>
int
kcgi_regress_cgi(int (*client)(void *), void *clientData, int (*server)(void *), void *serverData);
int
kcgi_regress_fcgi(int (*client)(void *), void *clientData, int (*server)(void *), void *serverData);

DESCRIPTION
The kcgi_regress_cgi and kcgi_regress_fcgi functions are used for automated testing of kcgi(3) systems, both as CGI and FastCGI scripts. It is the mechanism used for internal regression tests as well.

Applications wishing to use this framework provide callback functions to kcgi_regress_cgi() and kcgi_regress_fcgi(), which invoke server with argument serverArg within a CGI or FastCGI environment as if it were spawned by a web server, upon which the usual khttp_parse(3) or khttp_fcgi_init(3) and khttp_fcgi_parse(3) functions are used to test behaviour. Meanwhile, the client function is invoked for communicating with the server over port 17123. The libcurl(3) library is used for internal testing on the client side.

In most applications, the main function invokes kcgi_regress_cgi or kcgi_regress_fcgi, prepares a libCURL request in the client callback, then runs the usual kcgi(3) sequence in the server callback.

RETURN VALUES
Both the client and server functions should return zero on test failure. kcgi_regress_cgi() and kcgi_regress_fcgi() return zero if any tests or internal machinery fail.

EXAMPLES
The following regression test simple checks whether a given URL, login.json, is recognised (and returns HTTP error code 200) by CGI script foobar, which is assumed to be accessible by execl(3).

    #include <stdlib.h>
    #include <unistd.h>
    #include <curl/curl.h>
    #include <kcgiregress.h>
    static int
    child(void *arg)
    {
      execl("foobar", "foobar", (char *)NULL);
      _exit(EXIT_FAILURE);
    }
    static int
    parent(void *fp)
    {
      CURL *curl;
      long http;
      curl = curl_easy_init();
      curl_easy_setopt(curl, CURLOPT_URL,
        "http://localhost:17123/login.json");
      if (CURLE_OK != curl_easy_perform(curl))
        return(0);
      curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http);
      curl_easy_cleanup(curl);
      curl_global_cleanup();
      return(200 == http);
    }
    int
    main(void)
    {
      return(kcgi_regress_cgi(parent, NULL, child, NULL) ?
        EXIT_SUCCESS : EXIT_FAILURE);
    }

AUTHORS
The kcgiregress library was written by Kristaps Dzonsons <kristaps@bsd.lv>.