|
|
|
#ifndef RESPONSE_TEST
|
|
|
|
#define RESPONSE_TEST value
|
|
|
|
|
|
|
|
#include "munit/munit.h"
|
|
|
|
#ifndef REQUESTRESPONSE_C
|
|
|
|
#define REQUESTRESPONSE_C value
|
|
|
|
#include "../src/requestresponse.c"
|
|
|
|
#endif /* ifndef REQUESTRESPONSE_C */
|
|
|
|
#include "../src/response.c"
|
|
|
|
|
|
|
|
|
|
|
|
MunitResult testResponseNewStatus(const MunitParameter params[],
|
|
|
|
void* user_data_or_fixture){
|
|
|
|
Response *rsp = newResponse();
|
|
|
|
munit_assert_int( rsp->statusCode, ==, 200 );
|
|
|
|
return MUNIT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MunitResult testResponseNewStatusMessage(const MunitParameter params[],
|
|
|
|
void* user_data_or_fixture){
|
|
|
|
Response *rsp = newResponse();
|
|
|
|
munit_assert_string_equal( rsp->statusMessage, "OK" );
|
|
|
|
return MUNIT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MunitResult testResponseNewVersion(const MunitParameter params[],
|
|
|
|
void* user_data_or_fixture){
|
|
|
|
Response *rsp = newResponse();
|
|
|
|
munit_assert_float( rsp->version, ==, 1.1 );
|
|
|
|
return MUNIT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MunitResult testResponseSetBody(const MunitParameter params[],
|
|
|
|
void* user_data_or_fixture){
|
|
|
|
Response *rsp = newResponse();
|
|
|
|
responseSetBody( rsp, "Testing", 1 );
|
|
|
|
munit_assert_string_equal( rsp->body, "Testing" );
|
|
|
|
munit_assert_string_equal( getHeader( rsp->headers, "content-length" )->value, "7" );
|
|
|
|
return MUNIT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MunitResult testResponseToString(const MunitParameter params[],
|
|
|
|
void* user_data_or_fixture){
|
|
|
|
Response *rsp = newResponse();
|
|
|
|
responseSetBody( rsp, "Testing", 1 );
|
|
|
|
munit_assert_string_equal( responseToString( rsp ), "HTTP/1.1 200 OK\r\nContent-Length: 7\r\nContent-Type: text/plain\r\n\r\nTesting" );
|
|
|
|
return MUNIT_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static MunitTest response_tests[] = {
|
|
|
|
{
|
|
|
|
"/new/status", /* name */
|
|
|
|
testResponseNewStatus, /* test */
|
|
|
|
NULL, /* setup */
|
|
|
|
NULL, /* tear_down */
|
|
|
|
MUNIT_TEST_OPTION_NONE, /* options */
|
|
|
|
NULL /* parameters */
|
|
|
|
}, {
|
|
|
|
"/new/statusMessage", /* name */
|
|
|
|
testResponseNewStatusMessage, /* test */
|
|
|
|
NULL, /* setup */
|
|
|
|
NULL, /* tear_down */
|
|
|
|
MUNIT_TEST_OPTION_NONE, /* options */
|
|
|
|
NULL /* parameters */
|
|
|
|
}, {
|
|
|
|
"/new/version", /* name */
|
|
|
|
testResponseNewVersion, /* test */
|
|
|
|
NULL, /* setup */
|
|
|
|
NULL, /* tear_down */
|
|
|
|
MUNIT_TEST_OPTION_NONE, /* options */
|
|
|
|
NULL /* parameters */
|
|
|
|
}, {
|
|
|
|
"/set/body", /* name */
|
|
|
|
testResponseSetBody, /* test */
|
|
|
|
NULL, /* setup */
|
|
|
|
NULL, /* tear_down */
|
|
|
|
MUNIT_TEST_OPTION_NONE, /* options */
|
|
|
|
NULL /* parameters */
|
|
|
|
}, {
|
|
|
|
"/to/string", /* name */
|
|
|
|
testResponseToString, /* 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 response_test_suite = {
|
|
|
|
"/response", /* name */
|
|
|
|
response_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(&response_test_suite, NULL, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ifndef MAINTEST */
|
|
|
|
|
|
|
|
#endif /* ifndef RESPONSE_TEST */
|