Commit abe60cf6 authored by jehan's avatar jehan

put basic test into cunit

parent 379835d1
......@@ -54,8 +54,35 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR(belle_sip_channel_t)=
NULL, /*marshall*/
}
};
static void fix_incoming_via(belle_sip_request_t *msg, const struct addrinfo* origin){
char received[NI_MAXHOST];
char rport[NI_MAXSERV];
belle_sip_header_via_t *via;
int err=getnameinfo(origin->ai_addr,origin->ai_addrlen,received,sizeof(received),
rport,sizeof(rport),NI_NUMERICHOST|NI_NUMERICSERV);
if (err!=0){
belle_sip_error("fix_via: getnameinfo() failed: %s",gai_strerror(errno));
return;
}
via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header((belle_sip_message_t*)msg,"via"));
if (via){
belle_sip_header_via_set_received(via,received);
belle_sip_header_via_set_rport(via,atoi(rport));
}
}
void belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents){
int err;
err=belle_sip_channel_recv(obj,&obj->input_stream.buff,MAX_CHANNEL_BUFF_SIZE-1);
if (err>0){
obj->input_stream.buff[err]='\0';
belle_sip_message("read message from %s:%i\n%s",obj->peer_name,obj->peer_port,&obj->input_stream.buff);
obj->input_stream.msg=belle_sip_message_parse(obj->input_stream.buff);
if (obj->input_stream.msg){
if (belle_sip_message_is_request(obj->input_stream.msg)) fix_incoming_via(BELLE_SIP_REQUEST(obj->input_stream.msg),obj->peer);
}else{
belle_sip_error("Could not parse this message.");
}
}
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(obj->listeners,belle_sip_channel_listener_t,on_event,obj,revents);
}
......@@ -115,7 +142,12 @@ const struct addrinfo * belle_sip_channel_get_peer(belle_sip_channel_t *obj){
return obj->peer;
}
belle_sip_message_t* belle_sip_channel_pick_message(belle_sip_channel_t *obj) {
/*FIXME should be synchronized*/
belle_sip_message_t* result = obj->input_stream.msg;
obj->input_stream.msg=NULL;
return result;
}
static void channel_set_state(belle_sip_channel_t *obj, belle_sip_channel_state_t state){
belle_sip_message("channel %p: state %s",obj,channel_state_to_string(state));
......
......@@ -51,7 +51,7 @@ void (*on_sending)(belle_sip_channel_listener_t *l, belle_sip_channel_t *obj, be
BELLE_SIP_DECLARE_INTERFACE_END
#define BELLE_SIP_CHANNEL_LISTENER(obj) BELLE_SIP_INTERFACE_CAST(obj,belle_sip_channel_listener_t)
#define MAX_BUFF_SIZE 64000
#define MAX_CHANNEL_BUFF_SIZE 64000
typedef enum input_stream_state {
WAITING_MESSAGE_START=0
......@@ -61,7 +61,8 @@ typedef enum input_stream_state {
typedef struct belle_sip_channel_input_stream{
input_stream_state_t state;
char buff[MAX_BUFF_SIZE];
char buff[MAX_CHANNEL_BUFF_SIZE];
belle_sip_message_t *msg;
}belle_sip_channel_input_stream_t;
typedef struct belle_sip_stream_channel belle_sip_stream_channel_t;
......@@ -102,6 +103,10 @@ int belle_sip_channel_connect(belle_sip_channel_t *obj);
int belle_sip_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen);
int belle_sip_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen);
/**
* pickup last received message. This method take the ownership of the message.
*/
belle_sip_message_t* belle_sip_channel_pick_message(belle_sip_channel_t *obj);
int belle_sip_channel_queue_message(belle_sip_channel_t *obj, belle_sip_message_t *msg);
......
......@@ -48,22 +48,7 @@ static void belle_sip_provider_dispatch_message(belle_sip_provider_t *prov, bell
}
}
static void fix_incoming_via(belle_sip_request_t *msg, const struct addrinfo* origin){
char received[NI_MAXHOST];
char rport[NI_MAXSERV];
belle_sip_header_via_t *via;
int err=getnameinfo(origin->ai_addr,origin->ai_addrlen,received,sizeof(received),
rport,sizeof(rport),NI_NUMERICHOST|NI_NUMERICSERV);
if (err!=0){
belle_sip_error("fix_via: getnameinfo() failed: %s",gai_strerror(errno));
return;
}
via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header((belle_sip_message_t*)msg,"via"));
if (via){
belle_sip_header_via_set_received(via,received);
belle_sip_header_via_set_rport(via,atoi(rport));
}
}
static void fix_outgoing_via(belle_sip_provider_t *p, belle_sip_channel_t *chan, belle_sip_message_t *msg){
belle_sip_header_via_t *via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header(msg,"via"));
......@@ -83,7 +68,7 @@ static void fix_outgoing_via(belle_sip_provider_t *p, belle_sip_channel_t *chan,
belle_sip_free(branchid);
}
}
/*
static void belle_sip_provider_read_message(belle_sip_provider_t *prov, belle_sip_channel_t *chan){
char buffer[belle_sip_network_buffer_size];
int err;
......@@ -101,10 +86,10 @@ static void belle_sip_provider_read_message(belle_sip_provider_t *prov, belle_si
}
}
}
*/
static int channel_on_event(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, unsigned int revents){
if (revents & BELLE_SIP_EVENT_READ){
belle_sip_provider_read_message(BELLE_SIP_PROVIDER(obj),chan);
belle_sip_provider_dispatch_message(BELLE_SIP_PROVIDER(obj),belle_sip_channel_pick_message(chan));
}
return 0;
}
......
if BUILD_TESTS
noinst_PROGRAMS=belle_sip_tester basic_test belle_sip_object_describe
noinst_PROGRAMS=belle_sip_tester belle_sip_object_describe
belle_sip_tester_SOURCES= belle_sip_tester.c \
belle_sdp_tester.c \
......@@ -8,15 +8,13 @@ belle_sip_tester_SOURCES= belle_sip_tester.c \
belle_sip_headers_tester.c \
belle_sip_message_tester.c \
auth_helper_tester.c \
cast_test.c
cast_test.c \
belle_sip_register_tester.c
belle_sip_tester_CFLAGS=$(CUNIT_CFLAGS) $(STRICT_OPTIONS)
belle_sip_tester_LDFLAGS=$(CUNIT_LIBS)
basic_test_SOURCES=basic_test.c
belle_sip_object_describe_SOURCES=describe.c
INCLUDES=-I$(top_srcdir)/include -I$(top_srcdir)/src
......@@ -25,7 +23,7 @@ LDADD=$(top_builddir)/src/libbellesip.la
AM_LDFLAGS=-export-dynamic
AM_CFLAGS=$(STRICT_OPTIONS)
AM_CFLAGS=$(STRICT_OPTIONS)
test: belle_sip_tester
......
......@@ -17,8 +17,10 @@
*/
#include <stdio.h>
#include "CUnit/Basic.h"
#include "belle-sip/belle-sip.h"
static void process_dialog_terminated(belle_sip_listener_t *obj, const belle_sip_dialog_terminated_event_t *event){
belle_sip_message("process_dialog_terminated called");
}
......@@ -68,7 +70,8 @@ BELLE_SIP_DECLARE_IMPLEMENTED_INTERFACES_1(test_listener_t,belle_sip_listener_t)
BELLE_SIP_INSTANCIATE_VPTR(test_listener_t,belle_sip_object_t,NULL,NULL,NULL,FALSE);
int main(int argc, char *argv[]){
void register_test() {
belle_sip_stack_t * stack=belle_sip_stack_new(NULL);
belle_sip_listening_point_t *lp;
belle_sip_provider_t *prov;
......@@ -99,5 +102,13 @@ int main(int argc, char *argv[]){
printf("Exiting\n");
belle_sip_object_unref(prov);
belle_sip_object_unref(stack);
return 0;
return;
}
int belle_sip_register_test_suite(){
CU_pSuite pSuite = CU_add_suite("Register test suite", NULL, NULL);
if (NULL == CU_add_test(pSuite, "casting transactions", register_test)) {
return CU_get_error();
}
}
......@@ -25,6 +25,7 @@ extern int belle_sip_message_test_suite ();
extern int belle_sdp_test_suite();
extern int belle_sip_authentication_helper_suite ();
extern int belle_sip_cast_test_suite();
extern int belle_sip_register_test_suite();
int main (int argc, char *argv[]) {
......@@ -52,6 +53,8 @@ int main (int argc, char *argv[]) {
belle_sip_cast_test_suite();
belle_sip_authentication_helper_suite();
belle_sip_register_test_suite();
/* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests();
......
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