Work on requests

This commit is contained in:
Jonathan Hodgson 2022-01-17 14:03:34 +00:00
parent d49e86faff
commit 8912994e1d
3 changed files with 93 additions and 5 deletions

View file

@ -4,6 +4,10 @@
#include "munit/munit.h"
#include "../src/readline.c"
#include "../src/request.c"
#ifndef REQUESTRESPONSE_C
#define REQUESTRESPONSE_C
#include "../src/requestresponse.c"
#endif /* ifndef REQUESTRESPONSE_C */
typedef struct {
char *fullLine;
@ -99,6 +103,28 @@ MunitResult testFirstLineQueryString(const MunitParameter params[],
return MUNIT_OK;
}
MunitResult testRequestAddHeader(const MunitParameter params[],
void* user_data_or_fixture){
Request *req = newRequest();
munit_assert_null(req->headers);
requestAddHeader(req, "Content-Length: 0");
munit_assert_int( 1, ==, countHeaders(req->headers) );
requestAddHeader(req, "Test-header: 5");
munit_assert_int( 2, ==, countHeaders(req->headers) );
return MUNIT_OK;
}
MunitResult testRequestToString(const MunitParameter params[],
void* user_data_or_fixture){
Request *req = newRequest();
requestFirstLine( req, "GET /search?q=test HTTP/1.1" );
munit_assert_string_equal( requestToString( req, 0 ), "GET /search?q=test HTTP/1.1\r\n" );
requestAddHeader( req, "Host: example.com" );
munit_assert_string_equal( requestToString( req, 0 ), "GET /search?q=test HTTP/1.1\r\nHost: example.com\r\n" );
return MUNIT_OK;
}
static MunitTest request_tests[] = {
{
"/line1/versions", /* name */
@ -142,6 +168,20 @@ static MunitTest request_tests[] = {
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},{
"/headers/add", /* name */
testRequestAddHeader, /* test */
NULL, /* setup */
NULL, /* tear_down */
MUNIT_TEST_OPTION_NONE, /* options */
NULL /* parameters */
},{
"/tostring", /* name */
testRequestToString, /* 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 */