Use override/default for RTPortableServer
[ACE_TAO.git] / ACE / tests / OS_Test.cpp
blobb9fad7737490310552a69b8b7d4432557f45e485
1 // ============================================================================
2 //
3 // = LIBRARY
4 // tests
5 //
6 // = DESCRIPTION
7 // This simple test exercises and illustrates use of OS wrapper functions.
8 //
9 // = AUTHOR
10 // Steve Huston <shuston@riverace.com>
12 // ============================================================================
14 #include "test_config.h"
15 #include "ace/ACE.h"
16 //FUZZ: disable check_for_include_OS_h
17 #include "ace/OS.h"
18 //FUZZ: enable check_for_include_OS_h
20 #include "ace/OS_NS_math.h"
21 #include "ace/OS_NS_string.h"
22 #include "ace/OS_NS_strings.h"
23 #include "ace/OS_NS_stdlib.h"
24 #include "ace/OS_NS_sys_time.h"
25 #include "ace/OS_NS_time.h"
26 #include "ace/OS_NS_stdio.h"
27 #include "ace/OS_NS_sys_stat.h"
28 #include "ace/OS_NS_unistd.h"
29 #include "ace/OS_NS_errno.h"
30 #include "ace/OS_NS_ctype.h"
31 #include "ace/OS_NS_netdb.h"
33 #include <clocale>
34 #include <cmath>
35 #include <limits>
36 #undef THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
37 #define THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL(X) \
38 ((X) \
39 ? static_cast<void>(0) \
40 : ACE_VERSIONED_NAMESPACE_NAME::__ace_assert(__FILE__, __LINE__, ACE_TEXT_CHAR_TO_TCHAR (#X)))
42 // Test ACE_OS::access() to be sure a file's existence is correctly noted.
43 int
44 access_test ()
46 ACE_DEBUG ((LM_DEBUG,
47 ACE_TEXT ("Testing access method\n")));
49 int test_status = 0;
51 int status = ACE_OS::access (ACE_TEXT ("missing_file.txt"), F_OK);
52 if (status == -1)
54 if (errno == ENOTSUP)
55 ACE_ERROR_RETURN ((LM_INFO,
56 ACE_TEXT ("ACE_OS::access() not supported\n")),
57 0);
59 else
61 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Missing file noted as present.\n")));
62 test_status = -1;
65 return test_status;
68 // Test ACE_OS::rename to be sure the files come and go as expected.
69 int
70 rename_test ()
72 #if defined (ACE_LACKS_RENAME) || defined (ACE_VXWORKS)
73 // On VxWorks only some filesystem drivers support rename
74 // and as we do not know which is used, skip the test here
75 ACE_ERROR_RETURN ((LM_INFO,
76 ACE_TEXT ("rename not supported on this platform\n")),
77 0);
78 #else
79 ACE_TCHAR old_file[MAXPATHLEN];
80 ACE_TCHAR new_file[MAXPATHLEN];
81 ACE_OS::strcpy (old_file, ACE_TEXT ("rename_test_old"));
82 ACE_OS::strcpy (new_file, ACE_TEXT ("rename_test_new"));
84 // Test 1. Rename old to new when new already exists.
85 // To set up, create two files, old and new. Both get opened and truncated
86 // in case they're left over from a previous run. The first one (old) gets
87 // something written in it so it's non-zero length - this is how the rename
88 // is verified.
89 FILE *f = ACE_OS::fopen (old_file, ACE_TEXT ("w+"));
90 if (f == 0)
91 ACE_ERROR_RETURN ((LM_ERROR,
92 ACE_TEXT ("%s: %p\n"),
93 old_file,
94 ACE_TEXT ("fopen")),
95 -1);
96 // Write something in the old_file so it has non-zero length
97 ACE_OS::fwrite (ACE_TEXT ("this is a test\n"), sizeof (ACE_TCHAR), 15, f);
98 ACE_OS::fclose (f);
99 f = ACE_OS::fopen (new_file, ACE_TEXT ("w+"));
100 if (f == 0)
102 ACE_OS::unlink (old_file);
103 ACE_ERROR_RETURN ((LM_ERROR,
104 ACE_TEXT ("%s: %p\n"),
105 new_file,
106 ACE_TEXT ("fopen")),
107 -1);
109 ACE_OS::fclose (f);
111 #if defined (ACE_WIN32) && defined (ACE_LACKS_WIN32_MOVEFILEEX)
112 // Can't rename if new_file exists already.
113 ACE_OS::unlink (new_file);
114 #endif
116 if (ACE_OS::rename (old_file, new_file) != 0)
118 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("rename test 1")));
119 ACE_OS::unlink (old_file);
120 ACE_OS::unlink (new_file);
121 return -1;
123 // Verify that the old file was really renamed.
124 ACE_stat checking;
125 int result = 0;
126 if (ACE_OS::stat (new_file, &checking) == -1 || checking.st_size == 0)
128 result = -1;
129 ACE_ERROR ((LM_ERROR,
130 ACE_TEXT ("Rename test 1: new_file not correct\n")));
132 if (ACE_OS::stat (old_file, &checking) == 0)
134 result = -1;
135 ACE_ERROR ((LM_ERROR,
136 ACE_TEXT ("Rename test 1: old_file still there\n")));
138 if (result == 0)
139 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Rename when dest. exists: success\n")));
141 // Now test 2 - rename when the new file does not exist. If test 1 worked,
142 // the old_file is now new_file and there is no old_file.
143 if (ACE_OS::rename (new_file, old_file) != 0)
145 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("rename test 2")));
146 ACE_OS::unlink (old_file);
147 ACE_OS::unlink (new_file);
148 return -1;
150 if (ACE_OS::stat (old_file, &checking) == -1 || checking.st_size == 0)
152 result = -1;
153 ACE_ERROR ((LM_ERROR,
154 ACE_TEXT ("Rename test 2: new_file not correct\n")));
156 else if (ACE_OS::stat (new_file, &checking) == 0)
158 result = -1;
159 ACE_ERROR ((LM_ERROR,
160 ACE_TEXT ("Rename test 2: old_file still there\n")));
162 else
163 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Rename when dest. gone: success\n")));
165 ACE_OS::unlink (new_file);
166 ACE_OS::unlink (old_file);
168 // Test 3: It should fail... there are no files.
169 if (ACE_OS::rename (old_file, new_file) == -1)
170 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Rename test 3 should bomb, and did.\n")));
171 else
173 result = -1;
174 ACE_ERROR ((LM_ERROR,
175 ACE_TEXT ("Rename expected fail, but succeeded\n")));
178 return result;
179 #endif /* ACE_VXWORKS */
184 string_emulation_test ()
187 // ========================================================================
188 // Test memchr
189 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing memchr\n")));
191 const char *memchr1 = "abcdefghijklmnopqrstuvwxyz";
193 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::memchr (static_cast<const void *> (0),
194 'a',
195 0) == 0);
196 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::memchr (memchr1, 'a', sizeof (memchr1)) != 0);
197 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::memchr (memchr1, '1', sizeof (memchr1)) == 0);
199 // ========================================================================
200 // Test strchr
201 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strchr\n")));
203 const char *strchr1 = "abcdefghijkabcdefghijk";
205 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (*ACE_OS::strchr (strchr1, 'h') == 'h');
206 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strchr (strchr1, 'h') == strchr1 + 7);
207 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strchr (strchr1, '1') == 0);
209 // ========================================================================
210 // Test strrchr
211 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strrchr\n")));
213 const char *strrchr1 = "abcdefghijkabcdefghijk";
215 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (*ACE_OS::strrchr (strrchr1, 'h') == 'h');
216 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strrchr (strrchr1, 'h') == strrchr1 + 18);
217 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strrchr (strrchr1, '1') == 0);
219 // ========================================================================
220 // Test strcspn
221 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strcspn\n")));
223 const char *strcspn1 = "abcdefghijkabcdefghijk";
225 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcspn (strcspn1, "d") == 3);
226 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcspn (strcspn1, "abcdefghijk") == 0);
228 // ========================================================================
229 // Test strcasecmp
230 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strcasecmp\n")));
232 const char *strcasecmp1 = "stringf";
233 const char *strcasecmp2 = "stringfe"; // An extra character
234 const char *strcasecmp3 = "stringg"; // The last letter is higher
235 const char *strcasecmp4 = "STRINGF"; // Different case
236 const char *strcasecmp5 = "stringe"; // The last letter is lower
238 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp1) == 0);
239 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp2) < 0);
240 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp3) < 0);
241 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp4) == 0);
242 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp5) > 0);
244 // ========================================================================
245 // Test strtok_r
246 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strtok_r\n")));
248 char strtok_r1[] = "A string of tokens";
249 char *strtok_r2;
251 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (strtok_r1,
252 " ",
253 &strtok_r2),
254 "A") == 0);
255 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (0,
256 " ",
257 &strtok_r2),
258 "string") == 0);
259 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (0,
260 " ",
261 &strtok_r2),
262 "of") == 0);
263 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (0,
264 " ",
265 &strtok_r2),
266 "tokens") == 0);
267 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strtok_r (0, " ", &strtok_r2) == 0);
269 // ========================================================================
270 // Test itoa
271 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing itoa\n")));
273 char itoa1[33];
275 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itoa1, 2),
276 "101010") == 0);
278 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itoa1, 3),
279 "1120") == 0);
281 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itoa1, 16),
282 "2a") == 0);
284 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (8, itoa1, 10),
285 "8") == 0);
287 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (-8, itoa1, 10),
288 "-8") == 0);
290 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (20345, itoa1, 10),
291 "20345") == 0);
293 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (-20345, itoa1, 10),
294 "-20345") == 0);
296 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (4566733, itoa1, 10),
297 "4566733") == 0);
299 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (-4566733, itoa1, 10),
300 "-4566733") == 0);
303 #if defined (ACE_HAS_WCHAR)
305 //FUZZ: disable check_for_lack_ACE_OS
306 // ========================================================================
307 // Test itoa (wchar_t version)
308 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing itoa (wchar_t version)\n")));
309 //FUZZ: enable check_for_lack_ACE_OS
311 wchar_t itow1[33];
313 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itow1, 2),
314 ACE_TEXT_WIDE ("101010")) == 0);
316 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itow1, 3),
317 ACE_TEXT_WIDE ("1120")) == 0);
319 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itow1, 16),
320 ACE_TEXT_WIDE ("2a")) == 0);
323 //FUZZ: disable check_for_lack_ACE_OS
324 // ========================================================================
325 // Test strcmp (wchar_t version)
326 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strcmp (wchar_t version)\n")));
327 //FUZZ: enable check_for_lack_ACE_OS
329 const wchar_t *strcmp1 = ACE_TEXT_WIDE ("stringf");
330 const wchar_t *strcmp2 = ACE_TEXT_WIDE ("stringfe");
331 const wchar_t *strcmp3 = ACE_TEXT_WIDE ("stringg");
332 const wchar_t *strcmp4 = ACE_TEXT_WIDE ("STRINGF");
333 const wchar_t *strcmp5 = ACE_TEXT_WIDE ("stringe");
335 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strcmp1, strcmp1) == 0);
336 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strcmp1, strcmp2) < 0);
337 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strcmp1, strcmp3) < 0);
338 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strcmp1, strcmp4) != 0);
339 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strcmp1, strcmp5) > 0);
341 //FUZZ: disable check_for_lack_ACE_OS
342 // ========================================================================
343 // Test strcpy (wchar_t version)
344 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strcpy (wchar_t version)\n")));
345 //FUZZ: enable check_for_lack_ACE_OS
347 const wchar_t *strcpy1 = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyz");
348 wchar_t strcpy2[27];
350 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
351 (ACE_OS::strcmp (ACE_OS::strcpy (strcpy2, strcpy1),
352 strcpy1) == 0);
353 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strcpy2, strcpy1) == 0);
355 //FUZZ: disable check_for_lack_ACE_OS
356 // ========================================================================
357 // Test strcat (wchar_t version)
358 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strcat (wchar_t version)\n")));
359 //FUZZ: enable check_for_lack_ACE_OS
361 const wchar_t *strcat1 = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyz");
362 wchar_t strcat2[27] = ACE_TEXT_WIDE ("abcdefghijkl");
363 const wchar_t *strcat3 = ACE_TEXT_WIDE ("mnopqrstuvwxyz");
365 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
366 (ACE_OS::strcmp (ACE_OS::strcat (strcat2, strcat3),
367 strcat1) == 0);
368 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strcat2, strcat1) == 0);
370 //FUZZ: disable check_for_lack_ACE_OS
371 // ========================================================================
372 // Test strncat (wchar_t version)
373 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strncat (wchar_t version)\n")));
374 //FUZZ: enable check_for_lack_ACE_OS
376 const wchar_t *strncat1 = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyz");
377 wchar_t strncat2[27] = ACE_TEXT_WIDE ("abcdefghijkl");
378 const wchar_t *strncat3 = ACE_TEXT_WIDE ("mnopqrstuvwxyzabc");
380 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
381 (ACE_OS::strcmp (ACE_OS::strncat (strncat2, strncat3, 14),
382 strncat1) == 0);
383 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strncat2, strncat1) == 0);
385 //FUZZ: disable check_for_lack_ACE_OS
386 // ========================================================================
387 // Test strspn (wchar_t version)
388 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strspn (wchar_t version)\n")));
389 //FUZZ: enable check_for_lack_ACE_OS
391 const wchar_t *strspn1 = ACE_TEXT_WIDE ("abcdefghijkabcdefghijk");
393 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strspn (strspn1,
394 ACE_TEXT_WIDE ("abcdf")) == 4);
395 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strspn (strspn1,
396 ACE_TEXT_WIDE ("mno")) == 0);
398 //FUZZ: disable check_for_lack_ACE_OS
399 // ========================================================================
400 // Test strchr (wchar_t version)
401 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strchr (wchar_t version)\n")));
402 //FUZZ: enable check_for_lack_ACE_OS
404 const wchar_t *strchr1 = ACE_TEXT_WIDE ("abcdefghijkabcdefghijk");
406 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (*ACE_OS::strchr (strchr1, ACE_TEXT_WIDE ('h'))
407 == ACE_TEXT_WIDE ('h'));
408 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strchr (strchr1, ACE_TEXT_WIDE ('h'))
409 == strchr1 + 7);
410 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strchr (strchr1, ACE_TEXT_WIDE ('1')) == 0);
412 //FUZZ: disable check_for_lack_ACE_OS
413 // ========================================================================
414 // Test strstr (wchar_t version)
415 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strstr (wchar_t version)\n")));
416 //FUZZ: enable check_for_lack_ACE_OS
418 const wchar_t *strstr1 = ACE_TEXT_WIDE ("abcdefghijkabcdefghijk");
420 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strncmp (
421 ACE_OS::strstr (strstr1, ACE_TEXT_WIDE ("def")),
422 ACE_TEXT_WIDE ("def"),
424 == 0);
425 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strstr (strstr1,
426 ACE_TEXT_WIDE ("mno")) == 0);
428 //FUZZ: disable check_for_lack_ACE_OS
429 // ========================================================================
430 // Test strlen (wchar_t version)
431 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strlen (wchar_t version)\n")));
432 //FUZZ: enable check_for_lack_ACE_OS
434 const wchar_t *strlen1 = ACE_TEXT_WIDE ("");
435 const wchar_t *strlen2 = ACE_TEXT_WIDE ("12345");
437 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strlen (strlen1) == 0);
438 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strlen (strlen2) == 5);
440 //FUZZ: disable check_for_lack_ACE_OS
441 // ========================================================================
442 // Test strpbrk (wchar_t version)
443 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strpbrk (wchar_t version)\n")));
444 //FUZZ: enable check_for_lack_ACE_OS
446 const wchar_t *strpbrk1 = ACE_TEXT_WIDE ("abcdefghijkabcdefghijk");
448 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strpbrk (strpbrk1, ACE_TEXT_WIDE ("ijkb"))
449 == strpbrk1 + 1);
450 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strpbrk (strpbrk1,
451 ACE_TEXT_WIDE ("mno")) == 0);
453 //FUZZ: disable check_for_lack_ACE_OS
454 // ========================================================================
455 // Test strrchr (wchar_t version)
456 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strrchr (wchar_t version)\n")));
457 //FUZZ: enable check_for_lack_ACE_OS
459 const wchar_t *strrchr1 = ACE_TEXT_WIDE ("abcdefghijkabcdefghijk");
461 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (*ACE_OS::strrchr (strrchr1, ACE_TEXT_WIDE ('h'))
462 == ACE_TEXT_WIDE ('h'));
463 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strrchr (strrchr1, ACE_TEXT_WIDE ('h'))
464 == strrchr1 + 18);
465 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strrchr (strrchr1, ACE_TEXT_WIDE ('1'))
466 == 0);
468 //FUZZ: disable check_for_lack_ACE_OS
469 // ========================================================================
470 // Test strcasecmp (wchar_t version)
471 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strcasecmp (wchar_t version)\n")));
472 //FUZZ: enable check_for_lack_ACE_OS
474 const wchar_t *strcasecmp1 = ACE_TEXT_WIDE ("stringf");
475 const wchar_t *strcasecmp2 = ACE_TEXT_WIDE ("stringfe");
476 const wchar_t *strcasecmp3 = ACE_TEXT_WIDE ("stringg");
477 const wchar_t *strcasecmp4 = ACE_TEXT_WIDE ("STRINGF");
478 const wchar_t *strcasecmp5 = ACE_TEXT_WIDE ("stringe");
480 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp1) == 0);
481 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp2) < 0);
482 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp3) < 0);
483 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp4) == 0);
484 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcasecmp (strcasecmp1, strcasecmp5) > 0);
486 //FUZZ: disable check_for_lack_ACE_OS
487 // ========================================================================
488 // Test strncasecmp (wchar_t version)
489 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strncasecmp (wchar_t version)\n")));
490 //FUZZ: enable check_for_lack_ACE_OS
492 const wchar_t *strncasecmp1 = ACE_TEXT_WIDE ("stringf");
493 const wchar_t *strncasecmp2 = ACE_TEXT_WIDE ("stringfe");
494 const wchar_t *strncasecmp3 = ACE_TEXT_WIDE ("stringg");
495 const wchar_t *strncasecmp4 = ACE_TEXT_WIDE ("STRINGF");
496 const wchar_t *strncasecmp5 = ACE_TEXT_WIDE ("stringe");
498 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
499 (ACE_OS::strncasecmp (strncasecmp1, strncasecmp2, 7) == 0);
500 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
501 (ACE_OS::strncasecmp (strncasecmp1, strncasecmp2, 8) < 0);
502 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
503 (ACE_OS::strncasecmp (strncasecmp1, strncasecmp3, 7) < 0);
504 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
505 (ACE_OS::strncasecmp (strncasecmp1, strncasecmp4, 7) == 0);
506 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
507 (ACE_OS::strncasecmp (strncasecmp1, strncasecmp5, 7) > 0);
509 //FUZZ: disable check_for_lack_ACE_OS
510 // ========================================================================
511 // Test strncmp (wchar_t version)
512 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strncmp (wchar_t version)\n")));
513 //FUZZ: enable check_for_lack_ACE_OS
515 const wchar_t *strncmp1 = ACE_TEXT_WIDE ("stringf");
516 const wchar_t *strncmp2 = ACE_TEXT_WIDE ("stringfe");
517 const wchar_t *strncmp3 = ACE_TEXT_WIDE ("stringg");
518 const wchar_t *strncmp4 = ACE_TEXT_WIDE ("STRINGF");
519 const wchar_t *strncmp5 = ACE_TEXT_WIDE ("stringe");
521 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strncmp (strncmp1, strncmp2, 7) == 0);
522 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strncmp (strncmp1, strncmp2, 8) < 0);
523 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strncmp (strncmp1, strncmp3, 7) < 0);
524 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strncmp (strncmp1, strncmp4, 7) != 0);
525 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strncmp (strncmp1, strncmp5, 7) > 0);
527 //FUZZ: disable check_for_lack_ACE_OS
528 // ========================================================================
529 // Test strncpy (wchar_t version)
530 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strncpy (wchar_t version)\n")));
531 //FUZZ: enable check_for_lack_ACE_OS
533 wchar_t strncpy1[] = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyzabc");
534 wchar_t strncpy2[27];
536 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
537 (ACE_OS::strncmp (ACE_OS::strncpy (strncpy2,
538 strncpy1,
539 26),
540 strncpy1,
541 26) == 0);
543 strncpy1[26] = 0;
544 strncpy2[26] = 0;
545 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strncpy2, strncpy1) == 0);
547 //FUZZ: disable check_for_lack_ACE_OS
548 // ========================================================================
549 // Test strtok (wchar_t version)
550 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing strtok (wchar_t version)\n")));
551 # ifdef ACE_LACKS_WCSTOK
552 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Skipped because platform lacks wcstok\n")));
553 # else
554 //FUZZ: enable check_for_lack_ACE_OS
556 wchar_t strtok_r1[] = ACE_TEXT_WIDE ("A string of tokens");
558 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok (strtok_r1,
559 ACE_TEXT_WIDE (" ")),
560 ACE_TEXT_WIDE ("A")) == 0);
561 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok (0,
562 ACE_TEXT_WIDE (" ")),
563 ACE_TEXT_WIDE ("string") ) == 0);
564 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok (0,
565 ACE_TEXT_WIDE (" ")),
566 ACE_TEXT_WIDE ("of") ) == 0);
567 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok (0,
568 ACE_TEXT_WIDE (" ")),
569 ACE_TEXT_WIDE ("tokens") ) == 0);
570 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strtok (0, ACE_TEXT_WIDE (" ")) == 0);
571 # endif /* ACE_LACKS_WCSTOK */
575 #endif /* ACE_HAS_WCHAR */
577 return 0;
580 // Test ACE_OS::snprintf
581 using SNPrintF_t = int (*)(char *, size_t, const char *, ...);
584 snprintf_test (SNPrintF_t fn)
586 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing snprintf\n")));
588 int error_count = 0;
589 const int BUFFER_SIZE = 4;
590 char buf[2*BUFFER_SIZE];
591 int retval;
593 ACE_OS::memset(buf, 0xab, 2*BUFFER_SIZE);
594 retval = fn (buf, BUFFER_SIZE, "%d", 123);
595 if (retval != 3)
597 ACE_ERROR ((LM_ERROR,
598 ACE_TEXT ("[1] ACE_OS::snprintf() returns %d, should be 3\n"),
599 retval));
600 ++error_count;
603 ACE_OS::memset(buf, 0xab, 2*BUFFER_SIZE);
604 retval = fn (buf, BUFFER_SIZE, "%d", 1234);
606 if (retval != 4)
608 ACE_ERROR ((LM_ERROR,
609 ACE_TEXT ("[2] ACE_OS::snprintf() returns %d, should be 4\n"),
610 retval));
611 ++error_count;
614 if (buf[3] != 0)
616 ACE_ERROR ((LM_ERROR,
617 ACE_TEXT ("[3] ACE_OS::snprintf() doesn't terminate string correctly\n")));
618 ++error_count;
620 else if (ACE_OS::strcmp(buf, "123") != 0)
622 ACE_ERROR ((LM_ERROR,
623 ACE_TEXT ("[4] ACE_OS::snprintf() incorrect output\n")));
624 ++error_count;
627 ACE_OS::memset(buf, 0xab, 2*BUFFER_SIZE);
628 retval = fn (buf, BUFFER_SIZE, "%d", 12345);
629 if (retval != 5)
631 ACE_ERROR ((LM_ERROR,
632 ACE_TEXT ("[5] ACE_OS::snprintf() returns %d, should be 5\n"),
633 retval));
634 ++error_count;
636 else if (buf[3] != 0)
638 ACE_ERROR ((LM_ERROR,
639 ACE_TEXT ("[6] ACE_OS::snprintf() doesn't terminate string correctly\n")));
640 ++error_count;
642 else if (ACE_OS::strcmp(buf, "123") != 0)
644 ACE_ERROR ((LM_ERROR,
645 ACE_TEXT ("[6] ACE_OS::snprintf() incorrect output\n")));
646 ++error_count;
649 return error_count;
652 static int
653 getpwnam_r_test ()
655 int result = 0;
657 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
658 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing getpwnam_r\n")));
660 struct passwd pwd;
661 struct passwd *pwd_ptr;
662 char buf[1024];
664 const char* login = getlogin ();
665 if (login == 0)
666 login = "root";
668 if (ACE_OS::getpwnam_r (login,
669 &pwd,
670 buf,
671 sizeof (buf),
672 &pwd_ptr) != 0)
674 result = 1;
675 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("getpwnam_r() failed\n")));
677 else
679 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" User '%s' has uid=%d and gid=%d\n"),
680 pwd_ptr->pw_name, pwd_ptr->pw_uid, pwd_ptr->pw_gid));
682 #endif
684 return result;
687 static int
688 compiler_test ()
690 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing compiler methods\n")));
692 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Using compiler %s with major version %d minor version %d beta version %d\n"),
693 ACE::compiler_name(),
694 ACE::compiler_major_version(),
695 ACE::compiler_minor_version (),
696 ACE::compiler_beta_version ()));
698 return 0;
701 static int
702 version_test ()
704 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing version macros\n")));
706 int const code = ACE_MAKE_VERSION_CODE(ACE_MAJOR_VERSION, ACE_MINOR_VERSION, ACE_MICRO_VERSION);
707 bool const run_time_check = code == ACE_VERSION_CODE;
708 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE release time version code: %d, runtime version code: %d, %s\n"),
709 ACE_VERSION_CODE, code, run_time_check ? ACE_TEXT ("OK") : ACE_TEXT ("FAIL")));
711 // Compile time check. Check we have ACE version 6.x
712 #if ACE_VERSION_CODE > ACE_MAKE_VERSION_CODE(5, 88, 99)
713 bool const compile_time_check = true;
714 #else
715 bool compile_time_check = false;
716 #endif
718 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Compile time version check, %s\n"),
719 compile_time_check ? ACE_TEXT ("OK") : ACE_TEXT ("FAIL")));
721 if(run_time_check && compile_time_check)
722 return 0;
723 return 1;
726 static int
727 ctime_r_test ()
729 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing ctime_r\n")));
731 int result = 0;
733 // test 'normal' buffer
734 ACE_TCHAR buf[27];
735 buf[26] = 'Z';
737 ACE_Time_Value cur_time =
738 ACE_OS::gettimeofday ();
740 time_t const secs = cur_time.sec ();
741 if (ACE_OS::ctime_r (&secs, buf, 26) == 0)
743 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
744 ACE_TEXT ("ctime_r with 26 bytes")));
745 result = -1;
747 else if (buf[0] == '\0')
749 result = -1;
751 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Truncated input buffer\n")));
753 else if (buf[26] != 'Z')
755 result = -1;
756 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Wrote past end of input buffer\n")));
759 // test small buffer - should not do anything unless 3rd arg is at least 26.
760 if (result == 0)
762 ACE_TCHAR bufcheck[27];
763 ACE_OS::strcpy (bufcheck, buf);
764 if (ACE_OS::ctime_r (&secs, buf, 10) != 0)
766 ACE_ERROR ((LM_ERROR,
767 ACE_TEXT ("ctime_r with short len returned %s\n"),
768 buf));
769 result = -1;
771 else if (errno != ERANGE)
773 ACE_ERROR ((LM_ERROR,
774 ACE_TEXT ("%p\n"),
775 ACE_TEXT ("ctime_r short; wrong error")));
776 result = -1;
778 // Make sure it didn't scribble
779 else if (ACE_OS::strcmp (buf, bufcheck) != 0)
781 result = -1;
782 ACE_ERROR ((LM_ERROR,
783 ACE_TEXT ("ctime_r short; got %s, expected %s\n"),
784 buf, bufcheck));
788 return result;
793 string_strsncpy_test ()
796 //FUZZ: disable check_for_lack_ACE_OS
797 // Test strsncpy (char version)
798 ACE_DEBUG ((LM_DEBUG,
799 ACE_TEXT ("Testing strsncpy (char version)\n")));
800 //FUZZ: enable check_for_lack_ACE_OS
802 char const strsncpy1[] = "abcdefghijklmnopqrstuvwxyzabc";
803 char strsncpy2[36];
805 // strsncpy() where the max. length doesn't matter
806 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
807 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
808 strsncpy1,
809 36),
810 strsncpy1) == 0);
812 // strsncpy() where the max length does matter
813 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
814 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
815 strsncpy1,
816 26),
817 strsncpy1,
818 25) == 0);
820 // strsncpy1 and strsncpy2 are different size --> not equal
821 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strsncpy2, strsncpy1) != 0);
823 // max. length == 2 --> 1 char available
824 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
825 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
826 strsncpy1,
828 strsncpy1,
829 1) == 0);
831 // max length == 1 --> empty string
832 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
833 (ACE_OS::strlen (ACE_OS::strsncpy (strsncpy2,
834 strsncpy1,
835 1)) == 0);
837 // just preparation for the next assert
838 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
839 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
840 strsncpy1,
841 36),
842 strsncpy1) == 0);
844 // A tricky one, if the max. length == 0 --> do nothing
845 // so the strsncpy2 shouldn't change
846 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
847 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
848 "test",
850 strsncpy1) == 0);
852 // If src == dst --> truncate dst if needed!
853 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
854 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
855 strsncpy2,
856 10),
857 strsncpy1,
858 9) == 0);
859 // size should be 9 (+ '\0' char)
860 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL(ACE_OS::strlen(strsncpy2) == 9);
863 #if defined (ACE_HAS_WCHAR)
865 //FUZZ: disable check_for_lack_ACE_OS
866 // Test strsncpy (wchar_t version)
867 ACE_DEBUG ((LM_DEBUG,
868 ACE_TEXT ("Testing strsncpy (wchar_t version)\n")));
869 //FUZZ: enable check_for_lack_ACE_OS
871 wchar_t const strsncpy1[] = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyzabc");
872 wchar_t strsncpy2[36];
874 // strsncpy() where the max. length doesn't matter
875 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
876 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
877 strsncpy1,
878 36),
879 strsncpy1) == 0);
881 // strsncpy() where the max length does matter
882 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
883 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
884 strsncpy1,
885 26),
886 strsncpy1,
887 25) == 0);
889 // strsncpy1 and strsncpy2 are different size --> not equal
890 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strsncpy2, strsncpy1) != 0);
892 // max. length == 2 --> 1 char available
893 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
894 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
895 strsncpy1,
897 strsncpy1,
898 1) == 0);
900 // max length == 1 --> empty string
901 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
902 (ACE_OS::strlen (ACE_OS::strsncpy (strsncpy2,
903 strsncpy1,
904 1)) == 0);
906 // just preparation for the next assert
907 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
908 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
909 strsncpy1,
910 36),
911 strsncpy1) == 0);
913 // A tricky one, if the max. length == 0 --> do nothing
914 // so the strsncpy2 shouldn't change
915 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
916 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
917 ACE_TEXT_WIDE
918 ("test"),
920 strsncpy1) == 0);
922 // If src == dst --> truncate dst if needed!
923 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
924 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
925 strsncpy2,
926 10),
927 strsncpy1,
928 9) == 0);
929 // size should be 9 (+ '\0' char)
930 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL(ACE_OS::strlen(strsncpy2) == 9);
932 #endif /* ACE_HAS_WCHAR */
934 return 0;
938 // Test conversion between narrow and wide chars.
940 string_convert_test ()
942 #if defined (ACE_HAS_WCHAR)
943 ACE_DEBUG ((LM_DEBUG,
944 ACE_TEXT ("Testing narrow/wide string conversion\n")));
946 int result = 0;
947 const char *test1_n = "abcdefg";
948 const wchar_t *test1_w = ACE_TEXT_WIDE ("abcdefg");
949 const char *test2_n = "\xe9\xe8\xe0\xf9\xea";
950 const wchar_t *test2_w = ACE_TEXT_WIDE ("\xe9\xe8\xe0\xf9\xea");
951 wchar_t str_w[10];
952 char str_n[10];
953 ACE_OS::strcpy (str_w, ACE_Ascii_To_Wide (test1_n).wchar_rep ());
954 if (0 != ACE_OS::strcmp (test1_w, str_w))
956 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Simple narrow->wide failed: ")
957 ACE_TEXT ("Expected \"%W\"; Got \"%W\"\n"), test1_w, str_w));
958 result = 1;
960 ACE_OS::strcpy (str_n, ACE_Wide_To_Ascii (test1_w).char_rep ());
961 if (0 != ACE_OS::strcmp (test1_n, str_n))
963 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Simple wide->narrow failed: ")
964 ACE_TEXT ("Expected \"%C\"; Got \"%C\"\n"), test1_n, str_n));
965 result = 1;
967 ACE_OS::strcpy (str_w, ACE_Ascii_To_Wide (test2_n).wchar_rep ());
968 if (0 != ACE_OS::strcmp (test2_w, str_w))
970 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Complex narrow->wide failed: ")
971 ACE_TEXT ("Expected \"%W\"; Got \"%W\"\n"), test2_w, str_w));
972 result = 1;
974 ACE_OS::strcpy (str_n, ACE_Wide_To_Ascii (test2_w).char_rep ());
975 if (0 != ACE_OS::strcmp (test2_n, str_n))
977 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Complex wide->narrow failed: ")
978 ACE_TEXT ("Expected \"%C\"; Got \"%C\"\n"), test2_n, str_n));
979 result = 1;
981 return result;
982 #else
983 return 0;
984 #endif /* ACE_HAS_WCHAR */
987 // Test ACE_OS::strsignal()
989 strsignal_test ()
991 ACE_DEBUG ((LM_DEBUG,
992 ACE_TEXT ("Testing strsignal method\n")));
994 int test_status = 0;
996 const char* result = 0;
998 for (int i=-1; i < (ACE_NSIG + 1); ++i)
1000 result = ACE_OS::strsignal (i);
1001 if (result == 0)
1003 ACE_ERROR ((LM_ERROR, ACE_TEXT ("strsignal returned null\n")));
1004 test_status = 1;
1006 else
1008 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Sig #%d: %C\n"), i, result));
1012 return test_status;
1015 // Test the methods for getting cpu info
1017 cpu_info_test ()
1019 ACE_DEBUG ((LM_DEBUG,
1020 ACE_TEXT ("Testing cpu info methods\n")));
1022 long const number_processors = ACE_OS::num_processors();
1023 long const number_processors_online = ACE_OS::num_processors_online();
1025 if (number_processors == -1)
1027 ACE_ERROR ((LM_INFO,
1028 ACE_TEXT ("number of processors not supported on ")
1029 ACE_TEXT ("this platform\n")));
1031 else
1033 ACE_DEBUG ((LM_DEBUG,
1034 ACE_TEXT ("This system has %d processors\n"),
1035 number_processors));
1038 if (number_processors_online == -1)
1040 ACE_ERROR ((LM_INFO,
1041 ACE_TEXT ("number of processors online not supported on ")
1042 ACE_TEXT ("this platform\n")));
1044 else
1046 ACE_DEBUG ((LM_DEBUG,
1047 ACE_TEXT ("This system has %d processors online\n"),
1048 number_processors_online));
1051 if ((number_processors_online != -1 && number_processors != -1) &&
1052 number_processors_online > number_processors)
1053 ACE_ERROR_RETURN ((LM_ERROR,
1054 ACE_TEXT ("%d online processors; should be <= %d\n"),
1055 number_processors_online,
1056 number_processors),
1057 -1);
1059 return 0;
1063 last_error_test ()
1065 ACE_DEBUG ((LM_DEBUG,
1066 ACE_TEXT ("Testing last_error method\n")));
1068 ACE_OS::last_error (ETIME);
1070 int const l_error = ACE_OS::last_error ();
1071 if (l_error != ETIME)
1073 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Last error returned %d instead of ETIME"),
1074 l_error));
1075 return 1;
1078 ACE_OS::last_error (0);
1080 return 0;
1084 pagesize_test ()
1086 ACE_DEBUG ((LM_DEBUG,
1087 ACE_TEXT ("Testing getpagesize method\n")));
1089 long const pagesize = ACE_OS::getpagesize ();
1090 if (pagesize <= 0)
1092 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, pagesize should return a value bigger ")
1093 ACE_TEXT ("then zero, it returned %d\n"), pagesize));
1094 return 1;
1096 else
1098 ACE_DEBUG ((LM_DEBUG,
1099 ACE_TEXT ("Pagesize returned %d\n"),
1100 pagesize));
1102 return 0;
1106 ace_ctype_test ()
1108 ACE_DEBUG ((LM_DEBUG,
1109 ACE_TEXT ("Testing ace ctype methods\n")));
1111 int retval = 0;
1112 int result = ACE_OS::ace_isprint (ACE_TEXT('\t'));
1113 if (result != 0)
1115 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isprint should return 0 for tab ")
1116 ACE_TEXT ("but it returned %d\n"), result));
1117 ++retval;
1119 result = ACE_OS::ace_isblank (ACE_TEXT('\t'));
1120 if (result == 0)
1122 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isblank should return != 0 for tab ")
1123 ACE_TEXT ("but it returned %d\n"), result));
1124 ++retval;
1126 result = ACE_OS::ace_isblank (ACE_TEXT(' '));
1127 if (result == 0)
1129 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isblank should return != 0 for space ")
1130 ACE_TEXT ("but it returned %d\n"), result));
1131 ++retval;
1133 result = ACE_OS::ace_isalpha (ACE_TEXT('\t'));
1134 if (result != 0)
1136 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isalpha should return 0 for tab ")
1137 ACE_TEXT ("but it returned %d\n"), result));
1138 ++retval;
1140 result = ACE_OS::ace_isupper (ACE_TEXT('\t'));
1141 if (result != 0)
1143 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isupper should return 0 for tab ")
1144 ACE_TEXT ("but it returned %d\n"), result));
1145 ++retval;
1147 result = ACE_OS::ace_islower (ACE_TEXT('\t'));
1148 if (result != 0)
1150 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_islower should return 0 for tab ")
1151 ACE_TEXT ("but it returned %d\n"), result));
1152 ++retval;
1154 result = ACE_OS::ace_isdigit (ACE_TEXT('\t'));
1155 if (result != 0)
1157 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isdigit should return 0 for tab ")
1158 ACE_TEXT ("but it returned %d\n"), result));
1159 ++retval;
1161 result = ACE_OS::ace_isxdigit (ACE_TEXT('\t'));
1162 if (result != 0)
1164 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isxdigit should return 0 for tab ")
1165 ACE_TEXT ("but it returned %d\n"), result));
1166 ++retval;
1168 result = ACE_OS::ace_isspace (ACE_TEXT('\t'));
1169 if (result == 0)
1171 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isspace should return != 0 for tab ")
1172 ACE_TEXT ("but it returned %d\n"), result));
1173 ++retval;
1175 result = ACE_OS::ace_ispunct (ACE_TEXT('\t'));
1176 if (result != 0)
1178 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_ispunct should return 0 for tab ")
1179 ACE_TEXT ("but it returned %d\n"), result));
1180 ++retval;
1182 result = ACE_OS::ace_isalnum (ACE_TEXT('\t'));
1183 if (result != 0)
1185 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isalnum should return 0 for tab ")
1186 ACE_TEXT ("but it returned %d\n"), result));
1187 ++retval;
1189 result = ACE_OS::ace_isgraph (ACE_TEXT('\t'));
1190 if (result != 0)
1192 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isgraph should return 0 for tab ")
1193 ACE_TEXT ("but it returned %d\n"), result));
1194 ++retval;
1196 result = ACE_OS::ace_iscntrl (ACE_TEXT('\t'));
1197 if (result == 0)
1199 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_iscntrl should return != 0 for tab ")
1200 ACE_TEXT ("but it returned %d\n"), result));
1201 ++retval;
1203 result = ACE_OS::ace_isascii (ACE_TEXT('\t'));
1204 if (result == 0)
1206 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isascii should return != 0 for tab ")
1207 ACE_TEXT ("but it returned %d\n"), result));
1208 ++retval;
1211 return 0;
1215 ceilf_test ()
1217 ACE_DEBUG ((LM_DEBUG,
1218 ACE_TEXT ("Testing ceilf method\n")));
1220 float const values[] = {-2.5, -1.5, 1.5, 2.5};
1221 float const results[] = {-2.0, -1.0, 2.0, 3.0};
1222 float result = 0.0;
1223 int error_count = 0;
1225 for (size_t i = 0 ; i < sizeof (values) / sizeof (float) ; i++)
1227 result = ACE_OS::ceil (values [i]);
1228 if (ACE::is_inequal(result, results[i]))
1230 ACE_ERROR ((LM_ERROR,
1231 ACE_TEXT ("ceilf error: input %.1F, output %1F, expected %1F\n"),
1232 values [i],
1233 result,
1234 results [i]));
1235 ++error_count;
1239 return error_count;
1243 floorf_test ()
1245 ACE_DEBUG ((LM_DEBUG,
1246 ACE_TEXT ("Testing floorf method\n")));
1248 float const values[] = {-2.5, -1.5, 1.5, 2.5};
1249 float const results[] = {-3.0, -2.0, 1.0, 2.0};
1250 float result = 0.0;
1251 int error_count = 0;
1253 for (size_t i = 0 ; i < sizeof (values) / sizeof (float) ; i++)
1255 result = ACE_OS::floor (values [i]);
1256 if (ACE::is_inequal(result, results[i]))
1258 ACE_ERROR ((LM_ERROR,
1259 ACE_TEXT ("floorf error: input %.1F, output %1F, expected %1F\n"),
1260 values [i], result, results [i]));
1261 ++error_count;
1265 return error_count;
1269 ceil_test ()
1271 ACE_DEBUG ((LM_DEBUG,
1272 ACE_TEXT ("Testing ceil method\n")));
1274 double const values[] = {-2.5, -1.5, 1.5, 2.5};
1275 double const results[] = {-2.0, -1.0, 2.0, 3.0};
1276 double result = 0.0;
1277 int error_count = 0;
1279 for (size_t i = 0 ; i < sizeof (values) / sizeof (double) ; i++)
1281 result = ACE_OS::ceil (values [i]);
1282 if (ACE::is_inequal(result, results[i]))
1284 ACE_ERROR ((LM_ERROR,
1285 ACE_TEXT ("ceil error: input %.1F, output %1F, expected %1F\n"),
1286 values [i],
1287 result,
1288 results [i]));
1289 ++error_count;
1293 return error_count;
1297 floor_test ()
1299 ACE_DEBUG ((LM_DEBUG,
1300 ACE_TEXT ("Testing floor method\n")));
1302 double const values[] = {-2.5, -1.5, 1.5, 2.5};
1303 double const results[] = {-3.0, -2.0, 1.0, 2.0};
1304 double result = 0.0;
1305 int error_count = 0;
1307 for (size_t i = 0 ; i < sizeof (values) / sizeof (double) ; i++)
1309 result = ACE_OS::floor (values [i]);
1310 if (ACE::is_inequal(result, results[i]))
1312 ACE_ERROR ((LM_ERROR,
1313 ACE_TEXT ("floor error: input %.1F, output %1F, expected %1F\n"),
1314 values [i],
1315 result,
1316 results [i]));
1317 ++error_count;
1321 return error_count;
1325 ceill_test ()
1327 ACE_DEBUG ((LM_DEBUG,
1328 ACE_TEXT ("Testing ceill method\n")));
1330 long double const values[] = {-2.5, -1.5, 1.5, 2.5};
1331 long double const results[] = {-2.0, -1.0, 2.0, 3.0};
1332 long double result = 0.0;
1333 int error_count = 0;
1335 for (size_t i = 0 ; i < sizeof (values) / sizeof (long double) ; i++)
1337 result = ACE_OS::ceil (values [i]);
1338 if (ACE::is_inequal(result, results[i]))
1340 ACE_ERROR ((LM_ERROR,
1341 ACE_TEXT ("ceil error: input %.1F, output %1F, expected %1F\n"),
1342 values [i],
1343 result,
1344 results [i]));
1345 ++error_count;
1349 return error_count;
1353 floorl_test ()
1355 ACE_DEBUG ((LM_DEBUG,
1356 ACE_TEXT ("Testing floorl method\n")));
1358 long double const values[] = {-2.5, -1.5, 1.5, 2.5};
1359 long double const results[] = {-3.0, -2.0, 1.0, 2.0};
1360 long double result = 0.0;
1361 int error_count = 0;
1363 for (size_t i = 0 ; i < sizeof (values) / sizeof (long double) ; i++)
1365 result = ACE_OS::floor (values [i]);
1366 if (ACE::is_inequal(result, results[i]))
1368 ACE_ERROR ((LM_ERROR,
1369 ACE_TEXT ("floor error: input %.1F, output %1F, expected %1F\n"),
1370 values [i], result, results [i]));
1371 ++error_count;
1375 return error_count;
1379 log2_test ()
1381 ACE_DEBUG ((LM_DEBUG,
1382 ACE_TEXT ("Testing log2 method\n")));
1384 double const values[] = {1.0, 2.0, 4.0, 8.0, 1048576.0};
1385 int const results[] = {0, 1, 2, 3, 20};
1386 int result = 0;
1387 int error_count = 0;
1389 for (size_t i = 0 ; i < sizeof (values) / sizeof (double) ; i++)
1391 result = static_cast<int> (ACE_OS::log2 (values [i]) + 0.5);
1392 if (result != results [i])
1394 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Log2 error: input %.1F, output %d, expected %d\n"), values [i], result, results [i]));
1395 ++error_count;
1399 return error_count;
1402 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1403 int snprintf_emulation (char *buf, size_t maxlen, const char *format, ...)
1405 va_list ap;
1406 va_start (ap, format);
1407 const int ret = ACE_OS::vsnprintf_emulation (buf, maxlen, format, ap);
1408 va_end (ap);
1409 return ret;
1412 #define TEST_STR_EQUAL(LHS, RHS) \
1413 if (ACE_OS::strcmp ((LHS), (RHS))) { \
1414 failed = true; \
1415 ACE_ERROR ((LM_ERROR, "Test assertion FAILED {%C} != {%C} at line %l\n", \
1416 (LHS), (RHS))); \
1419 #define TEST_INT_EQUAL(LHS, RHS) \
1420 if (!((LHS) == (RHS))) { \
1421 failed = true; \
1422 ACE_ERROR ((LM_ERROR, "Test assertion FAILED %d != %d at line %l\n", \
1423 (LHS), (RHS))); \
1426 #define EXPECTED_RESULT(STR) \
1427 TEST_INT_EQUAL (ACE_OS::strlen (STR), size_t (ret)) \
1428 TEST_STR_EQUAL (STR, buf)
1430 #define EXPECTED_RESULTS(STR_A, STR_B) \
1431 if (ACE_OS::strcmp ((STR_A), (buf)) && ACE_OS::strcmp ((STR_B), (buf))) { \
1432 failed = true; \
1433 ACE_ERROR ((LM_ERROR, "Test assertion FAILED {%C} != {%C} and " \
1434 "{%C} != {%C} at line %l\n", \
1435 (STR_A), (buf), (STR_B), (buf))); \
1438 #define EXPECTED_RESULT_LEN(STR, LEN) \
1439 TEST_INT_EQUAL (LEN, ret) \
1440 TEST_STR_EQUAL (STR, buf)
1442 #define LOG_RESULT(STR) \
1443 ACE_DEBUG ((LM_DEBUG, "Locale-dependent snprintf could be {%C}, was {%C}" \
1444 " at line %l\n", (STR), buf));
1446 int snprintf_emulation_test ()
1448 bool failed = false;
1449 char buf[BUFSIZ];
1451 int ret = snprintf_emulation (buf, sizeof buf, "[%d]", 314); EXPECTED_RESULT ("[314]");
1452 ret = snprintf_emulation (buf, sizeof buf, "[%i] %% [%u]", -314, 314); EXPECTED_RESULT ("[-314] % [314]");
1453 ret = snprintf_emulation (buf, sizeof buf, "%5d", 414); EXPECTED_RESULT (" 414");
1454 ret = snprintf_emulation (buf, sizeof buf, "%05d", 414); EXPECTED_RESULT ("00414");
1455 ret = snprintf_emulation (buf, sizeof buf, "%*d", 5, 414); EXPECTED_RESULT (" 414");
1456 ret = snprintf_emulation (buf, sizeof buf, "%-*d", 5, 414); EXPECTED_RESULT ("414 ");
1457 ret = snprintf_emulation (buf, sizeof buf, "%5i", -414); EXPECTED_RESULT (" -414");
1458 ret = snprintf_emulation (buf, sizeof buf, "%05i", -414); EXPECTED_RESULT ("-0414");
1459 ret = snprintf_emulation (buf, sizeof buf, "%2d", -414); EXPECTED_RESULT ("-414");
1460 ret = snprintf_emulation (buf, sizeof buf, "%.4d", -414); EXPECTED_RESULT ("-0414");
1461 ret = snprintf_emulation (buf, sizeof buf, "%6.4d", -314); EXPECTED_RESULT (" -0314");
1462 ret = snprintf_emulation (buf, sizeof buf, "%.4i", 314); EXPECTED_RESULT ("0314");
1463 ret = snprintf_emulation (buf, sizeof buf, "%6.4u", 414); EXPECTED_RESULT (" 0414");
1464 ret = snprintf_emulation (buf, sizeof buf, "%.d", 0); EXPECTED_RESULT ("");
1465 ret = snprintf_emulation (buf, sizeof buf, "% .0d", 0); EXPECTED_RESULT (" ");
1466 ret = snprintf_emulation (buf, sizeof buf, "%d", 0); EXPECTED_RESULT ("0");
1467 ret = snprintf_emulation (buf, sizeof buf, "%+d", 0); EXPECTED_RESULT ("+0");
1468 ret = snprintf_emulation (buf, sizeof buf, "% d", 0); EXPECTED_RESULT (" 0");
1470 ret = snprintf_emulation (buf, sizeof buf, "%04o", 0755); EXPECTED_RESULT ("0755");
1471 ret = snprintf_emulation (buf, sizeof buf, "%#o", 0644); EXPECTED_RESULT ("0644");
1472 ret = snprintf_emulation (buf, sizeof buf, "%#.o", 0); EXPECTED_RESULT ("0");
1473 ret = snprintf_emulation (buf, sizeof buf, "%#.5o", 0644); EXPECTED_RESULT ("00644");
1475 ret = snprintf_emulation (buf, sizeof buf, "%x", 0x987abc); EXPECTED_RESULT ("987abc");
1476 ret = snprintf_emulation (buf, sizeof buf, "%X", 0x987abc); EXPECTED_RESULT ("987ABC");
1477 ret = snprintf_emulation (buf, sizeof buf, "%02x", 0); EXPECTED_RESULT ("00");
1478 ret = snprintf_emulation (buf, sizeof buf, "%-#10x", 0x987abc); EXPECTED_RESULT ("0x987abc ");
1479 ret = snprintf_emulation (buf, sizeof buf, "%#10X", 0x987abc); EXPECTED_RESULT (" 0X987ABC");
1480 ret = snprintf_emulation (buf, sizeof buf, "%#X", 0); EXPECTED_RESULT ("0");
1481 ret = snprintf_emulation (buf, sizeof buf, "%#.X", 0); EXPECTED_RESULT ("");
1482 ret = snprintf_emulation (buf, sizeof buf, "%#05x", 20); EXPECTED_RESULT ("0x014");
1483 ret = snprintf_emulation (buf, sizeof buf, "%#.3X", 20); EXPECTED_RESULT ("0X014");
1484 ret = snprintf_emulation (buf, sizeof buf, "%#6.3X", 20); EXPECTED_RESULT (" 0X014");
1485 ret = snprintf_emulation (buf, sizeof buf, "%#-6.3X", 20); EXPECTED_RESULT ("0X014 ");
1487 ret = snprintf_emulation (buf, sizeof buf, "%c", 'a'); EXPECTED_RESULT ("a");
1488 ret = snprintf_emulation (buf, sizeof buf, "%2c", 'b'); EXPECTED_RESULT (" b");
1489 ret = snprintf_emulation (buf, sizeof buf, "%-2c", 'c'); EXPECTED_RESULT ("c ");
1490 ret = snprintf_emulation (buf, sizeof buf, "%-2s", "d"); EXPECTED_RESULT ("d ");
1491 ret = snprintf_emulation (buf, sizeof buf, "%2s", "e"); EXPECTED_RESULT (" e");
1492 ret = snprintf_emulation (buf, sizeof buf, "%2.1s", "fg"); EXPECTED_RESULT (" f");
1493 ret = snprintf_emulation (buf, sizeof buf, "%-2.1s", "gh"); EXPECTED_RESULT ("g ");
1494 ret = snprintf_emulation (buf, sizeof buf, "%.s", "x"); EXPECTED_RESULT ("");
1495 ret = snprintf_emulation (buf, sizeof buf, "%-4.9s", "hi"); EXPECTED_RESULT ("hi ");
1496 ret = snprintf_emulation (buf, sizeof buf, "%.s", "x"); EXPECTED_RESULT ("");
1498 int n;
1499 ret = snprintf_emulation (buf, sizeof buf, "%-5.2s%n %s", "jkl", &n, "lmn"); EXPECTED_RESULT ("jk lmn");
1500 ret = snprintf_emulation (buf, sizeof buf, "%0-3.2i", n); EXPECTED_RESULT ("05 ");
1502 ret = snprintf_emulation (buf, sizeof buf, "%p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT ("0x1234abc");
1503 ret = snprintf_emulation (buf, sizeof buf, "%12p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT (" 0x1234abc");
1504 ret = snprintf_emulation (buf, sizeof buf, "%-12p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT ("0x1234abc ");
1506 ret = snprintf_emulation (buf, sizeof buf, "%hhu", 0x101); EXPECTED_RESULT ("1");
1507 ret = snprintf_emulation (buf, sizeof buf, "%hu", 0x10002); EXPECTED_RESULT ("2");
1508 ret = snprintf_emulation (buf, sizeof buf, "%#lx", 0x87654321ul); EXPECTED_RESULT ("0x87654321");
1509 ret = snprintf_emulation (buf, sizeof buf, "%llu", 612578912487901265ull); EXPECTED_RESULT ("612578912487901265");
1511 ret = snprintf_emulation (buf, sizeof buf, "%-+010.7d", 98765); EXPECTED_RESULT ("+0098765 ");
1512 ret = snprintf_emulation (buf, 10, "%-+010.7d", 98765); EXPECTED_RESULT_LEN ("+0098765 ", 10);
1514 ret = snprintf_emulation (buf, sizeof buf, "%f", 3.14); EXPECTED_RESULT ("3.140000");
1515 ret = snprintf_emulation (buf, sizeof buf, "%10f", -3.14); EXPECTED_RESULT (" -3.140000");
1516 ret = snprintf_emulation (buf, sizeof buf, "%+-10F", 3.14); EXPECTED_RESULT ("+3.140000 ");
1517 ret = snprintf_emulation (buf, sizeof buf, "%010f", -3.14); EXPECTED_RESULT ("-03.140000");
1518 ret = snprintf_emulation (buf, sizeof buf, "% f", 3.14); EXPECTED_RESULT (" 3.140000");
1519 ret = snprintf_emulation (buf, sizeof buf, "% f", HUGE_VAL); EXPECTED_RESULT (" inf");
1520 ret = snprintf_emulation (buf, sizeof buf, "%f", -HUGE_VAL); EXPECTED_RESULT ("-inf");
1521 ret = snprintf_emulation (buf, sizeof buf, "%#F", HUGE_VAL); EXPECTED_RESULT ("INF");
1522 ret = snprintf_emulation (buf, sizeof buf, "%5F", -HUGE_VAL); EXPECTED_RESULT (" -INF");
1523 #ifndef ACE_LYNXOS_MAJOR
1524 ret = snprintf_emulation (buf, sizeof buf, "%f", std::numeric_limits<double>::quiet_NaN ()); EXPECTED_RESULTS ("nan", "-nan");
1525 ret = snprintf_emulation (buf, sizeof buf, "%+F", std::numeric_limits<double>::quiet_NaN ()); EXPECTED_RESULTS ("+NAN", "-NAN");
1526 #endif
1527 ret = snprintf_emulation (buf, sizeof buf, "%.f", 2.17); EXPECTED_RESULT ("2");
1528 ret = snprintf_emulation (buf, sizeof buf, "%#.f", 2.17); EXPECTED_RESULT ("2.");
1529 ret = snprintf_emulation (buf, sizeof buf, "%.1f", 18.); EXPECTED_RESULT ("18.0");
1530 ret = snprintf_emulation (buf, sizeof buf, "%.1f", .9); EXPECTED_RESULT ("0.9");
1531 ret = snprintf_emulation (buf, sizeof buf, "%.2f", .01); EXPECTED_RESULT ("0.01");
1533 ret = snprintf_emulation (buf, sizeof buf, "%.2e", .01); EXPECTED_RESULT ("1.00e-02");
1534 ret = snprintf_emulation (buf, sizeof buf, "%#.E", .01); EXPECTED_RESULT ("1.E-02");
1535 ret = snprintf_emulation (buf, sizeof buf, "%+.E", .01); EXPECTED_RESULT ("+1E-02");
1536 ret = snprintf_emulation (buf, sizeof buf, "%e", 3.14159265); EXPECTED_RESULT ("3.141592e+00");
1537 ret = snprintf_emulation (buf, sizeof buf, "% .e", 0.); EXPECTED_RESULT (" 0e+00");
1538 ret = snprintf_emulation (buf, sizeof buf, "% -8.e", 0.); EXPECTED_RESULT (" 0e+00 ");
1540 #if !defined _MSC_VER || ACE_CC_MAJOR_VERSION > 7
1541 ret = snprintf_emulation (buf, sizeof buf, "% -11.2e", -0.); EXPECTED_RESULT ("-0.00e+00 ");
1542 #endif
1544 ret = snprintf_emulation (buf, sizeof buf, "%.E", 9e101); EXPECTED_RESULTS ("9E+101", "8E+101"); // could be rounded
1546 ret = snprintf_emulation (buf, sizeof buf, "%g", 3.); EXPECTED_RESULT ("3");
1547 ret = snprintf_emulation (buf, sizeof buf, "%g", 3.000001); EXPECTED_RESULT ("3");
1548 ret = snprintf_emulation (buf, sizeof buf, "%.6g", 3.000001); EXPECTED_RESULT ("3");
1549 ret = snprintf_emulation (buf, sizeof buf, "%G", 3000000.1); EXPECTED_RESULT ("3E+06");
1550 ret = snprintf_emulation (buf, sizeof buf, "%+#g", 3000000.1); EXPECTED_RESULT ("+3.00000e+06");
1551 ret = snprintf_emulation (buf, sizeof buf, "%G", -3000010.); EXPECTED_RESULTS ("-3.00001E+06", "-3E+06");
1552 ret = snprintf_emulation (buf, sizeof buf, "%g", .0001); EXPECTED_RESULT ("0.0001");
1553 ret = snprintf_emulation (buf, sizeof buf, "%- g", .00001); EXPECTED_RESULT (" 1e-05");
1555 ret = snprintf_emulation (buf, sizeof buf, "%a", 4.); EXPECTED_RESULT ("0x8p-1");
1556 ret = snprintf_emulation (buf, sizeof buf, "%#a", 4.); EXPECTED_RESULT ("0x8.p-1");
1557 ret = snprintf_emulation (buf, sizeof buf, "%A", -3.125); EXPECTED_RESULT ("-0XC.8P-2");
1558 ret = snprintf_emulation (buf, sizeof buf, "%+a", 0.); EXPECTED_RESULT ("+0x0p+0");
1559 ret = snprintf_emulation (buf, sizeof buf, "%+-10.1a", 0.); EXPECTED_RESULT ("+0x0.0p+0 ");
1560 ret = snprintf_emulation (buf, sizeof buf, "%0+10.1a", 0.); EXPECTED_RESULT ("+0x00.0p+0");
1561 ret = snprintf_emulation (buf, sizeof buf, "% 09A", 16.625); EXPECTED_RESULT (" 0X8.5P+1");
1562 ret = snprintf_emulation (buf, sizeof buf, "% 010a", 16.625); EXPECTED_RESULT (" 0x08.5p+1");
1564 ret = snprintf_emulation (buf, sizeof buf, "%%%d%#x", 1, 2); EXPECTED_RESULT ("%10x2");
1565 ret = snprintf_emulation (buf, sizeof buf, "foo %%%% bar"); EXPECTED_RESULT ("foo %% bar");
1566 ret = snprintf_emulation (buf, sizeof buf, ""); EXPECTED_RESULT ("");
1567 ret = snprintf_emulation (buf, sizeof buf, "foo"); EXPECTED_RESULT ("foo");
1569 ret = snprintf_emulation (buf, sizeof buf, "%'d", 12345); LOG_RESULT ("12,345");
1570 ret = snprintf_emulation (buf, sizeof buf, "%'d", 123456); LOG_RESULT ("123,456");
1571 ret = snprintf_emulation (buf, sizeof buf, "%'d", 1234567890); LOG_RESULT ("1,234,567,890");
1572 ret = snprintf_emulation (buf, sizeof buf, "%'.f", 12345.); LOG_RESULT ("12,345");
1573 ret = snprintf_emulation (buf, sizeof buf, "%'.f", 1234567890.); LOG_RESULT ("1,234,567,890");
1574 ret = snprintf_emulation (buf, sizeof buf, "%'.6d", 12345); LOG_RESULT ("012,345");
1575 ret = snprintf_emulation (buf, sizeof buf, "%0'8d", 12345); LOG_RESULT ("0012,345");
1577 ret = snprintf_emulation (buf, sizeof buf, "a%%b%2$*3$.*1$s %%%%%%%4$*3$.*1$s", 3, "cdef", 4, "fgh"); EXPECTED_RESULT ("a%b cde %%% fgh");
1578 ret = snprintf_emulation (buf, sizeof buf, "%3$d %6$d %5$d %4$d %8$d %9$d %7$d %1$d %2$d %10$d %11$d", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); EXPECTED_RESULT ("3 6 5 4 8 9 7 1 2 10 11");
1579 ret = snprintf_emulation (buf, sizeof buf, "%2$0*1$d %3$.*1$f %1$.*2$d", 3, 2, 3.1); EXPECTED_RESULT ("002 3.100 03");
1580 ret = snprintf_emulation (buf, sizeof buf, "%2$#*1$x", -4, 10); EXPECTED_RESULT ("0xa ");
1582 return failed ? 1 : 0;
1584 #endif // ACE_HAS_VSNPRINTF_EMULATION
1587 swab_test ()
1589 ACE_DEBUG ((LM_DEBUG,
1590 ACE_TEXT ("Testing swab method\n")));
1592 int error_count = 0;
1593 char const from[] = "BADCFEHGJILKNMPORQTSVUXWZY";
1594 char to[] = "..........................";
1595 char expect[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1597 ACE_OS::swab (from, to, sizeof (from));
1598 if (ACE_OS::strcmp (to, expect) != 0)
1600 ACE_ERROR ((LM_ERROR,
1601 ACE_TEXT ("swab error: %C, expected %C\n"),
1602 to, expect));
1603 ++error_count;
1606 return error_count;
1610 gai_strerror_test ()
1612 ACE_DEBUG ((LM_DEBUG,
1613 ACE_TEXT ("Testing gai_strerror method\n")));
1615 const ACE_TCHAR* error_text = ACE_OS::gai_strerror (EAI_FAMILY);
1617 ACE_UNUSED_ARG (error_text);
1619 return 0;
1623 run_main (int, ACE_TCHAR *[])
1625 ACE_START_TEST (ACE_TEXT ("OS_Test"));
1627 // Enable a locale that has digit grouping so that snprintf's %'d is
1628 // different than %d. If the locale is not available the test won't
1629 // fail (log file needs to be examined to check formatting).
1630 #ifdef ACE_WIN32
1631 std::setlocale(LC_NUMERIC, "en-US");
1632 #elif defined ACE_LINUX
1633 std::setlocale(LC_NUMERIC, "en_US.utf8");
1634 #endif
1636 int status = 0;
1637 int result;
1639 if ((result = access_test ()) != 0)
1640 status = result;
1642 if ((result = rename_test ()) != 0)
1643 status = result;
1645 if ((result = string_emulation_test ()) != 0)
1646 status = result;
1648 if ((result = snprintf_test (ACE_OS::snprintf)) != 0)
1649 status = result;
1651 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1652 if ((result = snprintf_test (snprintf_emulation)) != 0)
1653 status = result;
1655 if ((result = snprintf_emulation_test ()) != 0)
1656 status = result;
1657 #endif
1659 if ((result = getpwnam_r_test ()) != 0)
1660 status = result;
1662 if ((result = ctime_r_test ()) != 0)
1663 status = result;
1665 if ((result = string_strsncpy_test ()) != 0)
1666 status = result;
1668 if ((result = strsignal_test ()) != 0)
1669 status = result;
1671 if ((result = cpu_info_test ()) != 0)
1672 status = result;
1674 if ((result = pagesize_test ()) != 0)
1675 status = result;
1677 if ((result = ceilf_test ()) != 0)
1678 status = result;
1680 if ((result = floorf_test ()) != 0)
1681 status = result;
1683 if ((result = ceil_test ()) != 0)
1684 status = result;
1686 if ((result = floor_test ()) != 0)
1687 status = result;
1689 if ((result = ceill_test ()) != 0)
1690 status = result;
1692 if ((result = floorl_test ()) != 0)
1693 status = result;
1695 if ((result = log2_test ()) != 0)
1696 status = result;
1698 if ((result = last_error_test ()) != 0)
1699 status = result;
1701 if ((result = ace_ctype_test ()) != 0)
1702 status = result;
1704 if ((result = swab_test ()) != 0)
1705 status = result;
1707 if ((result = compiler_test ()) != 0)
1708 status = result;
1710 if ((result = version_test ()) != 0)
1711 status = result;
1713 if ((result = gai_strerror_test ()) != 0)
1714 status = result;
1716 ACE_END_TEST;
1717 return status;
1719 #undef THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL