reSIProcate/stack  9694
testGperfHash.cxx
Go to the documentation of this file.
00001 #include <assert.h>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <string.h>
00005 #include <string>
00006 #include "resip/stack/HeaderTypes.hxx"
00007 #include "resip/stack/HeaderHash.hxx"
00008 #include "resip/stack/MethodTypes.hxx"
00009 #include "resip/stack/MethodHash.hxx"
00010 #include "resip/stack/ParameterTypes.hxx"
00011 #include "resip/stack/ParameterHash.hxx"
00012 
00013 using namespace std;
00014 using namespace resip;
00015 
00016 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
00017 
00018 static bool
00019 testHeaderHash(bool verbose)
00020 {
00021   bool gotErrors = false;
00022 
00023   if (verbose)
00024     cerr << "Test header hashing" << endl;
00025 
00026   // HeaderNames start from 1, in effect; not sure why.
00027   //
00028   int nHeaderNames = sizeof(Headers::HeaderNames) / sizeof(Data);
00029   if (nHeaderNames != (Headers::MAX_HEADERS + 1))
00030   {
00031     if (verbose)
00032       cerr << "Mismatch: " << nHeaderNames << " header names vs. "
00033            << Headers::MAX_HEADERS << " header types" << endl;
00034     gotErrors = true;
00035   } 
00036   else
00037     for (int ht = 0; ht < Headers::MAX_HEADERS; ht++)
00038     {
00039       const Data& hName = Headers::getHeaderName(ht);
00040       Headers::Type ht1 = Headers::getType(hName.c_str(), hName.size());
00041       if (ht != ht1)
00042       {
00043         if (verbose)
00044           cerr << "Header " << ht << " => " << hName << " => " << ht1 << endl;
00045         gotErrors = true;
00046       }
00047     }
00048 
00049   return gotErrors;
00050 }
00051 
00052 
00053 static bool
00054 testMethodHash(bool verbose)
00055 {
00056   bool gotErrors = false;
00057 
00058   if (verbose)
00059     cerr << "Test method hashing" << endl;
00060 
00061 
00062     for (int mt = 0; mt < MAX_METHODS; mt++)
00063     {
00064         const Data& mName = getMethodName(static_cast<MethodTypes>(mt));
00065 //    cout << "Checking " << mName << endl;
00066       MethodTypes mt1 = getMethodType(mName);
00067       if (mt != mt1)
00068       {
00069         if (verbose)
00070           cerr << "Method " << mt << " => " << mName << " => " << mt1 << endl;
00071         gotErrors = true;;
00072       }
00073     }
00074 
00075   return gotErrors;
00076 }
00077 
00078 static bool
00079 testParameterHash(bool verbose)
00080 {
00081   bool gotErrors = false;
00082   if (verbose)
00083     cerr << "Test parameter hashing" << endl;
00084 
00085   int nParameterNames = sizeof(ParameterTypes::ParameterNames) / sizeof(Data);
00086   if (nParameterNames != ParameterTypes::MAX_PARAMETER)
00087   {
00088     if (verbose)
00089       cerr << "Mismatch: " << nParameterNames << " parameter names vs. "
00090            << ParameterTypes::MAX_PARAMETER << " parameter types" << endl;
00091     gotErrors = true;
00092   } 
00093   else
00094     for (int pt = 0; pt < ParameterTypes::MAX_PARAMETER; pt++)
00095     {
00096       const Data& pName = ParameterTypes::ParameterNames[pt];
00097 //    cout << "Checking " << pName << endl;
00098       ParameterTypes::Type pt1 = ParameterTypes::getType(pName.c_str(),
00099                                                          pName.size());
00100       if (pt != pt1 && pt1 != ParameterTypes::qopFactory) // qop is weird
00101       {
00102         if (verbose)
00103           cerr << "Parameter " << pt << " => " << pName << " => " << pt1 << endl;
00104         gotErrors = true;
00105       }
00106     }
00107 
00108   return gotErrors;
00109 }
00110 
00111 int main()
00112 {
00113   unsigned errors = 0;
00114 
00115   if (testHeaderHash(true))
00116     errors |= 1;
00117 
00118   if (testMethodHash(true))
00119     errors |= 2;
00120 
00121   if (testParameterHash(true))
00122     errors |= 4;
00123 
00124   if (!errors)
00125     cerr << "All OK" << endl;
00126 
00127   return errors;
00128 }
00129 
00130 /* ====================================================================
00131  * The Vovida Software License, Version 1.0 
00132  * 
00133  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00134  * 
00135  * Redistribution and use in source and binary forms, with or without
00136  * modification, are permitted provided that the following conditions
00137  * are met:
00138  * 
00139  * 1. Redistributions of source code must retain the above copyright
00140  *    notice, this list of conditions and the following disclaimer.
00141  * 
00142  * 2. Redistributions in binary form must reproduce the above copyright
00143  *    notice, this list of conditions and the following disclaimer in
00144  *    the documentation and/or other materials provided with the
00145  *    distribution.
00146  * 
00147  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00148  *    and "Vovida Open Communication Application Library (VOCAL)" must
00149  *    not be used to endorse or promote products derived from this
00150  *    software without prior written permission. For written
00151  *    permission, please contact vocal@vovida.org.
00152  *
00153  * 4. Products derived from this software may not be called "VOCAL", nor
00154  *    may "VOCAL" appear in their name, without prior written
00155  *    permission of Vovida Networks, Inc.
00156  * 
00157  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00158  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00159  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00160  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00161  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00162  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00163  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00164  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00165  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00166  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00167  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00168  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00169  * DAMAGE.
00170  * 
00171  * ====================================================================
00172  * 
00173  * This software consists of voluntary contributions made by Vovida
00174  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00175  * Inc.  For more information on Vovida Networks, Inc., please see
00176  * <http://www.vovida.org/>.
00177  *
00178  */