Implemented Debug Tag functionality
[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, NULL);
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, NULL);
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, NULL);
288 AssertTrue(!_tcscmp(str, _T("ma")));
289 free(str);
290 EndTest();
291
292 StartTest(_T("String - left #1"));
293 s = _T("alpha beta gamma");
294 String ls = s.left(5);
295 AssertTrue(ls.equals(_T("alpha")));
296 EndTest();
297
298 StartTest(_T("String - left #2"));
299 s = _T("alpha");
300 ls = s.left(15);
301 AssertTrue(ls.equals(_T("alpha")));
302 EndTest();
303
304 StartTest(_T("String - right #1"));
305 s = _T("alpha beta gamma");
306 String rs = s.right(5);
307 AssertTrue(rs.equals(_T("gamma")));
308 EndTest();
309
310 StartTest(_T("String - right #2"));
311 s = _T("alpha");
312 rs = s.right(15);
313 AssertTrue(rs.equals(_T("alpha")));
314 EndTest();
315
316 StartTest(_T("String - split"));
317 s = _T("alpha;;beta;gamma;;delta");
318 StringList *list = s.split(_T(";;"));
319 AssertNotNull(list);
320 AssertEquals(list->size(), 3);
321 AssertTrue(!_tcscmp(list->get(0), _T("alpha")));
322 AssertTrue(!_tcscmp(list->get(1), _T("beta;gamma")));
323 AssertTrue(!_tcscmp(list->get(2), _T("delta")));
324 delete list;
325 EndTest();
326 }
327
328 /**
329 * Test MacAddress class
330 */
331 static void TestMacAddress()
332 {
333 MacAddress a, b, c, d, e, f;
334
335 StartTest(_T("MacAddress - parse()"));
336 a = MacAddress::parse("0180C2300100");
337 AssertTrue(_tcscmp(_T("0180C2300100"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
338 AssertTrue(_tcscmp(_T("01:80:C2:30:01:00"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
339 AssertTrue(_tcscmp(_T("01-80-C2-30-01-00"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
340 AssertTrue(_tcscmp(_T("018.0C2.300.100"), (const TCHAR*)a.toString(MAC_ADDR_DOT_SEPARATED)) == 0);
341 AssertTrue(_tcscmp(_T("0180.C230.0100"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
342 AssertTrue(_tcscmp(_T("0180:C230:0100"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
343
344 a = MacAddress::parse("01:80:C2:00:00:00");
345 AssertTrue(_tcscmp(_T("0180C2000000"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
346 AssertTrue(_tcscmp(_T("01:80:C2:00:00:00"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
347 AssertTrue(_tcscmp(_T("01-80-C2-00-00-00"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
348 AssertTrue(_tcscmp(_T("018.0C2.000.000"), (const TCHAR*)a.toString(MAC_ADDR_DOT_SEPARATED)) == 0);
349 AssertTrue(_tcscmp(_T("0180.C200.0000"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
350 AssertTrue(_tcscmp(_T("0180:C200:0000"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
351
352 a = MacAddress::parse("09-80-C2-FF-FF-FF");
353 AssertTrue(_tcscmp(_T("0980C2FFFFFF"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
354 AssertTrue(_tcscmp(_T("09:80:C2:FF:FF:FF"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
355 AssertTrue(_tcscmp(_T("09-80-C2-FF-FF-FF"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
356 AssertTrue(_tcscmp(_T("098.0C2.FFF.FFF"), (const TCHAR*)a.toString(MAC_ADDR_DOT_SEPARATED)) == 0);
357 AssertTrue(_tcscmp(_T("0980.C2FF.FFFF"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
358 AssertTrue(_tcscmp(_T("0980:C2FF:FFFF"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
359
360 a = MacAddress::parse("482.C6A.1E5.93D");
361 AssertTrue(_tcscmp(_T("482C6A1E593D"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
362 AssertTrue(_tcscmp(_T("48:2C:6A:1E:59:3D"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
363 AssertTrue(_tcscmp(_T("48-2C-6A-1E-59-3D"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
364 AssertTrue(_tcscmp(_T("482.C6A.1E5.93D"), (const TCHAR*)a.toString(MAC_ADDR_DOT_SEPARATED)) == 0);
365 AssertTrue(_tcscmp(_T("482C.6A1E.593D"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
366 AssertTrue(_tcscmp(_T("482C:6A1E:593D"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
367
368 a = MacAddress::parse("48AC.6B1A.F6FD");
369 AssertTrue(_tcscmp(_T("48AC6B1AF6FD"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
370 AssertTrue(_tcscmp(_T("48:AC:6B:1A:F6:FD"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
371 AssertTrue(_tcscmp(_T("48-AC-6B-1A-F6-FD"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
372 AssertTrue(_tcscmp(_T("48A.C6B.1AF.6FD"), (const TCHAR*)a.toString(MAC_ADDR_DOT_SEPARATED)) == 0);
373 AssertTrue(_tcscmp(_T("48AC.6B1A.F6FD"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
374 AssertTrue(_tcscmp(_T("48AC:6B1A:F6FD"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
375
376 a = MacAddress::parse("482C:6A1E:593D");
377 AssertTrue(_tcscmp(_T("482C6A1E593D"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
378 AssertTrue(_tcscmp(_T("48:2C:6A:1E:59:3D"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
379 AssertTrue(_tcscmp(_T("48-2C-6A-1E-59-3D"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
380 AssertTrue(_tcscmp(_T("482.C6A.1E5.93D"), (const TCHAR*)a.toString(MAC_ADDR_DOT_SEPARATED)) == 0);
381 AssertTrue(_tcscmp(_T("482C.6A1E.593D"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
382 AssertTrue(_tcscmp(_T("482C:6A1E:593D"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
383
384 a = MacAddress::parse("70B3D5B020035F11");
385 AssertTrue(_tcscmp(_T("70B3D5B020035F11"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
386 AssertTrue(_tcscmp(_T("70:B3:D5:B0:20:03:5F:11"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
387 AssertTrue(_tcscmp(_T("70-B3-D5-B0-20-03-5F-11"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
388 AssertTrue(_tcscmp(_T("70B3.D5B0.2003.5F11"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
389 AssertTrue(_tcscmp(_T("70B3:D5B0:2003:5F11"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
390
391 a = MacAddress::parse("70:B3:D5:B0:20:03:5F:16");
392 AssertTrue(_tcscmp(_T("70B3D5B020035F16"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
393 AssertTrue(_tcscmp(_T("70:B3:D5:B0:20:03:5F:16"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
394 AssertTrue(_tcscmp(_T("70-B3-D5-B0-20-03-5F-16"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
395 AssertTrue(_tcscmp(_T("70B3.D5B0.2003.5F16"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
396 AssertTrue(_tcscmp(_T("70B3:D5B0:2003:5F16"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
397
398 a = MacAddress::parse("70-B3-D5-B0-20-00-00-39");
399 AssertTrue(_tcscmp(_T("70B3D5B020000039"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
400 AssertTrue(_tcscmp(_T("70:B3:D5:B0:20:00:00:39"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
401 AssertTrue(_tcscmp(_T("70-B3-D5-B0-20-00-00-39"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
402 AssertTrue(_tcscmp(_T("70B3.D5B0.2000.0039"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
403 AssertTrue(_tcscmp(_T("70B3:D5B0:2000:0039"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
404
405 a = MacAddress::parse("70B3.D5B0.2003.5D5E");
406 AssertTrue(_tcscmp(_T("70B3D5B020035D5E"), (const TCHAR*)a.toString(MAC_ADDR_FLAT_STRING)) == 0);
407 AssertTrue(_tcscmp(_T("70:B3:D5:B0:20:03:5D:5E"), (const TCHAR*)a.toString(MAC_ADDR_COLON_SEPARATED)) == 0);
408 AssertTrue(_tcscmp(_T("70-B3-D5-B0-20-03-5D-5E"), (const TCHAR*)a.toString(MAC_ADDR_HYPHEN_SEPARATED)) == 0);
409 AssertTrue(_tcscmp(_T("70B3.D5B0.2003.5D5E"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_DOT_SEPARATED)) == 0);
410 AssertTrue(_tcscmp(_T("70B3:D5B0:2003:5D5E"), (const TCHAR*)a.toString(MAC_ADDR_BYTEPAIR_COLON_SEPARATED)) == 0);
411 EndTest();
412
413 StartTest(_T("MacAddress - isMulticast()"));
414 a = MacAddress::parse("01:80:C2:00:00:00");
415 AssertTrue(a.isMulticast());
416 b = MacAddress::parse("09-80-C2-FF-FF-FF");
417 AssertTrue(b.isMulticast());
418 c = MacAddress::parse("482.C6A.1E5.93D");
419 AssertFalse(c.isMulticast());
420 EndTest();
421
422 StartTest(_T("MacAddress - isBroadcast()"));
423 a = MacAddress::parse("FF:FF:FF:FF:FF:FF");
424 AssertTrue(a.isBroadcast());
425 b = MacAddress::parse("FF-2C-6A-1E-59-3D");
426 AssertFalse(b.isBroadcast());
427 c = MacAddress::parse("FFF.FC2.FFF.FFF");
428 AssertFalse(c.isBroadcast());
429 EndTest();
430
431 StartTest(_T("MacAddress - equals()"));
432 a = MacAddress::parse("09-80-C2-FF-FF-FF");
433 b = MacAddress::parse("48:2C:6A:1E:59:3D");
434 c = MacAddress::parse("098.0C2.FFF.FFF");
435 d = MacAddress::parse("70B3D5B020035F11");
436 e = MacAddress::parse("70B3:D5B0:2003:5F11");
437 f = MacAddress::parse("70B3.D5B0.2003.5D5E");
438 AssertFalse(a.equals(b));
439 AssertFalse(b.equals(c));
440 AssertFalse(e.equals(f));
441 AssertFalse(d.equals(b));
442 AssertTrue(c.equals(a));
443 AssertTrue(d.equals(e));
444 EndTest();
445 }
446
447 /**
448 * Test InetAddress class
449 */
450 static void TestInetAddress()
451 {
452 InetAddress a, b, c;
453
454 StartTest(_T("InetAddress - isLoopback() - IPv4"));
455 a = InetAddress::parse("127.0.0.1");
456 AssertTrue(a.isLoopback());
457 a = InetAddress::parse("192.168.1.1");
458 AssertFalse(a.isLoopback());
459 EndTest();
460
461 StartTest(_T("InetAddress - isLoopback() - IPv6"));
462 a = InetAddress::parse("::1");
463 AssertTrue(a.isLoopback());
464 a = InetAddress::parse("2000:1234::1");
465 AssertFalse(a.isLoopback());
466 EndTest();
467
468 StartTest(_T("InetAddress - isSubnetBroadcast() - IPv4"));
469 a = InetAddress::parse("192.168.0.255");
470 AssertTrue(a.isSubnetBroadcast(24));
471 AssertFalse(a.isSubnetBroadcast(23));
472 EndTest();
473
474 StartTest(_T("InetAddress - isSubnetBroadcast() - IPv6"));
475 a = InetAddress::parse("fe80::ffff:ffff:ffff:ffff");
476 AssertFalse(a.isSubnetBroadcast(64));
477 AssertFalse(a.isSubnetBroadcast(63));
478 EndTest();
479
480 StartTest(_T("InetAddress - isLinkLocal() - IPv4"));
481 a = InetAddress::parse("169.254.17.198");
482 AssertTrue(a.isLinkLocal());
483 a = InetAddress::parse("192.168.1.1");
484 AssertFalse(a.isLinkLocal());
485 EndTest();
486
487 StartTest(_T("InetAddress - isLinkLocal() - IPv6"));
488 a = InetAddress::parse("fe80::1");
489 AssertTrue(a.isLinkLocal());
490 a = InetAddress::parse("2000:1234::1");
491 AssertFalse(a.isLinkLocal());
492 EndTest();
493
494 StartTest(_T("InetAddress - sameSubnet() - IPv4"));
495 a = InetAddress::parse("192.168.1.43");
496 a.setMaskBits(23);
497 b = InetAddress::parse("192.168.0.180");
498 b.setMaskBits(23);
499 c = InetAddress::parse("192.168.2.22");
500 c.setMaskBits(23);
501 AssertTrue(a.sameSubnet(b));
502 AssertFalse(a.sameSubnet(c));
503 EndTest();
504
505 StartTest(_T("InetAddress - sameSubnet() - IPv6"));
506 a = InetAddress::parse("2000:1234:1000:1000::1");
507 a.setMaskBits(62);
508 b = InetAddress::parse("2000:1234:1000:1001::cdef:1");
509 b.setMaskBits(62);
510 c = InetAddress::parse("2000:1234:1000:1007::1");
511 c.setMaskBits(62);
512 AssertTrue(a.sameSubnet(b));
513 AssertFalse(a.sameSubnet(c));
514 EndTest();
515
516 StartTest(_T("InetAddress - buildHashKey() - IPv4"));
517 a = InetAddress::parse("10.3.1.91");
518 BYTE key[18];
519 a.buildHashKey(key);
520 #if WORDS_BIGENDIAN
521 static BYTE keyIPv4[] = { 0x06, AF_INET, 0x0A, 0x03, 0x01, 0x5B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
522 AssertTrue(memcmp(key, keyIPv4, 18) == 0);
523 #else
524 static BYTE keyIPv4[] = { 0x06, AF_INET, 0x5B, 0x01, 0x03, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
525 AssertTrue(memcmp(key, keyIPv4, 18) == 0);
526 #endif
527 EndTest();
528
529 StartTest(_T("InetAddress - buildHashKey() - IPv6"));
530 a = InetAddress::parse("fe80:1234::6e88:14ff:fec4:b8f8");
531 a.buildHashKey(key);
532 static BYTE keyIPv6[] = { 0x12, AF_INET6, 0xFE, 0x80, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x6E, 0x88, 0x14, 0xFF, 0xFE, 0xC4, 0xB8, 0xF8 };
533 AssertTrue(memcmp(key, keyIPv6, 18) == 0);
534 EndTest();
535 }
536
537 /**
538 * Test itoa/itow
539 */
540 static void TestItoa()
541 {
542 char buffer[64];
543 WCHAR wbuffer[64];
544
545 StartTest(_T("itoa"));
546 AssertTrue(!strcmp(_itoa(127, buffer, 10), "127"));
547 AssertTrue(!strcmp(_itoa(0, buffer, 10), "0"));
548 AssertTrue(!strcmp(_itoa(-3, buffer, 10), "-3"));
549 AssertTrue(!strcmp(_itoa(0555, buffer, 8), "555"));
550 AssertTrue(!strcmp(_itoa(0xFA48, buffer, 16), "fa48"));
551 EndTest();
552
553 StartTest(_T("itow"));
554 AssertTrue(!wcscmp(_itow(127, wbuffer, 10), L"127"));
555 AssertTrue(!wcscmp(_itow(0, wbuffer, 10), L"0"));
556 AssertTrue(!wcscmp(_itow(-3, wbuffer, 10), L"-3"));
557 AssertTrue(!wcscmp(_itow(0555, wbuffer, 8), L"555"));
558 AssertTrue(!wcscmp(_itow(0xFA48, wbuffer, 16), L"fa48"));
559 EndTest();
560 }
561
562 /**
563 * Test queue
564 */
565 static void TestQueue()
566 {
567 Queue *q = new Queue(16, 16);
568
569 StartTest(_T("Queue: put/get"));
570 for(int i = 0; i < 40; i++)
571 q->put(CAST_TO_POINTER(i + 1, void *));
572 AssertEquals(q->size(), 40);
573 AssertEquals(q->allocated(), 48);
574 for(int i = 0; i < 40; i++)
575 {
576 void *p = q->get();
577 AssertNotNull(p);
578 AssertEquals(CAST_FROM_POINTER(p, int), i + 1);
579 }
580 EndTest();
581
582 StartTest(_T("Queue: shrink"));
583 for(int i = 0; i < 60; i++)
584 q->put(CAST_TO_POINTER(i + 1, void *));
585 AssertEquals(q->size(), 60);
586 AssertEquals(q->allocated(), 64);
587 for(int i = 0; i < 55; i++)
588 {
589 void *p = q->get();
590 AssertNotNull(p);
591 AssertEquals(CAST_FROM_POINTER(p, int), i + 1);
592 }
593 AssertEquals(q->size(), 5);
594 AssertEquals(q->allocated(), 16);
595 EndTest();
596
597 delete q;
598 }
599
600 /**
601 * Key for hash map
602 */
603 typedef char HASH_KEY[6];
604
605 /**
606 * Test hash map
607 */
608 static void TestHashMap()
609 {
610 StartTest(_T("HashMap: create"));
611 HashMap<HASH_KEY, String> *hashMap = new HashMap<HASH_KEY, String>(true);
612 AssertEquals(hashMap->size(), 0);
613 EndTest();
614
615 HASH_KEY k1 = { '1', '2', '3', '4', '5', '6' };
616 HASH_KEY k2 = { '0', '0', 'a', 'b', 'c', 'd' };
617 HASH_KEY k3 = { '0', '0', '3', 'X', '1', '1' };
618
619 StartTest(_T("HashMap: set/get"));
620
621 hashMap->set(k1, new String(_T("String 1")));
622 hashMap->set(k2, new String(_T("String 2")));
623 hashMap->set(k3, new String(_T("String 3")));
624
625 String *s = hashMap->get(k1);
626 AssertNotNull(s);
627 AssertTrue(!_tcscmp(s->getBuffer(), _T("String 1")));
628
629 s = hashMap->get(k2);
630 AssertNotNull(s);
631 AssertTrue(!_tcscmp(s->getBuffer(), _T("String 2")));
632
633 s = hashMap->get(k3);
634 AssertNotNull(s);
635 AssertTrue(!_tcscmp(s->getBuffer(), _T("String 3")));
636
637 EndTest();
638
639 StartTest(_T("HashMap: replace"));
640 hashMap->set(k2, new String(_T("REPLACE")));
641 s = hashMap->get(k2);
642 AssertNotNull(s);
643 AssertTrue(!_tcscmp(s->getBuffer(), _T("REPLACE")));
644 EndTest();
645
646 StartTest(_T("HashMap: iterator"));
647 Iterator<String> *it = hashMap->iterator();
648 AssertTrue(it->hasNext());
649 s = it->next();
650 AssertNotNull(s);
651 AssertNotNull(it->next());
652 AssertNotNull(it->next());
653 AssertFalse(it->hasNext());
654 AssertNull(it->next());
655 AssertFalse(it->hasNext());
656 delete it;
657 EndTest();
658
659 StartTest(_T("HashMap: iterator remove"));
660 it = hashMap->iterator();
661 AssertTrue(it->hasNext());
662 AssertNotNull(it->next());
663 s = it->next();
664 AssertNotNull(s);
665 it->remove();
666 AssertTrue(it->hasNext());
667 AssertNotNull(it->next());
668 AssertFalse(it->hasNext());
669 AssertNull(it->next());
670 delete it;
671 AssertNotNull(hashMap->get(k1));
672 AssertNull(hashMap->get(k2));
673 AssertNotNull(hashMap->get(k3));
674 EndTest();
675
676 StartTest(_T("HashMap: remove"));
677 hashMap->remove(k3);
678 AssertNull(hashMap->get(k3));
679 EndTest();
680
681 StartTest(_T("HashMap: clear"));
682 hashMap->clear();
683 AssertEquals(hashMap->size(), 0);
684 it = hashMap->iterator();
685 AssertFalse(it->hasNext());
686 AssertNull(it->next());
687 delete it;
688 EndTest();
689
690 delete hashMap;
691 }
692
693 /**
694 * Test array
695 */
696 static void TestObjectArray()
697 {
698 StartTest(_T("ObjectArray: create"));
699 ObjectArray<String> *array = new ObjectArray<String>(16, 16, true);
700 AssertEquals(array->size(), 0);
701 EndTest();
702
703 StartTest(_T("ObjectArray: add/get"));
704 array->add(new String(_T("value 1")));
705 array->add(new String(_T("value 2")));
706 array->add(new String(_T("value 3")));
707 array->add(new String(_T("value 4")));
708 AssertEquals(array->size(), 4);
709 AssertNull(array->get(4));
710 AssertNotNull(array->get(1));
711 AssertTrue(!_tcscmp(array->get(1)->getBuffer(), _T("value 2")));
712 EndTest();
713
714 StartTest(_T("ObjectArray: replace"));
715 array->replace(0, new String(_T("replace")));
716 AssertEquals(array->size(), 4);
717 AssertTrue(!_tcscmp(array->get(0)->getBuffer(), _T("replace")));
718 EndTest();
719
720 StartTest(_T("ObjectArray: remove"));
721 array->remove(0);
722 AssertEquals(array->size(), 3);
723 AssertTrue(!_tcscmp(array->get(0)->getBuffer(), _T("value 2")));
724 EndTest();
725
726 StartTest(_T("ObjectArray: iterator"));
727 Iterator<String> *it = array->iterator();
728 AssertTrue(it->hasNext());
729 String *s = it->next();
730 AssertTrue(!_tcscmp(s->getBuffer(), _T("value 2")));
731 s = it->next();
732 AssertTrue(!_tcscmp(s->getBuffer(), _T("value 3")));
733 s = it->next();
734 AssertTrue(!_tcscmp(s->getBuffer(), _T("value 4")));
735 s = it->next();
736 AssertNull(s);
737 delete it;
738 EndTest();
739
740 delete array;
741 }
742
743 /**
744 * Table tests
745 */
746 static void TestTable()
747 {
748 StartTest(_T("Table: create"));
749 Table *table = new Table();
750 AssertEquals(table->getNumRows(), 0);
751 EndTest();
752
753 StartTest(_T("Table: set on empty table"));
754 table->set(0, 1.0);
755 table->set(1, _T("test"));
756 table->setPreallocated(1, _tcsdup(_T("test")));
757 AssertEquals(table->getNumRows(), 0);
758 EndTest();
759
760 StartTest(_T("Table: add row"));
761 table->addRow();
762 AssertEquals(table->getNumRows(), 1);
763 AssertEquals(table->getNumColumns(), 0);
764 EndTest();
765
766 StartTest(_T("Table: set on empty row"));
767 table->set(0, _T("test"));
768 table->setPreallocated(1, _tcsdup(_T("test")));
769 AssertEquals(table->getNumRows(), 1);
770 AssertEquals(table->getNumColumns(), 0);
771 EndTest();
772
773 table->addColumn(_T("NAME"));
774 table->addColumn(_T("VALUE"));
775 table->addColumn(_T("DATA1"));
776 table->addColumn(_T("DATA2"));
777 table->addColumn(_T("DATA3"));
778 table->addColumn(_T("DATA4"));
779 for(int i = 0; i < 50; i++)
780 {
781 table->addRow();
782 TCHAR b[64];
783 _sntprintf(b, 64, _T("Process #%d"), i);
784 table->set(0, b);
785 table->set(1, i);
786 table->set(2, i * 100);
787 table->set(3, i * 100001);
788 table->set(4, _T("/some/long/path/on/file/system"));
789 table->set(5, _T("constant"));
790 }
791
792 StartTest(_T("Table: pack"));
793 INT64 start = GetCurrentTimeMs();
794 char *packedTable = table->createPackedXML();
795 AssertNotNull(packedTable);
796 EndTest(GetCurrentTimeMs() - start);
797
798 StartTest(_T("Table: unpack"));
799 start = GetCurrentTimeMs();
800 Table *table2 = Table::createFromPackedXML(packedTable);
801 free(packedTable);
802 AssertNotNull(table2);
803 AssertEquals(table2->getNumColumns(), table->getNumColumns());
804 AssertEquals(table2->getNumRows(), table->getNumRows());
805 AssertEquals(table2->getAsInt(10, 1), table->getAsInt(10, 1));
806 EndTest(GetCurrentTimeMs() - start);
807
808 delete table;
809 delete table2;
810 }
811
812 /**
813 * Test byte swap
814 */
815 static void TestByteSwap()
816 {
817 StartTest(_T("bswap_16"));
818 AssertEquals(bswap_16(0xABCD), 0xCDAB);
819 EndTest();
820
821 StartTest(_T("bswap_32"));
822 AssertEquals(bswap_32(0x0102ABCD), 0xCDAB0201);
823 EndTest();
824
825 StartTest(_T("bswap_64"));
826 AssertEquals(bswap_64(_ULL(0x01020304A1A2A3A4)), _ULL(0xA4A3A2A104030201));
827 EndTest();
828
829 StartTest(_T("bswap_array_16"));
830 UINT16 s16[] = { 0xABCD, 0x1020, 0x2233, 0x0102 };
831 UINT16 d16[] = { 0xCDAB, 0x2010, 0x3322, 0x0201 };
832 bswap_array_16(s16, 4);
833 AssertTrue(!memcmp(s16, d16, 8));
834 EndTest();
835
836 StartTest(_T("bswap_array_16 (string)"));
837 UINT16 ss16[] = { 0xABCD, 0x1020, 0x2233, 0x0102, 0 };
838 UINT16 sd16[] = { 0xCDAB, 0x2010, 0x3322, 0x0201, 0 };
839 bswap_array_16(ss16, -1);
840 AssertTrue(!memcmp(ss16, sd16, 10));
841 EndTest();
842
843 StartTest(_T("bswap_array_32"));
844 UINT32 s32[] = { 0xABCDEF01, 0x10203040, 0x22334455, 0x01020304 };
845 UINT32 d32[] = { 0x01EFCDAB, 0x40302010, 0x55443322, 0x04030201 };
846 bswap_array_32(s32, 4);
847 AssertTrue(!memcmp(s32, d32, 16));
848 EndTest();
849
850 StartTest(_T("bswap_array_32 (string)"));
851 UINT32 ss32[] = { 0xABCDEF01, 0x10203040, 0x22334455, 0x01020304, 0 };
852 UINT32 sd32[] = { 0x01EFCDAB, 0x40302010, 0x55443322, 0x04030201, 0 };
853 bswap_array_32(ss32, -1);
854 AssertTrue(!memcmp(ss32, sd32, 20));
855 EndTest();
856 }
857
858 /**
859 * Test diff
860 */
861 static void TestDiff()
862 {
863 static const TCHAR *diffLeft = _T("line 1\nline 2\nline3\nFIXED TEXT\nalpha\n");
864 static const TCHAR *diffRight = _T("line 1\nline 3\nline 4\nFIXED TEXT\nbeta\n");
865 static const TCHAR *expectedDiff = _T("-line 2\n-line3\n+line 3\n+line 4\n-alpha\n+beta\n");
866
867 StartTest(_T("GenerateLineDiff (multiple lines)"));
868 String diff = GenerateLineDiff(diffLeft, diffRight);
869 AssertTrue(diff.equals(expectedDiff));
870 EndTest();
871
872 StartTest(_T("GenerateLineDiff (single line)"));
873 diff = GenerateLineDiff(_T("prefix-alpha"), _T("prefix-beta"));
874 AssertTrue(diff.equals(_T("-prefix-alpha\n+prefix-beta\n")));
875 EndTest();
876 }
877
878 /**
879 * Test ring buffer
880 */
881 static void TestRingBuffer()
882 {
883 RingBuffer rb(32, 32);
884 BYTE buffer[256];
885
886 StartTest(_T("RingBuffer: write #1"));
887 rb.write((const BYTE *)"short data", 10);
888 AssertEquals(rb.size(), 10);
889 EndTest();
890
891 StartTest(_T("RingBuffer: read #1"));
892 size_t bytes = rb.read(buffer, 256);
893 AssertEquals(bytes, 10);
894 AssertTrue(!memcmp(buffer, "short data", 10));
895 AssertEquals(rb.size(), 0);
896 EndTest();
897
898 StartTest(_T("RingBuffer: write #2"));
899 rb.write((const BYTE *)"short data", 10);
900 AssertEquals(rb.size(), 10);
901 EndTest();
902
903 StartTest(_T("RingBuffer: read #2"));
904 memset(buffer, 0, 256);
905 bytes = rb.read(buffer, 4);
906 AssertEquals(bytes, 4);
907 AssertTrue(!memcmp(buffer, "shor", 4));
908 AssertEquals(rb.size(), 6);
909 EndTest();
910
911 StartTest(_T("RingBuffer: write #3"));
912 rb.write((const BYTE *)"long data: 123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.", 111);
913 AssertEquals(rb.size(), 117);
914 EndTest();
915
916 StartTest(_T("RingBuffer: read #3"));
917 memset(buffer, 0, 256);
918 bytes = rb.read(buffer, 17);
919 AssertEquals(bytes, 17);
920 AssertTrue(!memcmp(buffer, "t datalong data: ", 17));
921 AssertEquals(rb.size(), 100);
922 EndTest();
923
924 StartTest(_T("RingBuffer: write #4"));
925 rb.write((const BYTE *)"short data", 10);
926 AssertEquals(rb.size(), 110);
927 EndTest();
928
929 StartTest(_T("RingBuffer: read #4"));
930 memset(buffer, 0, 256);
931 bytes = rb.read(buffer, 108);
932 AssertEquals(bytes, 108);
933 AssertTrue(!memcmp(buffer, "123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.short da", 108));
934 AssertEquals(rb.size(), 2);
935 EndTest();
936
937 StartTest(_T("RingBuffer: write #5"));
938 rb.write((const BYTE *)"test", 4);
939 AssertEquals(rb.size(), 6);
940 EndTest();
941
942 StartTest(_T("RingBuffer: read #5"));
943 memset(buffer, 0, 256);
944 bytes = rb.read(buffer, 256);
945 AssertEquals(bytes, 6);
946 AssertTrue(!memcmp(buffer, "tatest", 6));
947 AssertEquals(rb.size(), 0);
948 EndTest();
949
950 StartTest(_T("RingBuffer: random read/write"));
951 AssertTrue(rb.isEmpty());
952 for(int i = 0; i < 10000; i++)
953 {
954 int writes = rand() % 10;
955 int reads = rand() % 10;
956 for(int j = 0; j < writes; j++)
957 {
958 rb.write((const BYTE *)"---------/---------/---------/---------/---------/---------/---------/---------/---------/---------/", 100);
959 }
960 for(int j = 0; j < reads; j++)
961 {
962 memset(buffer, 0, 256);
963 bytes = rb.read(buffer, 100);
964 AssertTrue(((bytes == 100) && !memcmp(buffer, "---------/---------/---------/---------/---------/---------/---------/---------/---------/---------/", 100)) || (bytes == 0));
965 }
966 }
967 while(!rb.isEmpty())
968 {
969 memset(buffer, 0, 256);
970 bytes = rb.read(buffer, 100);
971 AssertTrue((bytes == 100) && !memcmp(buffer, "---------/---------/---------/---------/---------/---------/---------/---------/---------/---------/", 100));
972 }
973 EndTest();
974 }
975
976 static void TestDebugTags()
977 {
978 StartTest(_T("Default debug level"));
979 AssertEquals(nxlog_get_debug_level(), 0);
980 AssertEquals(nxlog_get_debug_level_tag(_T("server.db")), 0);
981 EndTest();
982
983 StartTest(_T("Debug Tags"));
984 nxlog_set_debug_level_tag(_T("*"), 1);
985 nxlog_set_debug_level_tag(_T("db"), 2);
986 nxlog_set_debug_level_tag(_T("db.*"), 3);
987 nxlog_set_debug_level_tag(_T("db.local"), 4);
988 nxlog_set_debug_level_tag(_T("db.local.*"), 5);
989 nxlog_set_debug_level_tag(_T("db.local.sql"), 6);
990 nxlog_set_debug_level_tag(_T("db.local.sql.*"), 7);
991 nxlog_set_debug_level_tag(_T("db.local.sql.testing"), 8);
992 nxlog_set_debug_level_tag(_T("db.local.sql.testing.*"), 9);
993 nxlog_set_debug_level_tag(_T("server.objects.lock"), 9);
994
995 AssertEquals(nxlog_get_debug_level_tag(_T("server.objects.db")), 1);
996
997 AssertTrue(nxlog_get_debug_level_tag(_T("node")) == 1);
998 AssertTrue(nxlog_get_debug_level_tag(_T("node.status")) == 1);
999 AssertTrue(nxlog_get_debug_level_tag(_T("node.status.test")) == 1);
1000
1001 AssertTrue(nxlog_get_debug_level_tag(_T("db")) == 2);
1002 AssertTrue(nxlog_get_debug_level_tag(_T("db.status")) == 3);
1003 AssertTrue(nxlog_get_debug_level_tag(_T("db.status.test")) == 3);
1004
1005 AssertTrue(nxlog_get_debug_level_tag(_T("db.local")) == 4);
1006 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.server")) == 5);
1007 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.server.test")) == 5);
1008
1009 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql")) == 6);
1010 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.server")) == 7);
1011 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.server.status")) == 7);
1012
1013 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing")) == 8);
1014 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing.server")) == 9);
1015 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing.server.status")) == 9);
1016 EndTest();
1017
1018 StartTest(_T("Debug Tags: change debug level"));
1019 nxlog_set_debug_level_tag(_T("*"), 9);
1020 nxlog_set_debug_level_tag(_T("db"), 8);
1021 nxlog_set_debug_level_tag(_T("db.*"), 7);
1022 nxlog_set_debug_level_tag(_T("db.local"), 6);
1023 nxlog_set_debug_level_tag(_T("db.local.*"), 5);
1024 nxlog_set_debug_level_tag(_T("db.local.sql"), 4);
1025 nxlog_set_debug_level_tag(_T("db.local.sql.*"), 3);
1026 nxlog_set_debug_level_tag(_T("db.local.sql.testing"), 2);
1027 nxlog_set_debug_level_tag(_T("db.local.sql.testing.*"), 1);
1028
1029 AssertTrue(nxlog_get_debug_level_tag(_T("node")) == 9);
1030 AssertTrue(nxlog_get_debug_level_tag(_T("node.status")) == 9);
1031 AssertTrue(nxlog_get_debug_level_tag(_T("node.status.test")) == 9);
1032
1033 AssertTrue(nxlog_get_debug_level_tag(_T("db")) == 8);
1034 AssertTrue(nxlog_get_debug_level_tag(_T("db.status")) == 7);
1035 AssertTrue(nxlog_get_debug_level_tag(_T("db.status.test")) == 7);
1036
1037 AssertTrue(nxlog_get_debug_level_tag(_T("db.local")) == 6);
1038 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.server")) == 5);
1039 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.server.test")) == 5);
1040
1041 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql")) == 4);
1042 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.server")) == 3);
1043 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.server.status")) == 3);
1044
1045 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing")) == 2);
1046 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing.server")) == 1);
1047 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing.server.status")) == 1);
1048 EndTest();
1049
1050 StartTest(_T("Debug Tags: remove"));
1051 nxlog_set_debug_level_tag(_T("db.test.remove.*"), 4);
1052 nxlog_set_debug_level_tag(_T("db.test.remove.child.tag"), 3);
1053 nxlog_set_debug_level_tag(_T("db.local.child"), 2);
1054 nxlog_set_debug_level_tag(_T("db.local.child.*"), 5);
1055
1056 nxlog_set_debug_level_tag(_T("*"), -1);
1057 nxlog_set_debug_level_tag(_T("db"), -1);
1058 nxlog_set_debug_level_tag(_T("db.*"), -1);
1059 nxlog_set_debug_level_tag(_T("db.local"), -1);
1060 nxlog_set_debug_level_tag(_T("db.local.*"), -1);
1061 nxlog_set_debug_level_tag(_T("db.local.sql"), -1);
1062 nxlog_set_debug_level_tag(_T("db.local.sql.*"), -1);;
1063
1064 nxlog_set_debug_level_tag(_T("*"), 9);
1065 nxlog_set_debug_level_tag(_T("server"), 8);
1066 nxlog_set_debug_level_tag(_T("server.*"), 7);
1067 nxlog_set_debug_level_tag(_T("server.node"), 6);
1068 nxlog_set_debug_level_tag(_T("server.node.*"), 5);
1069 nxlog_set_debug_level_tag(_T("server.node.status"), 4);
1070 nxlog_set_debug_level_tag(_T("server.node.status.*"), 3);
1071 nxlog_set_debug_level_tag(_T("server.node.status.poll"), 2);
1072 nxlog_set_debug_level_tag(_T("server.node.status.poll.*"), 1);
1073
1074 AssertTrue(nxlog_get_debug_level_tag(_T("node")) == 9);
1075 AssertTrue(nxlog_get_debug_level_tag(_T("node.status")) == 9);
1076 AssertTrue(nxlog_get_debug_level_tag(_T("node.status.test")) == 9);
1077
1078 AssertTrue(nxlog_get_debug_level_tag(_T("server")) == 8);
1079 AssertTrue(nxlog_get_debug_level_tag(_T("server.object")) == 7);
1080 AssertTrue(nxlog_get_debug_level_tag(_T("server.object.add")) == 7);
1081
1082 AssertTrue(nxlog_get_debug_level_tag(_T("server.node")) == 6);
1083 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.add")) == 5);
1084 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.add.new")) == 5);
1085
1086 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.status")) == 4);
1087 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.status.interface")) == 3);
1088 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.status.interface.state")) == 3);
1089
1090 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.status.poll")) == 2);
1091 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.status.poll.time")) == 1);
1092 AssertTrue(nxlog_get_debug_level_tag(_T("server.node.status.poll.time.ms")) == 1);
1093
1094 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing")) == 2);
1095 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing.server")) == 1);
1096 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.sql.testing.server.status")) == 1);
1097
1098 AssertTrue(nxlog_get_debug_level_tag(_T("db.test.remove.something")) == 4);
1099 AssertTrue(nxlog_get_debug_level_tag(_T("db.test.remove.child.tag")) == 3);
1100 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.child")) == 2);
1101 AssertTrue(nxlog_get_debug_level_tag(_T("db.local.child.remove.something.else")) == 5);
1102
1103 AssertFalse(nxlog_get_debug_level_tag(_T("db")) == 8);
1104 AssertFalse(nxlog_get_debug_level_tag(_T("db.status")) == 7);
1105 AssertFalse(nxlog_get_debug_level_tag(_T("db.status.test")) == 7);
1106
1107 AssertFalse(nxlog_get_debug_level_tag(_T("db.local")) == 6);
1108 AssertFalse(nxlog_get_debug_level_tag(_T("db.local.server")) == 5);
1109 AssertFalse(nxlog_get_debug_level_tag(_T("db.local.server.test")) == 5);
1110
1111 AssertFalse(nxlog_get_debug_level_tag(_T("db.local.sql")) == 4);
1112 AssertFalse(nxlog_get_debug_level_tag(_T("db.local.sql.server")) == 3);
1113 AssertFalse(nxlog_get_debug_level_tag(_T("db.local.sql.server.status")) == 3);
1114 EndTest();
1115 }
1116 /**
1117 * main()
1118 */
1119 int main(int argc, char *argv[])
1120 {
1121 #ifdef _WIN32
1122 WSADATA wsaData;
1123 WSAStartup(MAKEWORD(2, 2), &wsaData);
1124 #endif
1125
1126 TestString();
1127 TestStringConversion();
1128 TestStringMap();
1129 TestStringSet();
1130 TestMessageClass();
1131 TestMsgWaitQueue();
1132 TestMacAddress();
1133 TestInetAddress();
1134 TestItoa();
1135 TestQueue();
1136 TestHashMap();
1137 TestObjectArray();
1138 TestTable();
1139 TestMutexWrapper();
1140 TestRWLockWrapper();
1141 TestConditionWrapper();
1142 TestByteSwap();
1143 TestDiff();
1144 TestRingBuffer();
1145 TestDebugTags();
1146
1147 MsgWaitQueue::shutdown();
1148 return 0;
1149 }