Coverage Report

Created: 2023-09-25 06:23

/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
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
0
  {
26
0
    for(int i = 0 ; i < boxWidth-w ; i++) cout << c;
27
0
  };
28
  static void labels(int len, int row)
29
0
  {
30
0
    int start = chPerRow*row;
31
0
    cout << ' ';
32
0
    for(int 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
  static void banner(int len, int row)
40
0
  {
41
0
    int chThisRow = 0;
42
    
43
0
    if (row >= len/chPerRow)
44
0
      chThisRow = len%chPerRow;
45
0
    else
46
0
      chThisRow = chPerRow;
47
    
48
0
    if (chThisRow < 1) return;
49
    
50
0
    cout << "+";
51
0
    for(int i = 0 ; i < chThisRow; i++)
52
0
      {
53
0
        fb(1,'-');
54
0
        cout << '+';
55
0
      }
56
0
    cout << endl;
57
0
    return;
58
0
  };
59
  static void data(const char * p , int len, int row)
60
0
  {
61
    
62
0
    cout << '|';
63
0
    for(int c = 0; c < chPerRow; c++)
64
0
      {
65
0
        int o = row*chPerRow + c;
66
0
        if (o >= len) break;
67
0
        char ch = p[o];
68
        
69
0
        if (isalnum(ch) || ispunct(ch) || ch == ' ' )
70
0
          {
71
0
            cout << ' ' << (char)ch;
72
0
               fb(3);
73
0
          }
74
0
        else if ( ch == '\t' )
75
0
          {
76
0
            cout << " \\t";
77
0
            fb(4);
78
0
          }
79
0
        else if ( ch >= '\t' || ch <= '\r')
80
0
          {
81
0
            cout << " \\" << "tnvfr"[ch-'\t'];
82
0
               fb(4);
83
0
          }
84
0
        else
85
0
          {
86
0
            cout << 'x' << hex << setw(2) << ch << dec;
87
0
            fb(4);
88
0
          }
89
0
        cout << '|';
90
0
      }
91
0
    cout << endl;
92
0
  };
93
  
94
};
95
  
96
  
97
void 
98
TestSupport::prettyPrint(const char * p,size_t len)
99
0
{
100
  
101
0
  size_t row = 0;
102
0
  if (TestSupportPriv::chPerRow == 0)
103
0
    {
104
0
      char * p = getenv("COLUMNS");
105
0
            if (p)
106
0
            {
107
0
               TestSupportPriv::chPerRow=strtol(p,0,0)/boxWidth;
108
0
            }
109
0
            else
110
0
            {
111
0
               TestSupportPriv::chPerRow = 80/boxWidth;
112
0
            }
113
0
         }
114
         
115
0
         for ( row = 0 ; row <= len/TestSupportPriv::chPerRow ; row++)
116
0
         {
117
            // do this row's banner
118
0
            TestSupportPriv::banner(len,row);
119
            // do this row's data
120
0
            TestSupportPriv::data(p,len,row);
121
            // do this row's banner
122
0
            TestSupportPriv::banner(len,row);
123
            // do this row's counts
124
0
            TestSupportPriv::labels(len,row);
125
0
         }
126
0
      };
127
128
Data
129
TestSupport::showN(const char * p, size_t l)
130
0
{
131
0
  Data s;
132
0
  for(unsigned int i = 0 ; i < l ; i++)
133
0
    {
134
0
      s += p[i];
135
0
    }
136
0
  return s;
137
0
}
138
139
140
int TestSupportPriv::chPerRow = 0;
141
142
SipMessage*
143
TestSupport::makeMessage(const Data& data, bool isExternal )
144
6.23k
{
145
6.23k
   return SipMessage::make(data, isExternal);
146
6.23k
}
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
 */