1 // ============================================================================
7 // This simple test exercises and illustrates use of OS wrapper functions.
10 // Steve Huston <shuston@riverace.com>
12 // ============================================================================
14 #include "test_config.h"
16 //FUZZ: disable check_for_include_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"
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) \
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.
47 ACE_TEXT ("Testing access method\n")));
51 int status
= ACE_OS::access (ACE_TEXT ("missing_file.txt"), F_OK
);
55 ACE_ERROR_RETURN ((LM_INFO
,
56 ACE_TEXT ("ACE_OS::access() not supported\n")),
61 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Missing file noted as present.\n")));
68 // Test ACE_OS::rename to be sure the files come and go as expected.
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")),
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
89 FILE *f
= ACE_OS::fopen (old_file
, ACE_TEXT ("w+"));
91 ACE_ERROR_RETURN ((LM_ERROR
,
92 ACE_TEXT ("%s: %p\n"),
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
);
99 f
= ACE_OS::fopen (new_file
, ACE_TEXT ("w+"));
102 ACE_OS::unlink (old_file
);
103 ACE_ERROR_RETURN ((LM_ERROR
,
104 ACE_TEXT ("%s: %p\n"),
111 #if defined (ACE_WIN32) && defined (ACE_LACKS_WIN32_MOVEFILEEX) || defined (ACE_HAS_WINCE)
112 // Can't rename if new_file exists already.
113 ACE_OS::unlink (new_file
);
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
);
123 // Verify that the old file was really renamed.
126 if (ACE_OS::stat (new_file
, &checking
) == -1 || checking
.st_size
== 0)
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)
135 ACE_ERROR ((LM_ERROR
,
136 ACE_TEXT ("Rename test 1: old_file still there\n")));
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
);
150 if (ACE_OS::stat (old_file
, &checking
) == -1 || checking
.st_size
== 0)
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)
159 ACE_ERROR ((LM_ERROR
,
160 ACE_TEXT ("Rename test 2: old_file still there\n")));
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")));
174 ACE_ERROR ((LM_ERROR
,
175 ACE_TEXT ("Rename expected fail, but succeeded\n")));
179 #endif /* ACE_VXWORKS */
184 string_emulation_test ()
187 // ========================================================================
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),
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 // ========================================================================
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 // ========================================================================
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 // ========================================================================
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 // ========================================================================
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 // ========================================================================
246 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Testing strtok_r\n")));
248 char strtok_r1
[] = "A string of tokens";
251 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (strtok_r1
,
255 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (0,
259 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (0,
263 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::strtok_r (0,
267 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strtok_r (0, " ", &strtok_r2
) == 0);
269 // ========================================================================
271 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Testing itoa\n")));
275 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itoa1
, 2),
278 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itoa1
, 3),
281 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (42, itoa1
, 16),
284 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (8, itoa1
, 10),
287 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (-8, itoa1
, 10),
290 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (20345, itoa1
, 10),
293 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (-20345, itoa1
, 10),
296 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (4566733, itoa1
, 10),
299 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (ACE_OS::itoa (-4566733, itoa1
, 10),
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
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");
350 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
351 (ACE_OS::strcmp (ACE_OS::strcpy (strcpy2
, strcpy1
),
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
),
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),
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'))
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"),
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"))
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'))
465 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strrchr (strrchr1
, ACE_TEXT_WIDE ('1'))
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
,
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")));
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 */
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")));
589 const int BUFFER_SIZE
= 4;
590 char buf
[2*BUFFER_SIZE
];
593 ACE_OS::memset(buf
, 0xab, 2*BUFFER_SIZE
);
594 retval
= fn (buf
, BUFFER_SIZE
, "%d", 123);
597 ACE_ERROR ((LM_ERROR
,
598 ACE_TEXT ("[1] ACE_OS::snprintf() returns %d, should be 3\n"),
603 ACE_OS::memset(buf
, 0xab, 2*BUFFER_SIZE
);
604 retval
= fn (buf
, BUFFER_SIZE
, "%d", 1234);
606 // HP-UX has broken vsnprintf
610 ACE_ERROR ((LM_ERROR
,
611 ACE_TEXT ("[2] ACE_OS::snprintf() returns %d, should be 4\n"),
619 ACE_ERROR ((LM_ERROR
,
620 ACE_TEXT ("[3] ACE_OS::snprintf() doesn't terminate string correctly\n")));
623 else if (ACE_OS::strcmp(buf
, "123") != 0)
625 ACE_ERROR ((LM_ERROR
,
626 ACE_TEXT ("[4] ACE_OS::snprintf() incorrect output\n")));
630 ACE_OS::memset(buf
, 0xab, 2*BUFFER_SIZE
);
631 retval
= fn (buf
, BUFFER_SIZE
, "%d", 12345);
634 ACE_ERROR ((LM_ERROR
,
635 ACE_TEXT ("[5] ACE_OS::snprintf() returns %d, should be 5\n"),
639 else if (buf
[3] != 0)
641 ACE_ERROR ((LM_ERROR
,
642 ACE_TEXT ("[6] ACE_OS::snprintf() doesn't terminate string correctly\n")));
645 else if (ACE_OS::strcmp(buf
, "123") != 0)
647 ACE_ERROR ((LM_ERROR
,
648 ACE_TEXT ("[6] ACE_OS::snprintf() incorrect output\n")));
660 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
661 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Testing getpwnam_r\n")));
664 struct passwd
*pwd_ptr
;
667 const char* login
= getlogin ();
671 if (ACE_OS::getpwnam_r (login
,
678 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("getpwnam_r() failed\n")));
682 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT (" User '%s' has uid=%d and gid=%d\n"),
683 pwd_ptr
->pw_name
, pwd_ptr
->pw_uid
, pwd_ptr
->pw_gid
));
693 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Testing compiler methods\n")));
695 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Using compiler %s with major version %d minor version %d beta version %d\n"),
696 ACE::compiler_name(),
697 ACE::compiler_major_version(),
698 ACE::compiler_minor_version (),
699 ACE::compiler_beta_version ()));
707 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Testing version macros\n")));
709 int const code
= ACE_MAKE_VERSION_CODE(ACE_MAJOR_VERSION
, ACE_MINOR_VERSION
, ACE_MICRO_VERSION
);
710 bool const run_time_check
= code
== ACE_VERSION_CODE
;
711 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("ACE release time version code: %d, runtime version code: %d, %s\n"),
712 ACE_VERSION_CODE
, code
, run_time_check
? ACE_TEXT ("OK") : ACE_TEXT ("FAIL")));
714 // Compile time check. Check we have ACE version 6.x
715 #if ACE_VERSION_CODE > ACE_MAKE_VERSION_CODE(5, 88, 99)
716 bool const compile_time_check
= true;
718 bool compile_time_check
= false;
721 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Compile time version check, %s\n"),
722 compile_time_check
? ACE_TEXT ("OK") : ACE_TEXT ("FAIL")));
724 if(run_time_check
&& compile_time_check
)
732 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Testing ctime_r\n")));
736 // test 'normal' buffer
740 ACE_Time_Value cur_time
=
741 ACE_OS::gettimeofday ();
743 time_t const secs
= cur_time
.sec ();
744 if (ACE_OS::ctime_r (&secs
, buf
, 26) == 0)
746 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("%p\n"),
747 ACE_TEXT ("ctime_r with 26 bytes")));
750 else if (buf
[0] == '\0')
754 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Truncated input buffer\n")));
756 else if (buf
[26] != 'Z')
759 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Wrote past end of input buffer\n")));
762 // test small buffer - should not do anything unless 3rd arg is at least 26.
765 ACE_TCHAR bufcheck
[27];
766 ACE_OS::strcpy (bufcheck
, buf
);
767 if (ACE_OS::ctime_r (&secs
, buf
, 10) != 0)
769 ACE_ERROR ((LM_ERROR
,
770 ACE_TEXT ("ctime_r with short len returned %s\n"),
774 else if (errno
!= ERANGE
)
776 ACE_ERROR ((LM_ERROR
,
778 ACE_TEXT ("ctime_r short; wrong error")));
781 // Make sure it didn't scribble
782 else if (ACE_OS::strcmp (buf
, bufcheck
) != 0)
785 ACE_ERROR ((LM_ERROR
,
786 ACE_TEXT ("ctime_r short; got %s, expected %s\n"),
796 string_strsncpy_test ()
799 //FUZZ: disable check_for_lack_ACE_OS
800 // Test strsncpy (char version)
801 ACE_DEBUG ((LM_DEBUG
,
802 ACE_TEXT ("Testing strsncpy (char version)\n")));
803 //FUZZ: enable check_for_lack_ACE_OS
805 char const strsncpy1
[] = "abcdefghijklmnopqrstuvwxyzabc";
808 // strsncpy() where the max. length doesn't matter
809 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
810 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2
,
815 // strsncpy() where the max length does matter
816 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
817 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2
,
823 // strsncpy1 and strsncpy2 are different size --> not equal
824 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strsncpy2
, strsncpy1
) != 0);
826 // max. length == 2 --> 1 char available
827 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
828 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2
,
834 // max length == 1 --> empty string
835 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
836 (ACE_OS::strlen (ACE_OS::strsncpy (strsncpy2
,
840 // just preparation for the next assert
841 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
842 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2
,
847 // A tricky one, if the max. length == 0 --> do nothing
848 // so the strsncpy2 shouldn't change
849 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
850 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2
,
855 // If src == dst --> truncate dst if needed!
856 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
857 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2
,
862 // size should be 9 (+ '\0' char)
863 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL(ACE_OS::strlen(strsncpy2
) == 9);
866 #if defined (ACE_HAS_WCHAR)
868 //FUZZ: disable check_for_lack_ACE_OS
869 // Test strsncpy (wchar_t version)
870 ACE_DEBUG ((LM_DEBUG
,
871 ACE_TEXT ("Testing strsncpy (wchar_t version)\n")));
872 //FUZZ: enable check_for_lack_ACE_OS
874 wchar_t const strsncpy1
[] = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyzabc");
875 wchar_t strsncpy2
[36];
877 // strsncpy() where the max. length doesn't matter
878 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
879 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2
,
884 // strsncpy() where the max length does matter
885 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
886 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2
,
892 // strsncpy1 and strsncpy2 are different size --> not equal
893 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strsncpy2
, strsncpy1
) != 0);
895 // max. length == 2 --> 1 char available
896 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
897 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2
,
903 // max length == 1 --> empty string
904 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
905 (ACE_OS::strlen (ACE_OS::strsncpy (strsncpy2
,
909 // just preparation for the next assert
910 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
911 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2
,
916 // A tricky one, if the max. length == 0 --> do nothing
917 // so the strsncpy2 shouldn't change
918 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
919 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2
,
925 // If src == dst --> truncate dst if needed!
926 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
927 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2
,
932 // size should be 9 (+ '\0' char)
933 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL(ACE_OS::strlen(strsncpy2
) == 9);
935 #endif /* ACE_HAS_WCHAR */
941 // Test conversion between narrow and wide chars.
943 string_convert_test ()
945 #if defined (ACE_HAS_WCHAR)
946 ACE_DEBUG ((LM_DEBUG
,
947 ACE_TEXT ("Testing narrow/wide string conversion\n")));
950 const char *test1_n
= "abcdefg";
951 const wchar_t *test1_w
= ACE_TEXT_WIDE ("abcdefg");
952 const char *test2_n
= "\xe9\xe8\xe0\xf9\xea";
953 const wchar_t *test2_w
= ACE_TEXT_WIDE ("\xe9\xe8\xe0\xf9\xea");
956 ACE_OS::strcpy (str_w
, ACE_Ascii_To_Wide (test1_n
).wchar_rep ());
957 if (0 != ACE_OS::strcmp (test1_w
, str_w
))
959 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Simple narrow->wide failed: ")
960 ACE_TEXT ("Expected \"%W\"; Got \"%W\"\n"), test1_w
, str_w
));
963 ACE_OS::strcpy (str_n
, ACE_Wide_To_Ascii (test1_w
).char_rep ());
964 if (0 != ACE_OS::strcmp (test1_n
, str_n
))
966 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Simple wide->narrow failed: ")
967 ACE_TEXT ("Expected \"%C\"; Got \"%C\"\n"), test1_n
, str_n
));
970 ACE_OS::strcpy (str_w
, ACE_Ascii_To_Wide (test2_n
).wchar_rep ());
971 if (0 != ACE_OS::strcmp (test2_w
, str_w
))
973 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Complex narrow->wide failed: ")
974 ACE_TEXT ("Expected \"%W\"; Got \"%W\"\n"), test2_w
, str_w
));
977 ACE_OS::strcpy (str_n
, ACE_Wide_To_Ascii (test2_w
).char_rep ());
978 if (0 != ACE_OS::strcmp (test2_n
, str_n
))
980 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Complex wide->narrow failed: ")
981 ACE_TEXT ("Expected \"%C\"; Got \"%C\"\n"), test2_n
, str_n
));
987 #endif /* ACE_HAS_WCHAR */
990 // Test ACE_OS::strsignal()
994 ACE_DEBUG ((LM_DEBUG
,
995 ACE_TEXT ("Testing strsignal method\n")));
999 const char* result
= 0;
1001 for (int i
=-1; i
< (ACE_NSIG
+ 1); ++i
)
1003 result
= ACE_OS::strsignal (i
);
1006 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("strsignal returned null\n")));
1011 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT (" Sig #%d: %C\n"), i
, result
));
1018 // Test the methods for getting cpu info
1022 ACE_DEBUG ((LM_DEBUG
,
1023 ACE_TEXT ("Testing cpu info methods\n")));
1025 long const number_processors
= ACE_OS::num_processors();
1026 long const number_processors_online
= ACE_OS::num_processors_online();
1028 if (number_processors
== -1)
1030 ACE_ERROR ((LM_INFO
,
1031 ACE_TEXT ("number of processors not supported on ")
1032 ACE_TEXT ("this platform\n")));
1036 ACE_DEBUG ((LM_DEBUG
,
1037 ACE_TEXT ("This system has %d processors\n"),
1038 number_processors
));
1041 if (number_processors_online
== -1)
1043 ACE_ERROR ((LM_INFO
,
1044 ACE_TEXT ("number of processors online not supported on ")
1045 ACE_TEXT ("this platform\n")));
1049 ACE_DEBUG ((LM_DEBUG
,
1050 ACE_TEXT ("This system has %d processors online\n"),
1051 number_processors_online
));
1054 if ((number_processors_online
!= -1 && number_processors
!= -1) &&
1055 number_processors_online
> number_processors
)
1056 ACE_ERROR_RETURN ((LM_ERROR
,
1057 ACE_TEXT ("%d online processors; should be <= %d\n"),
1058 number_processors_online
,
1068 ACE_DEBUG ((LM_DEBUG
,
1069 ACE_TEXT ("Testing last_error method\n")));
1071 ACE_OS::last_error (ETIME
);
1073 int const l_error
= ACE_OS::last_error ();
1074 if (l_error
!= ETIME
)
1076 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Last error returned %d instead of ETIME"),
1081 ACE_OS::last_error (0);
1089 ACE_DEBUG ((LM_DEBUG
,
1090 ACE_TEXT ("Testing getpagesize method\n")));
1092 long const pagesize
= ACE_OS::getpagesize ();
1095 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, pagesize should return a value bigger ")
1096 ACE_TEXT ("then zero, it returned %d\n"), pagesize
));
1101 ACE_DEBUG ((LM_DEBUG
,
1102 ACE_TEXT ("Pagesize returned %d\n"),
1111 ACE_DEBUG ((LM_DEBUG
,
1112 ACE_TEXT ("Testing ace ctype methods\n")));
1115 int result
= ACE_OS::ace_isprint (ACE_TEXT('\t'));
1118 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isprint should return 0 for tab ")
1119 ACE_TEXT ("but it returned %d\n"), result
));
1122 result
= ACE_OS::ace_isblank (ACE_TEXT('\t'));
1125 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isblank should return != 0 for tab ")
1126 ACE_TEXT ("but it returned %d\n"), result
));
1129 result
= ACE_OS::ace_isblank (ACE_TEXT(' '));
1132 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isblank should return != 0 for space ")
1133 ACE_TEXT ("but it returned %d\n"), result
));
1136 result
= ACE_OS::ace_isalpha (ACE_TEXT('\t'));
1139 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isalpha should return 0 for tab ")
1140 ACE_TEXT ("but it returned %d\n"), result
));
1143 result
= ACE_OS::ace_isupper (ACE_TEXT('\t'));
1146 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isupper should return 0 for tab ")
1147 ACE_TEXT ("but it returned %d\n"), result
));
1150 result
= ACE_OS::ace_islower (ACE_TEXT('\t'));
1153 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_islower should return 0 for tab ")
1154 ACE_TEXT ("but it returned %d\n"), result
));
1157 result
= ACE_OS::ace_isdigit (ACE_TEXT('\t'));
1160 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isdigit should return 0 for tab ")
1161 ACE_TEXT ("but it returned %d\n"), result
));
1164 result
= ACE_OS::ace_isxdigit (ACE_TEXT('\t'));
1167 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isxdigit should return 0 for tab ")
1168 ACE_TEXT ("but it returned %d\n"), result
));
1171 result
= ACE_OS::ace_isspace (ACE_TEXT('\t'));
1174 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isspace should return != 0 for tab ")
1175 ACE_TEXT ("but it returned %d\n"), result
));
1178 result
= ACE_OS::ace_ispunct (ACE_TEXT('\t'));
1181 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_ispunct should return 0 for tab ")
1182 ACE_TEXT ("but it returned %d\n"), result
));
1185 result
= ACE_OS::ace_isalnum (ACE_TEXT('\t'));
1188 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isalnum should return 0 for tab ")
1189 ACE_TEXT ("but it returned %d\n"), result
));
1192 result
= ACE_OS::ace_isgraph (ACE_TEXT('\t'));
1195 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isgraph should return 0 for tab ")
1196 ACE_TEXT ("but it returned %d\n"), result
));
1199 result
= ACE_OS::ace_iscntrl (ACE_TEXT('\t'));
1202 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_iscntrl should return != 0 for tab ")
1203 ACE_TEXT ("but it returned %d\n"), result
));
1206 result
= ACE_OS::ace_isascii (ACE_TEXT('\t'));
1209 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Error, ace_isascii should return != 0 for tab ")
1210 ACE_TEXT ("but it returned %d\n"), result
));
1220 ACE_DEBUG ((LM_DEBUG
,
1221 ACE_TEXT ("Testing ceilf method\n")));
1223 float const values
[] = {-2.5, -1.5, 1.5, 2.5};
1224 float const results
[] = {-2.0, -1.0, 2.0, 3.0};
1226 int error_count
= 0;
1228 for (size_t i
= 0 ; i
< sizeof (values
) / sizeof (float) ; i
++)
1230 result
= ACE_OS::ceil (values
[i
]);
1231 if (ACE::is_inequal(result
, results
[i
]))
1233 ACE_ERROR ((LM_ERROR
,
1234 ACE_TEXT ("ceilf error: input %.1F, output %1F, expected %1F\n"),
1248 ACE_DEBUG ((LM_DEBUG
,
1249 ACE_TEXT ("Testing floorf method\n")));
1251 float const values
[] = {-2.5, -1.5, 1.5, 2.5};
1252 float const results
[] = {-3.0, -2.0, 1.0, 2.0};
1254 int error_count
= 0;
1256 for (size_t i
= 0 ; i
< sizeof (values
) / sizeof (float) ; i
++)
1258 result
= ACE_OS::floor (values
[i
]);
1259 if (ACE::is_inequal(result
, results
[i
]))
1261 ACE_ERROR ((LM_ERROR
,
1262 ACE_TEXT ("floorf error: input %.1F, output %1F, expected %1F\n"),
1263 values
[i
], result
, results
[i
]));
1274 ACE_DEBUG ((LM_DEBUG
,
1275 ACE_TEXT ("Testing ceil method\n")));
1277 double const values
[] = {-2.5, -1.5, 1.5, 2.5};
1278 double const results
[] = {-2.0, -1.0, 2.0, 3.0};
1279 double result
= 0.0;
1280 int error_count
= 0;
1282 for (size_t i
= 0 ; i
< sizeof (values
) / sizeof (double) ; i
++)
1284 result
= ACE_OS::ceil (values
[i
]);
1285 if (ACE::is_inequal(result
, results
[i
]))
1287 ACE_ERROR ((LM_ERROR
,
1288 ACE_TEXT ("ceil error: input %.1F, output %1F, expected %1F\n"),
1302 ACE_DEBUG ((LM_DEBUG
,
1303 ACE_TEXT ("Testing floor method\n")));
1305 double const values
[] = {-2.5, -1.5, 1.5, 2.5};
1306 double const results
[] = {-3.0, -2.0, 1.0, 2.0};
1307 double result
= 0.0;
1308 int error_count
= 0;
1310 for (size_t i
= 0 ; i
< sizeof (values
) / sizeof (double) ; i
++)
1312 result
= ACE_OS::floor (values
[i
]);
1313 if (ACE::is_inequal(result
, results
[i
]))
1315 ACE_ERROR ((LM_ERROR
,
1316 ACE_TEXT ("floor error: input %.1F, output %1F, expected %1F\n"),
1330 ACE_DEBUG ((LM_DEBUG
,
1331 ACE_TEXT ("Testing ceill method\n")));
1333 long double const values
[] = {-2.5, -1.5, 1.5, 2.5};
1334 long double const results
[] = {-2.0, -1.0, 2.0, 3.0};
1335 long double result
= 0.0;
1336 int error_count
= 0;
1338 for (size_t i
= 0 ; i
< sizeof (values
) / sizeof (long double) ; i
++)
1340 result
= ACE_OS::ceil (values
[i
]);
1341 if (ACE::is_inequal(result
, results
[i
]))
1343 ACE_ERROR ((LM_ERROR
,
1344 ACE_TEXT ("ceil error: input %.1F, output %1F, expected %1F\n"),
1358 ACE_DEBUG ((LM_DEBUG
,
1359 ACE_TEXT ("Testing floorl method\n")));
1361 long double const values
[] = {-2.5, -1.5, 1.5, 2.5};
1362 long double const results
[] = {-3.0, -2.0, 1.0, 2.0};
1363 long double result
= 0.0;
1364 int error_count
= 0;
1366 for (size_t i
= 0 ; i
< sizeof (values
) / sizeof (long double) ; i
++)
1368 result
= ACE_OS::floor (values
[i
]);
1369 if (ACE::is_inequal(result
, results
[i
]))
1371 ACE_ERROR ((LM_ERROR
,
1372 ACE_TEXT ("floor error: input %.1F, output %1F, expected %1F\n"),
1373 values
[i
], result
, results
[i
]));
1384 ACE_DEBUG ((LM_DEBUG
,
1385 ACE_TEXT ("Testing log2 method\n")));
1387 double const values
[] = {1.0, 2.0, 4.0, 8.0, 1048576.0};
1388 int const results
[] = {0, 1, 2, 3, 20};
1390 int error_count
= 0;
1392 for (size_t i
= 0 ; i
< sizeof (values
) / sizeof (double) ; i
++)
1394 result
= static_cast<int> (ACE_OS::log2 (values
[i
]) + 0.5);
1395 if (result
!= results
[i
])
1397 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Log2 error: input %.1F, output %d, expected %d\n"), values
[i
], result
, results
[i
]));
1405 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1406 int snprintf_emulation (char *buf
, size_t maxlen
, const char *format
, ...)
1409 va_start (ap
, format
);
1410 const int ret
= ACE_OS::vsnprintf_emulation (buf
, maxlen
, format
, ap
);
1415 #define TEST_STR_EQUAL(LHS, RHS) \
1416 if (ACE_OS::strcmp ((LHS), (RHS))) { \
1418 ACE_ERROR ((LM_ERROR, "Test assertion FAILED {%C} != {%C} at line %l\n", \
1422 #define TEST_INT_EQUAL(LHS, RHS) \
1423 if (!((LHS) == (RHS))) { \
1425 ACE_ERROR ((LM_ERROR, "Test assertion FAILED %d != %d at line %l\n", \
1429 #define EXPECTED_RESULT(STR) \
1430 TEST_INT_EQUAL (ACE_OS::strlen (STR), size_t (ret)) \
1431 TEST_STR_EQUAL (STR, buf)
1433 #define EXPECTED_RESULTS(STR_A, STR_B) \
1434 if (ACE_OS::strcmp ((STR_A), (buf)) && ACE_OS::strcmp ((STR_B), (buf))) { \
1436 ACE_ERROR ((LM_ERROR, "Test assertion FAILED {%C} != {%C} and " \
1437 "{%C} != {%C} at line %l\n", \
1438 (STR_A), (buf), (STR_B), (buf))); \
1441 #define EXPECTED_RESULT_LEN(STR, LEN) \
1442 TEST_INT_EQUAL (LEN, ret) \
1443 TEST_STR_EQUAL (STR, buf)
1445 #define LOG_RESULT(STR) \
1446 ACE_DEBUG ((LM_DEBUG, "Locale-dependent snprintf could be {%C}, was {%C}" \
1447 " at line %l\n", (STR), buf));
1449 int snprintf_emulation_test ()
1451 bool failed
= false;
1454 int ret
= snprintf_emulation (buf
, sizeof buf
, "[%d]", 314); EXPECTED_RESULT ("[314]");
1455 ret
= snprintf_emulation (buf
, sizeof buf
, "[%i] %% [%u]", -314, 314); EXPECTED_RESULT ("[-314] % [314]");
1456 ret
= snprintf_emulation (buf
, sizeof buf
, "%5d", 414); EXPECTED_RESULT (" 414");
1457 ret
= snprintf_emulation (buf
, sizeof buf
, "%05d", 414); EXPECTED_RESULT ("00414");
1458 ret
= snprintf_emulation (buf
, sizeof buf
, "%*d", 5, 414); EXPECTED_RESULT (" 414");
1459 ret
= snprintf_emulation (buf
, sizeof buf
, "%-*d", 5, 414); EXPECTED_RESULT ("414 ");
1460 ret
= snprintf_emulation (buf
, sizeof buf
, "%5i", -414); EXPECTED_RESULT (" -414");
1461 ret
= snprintf_emulation (buf
, sizeof buf
, "%05i", -414); EXPECTED_RESULT ("-0414");
1462 ret
= snprintf_emulation (buf
, sizeof buf
, "%2d", -414); EXPECTED_RESULT ("-414");
1463 ret
= snprintf_emulation (buf
, sizeof buf
, "%.4d", -414); EXPECTED_RESULT ("-0414");
1464 ret
= snprintf_emulation (buf
, sizeof buf
, "%6.4d", -314); EXPECTED_RESULT (" -0314");
1465 ret
= snprintf_emulation (buf
, sizeof buf
, "%.4i", 314); EXPECTED_RESULT ("0314");
1466 ret
= snprintf_emulation (buf
, sizeof buf
, "%6.4u", 414); EXPECTED_RESULT (" 0414");
1467 ret
= snprintf_emulation (buf
, sizeof buf
, "%.d", 0); EXPECTED_RESULT ("");
1468 ret
= snprintf_emulation (buf
, sizeof buf
, "% .0d", 0); EXPECTED_RESULT (" ");
1469 ret
= snprintf_emulation (buf
, sizeof buf
, "%d", 0); EXPECTED_RESULT ("0");
1470 ret
= snprintf_emulation (buf
, sizeof buf
, "%+d", 0); EXPECTED_RESULT ("+0");
1471 ret
= snprintf_emulation (buf
, sizeof buf
, "% d", 0); EXPECTED_RESULT (" 0");
1473 ret
= snprintf_emulation (buf
, sizeof buf
, "%04o", 0755); EXPECTED_RESULT ("0755");
1474 ret
= snprintf_emulation (buf
, sizeof buf
, "%#o", 0644); EXPECTED_RESULT ("0644");
1475 ret
= snprintf_emulation (buf
, sizeof buf
, "%#.o", 0); EXPECTED_RESULT ("0");
1476 ret
= snprintf_emulation (buf
, sizeof buf
, "%#.5o", 0644); EXPECTED_RESULT ("00644");
1478 ret
= snprintf_emulation (buf
, sizeof buf
, "%x", 0x987abc); EXPECTED_RESULT ("987abc");
1479 ret
= snprintf_emulation (buf
, sizeof buf
, "%X", 0x987abc); EXPECTED_RESULT ("987ABC");
1480 ret
= snprintf_emulation (buf
, sizeof buf
, "%02x", 0); EXPECTED_RESULT ("00");
1481 ret
= snprintf_emulation (buf
, sizeof buf
, "%-#10x", 0x987abc); EXPECTED_RESULT ("0x987abc ");
1482 ret
= snprintf_emulation (buf
, sizeof buf
, "%#10X", 0x987abc); EXPECTED_RESULT (" 0X987ABC");
1483 ret
= snprintf_emulation (buf
, sizeof buf
, "%#X", 0); EXPECTED_RESULT ("0");
1484 ret
= snprintf_emulation (buf
, sizeof buf
, "%#.X", 0); EXPECTED_RESULT ("");
1485 ret
= snprintf_emulation (buf
, sizeof buf
, "%#05x", 20); EXPECTED_RESULT ("0x014");
1486 ret
= snprintf_emulation (buf
, sizeof buf
, "%#.3X", 20); EXPECTED_RESULT ("0X014");
1487 ret
= snprintf_emulation (buf
, sizeof buf
, "%#6.3X", 20); EXPECTED_RESULT (" 0X014");
1488 ret
= snprintf_emulation (buf
, sizeof buf
, "%#-6.3X", 20); EXPECTED_RESULT ("0X014 ");
1490 ret
= snprintf_emulation (buf
, sizeof buf
, "%c", 'a'); EXPECTED_RESULT ("a");
1491 ret
= snprintf_emulation (buf
, sizeof buf
, "%2c", 'b'); EXPECTED_RESULT (" b");
1492 ret
= snprintf_emulation (buf
, sizeof buf
, "%-2c", 'c'); EXPECTED_RESULT ("c ");
1493 ret
= snprintf_emulation (buf
, sizeof buf
, "%-2s", "d"); EXPECTED_RESULT ("d ");
1494 ret
= snprintf_emulation (buf
, sizeof buf
, "%2s", "e"); EXPECTED_RESULT (" e");
1495 ret
= snprintf_emulation (buf
, sizeof buf
, "%2.1s", "fg"); EXPECTED_RESULT (" f");
1496 ret
= snprintf_emulation (buf
, sizeof buf
, "%-2.1s", "gh"); EXPECTED_RESULT ("g ");
1497 ret
= snprintf_emulation (buf
, sizeof buf
, "%.s", "x"); EXPECTED_RESULT ("");
1498 ret
= snprintf_emulation (buf
, sizeof buf
, "%-4.9s", "hi"); EXPECTED_RESULT ("hi ");
1499 ret
= snprintf_emulation (buf
, sizeof buf
, "%.s", "x"); EXPECTED_RESULT ("");
1502 ret
= snprintf_emulation (buf
, sizeof buf
, "%-5.2s%n %s", "jkl", &n
, "lmn"); EXPECTED_RESULT ("jk lmn");
1503 ret
= snprintf_emulation (buf
, sizeof buf
, "%0-3.2i", n
); EXPECTED_RESULT ("05 ");
1505 ret
= snprintf_emulation (buf
, sizeof buf
, "%p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT ("0x1234abc");
1506 ret
= snprintf_emulation (buf
, sizeof buf
, "%12p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT (" 0x1234abc");
1507 ret
= snprintf_emulation (buf
, sizeof buf
, "%-12p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT ("0x1234abc ");
1509 ret
= snprintf_emulation (buf
, sizeof buf
, "%hhu", 0x101); EXPECTED_RESULT ("1");
1510 ret
= snprintf_emulation (buf
, sizeof buf
, "%hu", 0x10002); EXPECTED_RESULT ("2");
1511 ret
= snprintf_emulation (buf
, sizeof buf
, "%#lx", 0x87654321ul
); EXPECTED_RESULT ("0x87654321");
1512 ret
= snprintf_emulation (buf
, sizeof buf
, "%llu", 612578912487901265ull); EXPECTED_RESULT ("612578912487901265");
1514 ret
= snprintf_emulation (buf
, sizeof buf
, "%-+010.7d", 98765); EXPECTED_RESULT ("+0098765 ");
1515 ret
= snprintf_emulation (buf
, 10, "%-+010.7d", 98765); EXPECTED_RESULT_LEN ("+0098765 ", 10);
1517 ret
= snprintf_emulation (buf
, sizeof buf
, "%f", 3.14); EXPECTED_RESULT ("3.140000");
1518 ret
= snprintf_emulation (buf
, sizeof buf
, "%10f", -3.14); EXPECTED_RESULT (" -3.140000");
1519 ret
= snprintf_emulation (buf
, sizeof buf
, "%+-10F", 3.14); EXPECTED_RESULT ("+3.140000 ");
1520 ret
= snprintf_emulation (buf
, sizeof buf
, "%010f", -3.14); EXPECTED_RESULT ("-03.140000");
1521 ret
= snprintf_emulation (buf
, sizeof buf
, "% f", 3.14); EXPECTED_RESULT (" 3.140000");
1522 ret
= snprintf_emulation (buf
, sizeof buf
, "% f", HUGE_VAL
); EXPECTED_RESULT (" inf");
1523 ret
= snprintf_emulation (buf
, sizeof buf
, "%f", -HUGE_VAL
); EXPECTED_RESULT ("-inf");
1524 ret
= snprintf_emulation (buf
, sizeof buf
, "%#F", HUGE_VAL
); EXPECTED_RESULT ("INF");
1525 ret
= snprintf_emulation (buf
, sizeof buf
, "%5F", -HUGE_VAL
); EXPECTED_RESULT (" -INF");
1526 #ifndef ACE_LYNXOS_MAJOR
1527 ret
= snprintf_emulation (buf
, sizeof buf
, "%f", std::numeric_limits
<double>::quiet_NaN ()); EXPECTED_RESULTS ("nan", "-nan");
1528 ret
= snprintf_emulation (buf
, sizeof buf
, "%+F", std::numeric_limits
<double>::quiet_NaN ()); EXPECTED_RESULTS ("+NAN", "-NAN");
1530 ret
= snprintf_emulation (buf
, sizeof buf
, "%.f", 2.17); EXPECTED_RESULT ("2");
1531 ret
= snprintf_emulation (buf
, sizeof buf
, "%#.f", 2.17); EXPECTED_RESULT ("2.");
1532 ret
= snprintf_emulation (buf
, sizeof buf
, "%.1f", 18.); EXPECTED_RESULT ("18.0");
1533 ret
= snprintf_emulation (buf
, sizeof buf
, "%.1f", .9); EXPECTED_RESULT ("0.9");
1534 ret
= snprintf_emulation (buf
, sizeof buf
, "%.2f", .01); EXPECTED_RESULT ("0.01");
1536 ret
= snprintf_emulation (buf
, sizeof buf
, "%.2e", .01); EXPECTED_RESULT ("1.00e-02");
1537 ret
= snprintf_emulation (buf
, sizeof buf
, "%#.E", .01); EXPECTED_RESULT ("1.E-02");
1538 ret
= snprintf_emulation (buf
, sizeof buf
, "%+.E", .01); EXPECTED_RESULT ("+1E-02");
1539 ret
= snprintf_emulation (buf
, sizeof buf
, "%e", 3.14159265); EXPECTED_RESULT ("3.141592e+00");
1540 ret
= snprintf_emulation (buf
, sizeof buf
, "% .e", 0.); EXPECTED_RESULT (" 0e+00");
1541 ret
= snprintf_emulation (buf
, sizeof buf
, "% -8.e", 0.); EXPECTED_RESULT (" 0e+00 ");
1543 #if !defined _MSC_VER || ACE_CC_MAJOR_VERSION > 7
1544 ret
= snprintf_emulation (buf
, sizeof buf
, "% -11.2e", -0.); EXPECTED_RESULT ("-0.00e+00 ");
1547 ret
= snprintf_emulation (buf
, sizeof buf
, "%.E", 9e101
); EXPECTED_RESULTS ("9E+101", "8E+101"); // could be rounded
1549 ret
= snprintf_emulation (buf
, sizeof buf
, "%g", 3.); EXPECTED_RESULT ("3");
1550 ret
= snprintf_emulation (buf
, sizeof buf
, "%g", 3.000001); EXPECTED_RESULT ("3");
1551 ret
= snprintf_emulation (buf
, sizeof buf
, "%.6g", 3.000001); EXPECTED_RESULT ("3");
1552 ret
= snprintf_emulation (buf
, sizeof buf
, "%G", 3000000.1); EXPECTED_RESULT ("3E+06");
1553 ret
= snprintf_emulation (buf
, sizeof buf
, "%+#g", 3000000.1); EXPECTED_RESULT ("+3.00000e+06");
1554 ret
= snprintf_emulation (buf
, sizeof buf
, "%G", -3000010.); EXPECTED_RESULTS ("-3.00001E+06", "-3E+06");
1555 ret
= snprintf_emulation (buf
, sizeof buf
, "%g", .0001); EXPECTED_RESULT ("0.0001");
1556 ret
= snprintf_emulation (buf
, sizeof buf
, "%- g", .00001); EXPECTED_RESULT (" 1e-05");
1558 ret
= snprintf_emulation (buf
, sizeof buf
, "%a", 4.); EXPECTED_RESULT ("0x8p-1");
1559 ret
= snprintf_emulation (buf
, sizeof buf
, "%#a", 4.); EXPECTED_RESULT ("0x8.p-1");
1560 ret
= snprintf_emulation (buf
, sizeof buf
, "%A", -3.125); EXPECTED_RESULT ("-0XC.8P-2");
1561 ret
= snprintf_emulation (buf
, sizeof buf
, "%+a", 0.); EXPECTED_RESULT ("+0x0p+0");
1562 ret
= snprintf_emulation (buf
, sizeof buf
, "%+-10.1a", 0.); EXPECTED_RESULT ("+0x0.0p+0 ");
1563 ret
= snprintf_emulation (buf
, sizeof buf
, "%0+10.1a", 0.); EXPECTED_RESULT ("+0x00.0p+0");
1564 ret
= snprintf_emulation (buf
, sizeof buf
, "% 09A", 16.625); EXPECTED_RESULT (" 0X8.5P+1");
1565 ret
= snprintf_emulation (buf
, sizeof buf
, "% 010a", 16.625); EXPECTED_RESULT (" 0x08.5p+1");
1567 ret
= snprintf_emulation (buf
, sizeof buf
, "%%%d%#x", 1, 2); EXPECTED_RESULT ("%10x2");
1568 ret
= snprintf_emulation (buf
, sizeof buf
, "foo %%%% bar"); EXPECTED_RESULT ("foo %% bar");
1569 ret
= snprintf_emulation (buf
, sizeof buf
, ""); EXPECTED_RESULT ("");
1570 ret
= snprintf_emulation (buf
, sizeof buf
, "foo"); EXPECTED_RESULT ("foo");
1572 ret
= snprintf_emulation (buf
, sizeof buf
, "%'d", 12345); LOG_RESULT ("12,345");
1573 ret
= snprintf_emulation (buf
, sizeof buf
, "%'d", 123456); LOG_RESULT ("123,456");
1574 ret
= snprintf_emulation (buf
, sizeof buf
, "%'d", 1234567890); LOG_RESULT ("1,234,567,890");
1575 ret
= snprintf_emulation (buf
, sizeof buf
, "%'.f", 12345.); LOG_RESULT ("12,345");
1576 ret
= snprintf_emulation (buf
, sizeof buf
, "%'.f", 1234567890.); LOG_RESULT ("1,234,567,890");
1577 ret
= snprintf_emulation (buf
, sizeof buf
, "%'.6d", 12345); LOG_RESULT ("012,345");
1578 ret
= snprintf_emulation (buf
, sizeof buf
, "%0'8d", 12345); LOG_RESULT ("0012,345");
1580 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");
1581 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");
1582 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");
1583 ret
= snprintf_emulation (buf
, sizeof buf
, "%2$#*1$x", -4, 10); EXPECTED_RESULT ("0xa ");
1585 return failed
? 1 : 0;
1587 #endif // ACE_HAS_VSNPRINTF_EMULATION
1592 ACE_DEBUG ((LM_DEBUG
,
1593 ACE_TEXT ("Testing swab method\n")));
1595 int error_count
= 0;
1596 char const from
[] = "BADCFEHGJILKNMPORQTSVUXWZY";
1597 char to
[] = "..........................";
1598 char expect
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1600 ACE_OS::swab (from
, to
, sizeof (from
));
1601 if (ACE_OS::strcmp (to
, expect
) != 0)
1603 ACE_ERROR ((LM_ERROR
,
1604 ACE_TEXT ("swab error: %C, expected %C\n"),
1613 gai_strerror_test ()
1615 ACE_DEBUG ((LM_DEBUG
,
1616 ACE_TEXT ("Testing gai_strerror method\n")));
1618 const ACE_TCHAR
* error_text
= ACE_OS::gai_strerror (EAI_FAMILY
);
1620 ACE_UNUSED_ARG (error_text
);
1626 run_main (int, ACE_TCHAR
*[])
1628 ACE_START_TEST (ACE_TEXT ("OS_Test"));
1630 // Enable a locale that has digit grouping so that snprintf's %'d is
1631 // different than %d. If the locale is not available the test won't
1632 // fail (log file needs to be examined to check formatting).
1634 std::setlocale(LC_NUMERIC
, "en-US");
1635 #elif defined ACE_LINUX
1636 std::setlocale(LC_NUMERIC
, "en_US.utf8");
1642 if ((result
= access_test ()) != 0)
1645 if ((result
= rename_test ()) != 0)
1648 if ((result
= string_emulation_test ()) != 0)
1651 if ((result
= snprintf_test (ACE_OS::snprintf
)) != 0)
1654 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1655 if ((result
= snprintf_test (snprintf_emulation
)) != 0)
1658 if ((result
= snprintf_emulation_test ()) != 0)
1662 if ((result
= getpwnam_r_test ()) != 0)
1665 if ((result
= ctime_r_test ()) != 0)
1668 if ((result
= string_strsncpy_test ()) != 0)
1671 if ((result
= strsignal_test ()) != 0)
1674 if ((result
= cpu_info_test ()) != 0)
1677 if ((result
= pagesize_test ()) != 0)
1680 if ((result
= ceilf_test ()) != 0)
1683 if ((result
= floorf_test ()) != 0)
1686 if ((result
= ceil_test ()) != 0)
1689 if ((result
= floor_test ()) != 0)
1692 if ((result
= ceill_test ()) != 0)
1695 if ((result
= floorl_test ()) != 0)
1698 if ((result
= log2_test ()) != 0)
1701 if ((result
= last_error_test ()) != 0)
1704 if ((result
= ace_ctype_test ()) != 0)
1707 if ((result
= swab_test ()) != 0)
1710 if ((result
= compiler_test ()) != 0)
1713 if ((result
= version_test ()) != 0)
1716 if ((result
= gai_strerror_test ()) != 0)
1722 #undef THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL