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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 #include "resip/stack/test/TestSupport.hxx"
2 #include "rutil/Data.hxx"
3 #include "rutil/Logger.hxx"
4
5 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
6
7 #include <iostream>
8 #include <iomanip>
9
10
11 using namespace std;
12
13
14 const int boxWidth = 4;
15 namespace resip
16 {
17 class TestSupportPriv
18 {
19 private:
20 static int chPerRow;
21 friend class TestSupport;
22
23 public:
24 static void fb(int w, char c=' ')
25 {
26 for(int i = 0 ; i < boxWidth-w ; i++) cout << c;
27 };
28 static void labels(int len, int row)
29 {
30 int start = chPerRow*row;
31 cout << ' ';
32 for(int i = 0; i < chPerRow && start+i < len; i++)
33 {
34 cout << setw(boxWidth-1) << start+i;
35 fb(3);
36 }
37 cout << endl;
38 }
39 static void banner(int len, int row)
40 {
41 int chThisRow = 0;
42
43 if (row >= len/chPerRow)
44 chThisRow = len%chPerRow;
45 else
46 chThisRow = chPerRow;
47
48 if (chThisRow < 1) return;
49
50 cout << "+";
51 for(int i = 0 ; i < chThisRow; i++)
52 {
53 fb(1,'-');
54 cout << '+';
55 }
56 cout << endl;
57 return;
58 };
59 static void data(const char * p , int len, int row)
60 {
61
62 cout << '|';
63 for(int c = 0; c < chPerRow; c++)
64 {
65 int o = row*chPerRow + c;
66 if (o >= len) break;
67 char ch = p[o];
68
69 if (isalnum(ch) || ispunct(ch) || ch == ' ' )
70 {
71 cout << ' ' << (char)ch;
72 fb(3);
73 }
74 else if ( ch == '\t' )
75 {
76 cout << " \\t";
77 fb(4);
78 }
79 else if ( ch >= '\t' || ch <= '\r')
80 {
81 cout << " \\" << "tnvfr"[ch-'\t'];
82 fb(4);
83 }
84 else
85 {
86 cout << 'x' << hex << setw(2) << ch << dec;
87 fb(4);
88 }
89 cout << '|';
90 }
91 cout << endl;
92 };
93
94 };
95
96
97 void
98 TestSupport::prettyPrint(const char * p,size_t len)
99 {
100
101 size_t row = 0;
102 if (TestSupportPriv::chPerRow == 0)
103 {
104 char * p = getenv("COLUMNS");
105 if (p)
106 {
107 TestSupportPriv::chPerRow=strtol(p,0,0)/boxWidth;
108 }
109 else
110 {
111 TestSupportPriv::chPerRow = 80/boxWidth;
112 }
113 }
114
115 for ( row = 0 ; row <= len/TestSupportPriv::chPerRow ; row++)
116 {
117 // do this row's banner
118 TestSupportPriv::banner(len,row);
119 // do this row's data
120 TestSupportPriv::data(p,len,row);
121 // do this row's banner
122 TestSupportPriv::banner(len,row);
123 // do this row's counts
124 TestSupportPriv::labels(len,row);
125 }
126 };
127
128 Data
129 TestSupport::showN(const char * p, size_t l)
130 {
131 Data s;
132 for(unsigned int i = 0 ; i < l ; i++)
133 {
134 s += p[i];
135 }
136 return s;
137 }
138
139
140 int TestSupportPriv::chPerRow = 0;
141
142 SipMessage*
143 TestSupport::makeMessage(const Data& data, bool isExternal )
144 {
145 return SipMessage::make(data, isExternal);
146 }
147
148 };
149
150
151 /* ====================================================================
152 * The Vovida Software License, Version 1.0
153 *
154 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
155 *
156 * Redistribution and use in source and binary forms, with or without
157 * modification, are permitted provided that the following conditions
158 * are met:
159 *
160 * 1. Redistributions of source code must retain the above copyright
161 * notice, this list of conditions and the following disclaimer.
162 *
163 * 2. Redistributions in binary form must reproduce the above copyright
164 * notice, this list of conditions and the following disclaimer in
165 * the documentation and/or other materials provided with the
166 * distribution.
167 *
168 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
169 * and "Vovida Open Communication Application Library (VOCAL)" must
170 * not be used to endorse or promote products derived from this
171 * software without prior written permission. For written
172 * permission, please contact vocal@vovida.org.
173 *
174 * 4. Products derived from this software may not be called "VOCAL", nor
175 * may "VOCAL" appear in their name, without prior written
176 * permission of Vovida Networks, Inc.
177 *
178 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
179 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
180 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
181 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
182 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
183 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
184 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
185 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
186 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
187 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
188 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
189 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
190 * DAMAGE.
191 *
192 * ====================================================================
193 *
194 * This software consists of voluntary contributions made by Vovida
195 * Networks, Inc. and many individuals on behalf of Vovida Networks,
196 * Inc. For more information on Vovida Networks, Inc., please see
197 * <http://www.vovida.org/>.
198 *
199 */

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