Coverage Report

Created: 2025-07-23 06:03

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