byte swap functions refactored; added helper functions for swapping bytes in arrays
[public/netxms.git] / tests / test-libnetxms / test-libnetxms.cpp
1 #include <nms_common.h>
2 #include <nms_util.h>
3 #include <nxqueue.h>
4 #include <nxcpapi.h>
5 #include <testtools.h>
6
7 void TestMsgWaitQueue();
8 void TestMessageClass();
9 void TestMutexWrapper();
10 void TestRWLockWrapper();
11 void TestConditionWrapper();
12
13 static char mbText[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
14 static WCHAR wcText[] = L"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
15 static char mbTextShort[] = "Lorem ipsum";
16 static UCS2CHAR ucs2TextShort[] = { 'L', 'o', 'r', 'e', 'm', ' ', 'i', 'p', 's', 'u', 'm', 0 };
17
18 /**
19 * Test string conversion
20 */
21 static void TestStringConversion()
22 {
23 StartTest(_T("ANSI to UCS-2 conversion"));
24 UCS2CHAR ucs2buffer[1024];
25 mb_to_ucs2(mbTextShort, -1, ucs2buffer, 1024);
26 AssertTrue(!memcmp(ucs2buffer, ucs2TextShort, sizeof(UCS2CHAR) * 12));
27 EndTest();
28
29 StartTest(_T("UCS-2 to ANSI conversion"));
30 char mbBuffer[1024];
31 ucs2_to_mb(ucs2TextShort, -1, mbBuffer, 1024);
32 AssertTrue(!strcmp(mbBuffer, mbTextShort));
33 EndTest();
34
35 StartTest(_T("ANSI to UCS-2 conversion performance"));
36 INT64 start = GetCurrentTimeMs();
37 for(int i = 0; i < 10000; i++)
38 {
39 UCS2CHAR buffer[1024];
40 mb_to_ucs2(mbText, -1, buffer, 1024);
41 }
42 EndTest(GetCurrentTimeMs() - start);
43
44 StartTest(_T("UCS-2 to ANSI conversion performance"));
45 mb_to_ucs2(mbText, -1, ucs2buffer, 1024);
46 start = GetCurrentTimeMs();
47 for(int i = 0; i < 10000; i++)
48 {
49 char buffer[1024];
50 ucs2_to_mb(ucs2buffer, -1, buffer, 1024);
51 }
52 EndTest(GetCurrentTimeMs() - start);
53
54 #ifdef UNICODE_UCS4
55 StartTest(_T("ANSI to UCS-4 conversion performance"));
56 start = GetCurrentTimeMs();
57 for(int i = 0; i < 10000; i++)
58 {
59 WCHAR buffer[1024];
60 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, mbText, -1, buffer, 1024);
61 }
62 EndTest(GetCurrentTimeMs() - start);
63
64 StartTest(_T("UCS-4 to ANSI conversion performance"));
65 start = GetCurrentTimeMs();
66 for(int i = 0; i < 10000; i++)
67 {
68 char buffer[1024];
69 WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, wcText, -1, buffer, 1024, NULL, NULL);
70 }
71 EndTest(GetCurrentTimeMs() - start);
72
73 StartTest(_T("UCS-2 to UCS-4 conversion performance"));
74 mb_to_ucs2(mbText, -1, ucs2buffer, 1024);
75 start = GetCurrentTimeMs();
76 for(int i = 0; i < 10000; i++)
77 {
78 WCHAR buffer[1024];
79 ucs2_to_ucs4(ucs2buffer, -1, buffer, 1024);
80 }
81 EndTest(GetCurrentTimeMs() - start);
82
83 StartTest(_T("UCS-4 to UCS-2 conversion performance"));
84 start = GetCurrentTimeMs();
85 for(int i = 0; i < 10000; i++)
86 {
87 UCS2CHAR buffer[1024];
88 ucs4_to_ucs2(wcText, -1, buffer, 1024);
89 }
90 EndTest(GetCurrentTimeMs() - start);
91 #endif
92 }
93
94 /**
95 * Test string map
96 */
97 static void TestStringMap()
98 {
99 StringMap *m = new StringMap();
100
101 StartTest(_T("String map - insert"));
102 INT64 start = GetCurrentTimeMs();
103 for(int i = 0; i < 10000; i++)
104 {
105 TCHAR key[64];
106 _sntprintf(key, 64, _T("key-%d"), i);
107 m->set(key, _T("Lorem ipsum dolor sit amet"));
108 }
109 AssertEquals(m->size(), 10000);
110 const TCHAR *v = m->get(_T("key-42"));
111 AssertNotNull(v);
112 AssertTrue(!_tcscmp(v, _T("Lorem ipsum dolor sit amet")));
113 EndTest(GetCurrentTimeMs() - start);
114
115 StartTest(_T("String map - replace"));
116 start = GetCurrentTimeMs();
117 for(int i = 0; i < 10000; i++)
118 {
119 TCHAR key[64];
120 _sntprintf(key, 64, _T("key-%d"), i);
121 m->set(key, _T("consectetur adipiscing elit"));
122 }
123 AssertEquals(m->size(), 10000);
124 v = m->get(_T("key-42"));
125 AssertNotNull(v);
126 AssertTrue(!_tcscmp(v, _T("consectetur adipiscing elit")));
127 EndTest(GetCurrentTimeMs() - start);
128
129 StartTest(_T("String map - get"));
130 start = GetCurrentTimeMs();
131 v = m->get(_T("key-888"));
132 AssertNotNull(v);
133 AssertTrue(!_tcscmp(v, _T("consectetur adipiscing elit")));
134 EndTest(GetCurrentTimeMs() - start);
135
136 StartTest(_T("String map - clear"));
137 start = GetCurrentTimeMs();
138 m->clear();
139 AssertEquals(m->size(), 0);
140 EndTest(GetCurrentTimeMs() - start);
141
142 delete m;
143 }
144
145 /**
146 * Test string set
147 */
148 static void TestStringSet()
149 {
150 StringSet *s = new StringSet();
151
152 StartTest(_T("String set - insert"));
153 INT64 start = GetCurrentTimeMs();
154 for(int i = 0; i < 10000; i++)
155 {
156 TCHAR key[64];
157 _sntprintf(key, 64, _T("key-%d lorem ipsum"), i);
158 s->add(key);
159 }
160 AssertEquals(s->size(), 10000);
161 AssertTrue(s->contains(_T("key-42 lorem ipsum")));
162 EndTest(GetCurrentTimeMs() - start);
163
164 StartTest(_T("String set - replace"));
165 start = GetCurrentTimeMs();
166 for(int i = 0; i < 10000; i++)
167 {
168 TCHAR key[64];
169 _sntprintf(key, 64, _T("key-%d lorem ipsum"), i);
170 s->add(key);
171 }
172 AssertEquals(s->size(), 10000);
173 AssertTrue(s->contains(_T("key-42 lorem ipsum")));
174 EndTest(GetCurrentTimeMs() - start);
175
176 StartTest(_T("String set - contains"));
177 start = GetCurrentTimeMs();
178 AssertTrue(s->contains(_T("key-888 lorem ipsum")));
179 EndTest(GetCurrentTimeMs() - start);
180
181 StartTest(_T("String set - iterator"));
182 Iterator<const TCHAR> *it = s->iterator();
183 AssertTrue(it->hasNext());
184 bool found = false;
185 while(it->hasNext())
186 {
187 const TCHAR *v = it->next();
188 AssertNotNull(v);
189 if (!_tcscmp(v, _T("key-42 lorem ipsum")))
190 {
191 found = true;
192 break;
193 }
194 }
195 AssertTrue(found);
196 it->remove();
197 AssertEquals(s->size(), 9999);
198 AssertFalse(s->contains(_T("key-42 lorem ipsum")));
199 delete it;
200 EndTest();
201
202 StartTest(_T("String set - clear"));
203 start = GetCurrentTimeMs();
204 s->clear();
205 AssertEquals(s->size(), 0);
206 EndTest(GetCurrentTimeMs() - start);
207
208 delete s;
209 }
210
211 /**
212 * Test string class
213 */
214 static void TestString()
215 {
216 String s;
217
218 StartTest(_T("String - append"));
219 for(int i = 0; i < 256; i++)
220 s.append(_T("ABC "));
221 AssertEquals(s.length(), 1024);
222 AssertTrue(!_tcsncmp(s.getBuffer(), _T("ABC ABC ABC ABC "), 16));
223 EndTest();
224
225 StartTest(_T("String - assign #1"));
226 s = _T("alpha");
227 AssertEquals(s.length(), 5);
228 AssertTrue(!_tcscmp(s.getBuffer(), _T("alpha")));
229 EndTest();
230
231 StartTest(_T("String - assign #2"));
232 String t(_T("init string"));
233 s = t;
234 AssertEquals(s.length(), 11);
235 AssertTrue(!_tcscmp(s.getBuffer(), _T("init string")));
236 EndTest();
237
238 StartTest(_T("String - shrink"));
239 s.shrink();
240 AssertEquals(s.length(), 10);
241 AssertTrue(!_tcscmp(s.getBuffer(), _T("init strin")));
242 EndTest();
243
244 StartTest(_T("String - escape"));
245 s.escapeCharacter('i', '+');
246 AssertEquals(s.length(), 13);
247 AssertTrue(!_tcscmp(s.getBuffer(), _T("+in+it str+in")));
248 EndTest();
249
250 StartTest(_T("String - replace #1"));
251 s = _T("alpha beta gamma");
252 s.replace(_T("beta"), _T("epsilon"));
253 AssertEquals(s.length(), 19);
254 AssertTrue(!_tcscmp(s.getBuffer(), _T("alpha epsilon gamma")));
255 EndTest();
256
257 StartTest(_T("String - replace #2"));
258 s = _T("alpha beta gamma");
259 s.replace(_T("beta"), _T("xxxx"));
260 AssertEquals(s.length(), 16);
261 AssertTrue(!_tcscmp(s.getBuffer(), _T("alpha xxxx gamma")));
262 EndTest();
263
264 StartTest(_T("String - replace #3"));
265 s = _T("alpha beta gamma alpha omega");
266 s.replace(_T("alpha"), _T("Z"));
267 AssertEquals(s.length(), 20);
268 AssertTrue(!_tcscmp(s.getBuffer(), _T("Z beta gamma Z omega")));
269 EndTest();
270
271 StartTest(_T("String - substring #1"));
272 s = _T("alpha beta gamma");
273 TCHAR *str = s.substring(0, 5);
274 AssertTrue(!_tcscmp(str, _T("alpha")));
275 free(str);
276 EndTest();
277
278 StartTest(_T("String - substring #2"));
279 s = _T("alpha beta gamma");
280 str = s.substring(5, -1);
281 AssertTrue(!_tcscmp(str, _T(" beta gamma")));
282 free(str);
283 EndTest();
284
285 StartTest(_T("String - substring #3"));
286 s = _T("alpha beta gamma");
287 str = s.substring(14, 4);
288 AssertTrue(!_tcscmp(str, _T("ma")));
289 free(str);
290 EndTest();
291 }
292
293 /**
294 * Test InetAddress class
295 */
296 static void TestInetAddress()
297 {
298 InetAddress a, b, c;
299
300 StartTest(_T("InetAddress - isSubnetBroadcast() - IPv4"));
301 a = InetAddress::parse("192.168.0.255");
302 AssertTrue(a.isSubnetBroadcast(24));
303 AssertFalse(a.isSubnetBroadcast(23));
304 EndTest();
305
306 StartTest(_T("InetAddress - isSubnetBroadcast() - IPv6"));
307 a = InetAddress::parse("fe80::ffff:ffff:ffff:ffff");
308 AssertFalse(a.isSubnetBroadcast(64));
309 AssertFalse(a.isSubnetBroadcast(63));
310 EndTest();
311
312 StartTest(_T("InetAddress - isLinkLocal() - IPv4"));
313 a = InetAddress::parse("169.254.17.198");
314 AssertTrue(a.isLinkLocal());
315 a = InetAddress::parse("192.168.1.1");
316 AssertFalse(a.isLinkLocal());
317 EndTest();
318
319 StartTest(_T("InetAddress - isLinkLocal() - IPv6"));
320 a = InetAddress::parse("fe80::1");
321 AssertTrue(a.isLinkLocal());
322 a = InetAddress::parse("2000:1234::1");
323 AssertFalse(a.isLinkLocal());
324 EndTest();
325
326 StartTest(_T("InetAddress - sameSubnet() - IPv4"));
327 a = InetAddress::parse("192.168.1.43");
328 a.setMaskBits(23);
329 b = InetAddress::parse("192.168.0.180");
330 b.setMaskBits(23);
331 c = InetAddress::parse("192.168.2.22");
332 c.setMaskBits(23);
333 AssertTrue(a.sameSubnet(b));
334 AssertFalse(a.sameSubnet(c));
335 EndTest();
336
337 StartTest(_T("InetAddress - sameSubnet() - IPv6"));
338 a = InetAddress::parse("2000:1234:1000:1000::1");
339 a.setMaskBits(62);
340 b = InetAddress::parse("2000:1234:1000:1001::cdef:1");
341 b.setMaskBits(62);
342 c = InetAddress::parse("2000:1234:1000:1007::1");
343 c.setMaskBits(62);
344 AssertTrue(a.sameSubnet(b));
345 AssertFalse(a.sameSubnet(c));
346 EndTest();
347
348 StartTest(_T("InetAddress - buildHashKey() - IPv4"));
349 a = InetAddress::parse("10.3.1.91");
350 BYTE key[18];
351 a.buildHashKey(key);
352 #if WORDS_BIGENDIAN
353 AssertTrue(memcmp(key, "\x06\x02\x0A\x03\x01\x5B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 18) == 0);
354 #else
355 AssertTrue(memcmp(key, "\x06\x02\x5B\x01\x03\x0A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 18) == 0);
356 #endif
357 EndTest();
358
359 StartTest(_T("InetAddress - buildHashKey() - IPv6"));
360 a = InetAddress::parse("fe80:1234::6e88:14ff:fec4:b8f8");
361 a.buildHashKey(key);
362 AssertTrue(memcmp(key, "\x12\x0A\xFE\x80\x12\x34\x00\x00\x00\x00\x6E\x88\x14\xFF\xFE\xC4\xB8\xF8", 18) == 0);
363 EndTest();
364 }
365
366 /**
367 * Test itoa/itow
368 */
369 static void TestItoa()
370 {
371 char buffer[64];
372 WCHAR wbuffer[64];
373
374 StartTest(_T("itoa"));
375 AssertTrue(!strcmp(_itoa(127, buffer, 10), "127"));
376 AssertTrue(!strcmp(_itoa(0, buffer, 10), "0"));
377 AssertTrue(!strcmp(_itoa(-3, buffer, 10), "-3"));
378 AssertTrue(!strcmp(_itoa(0555, buffer, 8), "555"));
379 AssertTrue(!strcmp(_itoa(0xFA48, buffer, 16), "fa48"));
380 EndTest();
381
382 StartTest(_T("itow"));
383 AssertTrue(!wcscmp(_itow(127, wbuffer, 10), L"127"));
384 AssertTrue(!wcscmp(_itow(0, wbuffer, 10), L"0"));
385 AssertTrue(!wcscmp(_itow(-3, wbuffer, 10), L"-3"));
386 AssertTrue(!wcscmp(_itow(0555, wbuffer, 8), L"555"));
387 AssertTrue(!wcscmp(_itow(0xFA48, wbuffer, 16), L"fa48"));
388 EndTest();
389 }
390
391 /**
392 * Test queue
393 */
394 static void TestQueue()
395 {
396 Queue *q = new Queue(16, 16);
397
398 StartTest(_T("Queue: put/get"));
399 for(int i = 0; i < 40; i++)
400 q->put(CAST_TO_POINTER(i + 1, void *));
401 AssertEquals(q->size(), 40);
402 AssertEquals(q->allocated(), 48);
403 for(int i = 0; i < 40; i++)
404 {
405 void *p = q->get();
406 AssertNotNull(p);
407 AssertEquals(CAST_FROM_POINTER(p, int), i + 1);
408 }
409 EndTest();
410
411 StartTest(_T("Queue: shrink"));
412 for(int i = 0; i < 60; i++)
413 q->put(CAST_TO_POINTER(i + 1, void *));
414 AssertEquals(q->size(), 60);
415 AssertEquals(q->allocated(), 64);
416 for(int i = 0; i < 55; i++)
417 {
418 void *p = q->get();
419 AssertNotNull(p);
420 AssertEquals(CAST_FROM_POINTER(p, int), i + 1);
421 }
422 AssertEquals(q->size(), 5);
423 AssertEquals(q->allocated(), 16);
424 EndTest();
425
426 delete q;
427 }
428
429 /**
430 * Key for hash map
431 */
432 typedef char HASH_KEY[6];
433
434 /**
435 * Test hash map
436 */
437 static void TestHashMap()
438 {
439 StartTest(_T("HashMap: create"));
440 HashMap<HASH_KEY, String> *hashMap = new HashMap<HASH_KEY, String>(true);
441 AssertEquals(hashMap->size(), 0);
442 EndTest();
443
444 HASH_KEY k1 = { '1', '2', '3', '4', '5', '6' };
445 HASH_KEY k2 = { '0', '0', 'a', 'b', 'c', 'd' };
446 HASH_KEY k3 = { '0', '0', '3', 'X', '1', '1' };
447
448 StartTest(_T("HashMap: set/get"));
449
450 hashMap->set(k1, new String(_T("String 1")));
451 hashMap->set(k2, new String(_T("String 2")));
452 hashMap->set(k3, new String(_T("String 3")));
453
454 String *s = hashMap->get(k1);
455 AssertNotNull(s);
456 AssertTrue(!_tcscmp(s->getBuffer(), _T("String 1")));
457
458 s = hashMap->get(k2);
459 AssertNotNull(s);
460 AssertTrue(!_tcscmp(s->getBuffer(), _T("String 2")));
461
462 s = hashMap->get(k3);
463 AssertNotNull(s);
464 AssertTrue(!_tcscmp(s->getBuffer(), _T("String 3")));
465
466 EndTest();
467
468 StartTest(_T("HashMap: replace"));
469 hashMap->set(k2, new String(_T("REPLACE")));
470 s = hashMap->get(k2);
471 AssertNotNull(s);
472 AssertTrue(!_tcscmp(s->getBuffer(), _T("REPLACE")));
473 EndTest();
474
475 StartTest(_T("HashMap: iterator"));
476 Iterator<String> *it = hashMap->iterator();
477 AssertTrue(it->hasNext());
478 s = it->next();
479 AssertNotNull(s);
480 AssertNotNull(it->next());
481 AssertNotNull(it->next());
482 AssertFalse(it->hasNext());
483 AssertNull(it->next());
484 AssertFalse(it->hasNext());
485 delete it;
486 EndTest();
487
488 StartTest(_T("HashMap: iterator remove"));
489 it = hashMap->iterator();
490 AssertTrue(it->hasNext());
491 AssertNotNull(it->next());
492 s = it->next();
493 AssertNotNull(s);
494 it->remove();
495 AssertTrue(it->hasNext());
496 AssertNotNull(it->next());
497 AssertFalse(it->hasNext());
498 AssertNull(it->next());
499 delete it;
500 AssertNotNull(hashMap->get(k1));
501 AssertNull(hashMap->get(k2));
502 AssertNotNull(hashMap->get(k3));
503 EndTest();
504
505 StartTest(_T("HashMap: remove"));
506 hashMap->remove(k3);
507 AssertNull(hashMap->get(k3));
508 EndTest();
509
510 StartTest(_T("HashMap: clear"));
511 hashMap->clear();
512 AssertEquals(hashMap->size(), 0);
513 it = hashMap->iterator();
514 AssertFalse(it->hasNext());
515 AssertNull(it->next());
516 delete it;
517 EndTest();
518
519 delete hashMap;
520 }
521
522 /**
523 * Test array
524 */
525 static void TestObjectArray()
526 {
527 StartTest(_T("ObjectArray: create"));
528 ObjectArray<String> *array = new ObjectArray<String>(16, 16, true);
529 AssertEquals(array->size(), 0);
530 EndTest();
531
532 StartTest(_T("ObjectArray: add/get"));
533 array->add(new String(_T("value 1")));
534 array->add(new String(_T("value 2")));
535 array->add(new String(_T("value 3")));
536 array->add(new String(_T("value 4")));
537 AssertEquals(array->size(), 4);
538 AssertNull(array->get(4));
539 AssertNotNull(array->get(1));
540 AssertTrue(!_tcscmp(array->get(1)->getBuffer(), _T("value 2")));
541 EndTest();
542
543 StartTest(_T("ObjectArray: replace"));
544 array->replace(0, new String(_T("replace")));
545 AssertEquals(array->size(), 4);
546 AssertTrue(!_tcscmp(array->get(0)->getBuffer(), _T("replace")));
547 EndTest();
548
549 StartTest(_T("ObjectArray: remove"));
550 array->remove(0);
551 AssertEquals(array->size(), 3);
552 AssertTrue(!_tcscmp(array->get(0)->getBuffer(), _T("value 2")));
553 EndTest();
554
555 StartTest(_T("ObjectArray: iterator"));
556 Iterator<String> *it = array->iterator();
557 AssertTrue(it->hasNext());
558 String *s = it->next();
559 AssertTrue(!_tcscmp(s->getBuffer(), _T("value 2")));
560 s = it->next();
561 AssertTrue(!_tcscmp(s->getBuffer(), _T("value 3")));
562 s = it->next();
563 AssertTrue(!_tcscmp(s->getBuffer(), _T("value 4")));
564 s = it->next();
565 AssertNull(s);
566 delete it;
567 EndTest();
568
569 delete array;
570 }
571
572 /**
573 * Table tests
574 */
575 static void TestTable()
576 {
577 StartTest(_T("Table: create"));
578 Table *table = new Table();
579 AssertEquals(table->getNumRows(), 0);
580 EndTest();
581
582 StartTest(_T("Table: set on empty table"));
583 table->set(0, 1.0);
584 table->set(1, _T("test"));
585 table->setPreallocated(1, _tcsdup(_T("test")));
586 AssertEquals(table->getNumRows(), 0);
587 EndTest();
588
589 StartTest(_T("Table: add row"));
590 table->addRow();
591 AssertEquals(table->getNumRows(), 1);
592 AssertEquals(table->getNumColumns(), 0);
593 EndTest();
594
595 StartTest(_T("Table: set on empty row"));
596 table->set(0, _T("test"));
597 table->setPreallocated(1, _tcsdup(_T("test")));
598 AssertEquals(table->getNumRows(), 1);
599 AssertEquals(table->getNumColumns(), 0);
600 EndTest();
601
602 table->addColumn(_T("NAME"));
603 table->addColumn(_T("VALUE"));
604 table->addColumn(_T("DATA1"));
605 table->addColumn(_T("DATA2"));
606 table->addColumn(_T("DATA3"));
607 table->addColumn(_T("DATA4"));
608 for(int i = 0; i < 50; i++)
609 {
610 table->addRow();
611 TCHAR b[64];
612 _sntprintf(b, 64, _T("Process #%d"), i);
613 table->set(0, b);
614 table->set(1, i);
615 table->set(2, i * 100);
616 table->set(3, i * 100001);
617 table->set(4, _T("/some/long/path/on/file/system"));
618 table->set(5, _T("constant"));
619 }
620
621 StartTest(_T("Table: pack"));
622 INT64 start = GetCurrentTimeMs();
623 char *packedTable = table->createPackedXML();
624 AssertNotNull(packedTable);
625 EndTest(GetCurrentTimeMs() - start);
626
627 StartTest(_T("Table: unpack"));
628 start = GetCurrentTimeMs();
629 Table *table2 = Table::createFromPackedXML(packedTable);
630 free(packedTable);
631 AssertNotNull(table2);
632 AssertEquals(table2->getNumColumns(), table->getNumColumns());
633 AssertEquals(table2->getNumRows(), table->getNumRows());
634 AssertEquals(table2->getAsInt(10, 1), table->getAsInt(10, 1));
635 EndTest(GetCurrentTimeMs() - start);
636
637 delete table;
638 delete table2;
639 }
640
641 /**
642 * Test byte swap
643 */
644 static void TestByteSwap()
645 {
646 StartTest(_T("bswap_16"));
647 AssertEquals(bswap_16(0xABCD), 0xCDAB);
648 EndTest();
649
650 StartTest(_T("bswap_32"));
651 AssertEquals(bswap_32(0x0102ABCD), 0xCDAB0201);
652 EndTest();
653
654 StartTest(_T("bswap_64"));
655 AssertEquals(bswap_64(_ULL(0x01020304A1A2A3A4)), _ULL(0xA4A3A2A104030201));
656 EndTest();
657
658 StartTest(_T("bswap_array_16"));
659 UINT16 s16[] = { 0xABCD, 0x1020, 0x2233, 0x0102 };
660 UINT16 d16[] = { 0xCDAB, 0x2010, 0x3322, 0x0201 };
661 bswap_array_16(s16, 4);
662 AssertTrue(!memcmp(s16, d16, 8));
663 EndTest();
664
665 StartTest(_T("bswap_array_16 (string)"));
666 UINT16 ss16[] = { 0xABCD, 0x1020, 0x2233, 0x0102, 0 };
667 UINT16 sd16[] = { 0xCDAB, 0x2010, 0x3322, 0x0201, 0 };
668 bswap_array_16(ss16, -1);
669 AssertTrue(!memcmp(ss16, sd16, 10));
670 EndTest();
671
672 StartTest(_T("bswap_array_32"));
673 UINT32 s32[] = { 0xABCDEF01, 0x10203040, 0x22334455, 0x01020304 };
674 UINT32 d32[] = { 0x01EFCDAB, 0x40302010, 0x55443322, 0x04030201 };
675 bswap_array_32(s32, 4);
676 AssertTrue(!memcmp(s32, d32, 16));
677 EndTest();
678
679 StartTest(_T("bswap_array_32 (string)"));
680 UINT32 ss32[] = { 0xABCDEF01, 0x10203040, 0x22334455, 0x01020304, 0 };
681 UINT32 sd32[] = { 0x01EFCDAB, 0x40302010, 0x55443322, 0x04030201, 0 };
682 bswap_array_32(ss32, -1);
683 AssertTrue(!memcmp(ss32, sd32, 20));
684 EndTest();
685 }
686
687 /**
688 * main()
689 */
690 int main(int argc, char *argv[])
691 {
692 #ifdef _WIN32
693 WSADATA wsaData;
694 WSAStartup(MAKEWORD(2, 2), &wsaData);
695 #endif
696
697 TestString();
698 TestStringConversion();
699 TestStringMap();
700 TestStringSet();
701 TestMessageClass();
702 TestMsgWaitQueue();
703 TestInetAddress();
704 TestItoa();
705 TestQueue();
706 TestHashMap();
707 TestObjectArray();
708 TestTable();
709 TestMutexWrapper();
710 TestRWLockWrapper();
711 TestConditionWrapper();
712 TestByteSwap();
713
714 MsgWaitQueue::shutdown();
715 return 0;
716 }