|
reSIProcate/rutil
9694
|
00001 #include "rutil/DataStream.hxx" 00002 00003 #include "rutil/Data.hxx" 00004 #include "assert.h" 00005 #include <iostream> 00006 00007 using namespace resip; 00008 using namespace std; 00009 00010 int main() 00011 { 00012 { 00013 // test overflow and synch with flush 00014 char buf[16]; 00015 Data data(Data::Borrow, buf, sizeof(buf)); 00016 data.clear(); 00017 00018 DataStream str(data); 00019 for (int i = 0; i < 32; ++i) { 00020 str << 'a'; 00021 str.flush(); 00022 } 00023 } 00024 00025 { 00026 Data foo; 00027 { 00028 oDataStream str(foo); 00029 00030 str << "some characters " << 42 << " for foo"; 00031 str << "some more characters " << 24 << " for foo"; 00032 00033 str.flush(); 00034 00035 str << "some a few more characters "; 00036 00037 str.reset(); 00038 00039 str << "all that remains"; 00040 } 00041 00042 std::cerr << "!! " << foo << std::endl; 00043 00044 assert(foo == "all that remains"); 00045 } 00046 00047 { 00048 Data d; 00049 d = (" SIP invitations used to create sessions carry session descriptions\n" 00050 "that allow participants to agree on a set of compatible media types.\n" 00051 "SIP makes use of elements called proxy servers to help route requests\n" 00052 "to the user's current location, authenticate and authorize users for\n" 00053 "services, implement provider call-routing policies, and provide\n" 00054 "features to users. SIP also provides a registration function that\n" 00055 "allows users to upload their current locations for use by proxy\n" 00056 "servers. SIP runs on top of several different transport protocols." 00057 ); 00058 00059 d.clear(); 00060 DataStream s(d); 00061 s << "all the kings horses and all the kings men..."; 00062 s.flush(); 00063 00064 cerr << d.size() << endl; 00065 cerr << d.c_str(); 00066 00067 assert(strcmp(d.c_str(), "all the kings horses and all the kings men...") == 0); 00068 } 00069 00070 { 00071 Data d; 00072 DataStream ds(d); 00073 00074 Data foo("foo"); 00075 00076 ds << "Here is some stuff " << foo << 17 << ' ' << 'c' << ' ' << -157 << endl; 00077 cerr << "!! <" << d << ">" << endl; 00078 ds.flush(); 00079 assert(d == "Here is some stuff foo17 c -157\n"); 00080 assert(strlen(d.c_str()) == d.size()); 00081 } 00082 { 00083 Data d(500, Data::Preallocate); 00084 DataStream ds(d); 00085 00086 Data foo("foo"); 00087 00088 ds << "Here is some stuff " << foo << 17 << ' ' << 'c' << ' ' << -157 << endl; 00089 cerr << "!! <" << d << ">" << endl; 00090 ds.flush(); 00091 assert(d == "Here is some stuff foo17 c -157\n"); 00092 assert(strlen(d.c_str()) == d.size()); 00093 } 00094 00095 { 00096 Data d(3, Data::Preallocate); 00097 DataStream ds(d); 00098 00099 for (int i = 0; i < 200; i++) 00100 { 00101 ds << Data(i) << ' '; 00102 } 00103 00104 ds.flush(); 00105 00106 assert(d == "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 "); 00107 } 00108 00109 cerr << "All OK" << endl; 00110 return 0; 00111 } 00112 /* ==================================================================== 00113 * The Vovida Software License, Version 1.0 00114 * 00115 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00116 * 00117 * Redistribution and use in source and binary forms, with or without 00118 * modification, are permitted provided that the following conditions 00119 * are met: 00120 * 00121 * 1. Redistributions of source code must retain the above copyright 00122 * notice, this list of conditions and the following disclaimer. 00123 * 00124 * 2. Redistributions in binary form must reproduce the above copyright 00125 * notice, this list of conditions and the following disclaimer in 00126 * the documentation and/or other materials provided with the 00127 * distribution. 00128 * 00129 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00130 * and "Vovida Open Communication Application Library (VOCAL)" must 00131 * not be used to endorse or promote products derived from this 00132 * software without prior written permission. For written 00133 * permission, please contact vocal@vovida.org. 00134 * 00135 * 4. Products derived from this software may not be called "VOCAL", nor 00136 * may "VOCAL" appear in their name, without prior written 00137 * permission of Vovida Networks, Inc. 00138 * 00139 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00140 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00141 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00142 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00143 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00144 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00145 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00146 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00147 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00148 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00149 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00150 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00151 * DAMAGE. 00152 * 00153 * ==================================================================== 00154 * 00155 * This software consists of voluntary contributions made by Vovida 00156 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00157 * Inc. For more information on Vovida Networks, Inc., please see 00158 * <http://www.vovida.org/>. 00159 * 00160 */
1.7.5.1