/[resiprocate]/main/resip/stack/test/testGperfHash.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testGperfHash.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5948 - (show annotations) (download)
Fri Feb 17 15:30:16 2006 UTC (13 years, 9 months ago) by dworley
File MIME type: text/plain
File size: 5368 byte(s)
Setting more svn: properties, and adding EOLs to the ends of files
that need it.

1 #include <assert.h>
2 #include <iostream>
3 #include <sstream>
4 #include <string.h>
5 #include <string>
6 #include "resip/stack/HeaderTypes.hxx"
7 #include "resip/stack/HeaderHash.hxx"
8 #include "resip/stack/MethodTypes.hxx"
9 #include "resip/stack/MethodHash.hxx"
10 #include "resip/stack/ParameterTypes.hxx"
11 #include "resip/stack/ParameterHash.hxx"
12
13 using namespace std;
14 using namespace resip;
15
16 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
17
18 static bool
19 testHeaderHash(bool verbose)
20 {
21 bool gotErrors = false;
22
23 if (verbose)
24 cerr << "Test header hashing" << endl;
25
26 // HeaderNames start from 1, in effect; not sure why.
27 //
28 int nHeaderNames = sizeof(Headers::HeaderNames) / sizeof(Data);
29 if (nHeaderNames != (Headers::MAX_HEADERS + 1))
30 {
31 if (verbose)
32 cerr << "Mismatch: " << nHeaderNames << " header names vs. "
33 << Headers::MAX_HEADERS << " header types" << endl;
34 gotErrors = true;
35 }
36 else
37 for (int ht = 0; ht < Headers::MAX_HEADERS; ht++)
38 {
39 const Data& hName = Headers::getHeaderName(ht);
40 Headers::Type ht1 = Headers::getType(hName.c_str(), hName.size());
41 if (ht != ht1)
42 {
43 if (verbose)
44 cerr << "Header " << ht << " => " << hName << " => " << ht1 << endl;
45 gotErrors = true;
46 }
47 }
48
49 return gotErrors;
50 }
51
52
53 static bool
54 testMethodHash(bool verbose)
55 {
56 bool gotErrors = false;
57
58 if (verbose)
59 cerr << "Test method hashing" << endl;
60
61
62 for (int mt = 0; mt < MAX_METHODS; mt++)
63 {
64 const Data& mName = getMethodName(static_cast<MethodTypes>(mt));
65 // cout << "Checking " << mName << endl;
66 MethodTypes mt1 = getMethodType(mName);
67 if (mt != mt1)
68 {
69 if (verbose)
70 cerr << "Method " << mt << " => " << mName << " => " << mt1 << endl;
71 gotErrors = true;;
72 }
73 }
74
75 return gotErrors;
76 }
77
78 static bool
79 testParameterHash(bool verbose)
80 {
81 bool gotErrors = false;
82 if (verbose)
83 cerr << "Test parameter hashing" << endl;
84
85 int nParameterNames = sizeof(ParameterTypes::ParameterNames) / sizeof(Data);
86 if (nParameterNames != ParameterTypes::MAX_PARAMETER)
87 {
88 if (verbose)
89 cerr << "Mismatch: " << nParameterNames << " parameter names vs. "
90 << ParameterTypes::MAX_PARAMETER << " parameter types" << endl;
91 gotErrors = true;
92 }
93 else
94 for (int pt = 0; pt < ParameterTypes::MAX_PARAMETER; pt++)
95 {
96 const Data& pName = ParameterTypes::ParameterNames[pt];
97 // cout << "Checking " << pName << endl;
98 ParameterTypes::Type pt1 = ParameterTypes::getType(pName.c_str(),
99 pName.size());
100 if (pt != pt1 && pt1 != ParameterTypes::qopFactory) // qop is weird
101 {
102 if (verbose)
103 cerr << "Parameter " << pt << " => " << pName << " => " << pt1 << endl;
104 gotErrors = true;
105 }
106 }
107
108 return gotErrors;
109 }
110
111 int main()
112 {
113 unsigned errors = 0;
114
115 if (testHeaderHash(true))
116 errors |= 1;
117
118 if (testMethodHash(true))
119 errors |= 2;
120
121 if (testParameterHash(true))
122 errors |= 4;
123
124 if (!errors)
125 cerr << "All OK" << endl;
126
127 return errors;
128 }
129
130 /* ====================================================================
131 * The Vovida Software License, Version 1.0
132 *
133 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
134 *
135 * Redistribution and use in source and binary forms, with or without
136 * modification, are permitted provided that the following conditions
137 * are met:
138 *
139 * 1. Redistributions of source code must retain the above copyright
140 * notice, this list of conditions and the following disclaimer.
141 *
142 * 2. Redistributions in binary form must reproduce the above copyright
143 * notice, this list of conditions and the following disclaimer in
144 * the documentation and/or other materials provided with the
145 * distribution.
146 *
147 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
148 * and "Vovida Open Communication Application Library (VOCAL)" must
149 * not be used to endorse or promote products derived from this
150 * software without prior written permission. For written
151 * permission, please contact vocal@vovida.org.
152 *
153 * 4. Products derived from this software may not be called "VOCAL", nor
154 * may "VOCAL" appear in their name, without prior written
155 * permission of Vovida Networks, Inc.
156 *
157 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
158 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
159 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
160 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
161 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
162 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
163 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
164 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
165 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
166 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
167 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
168 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
169 * DAMAGE.
170 *
171 * ====================================================================
172 *
173 * This software consists of voluntary contributions made by Vovida
174 * Networks, Inc. and many individuals on behalf of Vovida Networks,
175 * Inc. For more information on Vovida Networks, Inc., please see
176 * <http://www.vovida.org/>.
177 *
178 */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27