fixed perf tab display for DCIs created via instance discovery from template
[public/netxms.git] / tests / test-libnetxms / test-libnetxms.cpp
CommitLineData
ee2d686f
VK
1#include <nms_common.h>
2#include <nms_util.h>
3#include <testtools.h>
4
7a70e9de
VK
5void TestMsgWaitQueue();
6
ee2d686f
VK
7static char mbText[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
8static WCHAR wcText[] = L"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
9static char mbTextShort[] = "Lorem ipsum";
10static UCS2CHAR ucs2TextShort[] = { 'L', 'o', 'r', 'e', 'm', ' ', 'i', 'p', 's', 'u', 'm', 0 };
11
12/**
13 * Test string conversion
14 */
15static void TestStringConversion()
16{
17 StartTest(_T("ANSI to UCS-2 conversion"));
18 UCS2CHAR ucs2buffer[1024];
19 mb_to_ucs2(mbTextShort, -1, ucs2buffer, 1024);
20 AssertTrue(!memcmp(ucs2buffer, ucs2TextShort, sizeof(UCS2CHAR) * 12));
21 EndTest();
22
23 StartTest(_T("UCS-2 to ANSI conversion"));
24 char mbBuffer[1024];
25 ucs2_to_mb(ucs2TextShort, -1, mbBuffer, 1024);
26 AssertTrue(!strcmp(mbBuffer, mbTextShort));
27 EndTest();
28
29 StartTest(_T("ANSI to UCS-2 conversion performance"));
30 INT64 start = GetCurrentTimeMs();
31 for(int i = 0; i < 10000; i++)
32 {
33 UCS2CHAR buffer[1024];
34 mb_to_ucs2(mbText, -1, buffer, 1024);
35 }
36 EndTest(GetCurrentTimeMs() - start);
37
38 StartTest(_T("UCS-2 to ANSI conversion performance"));
39 mb_to_ucs2(mbText, -1, ucs2buffer, 1024);
40 start = GetCurrentTimeMs();
41 for(int i = 0; i < 10000; i++)
42 {
43 char buffer[1024];
44 ucs2_to_mb(ucs2buffer, -1, buffer, 1024);
45 }
46 EndTest(GetCurrentTimeMs() - start);
47
48#ifdef UNICODE_UCS4
49 StartTest(_T("ANSI to UCS-4 conversion performance"));
50 start = GetCurrentTimeMs();
51 for(int i = 0; i < 10000; i++)
52 {
53 WCHAR buffer[1024];
54 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, mbText, -1, buffer, 1024);
55 }
56 EndTest(GetCurrentTimeMs() - start);
57
58 StartTest(_T("UCS-4 to ANSI conversion performance"));
59 start = GetCurrentTimeMs();
60 for(int i = 0; i < 10000; i++)
61 {
62 char buffer[1024];
63 WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, wcText, -1, buffer, 1024, NULL, NULL);
64 }
65 EndTest(GetCurrentTimeMs() - start);
66
67 StartTest(_T("UCS-2 to UCS-4 conversion performance"));
68 mb_to_ucs2(mbText, -1, ucs2buffer, 1024);
69 start = GetCurrentTimeMs();
70 for(int i = 0; i < 10000; i++)
71 {
72 WCHAR buffer[1024];
73 ucs2_to_ucs4(ucs2buffer, -1, buffer, 1024);
74 }
75 EndTest(GetCurrentTimeMs() - start);
76
77 StartTest(_T("UCS-4 to UCS-2 conversion performance"));
78 start = GetCurrentTimeMs();
79 for(int i = 0; i < 10000; i++)
80 {
81 UCS2CHAR buffer[1024];
82 ucs4_to_ucs2(wcText, -1, buffer, 1024);
83 }
84 EndTest(GetCurrentTimeMs() - start);
85#endif
86}
87
88/**
89 * Test string map
90 */
91static void TestStringMap()
92{
93 StringMap *m = new StringMap();
94
95 StartTest(_T("String map - insert"));
96 INT64 start = GetCurrentTimeMs();
97 for(int i = 0; i < 10000; i++)
98 {
99 TCHAR key[64];
100 _sntprintf(key, 64, _T("key-%d"), i);
101 m->set(key, _T("Lorem ipsum dolor sit amet"));
102 }
103 AssertEquals(m->size(), 10000);
400e55c4
VK
104 const TCHAR *v = m->get(_T("key-42"));
105 AssertNotNull(v);
106 AssertTrue(!_tcscmp(v, _T("Lorem ipsum dolor sit amet")));
ee2d686f
VK
107 EndTest(GetCurrentTimeMs() - start);
108
109 StartTest(_T("String map - replace"));
110 start = GetCurrentTimeMs();
111 for(int i = 0; i < 10000; i++)
112 {
113 TCHAR key[64];
114 _sntprintf(key, 64, _T("key-%d"), i);
115 m->set(key, _T("consectetur adipiscing elit"));
116 }
117 AssertEquals(m->size(), 10000);
400e55c4
VK
118 v = m->get(_T("key-42"));
119 AssertNotNull(v);
120 AssertTrue(!_tcscmp(v, _T("consectetur adipiscing elit")));
ee2d686f
VK
121 EndTest(GetCurrentTimeMs() - start);
122
123 StartTest(_T("String map - get"));
124 start = GetCurrentTimeMs();
400e55c4 125 v = m->get(_T("key-888"));
ee2d686f
VK
126 AssertNotNull(v);
127 AssertTrue(!_tcscmp(v, _T("consectetur adipiscing elit")));
128 EndTest(GetCurrentTimeMs() - start);
129
130 StartTest(_T("String map - clear"));
131 start = GetCurrentTimeMs();
132 m->clear();
133 AssertEquals(m->size(), 0);
134 EndTest(GetCurrentTimeMs() - start);
4b6e5e27
VK
135
136 delete m;
137}
138
139/**
140 * Test string set
141 */
142static void TestStringSet()
143{
144 StringSet *s = new StringSet();
145
146 StartTest(_T("String set - insert"));
147 INT64 start = GetCurrentTimeMs();
148 for(int i = 0; i < 10000; i++)
149 {
150 TCHAR key[64];
151 _sntprintf(key, 64, _T("key-%d lorem ipsum"), i);
152 s->add(key);
153 }
154 AssertEquals(s->size(), 10000);
155 AssertTrue(s->contains(_T("key-42 lorem ipsum")));
156 EndTest(GetCurrentTimeMs() - start);
157
158 StartTest(_T("String set - replace"));
159 start = GetCurrentTimeMs();
160 for(int i = 0; i < 10000; i++)
161 {
162 TCHAR key[64];
163 _sntprintf(key, 64, _T("key-%d lorem ipsum"), i);
164 s->add(key);
165 }
166 AssertEquals(s->size(), 10000);
167 AssertTrue(s->contains(_T("key-42 lorem ipsum")));
168 EndTest(GetCurrentTimeMs() - start);
169
170 StartTest(_T("String set - contains"));
171 start = GetCurrentTimeMs();
172 AssertTrue(s->contains(_T("key-888 lorem ipsum")));
173 EndTest(GetCurrentTimeMs() - start);
174
175 StartTest(_T("String set - clear"));
176 start = GetCurrentTimeMs();
177 s->clear();
178 AssertEquals(s->size(), 0);
179 EndTest(GetCurrentTimeMs() - start);
180
181 delete s;
ee2d686f
VK
182}
183
184/**
185 * main()
186 */
bd96aa53 187int main(int argc, char *argv[])
ee2d686f
VK
188{
189 TestStringConversion();
190 TestStringMap();
4b6e5e27 191 TestStringSet();
7a70e9de 192 TestMsgWaitQueue();
ee2d686f
VK
193 return 0;
194}