|
reSIProcate/stack
9694
|
00001 #include "resip/stack/test/TestSupport.hxx" 00002 #include "rutil/Data.hxx" 00003 #include "rutil/Logger.hxx" 00004 00005 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP 00006 00007 #include <iostream> 00008 #include <iomanip> 00009 00010 00011 using namespace std; 00012 00013 00014 const int boxWidth = 4; 00015 namespace resip 00016 { 00017 class TestSupportPriv 00018 { 00019 private: 00020 static int chPerRow; 00021 friend class TestSupport; 00022 00023 public: 00024 static void fb(int w, char c=' ') 00025 { 00026 for(int i = 0 ; i < boxWidth-w ; i++) cout << c; 00027 }; 00028 static void labels(int len, int row) 00029 { 00030 int start = chPerRow*row; 00031 cout << ' '; 00032 for(int i = 0; i < chPerRow && start+i < len; i++) 00033 { 00034 cout << setw(boxWidth-1) << start+i; 00035 fb(3); 00036 } 00037 cout << endl; 00038 } 00039 static void banner(int len, int row) 00040 { 00041 int chThisRow = 0; 00042 00043 if (row >= len/chPerRow) 00044 chThisRow = len%chPerRow; 00045 else 00046 chThisRow = chPerRow; 00047 00048 if (chThisRow < 1) return; 00049 00050 cout << "+"; 00051 for(int i = 0 ; i < chThisRow; i++) 00052 { 00053 fb(1,'-'); 00054 cout << '+'; 00055 } 00056 cout << endl; 00057 return; 00058 }; 00059 static void data(const char * p , int len, int row) 00060 { 00061 00062 cout << '|'; 00063 for(int c = 0; c < chPerRow; c++) 00064 { 00065 int o = row*chPerRow + c; 00066 if (o >= len) break; 00067 char ch = p[o]; 00068 00069 if (isalnum(ch) || ispunct(ch) || ch == ' ' ) 00070 { 00071 cout << ' ' << (char)ch; 00072 fb(3); 00073 } 00074 else if ( ch == '\t' ) 00075 { 00076 cout << " \\t"; 00077 fb(4); 00078 } 00079 else if ( ch >= '\t' || ch <= '\r') 00080 { 00081 cout << " \\" << "tnvfr"[ch-'\t']; 00082 fb(4); 00083 } 00084 else 00085 { 00086 cout << 'x' << hex << setw(2) << ch << dec; 00087 fb(4); 00088 } 00089 cout << '|'; 00090 } 00091 cout << endl; 00092 }; 00093 00094 }; 00095 00096 00097 void 00098 TestSupport::prettyPrint(const char * p,size_t len) 00099 { 00100 00101 size_t row = 0; 00102 if (TestSupportPriv::chPerRow == 0) 00103 { 00104 char * p = getenv("COLUMNS"); 00105 if (p) 00106 { 00107 TestSupportPriv::chPerRow=strtol(p,0,0)/boxWidth; 00108 } 00109 else 00110 { 00111 TestSupportPriv::chPerRow = 80/boxWidth; 00112 } 00113 } 00114 00115 for ( row = 0 ; row <= len/TestSupportPriv::chPerRow ; row++) 00116 { 00117 // do this row's banner 00118 TestSupportPriv::banner(len,row); 00119 // do this row's data 00120 TestSupportPriv::data(p,len,row); 00121 // do this row's banner 00122 TestSupportPriv::banner(len,row); 00123 // do this row's counts 00124 TestSupportPriv::labels(len,row); 00125 } 00126 }; 00127 00128 Data 00129 TestSupport::showN(const char * p, size_t l) 00130 { 00131 Data s; 00132 for(unsigned int i = 0 ; i < l ; i++) 00133 { 00134 s += p[i]; 00135 } 00136 return s; 00137 } 00138 00139 00140 int TestSupportPriv::chPerRow = 0; 00141 00142 SipMessage* 00143 TestSupport::makeMessage(const Data& data, bool isExternal ) 00144 { 00145 return SipMessage::make(data, isExternal); 00146 } 00147 00148 }; 00149 00150 00151 /* ==================================================================== 00152 * The Vovida Software License, Version 1.0 00153 * 00154 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00155 * 00156 * Redistribution and use in source and binary forms, with or without 00157 * modification, are permitted provided that the following conditions 00158 * are met: 00159 * 00160 * 1. Redistributions of source code must retain the above copyright 00161 * notice, this list of conditions and the following disclaimer. 00162 * 00163 * 2. Redistributions in binary form must reproduce the above copyright 00164 * notice, this list of conditions and the following disclaimer in 00165 * the documentation and/or other materials provided with the 00166 * distribution. 00167 * 00168 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00169 * and "Vovida Open Communication Application Library (VOCAL)" must 00170 * not be used to endorse or promote products derived from this 00171 * software without prior written permission. For written 00172 * permission, please contact vocal@vovida.org. 00173 * 00174 * 4. Products derived from this software may not be called "VOCAL", nor 00175 * may "VOCAL" appear in their name, without prior written 00176 * permission of Vovida Networks, Inc. 00177 * 00178 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00179 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00180 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00181 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00182 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00183 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00184 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00185 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00186 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00187 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00188 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00189 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00190 * DAMAGE. 00191 * 00192 * ==================================================================== 00193 * 00194 * This software consists of voluntary contributions made by Vovida 00195 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00196 * Inc. For more information on Vovida Networks, Inc., please see 00197 * <http://www.vovida.org/>. 00198 * 00199 */
1.7.5.1