reSIProcate/stack  9694
testMessageWaiting.cxx
Go to the documentation of this file.
00001 #include "resip/stack/MessageWaitingContents.hxx"
00002 #include "resip/stack/HeaderFieldValue.hxx"
00003 #include "rutil/ParseBuffer.hxx"
00004 #include <iostream>
00005 
00006 using namespace resip;
00007 using namespace std;
00008 
00009 int
00010 main()
00011 {
00012    {
00013       const Data txt("s\r\nk");
00014       ParseBuffer pb(txt.data(), txt.size());
00015       pb.skipChar();
00016 
00017       assert(*skipSipLWS(pb) == '\r');
00018    }
00019 
00020    {
00021       const Data txt("s\r\n\r\nk");
00022       ParseBuffer pb(txt.data(), txt.size());
00023       pb.skipChar();
00024 
00025       assert(skipSipLWS(pb) == txt.data()+1);
00026    }
00027    {
00028       cerr << "Test unparsed copy constructor" << endl;
00029    
00030       const Data txt("Messages-Waiting: yes\r\n"
00031                      "voice-message: 7/0\r\n");
00032 
00033       HeaderFieldValue hfv(txt.data(), txt.size());
00034       Mime type("text", "data");
00035       MessageWaitingContents mwb(hfv, type);
00036 
00037       MessageWaitingContents* mwb2 =
00038          dynamic_cast<MessageWaitingContents*>(mwb.clone());
00039 
00040       assert(mwb2->header(mw_voice).newCount() == 7);
00041       assert(mwb2->header(mw_voice).oldCount() == 0);
00042    }
00043 
00044    {
00045       const Data txt("Messages-Waiting: yes\r\n");
00046 
00047       HeaderFieldValue hfv(txt.data(), txt.size());
00048       Mime type("application", "simple-message-summary");
00049       MessageWaitingContents mwb(hfv, type);
00050       
00051       assert(mwb.hasMessages() == true);      
00052    }
00053 
00054    {
00055       const Data txt("Messages-Waiting: no\r\n");
00056 
00057       HeaderFieldValue hfv(txt.data(), txt.size());
00058       Mime type("application", "simple-message-summary");
00059       MessageWaitingContents mwb(hfv, type);
00060       
00061       assert(mwb.hasMessages() == false);      
00062    }
00063 
00064    {
00065       const Data txt("Messages-Waiting: yes\r\n"
00066                      "Message-Account: sip:alice@vmail.example.com\r\n"
00067                      "Voice-Message: 4/8 (1/2)\r\n");
00068 
00069       HeaderFieldValue hfv(txt.data(), txt.size());
00070       Mime type("application", "simple-message-summary");
00071       MessageWaitingContents mwb(hfv, type);
00072 
00073       assert(mwb.header(mw_account).scheme() == "sip");
00074       assert(mwb.header(mw_account).user() == "alice");
00075       assert(mwb.header(mw_account).host() == "vmail.example.com");
00076       
00077       assert(mwb.header(mw_voice).newCount() == 4);
00078       assert(mwb.header(mw_voice).oldCount() == 8);
00079       assert(mwb.header(mw_voice).urgent() == true);
00080       assert(mwb.header(mw_voice).urgentNewCount() == 1);
00081       assert(mwb.header(mw_voice).urgentOldCount() == 2);
00082 
00083       assert(mwb.exists(mw_fax) == false);
00084    }
00085 
00086 
00087    {
00088       const Data txt("Messages-Waiting: yes\r\n"
00089                      "Message-Account: sip:alice@vmail.example.com\r\n"
00090                      "Voice-Message: 4/8 (1/2)\r\n"
00091                      "Fax-Message: 2/1\r\n"
00092                      "\r\n"
00093                      "Something: fine choice\r\n");
00094 
00095       HeaderFieldValue hfv(txt.data(), txt.size());
00096       Mime type("application", "simple-message-summary");
00097       MessageWaitingContents mwb(hfv, type);
00098 
00099       assert(mwb.header(mw_account).scheme() == "sip");
00100       assert(mwb.header(mw_account).user() == "alice");
00101       assert(mwb.header(mw_account).host() == "vmail.example.com");
00102       
00103       assert(mwb.header(mw_voice).newCount() == 4);
00104       assert(mwb.header(mw_voice).oldCount() == 8);
00105       assert(mwb.header(mw_voice).urgent() == true);
00106       assert(mwb.header(mw_voice).urgentNewCount() == 1);
00107       assert(mwb.header(mw_voice).urgentOldCount() == 2);
00108 
00109       assert(mwb.header(mw_fax).newCount() == 2);
00110       assert(mwb.header(mw_fax).oldCount() == 1);
00111       assert(mwb.header(mw_fax).urgent() == false);
00112       
00113       assert(mwb.header(Data("Something")) == Data("fine choice"));
00114 
00115       assert(mwb.exists(mw_fax) == true);
00116    }      
00117 
00118    cerr << "All OK" << endl;
00119    return 0;
00120 }
00121 
00122 /* ====================================================================
00123  * The Vovida Software License, Version 1.0 
00124  * 
00125  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00126  * 
00127  * Redistribution and use in source and binary forms, with or without
00128  * modification, are permitted provided that the following conditions
00129  * are met:
00130  * 
00131  * 1. Redistributions of source code must retain the above copyright
00132  *    notice, this list of conditions and the following disclaimer.
00133  * 
00134  * 2. Redistributions in binary form must reproduce the above copyright
00135  *    notice, this list of conditions and the following disclaimer in
00136  *    the documentation and/or other materials provided with the
00137  *    distribution.
00138  * 
00139  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00140  *    and "Vovida Open Communication Application Library (VOCAL)" must
00141  *    not be used to endorse or promote products derived from this
00142  *    software without prior written permission. For written
00143  *    permission, please contact vocal@vovida.org.
00144  *
00145  * 4. Products derived from this software may not be called "VOCAL", nor
00146  *    may "VOCAL" appear in their name, without prior written
00147  *    permission of Vovida Networks, Inc.
00148  * 
00149  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00150  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00151  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00152  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00153  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00154  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00155  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00156  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00157  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00158  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00159  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00160  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00161  * DAMAGE.
00162  * 
00163  * ====================================================================
00164  * 
00165  * This software consists of voluntary contributions made by Vovida
00166  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00167  * Inc.  For more information on Vovida Networks, Inc., please see
00168  * <http://www.vovida.org/>.
00169  *
00170  */