|
reSIProcate/stack
9694
|
00001 #include <iostream> 00002 #include <memory> 00003 00004 #include "rutil/DataStream.hxx" 00005 #include "resip/stack/SipMessage.hxx" 00006 #include "rutil/Logger.hxx" 00007 #include "resip/stack/TransportSelector.hxx" 00008 00009 using namespace resip; 00010 using namespace std; 00011 00012 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST 00013 00014 class TestTransportSelector 00015 { 00016 public: 00017 static void testEmptyFail() 00018 { 00019 InfoLog (<< "testEmptyFail" ); 00020 00021 Fifo<TransactionMessage> fif; 00022 TransportSelector ts(fif, 0); 00023 00024 Tuple tuple; 00025 00026 Transport* t = ts.findTransport(tuple); 00027 assert(t == 0); 00028 } 00029 00030 static void testExactFail() 00031 { 00032 InfoLog (<< "testExactFail" ); 00033 00034 Fifo<TransactionMessage> fif; 00035 TransportSelector ts(fif, 0); 00036 ts.addTransport(UDP, 5061, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00037 00038 Tuple tuple("127.0.0.2", 5060, true, UDP); 00039 Transport* t = ts.findTransport(tuple); 00040 assert(!t); 00041 } 00042 00043 static void testExact() 00044 { 00045 InfoLog (<< "testExact" ); 00046 00047 Fifo<TransactionMessage> fif; 00048 TransportSelector ts(fif, 0); 00049 ts.addTransport(UDP, 5060, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00050 00051 Tuple tuple("127.0.0.1", 5060, true, UDP); 00052 Transport* trans = ts.findTransport(tuple); 00053 assert(trans); 00054 assert(trans->port() == 5060); 00055 } 00056 00057 static void testExact2() 00058 { 00059 InfoLog (<< "testExact" ); 00060 00061 Fifo<TransactionMessage> fif; 00062 TransportSelector ts(fif, 0); 00063 ts.addTransport(UDP, 5060, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00064 ts.addTransport(UDP, 5100, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00065 00066 Tuple tuple("127.0.0.1", 5060, true, UDP); 00067 Transport* trans = ts.findTransport(tuple); 00068 assert(trans); 00069 assert(trans->port() == 5060); 00070 00071 Tuple tuple2("127.0.0.1", 5100, true, UDP); 00072 trans = ts.findTransport(tuple2); 00073 assert(trans); 00074 assert(trans->port() == 5100); 00075 00076 Tuple tuple3("127.0.0.2", 5100, true, UDP); 00077 trans = ts.findTransport(tuple3); 00078 assert(!trans); 00079 00080 Tuple tuple4("127.0.0.2", 5200, true, UDP); 00081 trans = ts.findTransport(tuple4); 00082 assert(!trans); 00083 } 00084 00085 00086 static void testExactAnyPort() 00087 { 00088 InfoLog (<< "testExactAnyPort" ); 00089 00090 Fifo<TransactionMessage> fif; 00091 TransportSelector ts(fif, 0); 00092 ts.addTransport(UDP, 5060, V4, "127.0.0.1", Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00093 00094 Tuple tuple("127.0.0.1", 0, true, UDP); 00095 Transport* trans = ts.findTransport(tuple); 00096 assert(trans); 00097 assert(trans->port() == 5060); 00098 } 00099 00100 00101 static void testAnyInterface() 00102 { 00103 InfoLog (<< "testAnyInterface" ); 00104 00105 Fifo<TransactionMessage> fif; 00106 TransportSelector ts(fif, 0); 00107 ts.addTransport(UDP,5060,V4, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00108 00109 Tuple tuple("127.0.0.1", 5060, true, UDP); 00110 Transport* trans = ts.findTransport(tuple); 00111 assert(trans); 00112 } 00113 00114 static void testAnyInterfaceAnyPort() 00115 { 00116 InfoLog (<< "testAnyInterfaceAnyPort" ); 00117 00118 Fifo<TransactionMessage> fif; 00119 TransportSelector ts(fif, 0); 00120 ts.addTransport(UDP, 5060, V4, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00121 00122 Tuple tuple("127.0.0.1", 0, true, UDP); 00123 Transport* trans = ts.findTransport(tuple); 00124 assert(trans); 00125 } 00126 00127 static void testAnyInterfaceAnyPortV6() 00128 { 00129 InfoLog (<< "testAnyInterfaceAnyPortV6" ); 00130 00131 Fifo<TransactionMessage> fif; 00132 TransportSelector ts(fif, 0); 00133 ts.addTransport(TCP, 5060, V6, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00134 00135 Tuple tuple("::1", 0, false, TCP); 00136 Transport* trans = ts.findTransport(tuple); 00137 assert(trans); 00138 } 00139 00140 static void testAnyInterfaceAnyPortV6Fail() 00141 { 00142 InfoLog (<< "testAnyInterfaceAnyPortV6" ); 00143 00144 Fifo<TransactionMessage> fif; 00145 TransportSelector ts(fif, 0); 00146 00147 ts.addTransport(TCP, 5060, V4, Data::Empty,Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00148 00149 Tuple tuple("::1", 0, false, TCP); 00150 Transport* trans = ts.findTransport(tuple); 00151 assert(!trans); 00152 } 00153 00154 static void testAnyInterfaceAnyPortFail() 00155 { 00156 InfoLog (<< "testAnyInterfaceAnyPortFail" ); 00157 00158 Fifo<TransactionMessage> fif; 00159 TransportSelector ts(fif, 0); 00160 ts.addTransport(UDP,5060,V4, Data::Empty, Data::Empty, Data::Empty, SecurityTypes::TLSv1); 00161 00162 Tuple tuple("127.0.0.1", 0, true, TCP); 00163 Transport* trans = ts.findTransport(tuple); 00164 assert(!trans); 00165 } 00166 }; 00167 00168 int 00169 main(int argc, char** argv) 00170 { 00171 Log::initialize(Log::Cout, Log::Debug, argv[0]); 00172 00173 #if 1 00174 TestTransportSelector::testEmptyFail(); 00175 TestTransportSelector::testExactFail(); 00176 TestTransportSelector::testExact(); 00177 TestTransportSelector::testExact2(); 00178 TestTransportSelector::testExactAnyPort(); 00179 TestTransportSelector::testAnyInterface(); 00180 TestTransportSelector::testAnyInterfaceAnyPort(); 00181 TestTransportSelector::testAnyInterfaceAnyPortFail(); 00182 TestTransportSelector::testAnyInterfaceAnyPortV6(); 00183 TestTransportSelector::testAnyInterfaceAnyPortV6Fail(); 00184 #else 00185 TestTransportSelector::testAnyInterfaceAnyPortV6(); 00186 #endif 00187 00188 InfoLog (<< "TEST OK" ); 00189 return 0; 00190 } 00191 00192 /* ==================================================================== 00193 * The Vovida Software License, Version 1.0 00194 * 00195 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00196 * 00197 * Redistribution and use in source and binary forms, with or without 00198 * modification, are permitted provided that the following conditions 00199 * are met: 00200 * 00201 * 1. Redistributions of source code must retain the above copyright 00202 * notice, this list of conditions and the following disclaimer. 00203 * 00204 * 2. Redistributions in binary form must reproduce the above copyright 00205 * notice, this list of conditions and the following disclaimer in 00206 * the documentation and/or other materials provided with the 00207 * distribution. 00208 * 00209 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00210 * and "Vovida Open Communication Application Library (VOCAL)" must 00211 * not be used to endorse or promote products derived from this 00212 * software without prior written permission. For written 00213 * permission, please contact vocal@vovida.org. 00214 * 00215 * 4. Products derived from this software may not be called "VOCAL", nor 00216 * may "VOCAL" appear in their name, without prior written 00217 * permission of Vovida Networks, Inc. 00218 * 00219 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00220 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00221 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00222 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00223 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00224 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00225 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00226 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00227 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00228 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00229 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00230 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00231 * DAMAGE. 00232 * 00233 * ==================================================================== 00234 * 00235 * This software consists of voluntary contributions made by Vovida 00236 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00237 * Inc. For more information on Vovida Networks, Inc., please see 00238 * <http://www.vovida.org/>. 00239 * 00240 */
1.7.5.1