Make x.0.10 publicly available
[ACE_TAO.git] / ACE / tests / OS_Test.cpp
blob03666ca0ae2b2cd1ef4539e01209e18dc33afff4
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) || defined (ACE_HAS_WINCE)
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 // HP-UX has broken vsnprintf
607 #if !defined (HPUX)
608 if (retval != 4)
610 ACE_ERROR ((LM_ERROR,
611 ACE_TEXT ("[2] ACE_OS::snprintf() returns %d, should be 4\n"),
612 retval));
613 ++error_count;
615 #endif /* !HPUX */
617 if (buf[3] != 0)
619 ACE_ERROR ((LM_ERROR,
620 ACE_TEXT ("[3] ACE_OS::snprintf() doesn't terminate string correctly\n")));
621 ++error_count;
623 else if (ACE_OS::strcmp(buf, "123") != 0)
625 ACE_ERROR ((LM_ERROR,
626 ACE_TEXT ("[4] ACE_OS::snprintf() incorrect output\n")));
627 ++error_count;
630 ACE_OS::memset(buf, 0xab, 2*BUFFER_SIZE);
631 retval = fn (buf, BUFFER_SIZE, "%d", 12345);
632 if (retval != 5)
634 ACE_ERROR ((LM_ERROR,
635 ACE_TEXT ("[5] ACE_OS::snprintf() returns %d, should be 5\n"),
636 retval));
637 ++error_count;
639 else if (buf[3] != 0)
641 ACE_ERROR ((LM_ERROR,
642 ACE_TEXT ("[6] ACE_OS::snprintf() doesn't terminate string correctly\n")));
643 ++error_count;
645 else if (ACE_OS::strcmp(buf, "123") != 0)
647 ACE_ERROR ((LM_ERROR,
648 ACE_TEXT ("[6] ACE_OS::snprintf() incorrect output\n")));
649 ++error_count;
652 return error_count;
655 static int
656 getpwnam_r_test ()
658 int result = 0;
660 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
661 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing getpwnam_r\n")));
663 struct passwd pwd;
664 struct passwd *pwd_ptr;
665 char buf[1024];
667 const char* login = getlogin ();
668 if (login == 0)
669 login = "root";
671 if (ACE_OS::getpwnam_r (login,
672 &pwd,
673 buf,
674 sizeof (buf),
675 &pwd_ptr) != 0)
677 result = 1;
678 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("getpwnam_r() failed\n")));
680 else
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));
685 #endif
687 return result;
690 static int
691 compiler_test ()
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 ()));
701 return 0;
704 static int
705 version_test ()
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;
717 #else
718 bool compile_time_check = false;
719 #endif
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)
725 return 0;
726 return 1;
729 static int
730 ctime_r_test ()
732 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing ctime_r\n")));
734 int result = 0;
736 // test 'normal' buffer
737 ACE_TCHAR buf[27];
738 buf[26] = 'Z';
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")));
748 result = -1;
750 else if (buf[0] == '\0')
752 result = -1;
754 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Truncated input buffer\n")));
756 else if (buf[26] != 'Z')
758 result = -1;
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.
763 if (result == 0)
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"),
771 buf));
772 result = -1;
774 else if (errno != ERANGE)
776 ACE_ERROR ((LM_ERROR,
777 ACE_TEXT ("%p\n"),
778 ACE_TEXT ("ctime_r short; wrong error")));
779 result = -1;
781 // Make sure it didn't scribble
782 else if (ACE_OS::strcmp (buf, bufcheck) != 0)
784 result = -1;
785 ACE_ERROR ((LM_ERROR,
786 ACE_TEXT ("ctime_r short; got %s, expected %s\n"),
787 buf, bufcheck));
791 return result;
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";
806 char strsncpy2[36];
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,
811 strsncpy1,
812 36),
813 strsncpy1) == 0);
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,
818 strsncpy1,
819 26),
820 strsncpy1,
821 25) == 0);
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,
829 strsncpy1,
831 strsncpy1,
832 1) == 0);
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,
837 strsncpy1,
838 1)) == 0);
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,
843 strsncpy1,
844 36),
845 strsncpy1) == 0);
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,
851 "test",
853 strsncpy1) == 0);
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,
858 strsncpy2,
859 10),
860 strsncpy1,
861 9) == 0);
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,
880 strsncpy1,
881 36),
882 strsncpy1) == 0);
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,
887 strsncpy1,
888 26),
889 strsncpy1,
890 25) == 0);
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,
898 strsncpy1,
900 strsncpy1,
901 1) == 0);
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,
906 strsncpy1,
907 1)) == 0);
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,
912 strsncpy1,
913 36),
914 strsncpy1) == 0);
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,
920 ACE_TEXT_WIDE
921 ("test"),
923 strsncpy1) == 0);
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,
928 strsncpy2,
929 10),
930 strsncpy1,
931 9) == 0);
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 */
937 return 0;
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")));
949 int result = 0;
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");
954 wchar_t str_w[10];
955 char str_n[10];
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));
961 result = 1;
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));
968 result = 1;
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));
975 result = 1;
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));
982 result = 1;
984 return result;
985 #else
986 return 0;
987 #endif /* ACE_HAS_WCHAR */
990 // Test ACE_OS::strsignal()
992 strsignal_test ()
994 ACE_DEBUG ((LM_DEBUG,
995 ACE_TEXT ("Testing strsignal method\n")));
997 int test_status = 0;
999 const char* result = 0;
1001 for (int i=-1; i < (ACE_NSIG + 1); ++i)
1003 result = ACE_OS::strsignal (i);
1004 if (result == 0)
1006 ACE_ERROR ((LM_ERROR, ACE_TEXT ("strsignal returned null\n")));
1007 test_status = 1;
1009 else
1011 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Sig #%d: %C\n"), i, result));
1015 return test_status;
1018 // Test the methods for getting cpu info
1020 cpu_info_test ()
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")));
1034 else
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")));
1047 else
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,
1059 number_processors),
1060 -1);
1062 return 0;
1066 last_error_test ()
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"),
1077 l_error));
1078 return 1;
1081 ACE_OS::last_error (0);
1083 return 0;
1087 pagesize_test ()
1089 ACE_DEBUG ((LM_DEBUG,
1090 ACE_TEXT ("Testing getpagesize method\n")));
1092 long const pagesize = ACE_OS::getpagesize ();
1093 if (pagesize <= 0)
1095 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, pagesize should return a value bigger ")
1096 ACE_TEXT ("then zero, it returned %d\n"), pagesize));
1097 return 1;
1099 else
1101 ACE_DEBUG ((LM_DEBUG,
1102 ACE_TEXT ("Pagesize returned %d\n"),
1103 pagesize));
1105 return 0;
1109 ace_ctype_test ()
1111 ACE_DEBUG ((LM_DEBUG,
1112 ACE_TEXT ("Testing ace ctype methods\n")));
1114 int retval = 0;
1115 int result = ACE_OS::ace_isprint (ACE_TEXT('\t'));
1116 if (result != 0)
1118 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isprint should return 0 for tab ")
1119 ACE_TEXT ("but it returned %d\n"), result));
1120 ++retval;
1122 result = ACE_OS::ace_isblank (ACE_TEXT('\t'));
1123 if (result == 0)
1125 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isblank should return != 0 for tab ")
1126 ACE_TEXT ("but it returned %d\n"), result));
1127 ++retval;
1129 result = ACE_OS::ace_isblank (ACE_TEXT(' '));
1130 if (result == 0)
1132 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isblank should return != 0 for space ")
1133 ACE_TEXT ("but it returned %d\n"), result));
1134 ++retval;
1136 result = ACE_OS::ace_isalpha (ACE_TEXT('\t'));
1137 if (result != 0)
1139 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isalpha should return 0 for tab ")
1140 ACE_TEXT ("but it returned %d\n"), result));
1141 ++retval;
1143 result = ACE_OS::ace_isupper (ACE_TEXT('\t'));
1144 if (result != 0)
1146 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isupper should return 0 for tab ")
1147 ACE_TEXT ("but it returned %d\n"), result));
1148 ++retval;
1150 result = ACE_OS::ace_islower (ACE_TEXT('\t'));
1151 if (result != 0)
1153 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_islower should return 0 for tab ")
1154 ACE_TEXT ("but it returned %d\n"), result));
1155 ++retval;
1157 result = ACE_OS::ace_isdigit (ACE_TEXT('\t'));
1158 if (result != 0)
1160 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isdigit should return 0 for tab ")
1161 ACE_TEXT ("but it returned %d\n"), result));
1162 ++retval;
1164 result = ACE_OS::ace_isxdigit (ACE_TEXT('\t'));
1165 if (result != 0)
1167 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isxdigit should return 0 for tab ")
1168 ACE_TEXT ("but it returned %d\n"), result));
1169 ++retval;
1171 result = ACE_OS::ace_isspace (ACE_TEXT('\t'));
1172 if (result == 0)
1174 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isspace should return != 0 for tab ")
1175 ACE_TEXT ("but it returned %d\n"), result));
1176 ++retval;
1178 result = ACE_OS::ace_ispunct (ACE_TEXT('\t'));
1179 if (result != 0)
1181 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_ispunct should return 0 for tab ")
1182 ACE_TEXT ("but it returned %d\n"), result));
1183 ++retval;
1185 result = ACE_OS::ace_isalnum (ACE_TEXT('\t'));
1186 if (result != 0)
1188 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isalnum should return 0 for tab ")
1189 ACE_TEXT ("but it returned %d\n"), result));
1190 ++retval;
1192 result = ACE_OS::ace_isgraph (ACE_TEXT('\t'));
1193 if (result != 0)
1195 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isgraph should return 0 for tab ")
1196 ACE_TEXT ("but it returned %d\n"), result));
1197 ++retval;
1199 result = ACE_OS::ace_iscntrl (ACE_TEXT('\t'));
1200 if (result == 0)
1202 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_iscntrl should return != 0 for tab ")
1203 ACE_TEXT ("but it returned %d\n"), result));
1204 ++retval;
1206 result = ACE_OS::ace_isascii (ACE_TEXT('\t'));
1207 if (result == 0)
1209 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isascii should return != 0 for tab ")
1210 ACE_TEXT ("but it returned %d\n"), result));
1211 ++retval;
1214 return 0;
1218 ceilf_test ()
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};
1225 float result = 0.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"),
1235 values [i],
1236 result,
1237 results [i]));
1238 ++error_count;
1242 return error_count;
1246 floorf_test ()
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};
1253 float result = 0.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]));
1264 ++error_count;
1268 return error_count;
1272 ceil_test ()
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"),
1289 values [i],
1290 result,
1291 results [i]));
1292 ++error_count;
1296 return error_count;
1300 floor_test ()
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"),
1317 values [i],
1318 result,
1319 results [i]));
1320 ++error_count;
1324 return error_count;
1328 ceill_test ()
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"),
1345 values [i],
1346 result,
1347 results [i]));
1348 ++error_count;
1352 return error_count;
1356 floorl_test ()
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]));
1374 ++error_count;
1378 return error_count;
1382 log2_test ()
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};
1389 int result = 0;
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]));
1398 ++error_count;
1402 return error_count;
1405 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1406 int snprintf_emulation (char *buf, size_t maxlen, const char *format, ...)
1408 va_list ap;
1409 va_start (ap, format);
1410 const int ret = ACE_OS::vsnprintf_emulation (buf, maxlen, format, ap);
1411 va_end (ap);
1412 return ret;
1415 #define TEST_STR_EQUAL(LHS, RHS) \
1416 if (ACE_OS::strcmp ((LHS), (RHS))) { \
1417 failed = true; \
1418 ACE_ERROR ((LM_ERROR, "Test assertion FAILED {%C} != {%C} at line %l\n", \
1419 (LHS), (RHS))); \
1422 #define TEST_INT_EQUAL(LHS, RHS) \
1423 if (!((LHS) == (RHS))) { \
1424 failed = true; \
1425 ACE_ERROR ((LM_ERROR, "Test assertion FAILED %d != %d at line %l\n", \
1426 (LHS), (RHS))); \
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))) { \
1435 failed = true; \
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;
1452 char buf[BUFSIZ];
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 ("");
1501 int n;
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");
1529 #endif
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 ");
1545 #endif
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
1590 swab_test ()
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"),
1605 to, expect));
1606 ++error_count;
1609 return error_count;
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);
1622 return 0;
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).
1633 #ifdef ACE_WIN32
1634 std::setlocale(LC_NUMERIC, "en-US");
1635 #elif defined ACE_LINUX
1636 std::setlocale(LC_NUMERIC, "en_US.utf8");
1637 #endif
1639 int status = 0;
1640 int result;
1642 if ((result = access_test ()) != 0)
1643 status = result;
1645 if ((result = rename_test ()) != 0)
1646 status = result;
1648 if ((result = string_emulation_test ()) != 0)
1649 status = result;
1651 if ((result = snprintf_test (ACE_OS::snprintf)) != 0)
1652 status = result;
1654 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1655 if ((result = snprintf_test (snprintf_emulation)) != 0)
1656 status = result;
1658 if ((result = snprintf_emulation_test ()) != 0)
1659 status = result;
1660 #endif
1662 if ((result = getpwnam_r_test ()) != 0)
1663 status = result;
1665 if ((result = ctime_r_test ()) != 0)
1666 status = result;
1668 if ((result = string_strsncpy_test ()) != 0)
1669 status = result;
1671 if ((result = strsignal_test ()) != 0)
1672 status = result;
1674 if ((result = cpu_info_test ()) != 0)
1675 status = result;
1677 if ((result = pagesize_test ()) != 0)
1678 status = result;
1680 if ((result = ceilf_test ()) != 0)
1681 status = result;
1683 if ((result = floorf_test ()) != 0)
1684 status = result;
1686 if ((result = ceil_test ()) != 0)
1687 status = result;
1689 if ((result = floor_test ()) != 0)
1690 status = result;
1692 if ((result = ceill_test ()) != 0)
1693 status = result;
1695 if ((result = floorl_test ()) != 0)
1696 status = result;
1698 if ((result = log2_test ()) != 0)
1699 status = result;
1701 if ((result = last_error_test ()) != 0)
1702 status = result;
1704 if ((result = ace_ctype_test ()) != 0)
1705 status = result;
1707 if ((result = swab_test ()) != 0)
1708 status = result;
1710 if ((result = compiler_test ()) != 0)
1711 status = result;
1713 if ((result = version_test ()) != 0)
1714 status = result;
1716 if ((result = gai_strerror_test ()) != 0)
1717 status = result;
1719 ACE_END_TEST;
1720 return status;
1722 #undef THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL