Work on requests
This commit adds tests for a request and the implementation. The first line of a request should now be decoded correctly
This commit is contained in:
parent
66d4702297
commit
0e2b9dae2b
4 changed files with 224 additions and 11 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "munit/munit.h"
|
||||
#include "config.test.c"
|
||||
#include "request.test.c"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -13,6 +14,7 @@ int main (int argc, char* argv[]) {
|
|||
|
||||
MunitSuite all_suites[] = {
|
||||
config_test_suite,
|
||||
request_test_suite,
|
||||
{ NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE }
|
||||
};
|
||||
|
||||
|
|
162
tests/request.test.c
Normal file
162
tests/request.test.c
Normal file
|
@ -0,0 +1,162 @@
|
|||
#include "munit/munit.h"
|
||||
#include "../src/request.c"
|
||||
|
||||
typedef struct {
|
||||
char *fullLine;
|
||||
char *method;
|
||||
char *host;
|
||||
char *protocol;
|
||||
double version;
|
||||
char *path;
|
||||
char *queryString;
|
||||
} firstLine;
|
||||
|
||||
|
||||
static firstLine line1Examples[] = {
|
||||
//Full Line, Method Host Protocol Version Path
|
||||
{ "GET /search?q=test HTTP/2", "GET", "", "", 2, "/search", "?q=test"},
|
||||
{ "POST http://example.com/test HTTP/1.1", "POST", "example.com", "http", 1.1, "/test", "" },
|
||||
{ "POST https://example.com/test/test2/test3 HTTP/1.1", "POST", "example.com", "https", 1.1, "/test/test2/test3", ""},
|
||||
{ NULL, NULL, NULL, NULL, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
MunitResult testFirstLineProtocols(const MunitParameter params[],
|
||||
void* user_data_or_fixture){
|
||||
Request *req;
|
||||
for ( firstLine *line = line1Examples; line->fullLine != NULL; line++ ){
|
||||
req = newRequest();
|
||||
requestFirstLine( req, line->fullLine );
|
||||
munit_assert_string_equal( req->protocol, line->protocol );
|
||||
free( req );
|
||||
}
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
MunitResult testFirstLineMethod(const MunitParameter params[],
|
||||
void* user_data_or_fixture){
|
||||
Request *req;
|
||||
for ( firstLine *line = line1Examples; line->fullLine != NULL; line++ ){
|
||||
req = newRequest();
|
||||
requestFirstLine( req, line->fullLine );
|
||||
munit_assert_string_equal( req->method, line->method );
|
||||
free( req );
|
||||
}
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
MunitResult testFirstLineHosts(const MunitParameter params[],
|
||||
void* user_data_or_fixture){
|
||||
Request *req;
|
||||
for ( firstLine *line = line1Examples; line->fullLine != NULL; line++ ){
|
||||
req = newRequest();
|
||||
requestFirstLine( req, line->fullLine );
|
||||
munit_assert_string_equal( req->host, line->host );
|
||||
free( req );
|
||||
}
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
MunitResult testFirstLinePaths(const MunitParameter params[],
|
||||
void* user_data_or_fixture){
|
||||
Request *req;
|
||||
for ( firstLine *line = line1Examples; line->fullLine != NULL; line++ ){
|
||||
req = newRequest();
|
||||
requestFirstLine( req, line->fullLine );
|
||||
munit_assert_string_equal( req->path, line->path );
|
||||
free( req );
|
||||
}
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
MunitResult testFirstLineVersions(const MunitParameter params[],
|
||||
void* user_data_or_fixture){
|
||||
Request *req;
|
||||
for ( firstLine *line = line1Examples; line->fullLine != NULL; line++ ){
|
||||
req = newRequest();
|
||||
requestFirstLine( req, line->fullLine );
|
||||
munit_assert_float( req->version, ==, line->version );
|
||||
free( req );
|
||||
}
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
MunitResult testFirstLineQueryString(const MunitParameter params[],
|
||||
void* user_data_or_fixture){
|
||||
Request *req;
|
||||
for ( firstLine *line = line1Examples; line->fullLine != NULL; line++ ){
|
||||
req = newRequest();
|
||||
requestFirstLine( req, line->fullLine );
|
||||
munit_assert_string_equal( req->queryString, line->queryString );
|
||||
free( req );
|
||||
}
|
||||
return MUNIT_OK;
|
||||
}
|
||||
|
||||
static MunitTest request_tests[] = {
|
||||
{
|
||||
"/line1/versions", /* name */
|
||||
testFirstLineVersions, /* test */
|
||||
NULL, /* setup */
|
||||
NULL, /* tear_down */
|
||||
MUNIT_TEST_OPTION_NONE, /* options */
|
||||
NULL /* parameters */
|
||||
}, {
|
||||
"/line1/methods", /* name */
|
||||
testFirstLineMethod, /* test */
|
||||
NULL, /* setup */
|
||||
NULL, /* tear_down */
|
||||
MUNIT_TEST_OPTION_NONE, /* options */
|
||||
NULL /* parameters */
|
||||
},{
|
||||
"/line1/protocols", /* name */
|
||||
testFirstLineProtocols, /* test */
|
||||
NULL, /* setup */
|
||||
NULL, /* tear_down */
|
||||
MUNIT_TEST_OPTION_NONE, /* options */
|
||||
NULL /* parameters */
|
||||
},{
|
||||
"/line1/hosts", /* name */
|
||||
testFirstLineHosts, /* test */
|
||||
NULL, /* setup */
|
||||
NULL, /* tear_down */
|
||||
MUNIT_TEST_OPTION_NONE, /* options */
|
||||
NULL /* parameters */
|
||||
},{
|
||||
"/line1/paths", /* name */
|
||||
testFirstLinePaths, /* test */
|
||||
NULL, /* setup */
|
||||
NULL, /* tear_down */
|
||||
MUNIT_TEST_OPTION_NONE, /* options */
|
||||
NULL /* parameters */
|
||||
},{
|
||||
"/line1/queryStrings", /* name */
|
||||
testFirstLineQueryString, /* test */
|
||||
NULL, /* setup */
|
||||
NULL, /* tear_down */
|
||||
MUNIT_TEST_OPTION_NONE, /* options */
|
||||
NULL /* parameters */
|
||||
},
|
||||
/* Mark the end of the array with an entry where the test
|
||||
* function is NULL */
|
||||
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
|
||||
};
|
||||
|
||||
MunitSuite request_test_suite = {
|
||||
"/request", /* name */
|
||||
request_tests, /* tests */
|
||||
NULL, /* suites */
|
||||
1, /* iterations */
|
||||
MUNIT_SUITE_OPTION_NONE /* options */
|
||||
};
|
||||
|
||||
#ifndef MAINTEST
|
||||
#define MAINTEST
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
return munit_suite_main(&request_test_suite, NULL, argc, argv);
|
||||
}
|
||||
|
||||
#endif /* ifndef MAINTEST */
|
Loading…
Add table
Add a link
Reference in a new issue