/[resiprocate]/main/rutil/test/testData.cxx
ViewVC logotype

Contents of /main/rutil/test/testData.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1294 - (show annotations) (download)
Mon Mar 24 22:42:27 2003 UTC (16 years, 10 months ago) by jason
Original Path: main/sip/resiprocate/test/testData.cxx
File size: 10102 byte(s)
change from sip2 to resiprocate

1 #include "resiprocate/util/Data.hxx"
2 #include "resiprocate/util/DataStream.hxx"
3 #include "resiprocate/util/Log.hxx"
4 #include "assert.h"
5 #include <iostream>
6
7 using namespace Vocal2;
8 using namespace std;
9
10 // for friends
11 class TestData
12 {
13 public:
14 void main()
15 {
16
17 Log::initialize(Log::COUT, Log::DEBUG, Data::Empty);
18
19 {
20 Data v("some text");
21 assert(v.prefix("some"));
22 assert(v.prefix("some "));
23 assert(!v.prefix("ome "));
24
25 assert(v.prefix(Data::Empty));
26 assert(v.prefix("some text"));
27 assert(v.prefix(v));
28 assert(!v.prefix("some text "));
29 }
30
31 {
32 Data transport("transport");
33 assert(isEqualNoCase(transport, "transport"));
34 }
35
36 {
37 Data d1("0123456789");
38 assert(d1.find("0") == 0);
39 assert(d1.find("1") == 1);
40 assert(d1.find("8") == 8);
41 assert(d1.find("9") == 9);
42 assert(d1.find("01") == 0);
43 assert(d1.find("12") == 1);
44 assert(d1.find("a") == Data::npos);
45 assert(d1.find("0123456789") == 0);
46 assert(d1.find("0123456789a") == Data::npos);
47
48 Data d2;
49 assert(d2.find("0") == Data::npos);
50 assert(d2.find("abc") == Data::npos);
51 assert(d2.find("") == Data::npos);
52 }
53 {
54 Data d1("abcdefghi");
55 assert (d1.substr(d1.find("def"), 3) == "def");
56 cerr << "substr = " << d1.substr(5,4) << endl;
57 }
58 {
59 Data d1("0");
60 Data d2("0");
61 d1 ^= d2;
62 cerr << d1.hex() << endl;
63 assert(d1.size() == 1);
64 assert(d1[0] == 0);
65
66 d1 = "0";
67 d1 ^= Data();
68 cerr << d1.hex() << endl;
69 assert(d1.size() == 1);
70 assert(d1[0] == '0');
71
72 d1 = Data();
73 d1 ^= Data("0");
74 cerr << d1.hex() << endl;
75 assert(d1.size() == 1);
76 assert(d1[0] == '0');
77
78 d1 = Data();
79 d1 ^= Data();
80 cerr << d1.hex() << endl;
81 assert(d1.size() == 0);
82
83
84 d1 = "01234";
85 d1 ^= Data("01234");
86 cerr << d1.hex() << endl;
87 assert(d1.size() == 5);
88 assert(d1[0] == 0);
89 assert(d1[4] == 0);
90
91 d1 = "012";
92 d1 ^= Data("01234");
93 cerr << d1.hex() << endl;
94 assert(d1.size() == 5);
95 assert(d1[0] == 0);
96 assert(d1[1] == 0);
97 assert(d1[2] == 0);
98 assert(d1[3] == '3');
99 assert(d1[4] == '4');
100
101 d1 ^= Data("01234");
102 cerr << d1.hex() << endl;
103 assert(d1[0] == '0');
104 assert(d1[1] == '1');
105 assert(d1[2] == '2');
106 assert(d1[3] == 0);
107 assert(d1[4] == 0);
108
109 d1 = Data(100, true);
110 d1 ^= Data("0");
111 cerr << d1.hex() << endl;
112
113
114 Data buffer;
115 Data working;
116 DataStream strm(buffer);
117
118 buffer.clear();
119 strm << "user=phone";
120 strm.flush();
121 working ^= buffer;
122
123 buffer.clear();
124 strm << "maddr=192.168.1.1";
125 strm.flush();
126 working ^= buffer;
127
128
129 Data result = working;
130 working.clear();
131
132 buffer.clear();
133 strm << "maddr=192.168.1.1";
134 strm.flush();
135 working ^= buffer;
136
137 buffer.clear();
138 strm << "user=phone";
139 strm.flush();
140 working ^= buffer;
141
142 assert(result == working);
143 }
144
145
146
147 {
148 Data d("012345");
149 assert(d[0] == '0');
150 assert(d[1] == '1');
151 assert(d[2] == '2');
152 assert(d[3] == '3');
153 assert(d[4] == '4');
154 assert(d[5] == '5');
155 }
156
157 {
158 Data *d = new Data("origin",6);
159 {
160 Data * t = d;
161
162 d = new Data(*d);
163
164 assert(d->size() == t->size());
165 assert(d->mCapacity == t->mCapacity);
166 // cout << d->size() << ":" << d->mCapacity << endl;
167 delete t;
168 }
169 delete d;
170 }
171
172 {
173 char blah[] = "12345";
174 Data d(blah, 3);
175 assert(strlen(d.c_str()) == 3);
176 }
177
178 {
179 assert(Data(0) == "0");
180 assert(Data(1) == "1");
181 assert(Data(-1) == "-1");
182 assert(Data(11) == "11");
183 assert(Data(1234567) == "1234567");
184 assert(Data(-1234567) == "-1234567");
185 }
186
187 {
188 Data empt;
189 Data empt1;
190 assert(empt.size() == 0);
191 assert(empt == empt);
192 assert(empt == empt1);
193 assert(empt1 == empt);
194 assert(empt1 == "");
195
196 assert(!(empt != empt));
197 assert(!(empt != empt1));
198 assert(!(empt1 != empt));
199 assert(!(empt1 != ""));
200
201 assert(empt1 == "");
202 assert("sdf" != empt1);
203 assert(Data("SAfdsaf") != empt1);
204 empt = empt;
205 empt = empt1;
206 empt = "sdfasf";
207 }
208
209 {
210 Data d("qwerty");
211 cerr << d << endl;
212 assert(strcmp(d.data(), "qwerty") == 0);
213
214 Data e;
215
216 assert(e == "");
217 }
218
219 {
220 Data d("qwerty");
221 assert(strcmp(d.c_str(), "qwerty") == 0);
222
223 Data e;
224 assert(strcmp(e.c_str(), "") == 0);
225 }
226
227 {
228 Data c = "sadfsdf";
229 Data d;
230 d = c;
231 assert(c == d);
232 }
233
234 {
235 const char* f = "asdasd";
236 Data d = Data(f);
237 assert(d == f);
238 }
239
240 {
241 Data d;
242 const char* f = "asdasd";
243 d = f;
244 assert(d == f);
245 }
246
247 {
248 Data d("asdfasfdsadf");
249 const char* f = "asdasd";
250 d = f;
251 assert(d == f);
252 }
253
254 {
255 const char* f = "asdasd";
256 Data d = Data(f);
257 assert(!(d < f));
258 }
259
260 {
261 Data d;
262 const char* f = "asdasd";
263 d = f;
264 assert(!(d < f));
265 }
266
267 {
268 Data d("asdfasfdsadf");
269 const char* f = "asdasd";
270 d = f;
271 assert(!(d < f));
272 }
273
274
275 {
276 Data a("qwerty");
277 Data b("qwerty");
278 assert(!(a < b));
279 }
280 {
281 Data a("qwert");
282 Data b("qwerty");
283 assert(a < b);
284 }
285 {
286 Data a("qwert");
287 Data b("qwerty");
288 assert(a < b);
289 assert(!(b < a));
290 }
291
292 {
293 const char* f = "asdasda";
294 Data d("asdasd");
295 assert(d < f);
296 }
297
298 {
299 const char * c("asdfasfdsadf");
300 Data d(c, 4, true); //share memory
301 assert(d < c);
302 }
303
304 {
305 const char * c("asdfasfdsadf");
306 Data d(c, strlen(c), true); // share memory
307 assert(!(d < c));
308 }
309
310 {
311 const char * c("asdfasfdsadf");
312 Data d(c, strlen(c), true); // share memory
313 assert(!(d < c));
314 Data c1(d); // copy, null terminate
315 assert(!(d < c1));
316 assert(!(c1 < d));
317 }
318
319 {
320 Data d("123");
321 assert(d.size() == 3);
322 }
323
324 {
325 Data d("one");
326 Data c("two");
327 d += c;
328 assert(d == "onetwo");
329
330 Data empt;
331 assert(empt + d == d);
332 assert(empt + d == "onetwo");
333 assert(empt + "three" == "three");
334 }
335
336 {
337 Data s;
338 s = "c=";
339 assert(s == "c=");
340 s += "foo";
341 assert(s == "c=foo");
342 s += "\r\n";
343 s += "bar";
344 s += "\r\n";
345 assert (s == "c=foo\r\nbar\r\n");
346 }
347
348 {
349 Data s;
350 s += 'c';
351 assert(s == "c");
352 assert(s.size() == 1);
353 }
354
355 {
356 Data s;
357 s = "c=";
358 assert(s == "c=");
359 s += 'f';
360 assert(s == "c=f");
361 assert(s.size() == 3);
362 }
363
364 {
365 Data a("one");
366 Data b("two");
367 Data c("three");
368
369 assert(a+b+c == "onetwothree");
370 }
371
372 {
373 Data d("one");
374 cerr << "one + two = " << (d + "two") << endl;
375 assert((d + "two") == "onetwo");
376 }
377 {
378 Data mixed("MiXed");
379 mixed.lowercase();
380 assert(mixed == "mixed");
381 }
382 {
383 Data mixed("miXed");
384 mixed.uppercase();
385 assert(mixed == "MIXED");
386 }
387 {
388 Data a("a");
389 Data aa(a);
390 assert(a.size() == aa.size());
391 }
392 {
393 Data d("ssd");
394 Data c;
395 d = c;
396 assert(d.empty());
397 }
398 {
399 Data d;
400 Data c;
401 assert(!(d != c));
402 d = c;
403 assert(d.empty());
404 }
405 {
406 char s[] = "userB@whistler.gloo.net:6062\r\nCo\031";
407 char o[] = "S";
408 Data d(s, strlen(s), false);
409 Data c(o, strlen(o), false);
410
411 d = c;
412 assert(c == "S");
413 }
414 {
415 Data d((unsigned long)235235);
416 assert(d == "235235");
417 }
418 }
419 };
420
421 int
422 main()
423 {
424 TestData td;
425 td.main();
426 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27