Commit 0468d8a7 authored by Simon Morlat's avatar Simon Morlat

create test suite for http

parent 9c9d7e28
......@@ -36,13 +36,13 @@ struct belle_http_io_error_event{
typedef struct belle_http_io_error_event belle_http_io_error_event_t;
typedef struct belle_http_io_error_event belle_http_timeout_event;
typedef struct belle_http_io_error_event belle_http_timeout_event_t;
#define BELLE_HTTP_INTERFACE_FUNCS(argT) \
void (*process_response_event)(argT *user_ctx, const belle_http_response_event_t *event); \
void (*process_io_error)(argT *user_ctx, const belle_sip_io_error_event_t *event); \
void (*process_timeout)(argT *user_ctx, const belle_sip_timeout_event_t *event); \
void (*process_response)(argT *user_ctx, const belle_http_response_event_t *event); \
void (*process_io_error)(argT *user_ctx, const belle_http_io_error_event_t *event); \
void (*process_timeout)(argT *user_ctx, const belle_http_timeout_event_t *event); \
void (*process_auth_requested)(argT *user_ctx, belle_sip_auth_event_t *event);
BELLE_SIP_DECLARE_INTERFACE_BEGIN(belle_http_request_listener_t)
......@@ -50,7 +50,7 @@ BELLE_SIP_DECLARE_INTERFACE_BEGIN(belle_http_request_listener_t)
BELLE_SIP_DECLARE_INTERFACE_END
struct belle_http_request_listener_callbacks{
BELLE_HTTP_INTERFACE_FUNCS(void*)
BELLE_HTTP_INTERFACE_FUNCS(void)
void (*listener_destroyed)(void *user_ctx);
};
......
......@@ -30,17 +30,17 @@ struct belle_http_callbacks{
static void process_response_event(belle_http_request_listener_t *l, const belle_http_response_event_t *event){
belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
if (obj->cbs.process_response_event)
obj->cbs.process_response_event(obj->user_ctx,event);
if (obj->cbs.process_response)
obj->cbs.process_response(obj->user_ctx,event);
}
static void process_io_error(belle_http_request_listener_t *l, const belle_sip_io_error_event_t *event){
static void process_io_error(belle_http_request_listener_t *l, const belle_http_io_error_event_t *event){
belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
if (obj->cbs.process_io_error)
obj->cbs.process_io_error(obj->user_ctx,event);
}
static void process_timeout(belle_http_request_listener_t *l, const belle_sip_timeout_event_t *event){
static void process_timeout(belle_http_request_listener_t *l, const belle_http_timeout_event_t *event){
belle_http_callbacks_t *obj=(belle_http_callbacks_t*)l;
if (obj->cbs.process_timeout)
obj->cbs.process_timeout(obj->user_ctx,event);
......
......@@ -59,7 +59,7 @@ static int channel_on_event(belle_sip_channel_listener_t *obj, belle_sip_channel
ev.provider=NULL;
ev.request=req;
ev.response=(belle_http_response_t*)msg;
BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_response_event,&ev);
BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_response,&ev);
belle_sip_object_unref(req);
}
belle_sip_object_unref(msg);
......
......@@ -16,7 +16,8 @@ belle_sip_tester_SOURCES= belle_sip_tester.c belle_sip_tester.h\
belle_sip_resolver_tester.c \
belle_sip_core_tester.c \
belle_generic_uri_tester.c \
register_tester.h
register_tester.h \
belle_http_tester.c
belle_sip_tester_CFLAGS=$(CUNIT_CFLAGS) $(STRICT_OPTIONS) $(TLS_CFLAGS)
......
......@@ -19,6 +19,63 @@
#include <stdio.h>
#include "CUnit/Basic.h"
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
#include "belle_sip_tester.h"
#include <belle_sip_internal.h>
typedef struct http_counters{
int response_count;
int io_error_count;
}http_counters_t;
static void process_response(void *data, const belle_http_response_event_t *event){
http_counters_t *counters=(http_counters_t*)data;
counters->response_count++;
CU_ASSERT_PTR_NOT_NULL(event->response);
if (event->response){
int code=belle_http_response_get_status_code(event->response);
const char *body=belle_sip_message_get_body(BELLE_SIP_MESSAGE(event->response));
CU_ASSERT_EQUAL(code,200);
CU_ASSERT_PTR_NOT_NULL(body);
}
}
static void process_io_error(void *data, const belle_http_io_error_event_t *event){
http_counters_t *counters=(http_counters_t*)data;
counters->io_error_count++;
}
static void one_get(void){
belle_sip_stack_t *stack=belle_sip_stack_new(NULL);
belle_http_provider_t *prov=belle_sip_stack_create_http_provider(stack,"0.0.0.0");
belle_http_request_listener_callbacks_t cbs={0};
http_counters_t counters={0};
belle_http_request_listener_t *l;
belle_http_request_t *req=belle_http_request_create("GET",
belle_generic_uri_parse("http://smtp.linphone.org/"),
belle_sip_header_create("User-Agent","belle-sip/"PACKAGE_VERSION),
NULL);
cbs.process_response=process_response;
cbs.process_io_error=process_io_error;
l=belle_http_request_listener_create_from_callbacks(&cbs,NULL);
belle_http_provider_send_request(prov,req,l);
belle_sip_stack_sleep(stack,5000);
CU_ASSERT_TRUE(counters.response_count==1);
CU_ASSERT_TRUE(counters.io_error_count==0);
belle_sip_object_unref(l);
belle_sip_object_unref(prov);
belle_sip_object_unref(stack);
}
test_t http_tests[] = {
{ "One http GET", one_get },
};
test_suite_t http_test_suite = {
"http",
NULL,
NULL,
sizeof(http_tests) / sizeof(http_tests[0]),
http_tests
};
......@@ -138,6 +138,7 @@ void belle_sip_tester_init(void) {
add_test_suite(&register_test_suite);
add_test_suite(&dialog_test_suite);
add_test_suite(&refresher_test_suite);
add_test_suite(&http_test_suite);
}
......@@ -167,8 +168,16 @@ int belle_sip_tester_run_tests(const char *suite_name, const char *test_name) {
CU_pSuite suite;
CU_basic_set_mode(CU_BRM_VERBOSE);
suite=CU_get_suite(suite_name);
if (suite==NULL){
fprintf(stderr,"There is no suite named '%s'",suite_name);
exit(-1);
}
if (test_name) {
CU_pTest test=CU_get_test_by_name(test_name, suite);
if (test==NULL){
fprintf(stderr,"There is no suite named '%s'",suite_name);
exit(-1);
}
CU_basic_run_test(suite, test);
} else
CU_basic_run_suite(suite);
......
......@@ -56,6 +56,7 @@ extern test_suite_t authentication_helper_test_suite;
extern test_suite_t register_test_suite;
extern test_suite_t dialog_test_suite;
extern test_suite_t refresher_test_suite;
extern test_suite_t http_test_suite;
extern int belle_sip_tester_ipv6_available(void);
extern int belle_sip_tester_nb_test_suites(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment