reSIProcate/stack  9694
testHeaderFieldValueList.cxx
Go to the documentation of this file.
00001 #include "resip/stack/StringSubComponent.hxx"
00002 #include "resip/stack/SubComponentList.hxx"
00003 #include "resip/stack/HeaderFieldValueList.hxx"
00004 #include <iostream>
00005 
00006 using namespace resip;
00007 using namespace std;
00008 
00009 int main(int argc, char** argv)
00010 {
00011 
00012   HeaderFieldValueList *h = new HeaderFieldValueList;
00013   cout << "Empty list: " << endl;
00014   cout << *h << endl;
00015 
00016   HeaderFieldValue *myHeader1 = new HeaderFieldValue("foobar", 6);
00017   HeaderFieldValue *myHeader2 = new HeaderFieldValue("weekend", 7);
00018   
00019   h->push_front(myHeader1);
00020   h->push_front(myHeader2);
00021    
00022   cout << "List with two elements: " << endl;
00023   cout << *h;
00024   cout << "Front of h " << *(h->first) << endl;
00025   cout << "Back of h " << *(h->last) << endl;
00026   cout << endl;
00027 
00028   myHeader1 = new HeaderFieldValue("asdfgh", 6);
00029   myHeader2 = new HeaderFieldValue("qwertyu", 7);
00030 
00031   h->push_front(myHeader1);
00032   h->push_front(myHeader2);
00033 
00034   cout << "List with four elements: " << endl;
00035   cout << *h;
00036   cout << "Front of h " << *(h->first) << endl;
00037   cout << "Back of h " << *(h->last) << endl;
00038   cout << endl;
00039 
00040   myHeader1 = new HeaderFieldValue("poifds", 6);
00041   myHeader2 = new HeaderFieldValue("nmbhers", 7);
00042 
00043   h->push_back(myHeader1);
00044   h->push_back(myHeader2);
00045 
00046   cout << "List with six elements: " << endl;
00047   cout << *h;
00048   cout << "Front of h " << *(h->first) << endl;
00049   cout << "Back of h " << *(h->last) << endl;
00050   cout << endl;
00051 
00052   HeaderFieldValueList *i = new HeaderFieldValueList(*h);
00053 
00054   cout << "List h with six elements: " << endl;
00055   cout << *h;
00056   cout << "Front of h " << *(h->first) << endl;
00057   cout << "Back of h " << *(h->last) << endl;
00058   cout << endl;
00059 
00060   cout << "List i with six elements: " << endl;
00061   cout << *i;
00062   cout << "Front of i " << *(i->first) << endl;
00063   cout << "Back of i " << *(i->last) << endl;
00064   cout << endl;
00065 
00066   i->pop_front();
00067 
00068   cout << "List h with six elements: " << endl;
00069   cout << *h;
00070   cout << "Front of h " << *(h->first) << endl;
00071   cout << "Back of h " << *(h->last) << endl;
00072   cout << endl;
00073 
00074   cout << "List i with five elements: " << endl;
00075   cout << *i;
00076   cout << "Front of i " << *(i->first) << endl;
00077   cout << "Back of i " << *(i->last) << endl;
00078   cout << endl;
00079 
00080   i->pop_front();
00081 
00082   cout << "List h with six elements: " << endl;
00083   cout << *h;
00084   cout << "Front of h " << *(h->first) << endl;
00085   cout << "Back of h " << *(h->last) << endl;
00086   cout << endl;
00087 
00088   cout << "List i with four elements: " << endl;
00089   cout << *i;
00090   cout << "Front of i " << *(i->first) << endl;
00091   cout << "Back of i " << *(i->last) << endl;
00092   cout << endl;
00093 
00094   i->pop_front();
00095   i->pop_front();
00096   i->pop_front();
00097 
00098   cout << "List h with six elements: " << endl;
00099   cout << *h;
00100   cout << "Front of h " << *(h->first) << endl;
00101   cout << "Back of h " << *(h->last) << endl;
00102   cout << endl;
00103 
00104   cout << "List i with one element: " << endl;
00105   cout << *i;
00106   cout << "Front of i " << *(i->first) << endl;
00107   cout << "Back of i " << *(i->last) << endl;
00108   cout << endl;
00109 
00110   i->pop_front();
00111 
00112   cout << "List h with six elements: " << endl;
00113   cout << *h;
00114   cout << "Front of h " << *(h->first) << endl;
00115   cout << "Back of h " << *(h->last) << endl;
00116   cout << endl;
00117 
00118   cout << "List i with zero element: " << endl;
00119   cout << *i;
00120   cout << "Front of i " << (i->first) << endl;
00121   cout << "Back of i " << (i->last) << endl;
00122   cout << endl;
00123 
00124   myHeader1 = new HeaderFieldValue("jgjgjg", 6);
00125   myHeader2 = new HeaderFieldValue("asasasa", 7);
00126 
00127   i->push_front(myHeader1);
00128 
00129   cout << "List h with six elements: " << endl;
00130   cout << *h;
00131   cout << "Front of h " << *(h->first) << endl;
00132   cout << "Back of h " << *(h->last) << endl;
00133   cout << endl;
00134 
00135   cout << "List i with one element: " << endl;
00136   cout << *i;
00137   cout << "Front of i " << *(i->first) << endl;
00138   cout << "Back of i " << *(i->last) << endl;
00139   cout << endl;
00140 
00141 
00142 
00143   i->push_front(myHeader2);
00144 
00145   cout << "List h with six elements: " << endl;
00146   cout << *h;
00147   cout << "Front of h " << *(h->first) << endl;
00148   cout << "Back of h " << *(h->last) << endl;
00149   cout << endl;
00150 
00151   cout << "List i with two elements: " << endl;
00152   cout << *i;
00153   cout << "Front of i " << *(i->first) << endl;
00154   cout << "Back of i " << *(i->last) << endl;
00155   cout << endl;
00156 
00157   
00158 
00159 
00160 
00161    /*
00162    SubComponentList* p = new SubComponentList;
00163    cout << *p << endl;
00164    assert(p->find(SubComponent::TTL) == 0);
00165    delete p;
00166 
00167    p = new SubComponentList();
00168    p->insert(new StringSubComponent(SubComponent::TTL, "foo"));
00169    cout << *p << endl;
00170    assert(p->find(SubComponent::TTL)->getType() == SubComponent::TTL);
00171    delete p;
00172 
00173    p = new SubComponentList();
00174    p->insert(new StringSubComponent(SubComponent::TTL, "foo"));
00175    p->insert(new StringSubComponent(SubComponent::Transport, "bar"));
00176    cout << *p << endl;
00177    assert(p->find(SubComponent::TTL)->getType() == SubComponent::TTL);
00178    assert(p->find(SubComponent::Transport)->getType() == SubComponent::Transport);
00179    delete p;
00180 
00181    p = new SubComponentList();
00182    p->insert(new StringSubComponent(SubComponent::Method, "baz"));
00183    p->insert(new StringSubComponent(SubComponent::TTL, "foo"));
00184    p->insert(new StringSubComponent(SubComponent::Transport, "bar"));
00185    cout << *p << endl;
00186    assert(p->find(SubComponent::TTL)->getType() == SubComponent::TTL);
00187    assert(p->find(SubComponent::Transport)->getType() == SubComponent::Transport);
00188    assert(p->find(SubComponent::Method)->getType() == SubComponent::Method);
00189    delete p;
00190 
00191    cout << "Finished Insertion Tests." << endl;
00192    
00193    p = new SubComponentList();
00194    p->insert(new StringSubComponent(SubComponent::TTL, "foo"));
00195    p->erase(SubComponent::TTL);
00196    cout << *p << endl;
00197    assert(p->find(SubComponent::TTL) == 0);
00198    delete p;
00199 
00200    p = new SubComponentList();
00201    p->insert(new StringSubComponent(SubComponent::TTL, "foo"));
00202    p->insert(new StringSubComponent(SubComponent::Transport, "bar"));
00203    p->erase(SubComponent::TTL);
00204    cout << *p << endl;
00205    assert(p->find(SubComponent::TTL) == 0);
00206    delete p;
00207 
00208    p = new SubComponentList();
00209    p->insert(new StringSubComponent(SubComponent::Method, "baz"));
00210    p->insert(new StringSubComponent(SubComponent::TTL, "foo"));
00211    p->insert(new StringSubComponent(SubComponent::Transport, "bar"));
00212    p->erase(SubComponent::TTL);
00213    cout << *p << endl;
00214    assert(p->find(SubComponent::TTL) == 0);
00215    delete p;
00216 
00217    cout << "Deep copy test." << endl;
00218 
00219    p = new SubComponentList();
00220    p->insert(new StringSubComponent(SubComponent::Method, "baz"));
00221    p->insert(new StringSubComponent(SubComponent::TTL, "foo"));
00222    p->insert(new StringSubComponent(SubComponent::Transport, "bar"));
00223    
00224    cout << *p << endl;
00225 
00226    SubComponentList* p2 = new SubComponentList(*p);
00227 
00228    delete p;
00229 
00230    cout << *p2 << endl;
00231 
00232    delete p2;
00233    */
00234 
00235 
00236     return 0;
00237 }
00238 
00239    
00240    
00241    
00242    
00243    
00244 
00245    
00246 
00247    
00248    
00249    
00250    
00251    
00252 
00253    
00254 
00255 
00256 /* ====================================================================
00257  * The Vovida Software License, Version 1.0 
00258  * 
00259  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00260  * 
00261  * Redistribution and use in source and binary forms, with or without
00262  * modification, are permitted provided that the following conditions
00263  * are met:
00264  * 
00265  * 1. Redistributions of source code must retain the above copyright
00266  *    notice, this list of conditions and the following disclaimer.
00267  * 
00268  * 2. Redistributions in binary form must reproduce the above copyright
00269  *    notice, this list of conditions and the following disclaimer in
00270  *    the documentation and/or other materials provided with the
00271  *    distribution.
00272  * 
00273  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00274  *    and "Vovida Open Communication Application Library (VOCAL)" must
00275  *    not be used to endorse or promote products derived from this
00276  *    software without prior written permission. For written
00277  *    permission, please contact vocal@vovida.org.
00278  *
00279  * 4. Products derived from this software may not be called "VOCAL", nor
00280  *    may "VOCAL" appear in their name, without prior written
00281  *    permission of Vovida Networks, Inc.
00282  * 
00283  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00284  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00285  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00286  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00287  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00288  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00289  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00290  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00291  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00292  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00293  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00294  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00295  * DAMAGE.
00296  * 
00297  * ====================================================================
00298  * 
00299  * This software consists of voluntary contributions made by Vovida
00300  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00301  * Inc.  For more information on Vovida Networks, Inc., please see
00302  * <http://www.vovida.org/>.
00303  *
00304  */