Commit 3cf4815b authored by Ghislain MARY's avatar Ghislain MARY

Reorganize unit tests.

parent 70bc90cc
...@@ -17,9 +17,11 @@ ...@@ -17,9 +17,11 @@
*/ */
#include "belle-sip/auth-helper.h" #include "belle-sip/auth-helper.h"
#include "belle_sip_tester.h"
#include <stdio.h> #include <stdio.h>
#include "CUnit/Basic.h" #include "CUnit/Basic.h"
static void test_authentication(void) { static void test_authentication(void) {
const char* l_raw_header = "WWW-Authenticate: Digest " const char* l_raw_header = "WWW-Authenticate: Digest "
"algorithm=MD5, realm=\"sip.linphone.org\", opaque=\"1bc7f9097684320\"," "algorithm=MD5, realm=\"sip.linphone.org\", opaque=\"1bc7f9097684320\","
...@@ -34,6 +36,7 @@ static void test_authentication(void) { ...@@ -34,6 +36,7 @@ static void test_authentication(void) {
belle_sip_object_unref(www_authenticate); belle_sip_object_unref(www_authenticate);
belle_sip_object_unref(authorization); belle_sip_object_unref(authorization);
} }
static void test_authentication_qop_auth(void) { static void test_authentication_qop_auth(void) {
const char* l_raw_header = "WWW-Authenticate: Digest " const char* l_raw_header = "WWW-Authenticate: Digest "
"algorithm=MD5, realm=\"sip.linphone.org\", opaque=\"1bc7f9097684320\"," "algorithm=MD5, realm=\"sip.linphone.org\", opaque=\"1bc7f9097684320\","
...@@ -70,26 +73,19 @@ static void test_proxy_authentication(void) { ...@@ -70,26 +73,19 @@ static void test_proxy_authentication(void) {
belle_sip_object_unref(proxy_authorization); belle_sip_object_unref(proxy_authorization);
} }
int belle_sip_authentication_helper_suite () {
CU_pSuite pSuite = NULL;
test_t authentication_helper_tests[] = {
{ "Proxy-Authenticate", test_proxy_authentication },
{ "WWW-Authenticate", test_authentication },
{ "WWW-Authenticate (with qop)", test_authentication_qop_auth }
};
/* add a suite to the registry */ test_suite_t authentication_helper_test_suite = {
pSuite = CU_add_suite("Authentication-helper", NULL,NULL); "Authentication helper",
if (NULL == pSuite) { NULL,
return CU_get_error(); NULL,
} sizeof(authentication_helper_tests) / sizeof(authentication_helper_tests[0]),
authentication_helper_tests
};
if (NULL == CU_add_test(pSuite, "test_authentication", test_authentication)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_authentication_qop_auth", test_authentication_qop_auth)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_proxy_authentication", test_proxy_authentication)) {
return CU_get_error();
}
return CU_get_error();
}
...@@ -17,16 +17,11 @@ ...@@ -17,16 +17,11 @@
*/ */
#include "belle-sip/belle-sdp.h" #include "belle-sip/belle-sdp.h"
#include "belle_sip_tester.h"
#include <stdio.h> #include <stdio.h>
#include "CUnit/Basic.h" #include "CUnit/Basic.h"
static int init_suite_sdp(void) {
return 0;
}
static int clean_suite_sdp(void) {
return 0;
}
//v=0 //v=0
//o=jehan-mac 1239 1239 IN IP4 192.168.0.18 //o=jehan-mac 1239 1239 IN IP4 192.168.0.18
//s=Talk //s=Talk
...@@ -61,6 +56,7 @@ static void test_attribute(void) { ...@@ -61,6 +56,7 @@ static void test_attribute(void) {
CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute)); CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute)); belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
} }
static void test_attribute_2(void) { static void test_attribute_2(void) {
belle_sdp_attribute_t* lTmp; belle_sdp_attribute_t* lTmp;
belle_sdp_attribute_t* lAttribute = belle_sdp_attribute_parse("a=ice-pwd:31ec21eb38b2ec6d36e8dc7b\r\n"); belle_sdp_attribute_t* lAttribute = belle_sdp_attribute_parse("a=ice-pwd:31ec21eb38b2ec6d36e8dc7b\r\n");
...@@ -75,6 +71,7 @@ static void test_attribute_2(void) { ...@@ -75,6 +71,7 @@ static void test_attribute_2(void) {
CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute)); CU_ASSERT_TRUE(belle_sdp_attribute_as_value(lAttribute));
belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute)); belle_sip_object_unref(BELLE_SIP_OBJECT(lAttribute));
} }
static void test_bandwidth(void) { static void test_bandwidth(void) {
belle_sdp_bandwidth_t* lTmp; belle_sdp_bandwidth_t* lTmp;
belle_sdp_bandwidth_t* l_bandwidth = belle_sdp_bandwidth_parse("b=AS:380"); belle_sdp_bandwidth_t* l_bandwidth = belle_sdp_bandwidth_parse("b=AS:380");
...@@ -89,7 +86,6 @@ static void test_bandwidth(void) { ...@@ -89,7 +86,6 @@ static void test_bandwidth(void) {
belle_sip_free(l_raw_bandwidth); belle_sip_free(l_raw_bandwidth);
} }
static void test_connection(void) { static void test_connection(void) {
belle_sdp_connection_t* lTmp; belle_sdp_connection_t* lTmp;
belle_sdp_connection_t* lConnection = belle_sdp_connection_parse("c=IN IP4 192.168.0.18"); belle_sdp_connection_t* lConnection = belle_sdp_connection_parse("c=IN IP4 192.168.0.18");
...@@ -132,6 +128,7 @@ static void test_email(void) { ...@@ -132,6 +128,7 @@ static void test_email(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(l_email)); belle_sip_object_unref(BELLE_SIP_OBJECT(l_email));
belle_sip_free(l_raw_email); belle_sip_free(l_raw_email);
} }
static void test_info(void) { static void test_info(void) {
belle_sdp_info_t* lTmp; belle_sdp_info_t* lTmp;
belle_sdp_info_t* l_info = belle_sdp_info_parse("i=A Seminar on the session description protocol"); belle_sdp_info_t* l_info = belle_sdp_info_parse("i=A Seminar on the session description protocol");
...@@ -144,6 +141,7 @@ static void test_info(void) { ...@@ -144,6 +141,7 @@ static void test_info(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(l_info)); belle_sip_object_unref(BELLE_SIP_OBJECT(l_info));
belle_sip_free(l_raw_info); belle_sip_free(l_raw_info);
} }
static void test_media(void) { static void test_media(void) {
belle_sdp_media_t* lTmp; belle_sdp_media_t* lTmp;
belle_sip_list_t* list; belle_sip_list_t* list;
...@@ -231,7 +229,8 @@ static void test_media_description(void) { ...@@ -231,7 +229,8 @@ static void test_media_description(void) {
belle_sip_free(l_raw_media_description); belle_sip_free(l_raw_media_description);
return; return;
} }
static void simple_session_description(void) {
static void test_simple_session_description(void) {
const char* l_src = "v=0\r\n"\ const char* l_src = "v=0\r\n"\
"o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\ "o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\
"s=Talk\r\n"\ "s=Talk\r\n"\
...@@ -365,6 +364,7 @@ static belle_sdp_mime_parameter_t* find_mime_parameter(belle_sip_list_t* list,co ...@@ -365,6 +364,7 @@ static belle_sdp_mime_parameter_t* find_mime_parameter(belle_sip_list_t* list,co
} }
return NULL; return NULL;
} }
static void check_mime_param (belle_sdp_mime_parameter_t* mime_param static void check_mime_param (belle_sdp_mime_parameter_t* mime_param
,int rate ,int rate
,int channel_count ,int channel_count
...@@ -382,6 +382,7 @@ static void check_mime_param (belle_sdp_mime_parameter_t* mime_param ...@@ -382,6 +382,7 @@ static void check_mime_param (belle_sdp_mime_parameter_t* mime_param
if (type) CU_ASSERT_STRING_EQUAL(belle_sdp_mime_parameter_get_type(mime_param),type); if (type) CU_ASSERT_STRING_EQUAL(belle_sdp_mime_parameter_get_type(mime_param),type);
if (parameters) CU_ASSERT_STRING_EQUAL(belle_sdp_mime_parameter_get_parameters(mime_param),parameters); if (parameters) CU_ASSERT_STRING_EQUAL(belle_sdp_mime_parameter_get_parameters(mime_param),parameters);
} }
static void test_mime_parameter(void) { static void test_mime_parameter(void) {
const char* l_src = "m=audio 7078 RTP/AVP 111 110 0 8 9 3 101\r\n"\ const char* l_src = "m=audio 7078 RTP/AVP 111 110 0 8 9 3 101\r\n"\
"a=rtpmap:111 speex/16000\r\n"\ "a=rtpmap:111 speex/16000\r\n"\
...@@ -447,49 +448,28 @@ static void test_mime_parameter(void) { ...@@ -447,49 +448,28 @@ static void test_mime_parameter(void) {
belle_sip_list_free_with_data(mime_parameter_list, (void (*)(void*))belle_sip_object_unref); belle_sip_list_free_with_data(mime_parameter_list, (void (*)(void*))belle_sip_object_unref);
} }
int belle_sdp_test_suite () {
CU_pSuite pSuite = NULL;
/* add a suite to the registry */
pSuite = CU_add_suite("SDP", init_suite_sdp, clean_suite_sdp);
/* add the tests to the suite */ test_t sdp_tests[] = {
/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */ { "a= (attribute)", test_attribute },
if (NULL == CU_add_test(pSuite, "test_connection", test_connection)) { { "a= (attribute) 2", test_attribute_2 },
return CU_get_error(); { "b= (bandwidth)", test_bandwidth },
} { "c= (IPv4 connection)", test_connection },
if (NULL == CU_add_test(pSuite, "test_connection_6", test_connection_6)) { { "c= (IPv6 connection)", test_connection_6 },
return CU_get_error(); { "e= (email)", test_email },
} { "i= (info)", test_info },
if (NULL == CU_add_test(pSuite, "attribute", test_attribute)) { { "m= (media)", test_media },
return CU_get_error(); { "mime parameter", test_mime_parameter },
} { "Media description", test_media_description },
if (NULL == CU_add_test(pSuite, "test_attribute_2", test_attribute_2)) { { "Simple session description", test_simple_session_description },
return CU_get_error(); { "Session description", test_session_description }
} };
if (NULL == CU_add_test(pSuite, "bandwidth", test_bandwidth)) {
return CU_get_error(); test_suite_t sdp_test_suite = {
} "SDP",
if (NULL == CU_add_test(pSuite, "email", test_email)) { NULL,
return CU_get_error(); NULL,
} sizeof(sdp_tests) / sizeof(sdp_tests[0]),
if (NULL == CU_add_test(pSuite, "info", test_info)) { sdp_tests
return CU_get_error(); };
}
if (NULL == CU_add_test(pSuite, "media", test_media)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "media_description", test_media_description)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "mime_parameter", test_mime_parameter)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple_session_description", simple_session_description)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_session_description", test_session_description)) {
return CU_get_error();
}
return 0;
}
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
#include <stdio.h> #include <stdio.h>
#include "CUnit/Basic.h" #include "CUnit/Basic.h"
#include "belle-sip/belle-sip.h" #include "belle-sip/belle-sip.h"
#include "belle_sip_tester.h"
#include "register_tester.h" #include "register_tester.h"
static const char* sdp = "v=0\r\n"\ static const char* sdp = "v=0\r\n"\
"o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\ "o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\
"s=Talk\r\n"\ "s=Talk\r\n"\
...@@ -45,15 +45,11 @@ static const char* sdp = "v=0\r\n"\ ...@@ -45,15 +45,11 @@ static const char* sdp = "v=0\r\n"\
"a=rtpmap:98 H263-1998/90000\r\n"\ "a=rtpmap:98 H263-1998/90000\r\n"\
"a=fmtp:98 CIF=1;QCIF=1\r\n"; "a=fmtp:98 CIF=1;QCIF=1\r\n";
static int init(void) { static belle_sip_dialog_t* caller_dialog;
register_init(); static belle_sip_dialog_t* callee_dialog;
return 0; static belle_sip_response_t* ok_response;
} static belle_sip_server_transaction_t* inserv_transaction;
static int uninit(void) {
register_uninit();
return 0;
}
belle_sip_request_t* build_request(belle_sip_stack_t * stack belle_sip_request_t* build_request(belle_sip_stack_t * stack
, belle_sip_provider_t *prov , belle_sip_provider_t *prov
...@@ -91,21 +87,18 @@ belle_sip_request_t* build_request(belle_sip_stack_t * stack ...@@ -91,21 +87,18 @@ belle_sip_request_t* build_request(belle_sip_stack_t * stack
return req; return req;
} }
static belle_sip_dialog_t* caller_dialog;
static belle_sip_dialog_t* callee_dialog;
static belle_sip_response_t* ok_response;
static belle_sip_server_transaction_t* inserv_transaction;
static void process_dialog_terminated(void *user_ctx, const belle_sip_dialog_terminated_event_t *event){ static void process_dialog_terminated(void *user_ctx, const belle_sip_dialog_terminated_event_t *event){
BELLESIP_UNUSED(user_ctx); BELLESIP_UNUSED(user_ctx);
BELLESIP_UNUSED(event); BELLESIP_UNUSED(event);
belle_sip_message("process_dialog_terminated not implemented yet"); belle_sip_message("process_dialog_terminated not implemented yet");
} }
static void process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){ static void process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){
BELLESIP_UNUSED(user_ctx); BELLESIP_UNUSED(user_ctx);
BELLESIP_UNUSED(event); BELLESIP_UNUSED(event);
belle_sip_message("process_io_error not implemented yet"); belle_sip_message("process_io_error not implemented yet");
} }
static void caller_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) { static void caller_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) {
belle_sip_server_transaction_t* server_transaction; belle_sip_server_transaction_t* server_transaction;
belle_sip_response_t* resp; belle_sip_response_t* resp;
...@@ -124,6 +117,7 @@ static void caller_process_request_event(void *user_ctx, const belle_sip_request ...@@ -124,6 +117,7 @@ static void caller_process_request_event(void *user_ctx, const belle_sip_request
belle_sip_server_transaction_send_response(server_transaction,resp); belle_sip_server_transaction_send_response(server_transaction,resp);
} }
static void callee_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) { static void callee_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) {
belle_sip_dialog_t* dialog; belle_sip_dialog_t* dialog;
belle_sip_response_t* ringing_response; belle_sip_response_t* ringing_response;
...@@ -203,6 +197,7 @@ static void caller_process_response_event(void *user_ctx, const belle_sip_respon ...@@ -203,6 +197,7 @@ static void caller_process_response_event(void *user_ctx, const belle_sip_respon
} }
static void callee_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){ static void callee_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
belle_sip_dialog_t* dialog; belle_sip_dialog_t* dialog;
belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event); belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event);
...@@ -224,6 +219,7 @@ static void callee_process_response_event(void *user_ctx, const belle_sip_respon ...@@ -224,6 +219,7 @@ static void callee_process_response_event(void *user_ctx, const belle_sip_respon
,belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog))); ,belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog)));
} }
static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) { static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) {
BELLESIP_UNUSED(user_ctx); BELLESIP_UNUSED(user_ctx);
/* belle_sip_client_transaction_t* client_transaction = belle_sip_timeout_event_get_client_transaction(event); /* belle_sip_client_transaction_t* client_transaction = belle_sip_timeout_event_get_client_transaction(event);
...@@ -234,6 +230,7 @@ static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *eve ...@@ -234,6 +230,7 @@ static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *eve
belle_sip_message("Unhandled event timeout [%p]",event); belle_sip_message("Unhandled event timeout [%p]",event);
} }
} }
static void process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) { static void process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
BELLESIP_UNUSED(user_ctx); BELLESIP_UNUSED(user_ctx);
/* belle_sip_client_transaction_t* client_transaction = belle_sip_transaction_terminated_event_get_client_transaction(event); /* belle_sip_client_transaction_t* client_transaction = belle_sip_transaction_terminated_event_get_client_transaction(event);
...@@ -249,8 +246,6 @@ static void listener_destroyed(void *user_ctx){ ...@@ -249,8 +246,6 @@ static void listener_destroyed(void *user_ctx){
belle_sip_object_unref(user_ctx); belle_sip_object_unref(user_ctx);
} }
static void do_simple_call(void) { static void do_simple_call(void) {
#define CALLER "marie" #define CALLER "marie"
#define CALLEE "pauline" #define CALLEE "pauline"
...@@ -357,18 +352,17 @@ static void simple_call_with_delay(void){ ...@@ -357,18 +352,17 @@ static void simple_call_with_delay(void){
belle_sip_object_unref(lp); belle_sip_object_unref(lp);
}*/ }*/
int belle_sip_dialog_test_suite(){
CU_pSuite pSuite = CU_add_suite("Dialog", init, uninit);
if (NULL == CU_add_test(pSuite, "simple_call", simple_call)) { test_t dialog_tests[] = {
return CU_get_error(); { "Simple call", simple_call },
} { "Simple call with delay", simple_call_with_delay }
if (NULL == CU_add_test(pSuite, "simple_call_with_delay", simple_call_with_delay)) { };
return CU_get_error();
} test_suite_t dialog_test_suite = {
/* if (NULL == CU_add_test(pSuite, "simple_call_udp_tcp_with_delay", simple_call_udp_tcp_with_delay)) { "Dialog",
return CU_get_error(); register_init,
}*/ register_uninit,
return 0; sizeof(dialog_tests) / sizeof(dialog_tests[0]),
} dialog_tests
};
This diff is collapsed.
...@@ -17,17 +17,10 @@ ...@@ -17,17 +17,10 @@
*/ */
#include "belle-sip/belle-sip.h" #include "belle-sip/belle-sip.h"
#include "belle_sip_tester.h"
#include <stdio.h> #include <stdio.h>
#include "CUnit/Basic.h" #include "CUnit/Basic.h"
static int init_suite_message(void) {
return 0;
}
static int clean_suite_message(void) {
return 0;
}
static void check_uri_and_headers(belle_sip_message_t* message) { static void check_uri_and_headers(belle_sip_message_t* message) {
if (belle_sip_message_is_request(message)) { if (belle_sip_message_is_request(message)) {
...@@ -96,6 +89,7 @@ static void testRegisterMessage(void) { ...@@ -96,6 +89,7 @@ static void testRegisterMessage(void) {
belle_sip_object_unref(message); belle_sip_object_unref(message);
} }
static void testInviteMessage(void) { static void testInviteMessage(void) {
const char* raw_message = "INVITE sip:becheong@sip.linphone.org SIP/2.0\r\n"\ const char* raw_message = "INVITE sip:becheong@sip.linphone.org SIP/2.0\r\n"\
"Via: SIP/2.0/UDP 10.23.17.117:22600;branch=z9hG4bK-d8754z-4d7620d2feccbfac-1---d8754z-;rport=4820;received=202.165.193.129\r\n"\ "Via: SIP/2.0/UDP 10.23.17.117:22600;branch=z9hG4bK-d8754z-4d7620d2feccbfac-1---d8754z-;rport=4820;received=202.165.193.129\r\n"\
...@@ -124,6 +118,7 @@ static void testInviteMessage(void) { ...@@ -124,6 +118,7 @@ static void testInviteMessage(void) {
belle_sip_object_unref(message); belle_sip_object_unref(message);
belle_sip_free(encoded_message); belle_sip_free(encoded_message);
} }
static void test401Response(void) { static void test401Response(void) {
const char* raw_message = "SIP/2.0 401 Unauthorized\r\n" const char* raw_message = "SIP/2.0 401 Unauthorized\r\n"
"Call-ID: 577586163\r\n" "Call-ID: 577586163\r\n"
...@@ -147,6 +142,7 @@ static void test401Response(void) { ...@@ -147,6 +142,7 @@ static void test401Response(void) {
belle_sip_object_unref(message); belle_sip_object_unref(message);
belle_sip_free(encoded_message); belle_sip_free(encoded_message);
} }
static void testRegisterRaw(void) { static void testRegisterRaw(void) {
const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\ const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\
"Via: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\r\n"\ "Via: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\r\n"\
...@@ -242,6 +238,7 @@ static void test_extract_source(void) { ...@@ -242,6 +238,7 @@ static void test_extract_source(void) {
belle_sip_object_unref(message); belle_sip_object_unref(message);
} }
static void test_sipfrag(void) { static void test_sipfrag(void) {
const char* raw_message = "SIP/2.0 100 Trying\r\n"; const char* raw_message = "SIP/2.0 100 Trying\r\n";
belle_sip_response_t* response; belle_sip_response_t* response;
...@@ -255,42 +252,24 @@ static void test_sipfrag(void) { ...@@ -255,42 +252,24 @@ static void test_sipfrag(void) {
/*static void test_fix_contact_with_received_rport() { /*static void test_fix_contact_with_received_rport() {
}*/ }*/
int belle_sip_message_test_suite () {
CU_pSuite pSuite = NULL; /* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
test_t message_tests[] = {
{ "REGISTER", testRegisterMessage },
/* add a suite to the registry */ { "INVITE", testInviteMessage },
pSuite = CU_add_suite("Message", init_suite_message, clean_suite_message); { "Option message", testOptionMessage },
if (NULL == pSuite) { { "REGISTER (Raw)", testRegisterRaw },
return CU_get_error(); { "401 Response", test401Response },
} { "Origin extraction", test_extract_source },
{ "SIP frag", test_sipfrag },
/* add the tests to the suite */ };
/* NOTE - ORDER IS IMPORTANT - MUST TEST fread() AFTER fprintf() */
if (NULL == CU_add_test(pSuite, "testRegisterMessage", testRegisterMessage)) { test_suite_t message_test_suite = {
return CU_get_error(); "Message",
} NULL,
if (NULL == CU_add_test(pSuite, "testInviteMessage", testInviteMessage)) { NULL,
return CU_get_error(); sizeof(message_tests) / sizeof(message_tests[0]),
} message_tests
if (NULL == CU_add_test(pSuite, "testOptionMessage", testOptionMessage)) { };
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of register raw message", testRegisterRaw)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test of 401 response", test401Response)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test belle_sip_request_extract_origin", test_extract_source)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test_sipfrag", test_sipfrag)) {
return CU_get_error();
}
return CU_get_error();
}
...@@ -20,13 +20,18 @@ ...@@ -20,13 +20,18 @@
#include "CUnit/Basic.h" #include "CUnit/Basic.h"
#include "belle-sip/belle-sip.h" #include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h" #include "belle_sip_internal.h"
#include "belle_sip_tester.h"
#ifndef _MSC_VER #ifndef _MSC_VER
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#define USERNAME "toto" #define USERNAME "toto"
#define SIPDOMAIN "sip.linphone.org" #define SIPDOMAIN "sip.linphone.org"
#define PASSWD "secret" #define PASSWD "secret"
typedef enum auth_mode { typedef enum auth_mode {
none none
,digest ,digest
...@@ -38,6 +43,7 @@ typedef struct _stat { ...@@ -38,6 +43,7 @@ typedef struct _stat {
int fourHundredOne; int fourHundredOne;
int refreshOk; int refreshOk;
}stat_t; }stat_t;
typedef struct endpoint { typedef struct endpoint {
belle_sip_stack_t* stack; belle_sip_stack_t* stack;
belle_sip_listener_callbacks_t* listener_callbacks; belle_sip_listener_callbacks_t* listener_callbacks;
...@@ -54,6 +60,7 @@ typedef struct endpoint { ...@@ -54,6 +60,7 @@ typedef struct endpoint {
unsigned char unreconizable_contact; unsigned char unreconizable_contact;
} endpoint_t; } endpoint_t;
static unsigned int wait_for(belle_sip_stack_t*s1, belle_sip_stack_t*s2,int* counter,int value,int timeout) { static unsigned int wait_for(belle_sip_stack_t*s1, belle_sip_stack_t*s2,int* counter,int value,int timeout) {
int retry=0; int retry=0;
#define ITER 100 #define ITER 100
...@@ -73,6 +80,7 @@ static unsigned int wait_for(belle_sip_stack_t*s1, belle_sip_stack_t*s2,int* co ...@@ -73,6 +80,7 @@ static unsigned int wait_for(belle_sip_stack_t*s1, belle_sip_stack_t*s2,int* co
// /*belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));*/ // /*belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));*/
// /*CU_ASSERT(CU_FALSE);*/ // /*CU_ASSERT(CU_FALSE);*/
//} //}
static void compute_response(const char* username static void compute_response(const char* username
,const char* realm ,const char* realm
,const char* passwd ,const char* passwd
...@@ -85,6 +93,7 @@ static void compute_response(const char* username ...@@ -85,6 +93,7 @@ static void compute_response(const char* username
belle_sip_auth_helper_compute_ha2(method,uri,ha2); belle_sip_auth_helper_compute_ha2(method,uri,ha2);
belle_sip_auth_helper_compute_response(ha1,nonce,ha2,response); belle_sip_auth_helper_compute_response(ha1,nonce,ha2,response);
} }
static void compute_response_auth_qop(const char* username static void compute_response_auth_qop(const char* username
,const char* realm ,const char* realm
,const char* passwd ,const char* passwd
...@@ -100,7 +109,9 @@ static void compute_response_auth_qop(const char* username ...@@ -100,7 +109,9 @@ static void compute_response_auth_qop(const char* username
belle_sip_auth_helper_compute_ha2(method,uri,ha2); belle_sip_auth_helper_compute_ha2(method,uri,ha2);
belle_sip_auth_helper_compute_response_qop_auth(ha1, nonce,nonce_count, cnonce,qop,ha2,response); belle_sip_auth_helper_compute_response_qop_auth(ha1, nonce,nonce_count, cnonce,qop,ha2,response);
} }
#define MAX_NC_COUNT 3 #define MAX_NC_COUNT 3
static void server_process_request_event(void *obj, const belle_sip_request_event_t *event){ static void server_process_request_event(void *obj, const belle_sip_request_event_t *event){
endpoint_t* endpoint = (endpoint_t*)obj; endpoint_t* endpoint = (endpoint_t*)obj;
belle_sip_server_transaction_t* server_transaction =belle_sip_provider_create_server_transaction(endpoint->provider,belle_sip_request_event_get_request(event)); belle_sip_server_transaction_t* server_transaction =belle_sip_provider_create_server_transaction(endpoint->provider,belle_sip_request_event_get_request(event));
...@@ -207,6 +218,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even ...@@ -207,6 +218,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
} }
belle_sip_server_transaction_send_response(server_transaction,resp); belle_sip_server_transaction_send_response(server_transaction,resp);
} }
static void client_process_response_event(void *obj, const belle_sip_response_event_t *event){ static void client_process_response_event(void *obj, const belle_sip_response_event_t *event){
//belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event); //belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event);
endpoint_t* endpoint = (endpoint_t*)obj; endpoint_t* endpoint = (endpoint_t*)obj;
...@@ -220,12 +232,14 @@ static void client_process_response_event(void *obj, const belle_sip_response_ev ...@@ -220,12 +232,14 @@ static void client_process_response_event(void *obj, const belle_sip_response_ev
} }
//static void process_timeout(void *obj, const belle_sip_timeout_event_t *event){ //static void process_timeout(void *obj, const belle_sip_timeout_event_t *event){
// belle_sip_message("process_timeout"); // belle_sip_message("process_timeout");
//} //}
//static void process_transaction_terminated(void *obj, const belle_sip_transaction_terminated_event_t *event){ //static void process_transaction_terminated(void *obj, const belle_sip_transaction_terminated_event_t *event){
// belle_sip_message("process_transaction_terminated"); // belle_sip_message("process_transaction_terminated");
//} //}
static void client_process_auth_requested(void *obj, belle_sip_auth_event_t *event){ static void client_process_auth_requested(void *obj, belle_sip_auth_event_t *event){
BELLESIP_UNUSED(obj); BELLESIP_UNUSED(obj);
belle_sip_message("process_auth_requested requested for [%s@%s]" belle_sip_message("process_auth_requested requested for [%s@%s]"
...@@ -272,6 +286,7 @@ static void destroy_endpoint(endpoint_t* endpoint) { ...@@ -272,6 +286,7 @@ static void destroy_endpoint(endpoint_t* endpoint) {
static endpoint_t* create_udp_endpoint(int port,belle_sip_listener_callbacks_t* listener_callbacks) { static endpoint_t* create_udp_endpoint(int port,belle_sip_listener_callbacks_t* listener_callbacks) {
return create_endpoint(port,"udp",listener_callbacks); return create_endpoint(port,"udp",listener_callbacks);
} }
static void register_base(endpoint_t* client,endpoint_t *server) { static void register_base(endpoint_t* client,endpoint_t *server) {
belle_sip_request_t* req; belle_sip_request_t* req;
belle_sip_client_transaction_t* trans; belle_sip_client_transaction_t* trans;
...@@ -337,6 +352,7 @@ static void register_base(endpoint_t* client,endpoint_t *server) { ...@@ -337,6 +352,7 @@ static void register_base(endpoint_t* client,endpoint_t *server) {
belle_sip_refresher_stop(refresher); belle_sip_refresher_stop(refresher);
belle_sip_object_unref(refresher); belle_sip_object_unref(refresher);
} }
static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t auth_mode) { static void register_test_with_param(unsigned char expire_in_contact,auth_mode_t auth_mode) {
belle_sip_listener_callbacks_t client_callbacks; belle_sip_listener_callbacks_t client_callbacks;
belle_sip_listener_callbacks_t server_callbacks; belle_sip_listener_callbacks_t server_callbacks;
...@@ -433,9 +449,11 @@ static void subscribe_test(void) { ...@@ -433,9 +449,11 @@ static void subscribe_test(void) {