reSIProcate/stack  9694
testNonInviteClientTx.cxx
Go to the documentation of this file.
00001 #include "resip/stack/SipStack.hxx"
00002 #include "resip/stack/Transport.hxx"
00003 #include "resip/stack/Uri.hxx"
00004 #include "resip/stack/Helper.hxx"
00005 #include "resip/stack/test/TestSupport.hxx"
00006 #include "rutil/Logger.hxx"
00007 #include "rutil/DataStream.hxx"
00008 
00009 using namespace resip;
00010 using namespace std;
00011 
00012 #define RESIPROCATE_SUBSYSTEM Subsystem::APP
00013 #define CRLF "\r\n"
00014 
00015 
00016 SipStack* client=0;
00017 Fifo<Message> received;
00018 
00019 void
00020 doit(int serverResponse, int expectedRetrans, int expectedClientResponse);
00021 
00022 
00023 int
00024 main(int argc, char *argv[])
00025 {
00026    Log::initialize(Log::Cout, Log::Debug, argv[0]);
00027 
00028    DebugLog( << "Starting up, making stack");
00029    InfoLog( << "Starting up, making stack");
00030 
00031    client = new SipStack();
00032    client->addTransport(UDP, 5070);
00033 
00034    // Test 1: 
00035    // client sends a reg, server does nothing, client should retransmit 10
00036    // times, client should receive 408
00037 
00038    // Test 2: 
00039    // client sends a reg, server sends 100, client should retransmit 7 times
00040    // client should receive 408
00041     
00042    // Test 3:
00043    // client sends a reg, server sends 200, client shouldn't retransmit at all
00044    // client should receive 200
00045 
00046    // Test 4:
00047    // client sends a reg, server sends 400, client shouldn't retransmit at all
00048    // client should receive 400
00049 
00050    //doit(100, 7, 408);
00051    doit(200, 1, 200);
00052    //    doit(400, 1, 400);
00053    //doit(0, 10, 408);
00054     
00055    return 0;
00056 }
00057 
00058 
00059 void
00060 doit(int serverResponse, int expectedRetrans, int expectedClientResponse)
00061 {
00062    InfoLog (<< "Running test: " << serverResponse << " " << expectedRetrans << " " << expectedClientResponse);
00063    
00064    NameAddr me;
00065    me.uri().host() = "localhost";
00066    me.uri().port() = 5070;
00067    SipMessage* reg = Helper::makeRegister(me, me);
00068    InfoLog (<< "Sending: " << *reg);
00069 
00070    Data encoded(2048, true);
00071    DataStream strm(encoded);
00072    reg->encode(strm);
00073    strm.flush();
00074     
00075    client->send(*reg);   // send message down the stack
00076 
00077    FdSet fdset;
00078    client->process(fdset);
00079 
00080    // read the message off the stack
00081    Data fromStack;
00082    getFromWire(fromStack);
00083 
00084    InfoLog(<< "Received from wire " << fromStack);
00085 
00086    SipMessage* message = TestSupport::makeMessage(fromStack);
00087       
00088    // send the response message
00089 
00090    SipMessage* response = Helper::makeResponse(*message, 100);
00091    InfoLog (<< "sending to wire = " << endl << *response);
00092             
00093    Data encodedResponse(2048, true);
00094 
00095    DataStream estrm(encodedResponse);
00096    response->encode(estrm);
00097    estrm.flush();
00098 
00099    //    sendToWire(encodedResponse);
00100 
00101    while (1)
00102    {
00103       client->process(fdset);
00104       usleep(20);
00105    }
00106 }
00107 /* ====================================================================
00108  * The Vovida Software License, Version 1.0 
00109  * 
00110  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00111  * 
00112  * Redistribution and use in source and binary forms, with or without
00113  * modification, are permitted provided that the following conditions
00114  * are met:
00115  * 
00116  * 1. Redistributions of source code must retain the above copyright
00117  *    notice, this list of conditions and the following disclaimer.
00118  * 
00119  * 2. Redistributions in binary form must reproduce the above copyright
00120  *    notice, this list of conditions and the following disclaimer in
00121  *    the documentation and/or other materials provided with the
00122  *    distribution.
00123  * 
00124  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00125  *    and "Vovida Open Communication Application Library (VOCAL)" must
00126  *    not be used to endorse or promote products derived from this
00127  *    software without prior written permission. For written
00128  *    permission, please contact vocal@vovida.org.
00129  *
00130  * 4. Products derived from this software may not be called "VOCAL", nor
00131  *    may "VOCAL" appear in their name, without prior written
00132  *    permission of Vovida Networks, Inc.
00133  * 
00134  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00135  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00136  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00137  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00138  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00139  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00140  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00141  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00142  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00143  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00144  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00145  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00146  * DAMAGE.
00147  * 
00148  * ====================================================================
00149  * 
00150  * This software consists of voluntary contributions made by Vovida
00151  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00152  * Inc.  For more information on Vovida Networks, Inc., please see
00153  * <http://www.vovida.org/>.
00154  *
00155  */