/[resiprocate]/main/resip/stack/test/testTransportSelector.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testTransportSelector.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5948 - (show annotations) (download)
Fri Feb 17 15:30:16 2006 UTC (13 years, 8 months ago) by dworley
File MIME type: text/plain
File size: 8052 byte(s)
Setting more svn: properties, and adding EOLs to the ends of files
that need it.

1 #include <iostream>
2 #include <memory>
3
4 #include "rutil/DataStream.hxx"
5 #include "resip/stack/SipMessage.hxx"
6 #include "rutil/Logger.hxx"
7 #include "resip/stack/TransportSelector.hxx"
8
9 using namespace resip;
10 using namespace std;
11
12 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
13
14 class TestTransportSelector
15 {
16 public:
17 static void testEmptyFail()
18 {
19 InfoLog (<< "testEmptyFail" );
20
21 Fifo<TransactionMessage> fif;
22 TransportSelector ts(fif, 0);
23
24 Tuple tuple;
25
26 Transport* t = ts.findTransport(tuple);
27 assert(t == 0);
28 }
29
30 static void testExactFail()
31 {
32 InfoLog (<< "testExactFail" );
33
34 Fifo<TransactionMessage> fif;
35 TransportSelector ts(fif, 0);
36 ts.addTransport(UDP, 5061, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1);
37
38 Tuple tuple("127.0.0.2", 5060, true, UDP);
39 Transport* t = ts.findTransport(tuple);
40 assert(!t);
41 }
42
43 static void testExact()
44 {
45 InfoLog (<< "testExact" );
46
47 Fifo<TransactionMessage> fif;
48 TransportSelector ts(fif, 0);
49 ts.addTransport(UDP, 5060, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1);
50
51 Tuple tuple("127.0.0.1", 5060, true, UDP);
52 Transport* trans = ts.findTransport(tuple);
53 assert(trans);
54 assert(trans->port() == 5060);
55 }
56
57 static void testExact2()
58 {
59 InfoLog (<< "testExact" );
60
61 Fifo<TransactionMessage> fif;
62 TransportSelector ts(fif, 0);
63 ts.addTransport(UDP, 5060, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1);
64 ts.addTransport(UDP, 5100, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1);
65
66 Tuple tuple("127.0.0.1", 5060, true, UDP);
67 Transport* trans = ts.findTransport(tuple);
68 assert(trans);
69 assert(trans->port() == 5060);
70
71 Tuple tuple2("127.0.0.1", 5100, true, UDP);
72 trans = ts.findTransport(tuple2);
73 assert(trans);
74 assert(trans->port() == 5100);
75
76 Tuple tuple3("127.0.0.2", 5100, true, UDP);
77 trans = ts.findTransport(tuple3);
78 assert(!trans);
79
80 Tuple tuple4("127.0.0.2", 5200, true, UDP);
81 trans = ts.findTransport(tuple4);
82 assert(!trans);
83 }
84
85
86 static void testExactAnyPort()
87 {
88 InfoLog (<< "testExactAnyPort" );
89
90 Fifo<TransactionMessage> fif;
91 TransportSelector ts(fif, 0);
92 ts.addTransport(UDP, 5060, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1);
93
94 Tuple tuple("127.0.0.1", 0, true, UDP);
95 Transport* trans = ts.findTransport(tuple);
96 assert(trans);
97 assert(trans->port() == 5060);
98 }
99
100
101 static void testAnyInterface()
102 {
103 InfoLog (<< "testAnyInterface" );
104
105 Fifo<TransactionMessage> fif;
106 TransportSelector ts(fif, 0);
107 ts.addTransport(UDP,5060,V4, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1);
108
109 Tuple tuple("127.0.0.1", 5060, true, UDP);
110 Transport* trans = ts.findTransport(tuple);
111 assert(trans);
112 }
113
114 static void testAnyInterfaceAnyPort()
115 {
116 InfoLog (<< "testAnyInterfaceAnyPort" );
117
118 Fifo<TransactionMessage> fif;
119 TransportSelector ts(fif, 0);
120 ts.addTransport(UDP, 5060, V4, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1);
121
122 Tuple tuple("127.0.0.1", 0, true, UDP);
123 Transport* trans = ts.findTransport(tuple);
124 assert(trans);
125 }
126
127 static void testAnyInterfaceAnyPortV6()
128 {
129 InfoLog (<< "testAnyInterfaceAnyPortV6" );
130
131 Fifo<TransactionMessage> fif;
132 TransportSelector ts(fif, 0);
133 ts.addTransport(TCP, 5060, V6, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1);
134
135 Tuple tuple("::1", 0, false, TCP);
136 Transport* trans = ts.findTransport(tuple);
137 assert(trans);
138 }
139
140 static void testAnyInterfaceAnyPortV6Fail()
141 {
142 InfoLog (<< "testAnyInterfaceAnyPortV6" );
143
144 Fifo<TransactionMessage> fif;
145 TransportSelector ts(fif, 0);
146
147 ts.addTransport(TCP, 5060, V4, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1);
148
149 Tuple tuple("::1", 0, false, TCP);
150 Transport* trans = ts.findTransport(tuple);
151 assert(!trans);
152 }
153
154 static void testAnyInterfaceAnyPortFail()
155 {
156 InfoLog (<< "testAnyInterfaceAnyPortFail" );
157
158 Fifo<TransactionMessage> fif;
159 TransportSelector ts(fif, 0);
160 ts.addTransport(UDP,5060,V4, Data::Empty, Data::Empty, Data::Empty, SecurityTypes::TLSv1);
161
162 Tuple tuple("127.0.0.1", 0, true, TCP);
163 Transport* trans = ts.findTransport(tuple);
164 assert(!trans);
165 }
166 };
167
168 int
169 main(int argc, char** argv)
170 {
171 Log::initialize(Log::Cout, Log::Debug, argv[0]);
172
173 #if 1
174 TestTransportSelector::testEmptyFail();
175 TestTransportSelector::testExactFail();
176 TestTransportSelector::testExact();
177 TestTransportSelector::testExact2();
178 TestTransportSelector::testExactAnyPort();
179 TestTransportSelector::testAnyInterface();
180 TestTransportSelector::testAnyInterfaceAnyPort();
181 TestTransportSelector::testAnyInterfaceAnyPortFail();
182 TestTransportSelector::testAnyInterfaceAnyPortV6();
183 TestTransportSelector::testAnyInterfaceAnyPortV6Fail();
184 #else
185 TestTransportSelector::testAnyInterfaceAnyPortV6();
186 #endif
187
188 InfoLog (<< "TEST OK" );
189 return 0;
190 }
191
192 /* ====================================================================
193 * The Vovida Software License, Version 1.0
194 *
195 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
196 *
197 * Redistribution and use in source and binary forms, with or without
198 * modification, are permitted provided that the following conditions
199 * are met:
200 *
201 * 1. Redistributions of source code must retain the above copyright
202 * notice, this list of conditions and the following disclaimer.
203 *
204 * 2. Redistributions in binary form must reproduce the above copyright
205 * notice, this list of conditions and the following disclaimer in
206 * the documentation and/or other materials provided with the
207 * distribution.
208 *
209 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
210 * and "Vovida Open Communication Application Library (VOCAL)" must
211 * not be used to endorse or promote products derived from this
212 * software without prior written permission. For written
213 * permission, please contact vocal@vovida.org.
214 *
215 * 4. Products derived from this software may not be called "VOCAL", nor
216 * may "VOCAL" appear in their name, without prior written
217 * permission of Vovida Networks, Inc.
218 *
219 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
220 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
221 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
222 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
223 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
224 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
225 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
226 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
227 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
228 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
229 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
230 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
231 * DAMAGE.
232 *
233 * ====================================================================
234 *
235 * This software consists of voluntary contributions made by Vovida
236 * Networks, Inc. and many individuals on behalf of Vovida Networks,
237 * Inc. For more information on Vovida Networks, Inc., please see
238 * <http://www.vovida.org/>.
239 *
240 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27