/* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "test.h" #include #include #define THIS_FILE "transport_udp_test.c" static pj_status_t multi_transport_test(pjsip_transport *tp[], unsigned max_tp) { #define ERR(rc__) { rc=rc__; goto on_return; } int rc; unsigned i, num_tp=0; pj_str_t s; pjsip_transport *other_udp_tp = NULL, *udp_tp = NULL; pj_sockaddr_in rem_addr; pjsip_tpselector tp_sel; /* Check if an UDP transport has been registered by other part of * pjsip-test */ pj_sockaddr_in_init(&rem_addr, pj_cstr(&s, "1.1.1.1"), 80); pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_UDP, &rem_addr, sizeof(rem_addr), NULL, &other_udp_tp); for (i=num_tp; iref_cnt), 1, NULL, ERR(-120)); tp[num_tp++] = udp_tp; } for (i = 0; i < num_tp; ++i) { PJ_TEST_EQ(pj_atomic_get(tp[i]->ref_cnt), 1, NULL, ERR(-130)); /* Test basic transport attributes */ rc = generic_transport_test(udp_tp); if (rc != 0) goto on_return; } /* Acquire transport test without selector. */ pj_sockaddr_in_init(&rem_addr, pj_cstr(&s, "1.1.1.1"), 80); PJ_TEST_SUCCESS(pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_UDP, &rem_addr, sizeof(rem_addr), NULL, &udp_tp), NULL, ERR(-140)); for (i = 0; i < num_tp; ++i) { if (udp_tp == tp[i]) { break; } } PJ_TEST_TRUE(iref_cnt), 1, NULL, ERR(-160)); } else { PJ_TEST_EQ(pj_atomic_get(udp_tp->ref_cnt), 1, NULL, ERR(-165)); } /* Acquire transport test with selector. */ pj_bzero(&tp_sel, sizeof(tp_sel)); tp_sel.type = PJSIP_TPSELECTOR_TRANSPORT; tp_sel.u.transport = tp[num_tp-1]; pj_sockaddr_in_init(&rem_addr, pj_cstr(&s, "1.1.1.1"), 80); PJ_TEST_SUCCESS( pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_UDP, &rem_addr, sizeof(rem_addr), &tp_sel, &udp_tp), NULL, ERR(-170)); PJ_TEST_EQ(udp_tp, tp[num_tp-1], NULL, ERR(-180)); pjsip_transport_dec_ref(udp_tp); PJ_TEST_EQ(pj_atomic_get(udp_tp->ref_cnt), 1, NULL, ERR(-190)); rc = 0; on_return: if (other_udp_tp) { pjsip_transport_dec_ref(other_udp_tp); } if (rc != 0) { for (i=0; iref_cnt) != 1) return -80; /* Destroy this transport. */ pjsip_transport_dec_ref(udp_tp); status = pjsip_transport_destroy(udp_tp); if (status != PJ_SUCCESS) return -90; } /* Flush events. */ PJ_LOG(3,(THIS_FILE, " Flushing events, 1 second...")); flush_events(1000); /* Done */ return 0; }