initial load of upstream version 1.06.32
[xmlrpc-c] / src / test / cgi.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <errno.h>
5
6 #include "xmlrpc_config.h"
7
8 #include "test.h"
9 #include "cgi.h"
10
11 static const char cgiResponse1[] =
12   "....Status: 200 OK\n"
13   "Content-type: text/xml; charset=\"utf-8\"\n"
14   "Content-length: 141\n"
15   "\n"
16   "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
17   "<methodResponse>\r\n"
18   "<params>\r\n"
19   "<param><value><i4>12</i4></value></param>\r\n"
20   "</params>\r\n"
21   "</methodResponse>\r\n";
22
23
24 #define TESTDATA_DIR "data"
25 #define DIRSEP DIRECTORY_SEPARATOR
26
27 void
28 test_server_cgi(void) {
29 /*----------------------------------------------------------------------------
30   Here, we pretend to be a web server when someone has requested a POST
31   to the CGI script "cgitest1".
32 -----------------------------------------------------------------------------*/
33     FILE * cgiOutputP;
34
35     printf("Running CGI tests...\n");
36
37     cgiOutputP = popen("REQUEST_METHOD=POST "
38                        "CONTENT_TYPE=text/xml "
39                        "CONTENT_LENGTH=211 "
40                        "./cgitest1 "
41                        "<"
42                        TESTDATA_DIR DIRSEP "sample_add_call.xml",
43                        "r");
44
45     if (cgiOutputP == NULL)
46         TEST_ERROR("Unable to run 'cgitest' program.");
47     else {
48         unsigned char cgiResponse[4096];
49         size_t bytesRead;
50
51         bytesRead = fread(cgiResponse, 1, sizeof(cgiResponse), cgiOutputP);
52
53         TEST(bytesRead == strlen(cgiResponse1));
54
55         TEST(memcmp(cgiResponse, cgiResponse1, bytesRead) == 0);
56     }
57     fclose(cgiOutputP);
58     printf("\n");
59     printf("CGI tests done.\n");
60 }