cast_test.c 2.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
	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/>.
*/

Simon Morlat's avatar
Simon Morlat committed
19
#include "CUnit/Basic.h"
20 21 22

#include "belle-sip/belle-sip.h"

Simon Morlat's avatar
Simon Morlat committed
23 24 25 26 27 28 29 30 31
static int init_cast_suite(){
	return 0;
}

static int cleanup_cast_suite(){
	return 0;
}

static void cast_test(){
32
	belle_sip_stack_t *stack=belle_sip_stack_new(NULL);
33 34
	belle_sip_listening_point_t *lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"UDP");
	belle_sip_provider_t *provider;
35 36 37
	belle_sip_request_t *req=belle_sip_request_new();
	belle_sip_response_t *resp=belle_sip_response_new();
	belle_sip_message_t *msg;
Simon Morlat's avatar
Simon Morlat committed
38 39 40
	int tmp;
	
	CU_ASSERT_PTR_NOT_NULL(stack);
41 42
	CU_ASSERT_PTR_NOT_NULL(lp);
	provider=belle_sip_stack_create_provider(stack,lp);
Simon Morlat's avatar
Simon Morlat committed
43
	CU_ASSERT_PTR_NOT_NULL(provider);
44 45
	CU_ASSERT_PTR_NOT_NULL(req);
	CU_ASSERT_PTR_NOT_NULL(resp);
46
	
47 48 49
	belle_sip_message("Casting belle_sip_request_t to belle_sip_message_t");
	msg=BELLE_SIP_MESSAGE(req);
	CU_ASSERT_PTR_NOT_NULL(msg);
Simon Morlat's avatar
Simon Morlat committed
50
	belle_sip_message("Ok.");
51 52 53
	belle_sip_message("Casting belle_sip_response_t to belle_sip_message_t");
	msg=BELLE_SIP_MESSAGE(resp);
	CU_ASSERT_PTR_NOT_NULL(msg);
Simon Morlat's avatar
Simon Morlat committed
54
	belle_sip_message("Ok.");
55 56
	tmp=BELLE_SIP_IS_INSTANCE_OF(req,belle_sip_response_t);
	belle_sip_message("Casting belle_sip_request_t to belle_sip_response_t: %s",tmp ? "yes" : "no");
Simon Morlat's avatar
Simon Morlat committed
57
	CU_ASSERT_EQUAL(tmp,0);
jehan's avatar
jehan committed
58 59 60
	belle_sip_object_unref(req);
	belle_sip_object_unref(resp);
	belle_sip_object_unref(provider);
61
	belle_sip_object_unref(lp);
jehan's avatar
jehan committed
62
	belle_sip_object_unref(stack);
Simon Morlat's avatar
Simon Morlat committed
63 64 65 66 67 68
}


int belle_sip_cast_test_suite(){
	CU_pSuite pSuite = CU_add_suite("Object inheritence", init_cast_suite, cleanup_cast_suite);

69
	if (NULL == CU_add_test(pSuite, "casting requests and responses", cast_test)) {
Simon Morlat's avatar
Simon Morlat committed
70 71
		return CU_get_error();
	}
72
	return 0;
73
}
Simon Morlat's avatar
Simon Morlat committed
74