belle_sip_register_tester.c 3.97 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  Belledonne Communications SARL

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
jehan's avatar
jehan committed
20
#include "CUnit/Basic.h"
Simon Morlat's avatar
Simon Morlat committed
21 22
#include "belle-sip/belle-sip.h"

jehan's avatar
jehan committed
23

Simon Morlat's avatar
Simon Morlat committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
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");
}
static void process_io_error(belle_sip_listener_t *obj, const belle_sip_io_error_event_t *event){
	belle_sip_message("process_io_error");
}
static void process_request_event(belle_sip_listener_t *obj, const belle_sip_request_event_t *event){
	belle_sip_message("process_request_event");
}
static void process_response_event(belle_sip_listener_t *obj, const belle_sip_response_event_t *event){
	belle_sip_message("process_response_event");
}
static void process_timeout(belle_sip_listener_t *obj, const belle_sip_timeout_event_t *event){
	belle_sip_message("process_timeout");
}
static void process_transaction_terminated(belle_sip_listener_t *obj, const belle_sip_transaction_terminated_event_t *event){
	belle_sip_message("process_transaction_terminated");
}

/*this would normally go to a .h file*/
struct test_listener{
	belle_sip_object_t base;
	void *some_context;
};

typedef struct test_listener test_listener_t;

BELLE_SIP_DECLARE_TYPES_BEGIN(test,0x1000)
	BELLE_SIP_TYPE_ID(test_listener_t)
BELLE_SIP_DECLARE_TYPES_END

BELLE_SIP_DECLARE_VPTR(test_listener_t);

/*the following would go to .c file */

BELLE_SIP_IMPLEMENT_INTERFACE_BEGIN(test_listener_t,belle_sip_listener_t)
	process_dialog_terminated,
	process_io_error,
	process_request_event,
	process_response_event,
	process_timeout,
	process_transaction_terminated
BELLE_SIP_IMPLEMENT_INTERFACE_END

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);


jehan's avatar
jehan committed
73 74

void register_test() {
Simon Morlat's avatar
Simon Morlat committed
75 76 77 78
	belle_sip_stack_t * stack=belle_sip_stack_new(NULL);
	belle_sip_listening_point_t *lp;
	belle_sip_provider_t *prov;
	belle_sip_request_t *req;
Simon Morlat's avatar
Simon Morlat committed
79
	test_listener_t *listener=belle_sip_object_new(test_listener_t);
Simon Morlat's avatar
Simon Morlat committed
80

Simon Morlat's avatar
Simon Morlat committed
81
	belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG);
Simon Morlat's avatar
Simon Morlat committed
82 83 84
	
	lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"UDP");
	prov=belle_sip_stack_create_provider(stack,lp);
Simon Morlat's avatar
Simon Morlat committed
85
	belle_sip_provider_add_sip_listener(prov,BELLE_SIP_LISTENER(listener));
Simon Morlat's avatar
Simon Morlat committed
86 87 88 89 90 91 92
	req=belle_sip_request_create(
	                    belle_sip_uri_parse("sip:test.linphone.org"),
	                    "REGISTER",
	                    belle_sip_provider_create_call_id(prov),
	                    belle_sip_header_cseq_create(20,"REGISTER"),
	                    belle_sip_header_from_create("Tester <sip:tester@test.linphone.org>","a0dke45"),
	                    belle_sip_header_to_create("Tester <sip:tester@test.linphone.org>",NULL),
93
	                    belle_sip_header_via_new(),
Simon Morlat's avatar
Simon Morlat committed
94 95 96 97 98 99 100
	                    70);
	char *tmp=belle_sip_object_to_string(BELLE_SIP_OBJECT(req));

	
	printf("Message to send:\n%s\n",tmp);
	belle_sip_free(tmp);
	belle_sip_provider_send_request(prov,req);
Simon Morlat's avatar
Simon Morlat committed
101
	belle_sip_stack_sleep(stack,25000);
Simon Morlat's avatar
Simon Morlat committed
102
	printf("Exiting\n");
Simon Morlat's avatar
Simon Morlat committed
103 104
	belle_sip_object_unref(prov);
	belle_sip_object_unref(stack);
jehan's avatar
jehan committed
105
	return;
Simon Morlat's avatar
Simon Morlat committed
106
}
jehan's avatar
jehan committed
107 108 109 110 111 112 113 114
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();
	}
}