Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / OS_Test.cpp
blob65115e9b27bbdb68668bd0c17fc9019038ed5cc2
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 (void)
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 (void)
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 (void)
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 typedef int (*SNPrintF_t) (char *buf, size_t maxlen, const char *format, ...);
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 (void)
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 (void)
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 (void)
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 (void)
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 (void)
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);
867 #if defined (ACE_HAS_WCHAR)
869 //FUZZ: disable check_for_lack_ACE_OS
870 // Test strsncpy (wchar_t version)
871 ACE_DEBUG ((LM_DEBUG,
872 ACE_TEXT ("Testing strsncpy (wchar_t version)\n")));
873 //FUZZ: enable check_for_lack_ACE_OS
875 wchar_t const strsncpy1[] = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyzabc");
876 wchar_t strsncpy2[36];
878 // strsncpy() where the max. length doesn't matter
879 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
880 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
881 strsncpy1,
882 36),
883 strsncpy1) == 0);
885 // strsncpy() where the max length does matter
886 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
887 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
888 strsncpy1,
889 26),
890 strsncpy1,
891 25) == 0);
893 // strsncpy1 and strsncpy2 are different size --> not equal
894 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL (ACE_OS::strcmp (strsncpy2, strsncpy1) != 0);
896 // max. length == 2 --> 1 char available
897 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
898 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
899 strsncpy1,
901 strsncpy1,
902 1) == 0);
904 // max length == 1 --> empty string
905 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
906 (ACE_OS::strlen (ACE_OS::strsncpy (strsncpy2,
907 strsncpy1,
908 1)) == 0);
910 // just preparation for the next assert
911 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
912 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
913 strsncpy1,
914 36),
915 strsncpy1) == 0);
917 // A tricky one, if the max. length == 0 --> do nothing
918 // so the strsncpy2 shouldn't change
919 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
920 (ACE_OS::strcmp (ACE_OS::strsncpy (strsncpy2,
921 ACE_TEXT_WIDE
922 ("test"),
924 strsncpy1) == 0);
926 // If src == dst --> truncate dst if needed!
927 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL
928 (ACE_OS::strncmp (ACE_OS::strsncpy (strsncpy2,
929 strsncpy2,
930 10),
931 strsncpy1,
932 9) == 0);
933 // size should be 9 (+ '\0' char)
934 THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL(ACE_OS::strlen(strsncpy2) == 9);
936 #endif /* ACE_HAS_WCHAR */
938 return 0;
942 // Test conversion between narrow and wide chars.
944 string_convert_test (void)
946 #if defined (ACE_HAS_WCHAR)
947 ACE_DEBUG ((LM_DEBUG,
948 ACE_TEXT ("Testing narrow/wide string conversion\n")));
950 int result = 0;
951 const char *test1_n = "abcdefg";
952 const wchar_t *test1_w = ACE_TEXT_WIDE ("abcdefg");
953 const char *test2_n = "\xe9\xe8\xe0\xf9\xea";
954 const wchar_t *test2_w = ACE_TEXT_WIDE ("\xe9\xe8\xe0\xf9\xea");
955 wchar_t str_w[10];
956 char str_n[10];
957 ACE_OS::strcpy (str_w, ACE_Ascii_To_Wide (test1_n).wchar_rep ());
958 if (0 != ACE_OS::strcmp (test1_w, str_w))
960 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Simple narrow->wide failed: ")
961 ACE_TEXT ("Expected \"%W\"; Got \"%W\"\n"), test1_w, str_w));
962 result = 1;
964 ACE_OS::strcpy (str_n, ACE_Wide_To_Ascii (test1_w).char_rep ());
965 if (0 != ACE_OS::strcmp (test1_n, str_n))
967 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Simple wide->narrow failed: ")
968 ACE_TEXT ("Expected \"%C\"; Got \"%C\"\n"), test1_n, str_n));
969 result = 1;
971 ACE_OS::strcpy (str_w, ACE_Ascii_To_Wide (test2_n).wchar_rep ());
972 if (0 != ACE_OS::strcmp (test2_w, str_w))
974 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Complex narrow->wide failed: ")
975 ACE_TEXT ("Expected \"%W\"; Got \"%W\"\n"), test2_w, str_w));
976 result = 1;
978 ACE_OS::strcpy (str_n, ACE_Wide_To_Ascii (test2_w).char_rep ());
979 if (0 != ACE_OS::strcmp (test2_n, str_n))
981 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Complex wide->narrow failed: ")
982 ACE_TEXT ("Expected \"%C\"; Got \"%C\"\n"), test2_n, str_n));
983 result = 1;
985 return result;
986 #else
987 return 0;
988 #endif /* ACE_HAS_WCHAR */
991 // Test ACE_OS::strsignal()
993 strsignal_test (void)
995 ACE_DEBUG ((LM_DEBUG,
996 ACE_TEXT ("Testing strsignal method\n")));
998 int test_status = 0;
1000 const char* result = 0;
1002 for (int i=-1; i < (ACE_NSIG + 1); ++i)
1004 result = ACE_OS::strsignal (i);
1005 if (result == 0)
1007 ACE_ERROR ((LM_ERROR, ACE_TEXT ("strsignal returned null\n")));
1008 test_status = 1;
1010 else
1012 ACE_DEBUG ((LM_DEBUG, ACE_TEXT (" Sig #%d: %C\n"), i, result));
1016 return test_status;
1019 // Test the methods for getting cpu info
1021 cpu_info_test (void)
1023 ACE_DEBUG ((LM_DEBUG,
1024 ACE_TEXT ("Testing cpu info methods\n")));
1026 long const number_processors = ACE_OS::num_processors();
1027 long const number_processors_online = ACE_OS::num_processors_online();
1029 if (number_processors == -1)
1031 ACE_ERROR ((LM_INFO,
1032 ACE_TEXT ("number of processors not supported on ")
1033 ACE_TEXT ("this platform\n")));
1035 else
1037 ACE_DEBUG ((LM_DEBUG,
1038 ACE_TEXT ("This system has %d processors\n"),
1039 number_processors));
1042 if (number_processors_online == -1)
1044 ACE_ERROR ((LM_INFO,
1045 ACE_TEXT ("number of processors online not supported on ")
1046 ACE_TEXT ("this platform\n")));
1048 else
1050 ACE_DEBUG ((LM_DEBUG,
1051 ACE_TEXT ("This system has %d processors online\n"),
1052 number_processors_online));
1055 if ((number_processors_online != -1 && number_processors != -1) &&
1056 number_processors_online > number_processors)
1057 ACE_ERROR_RETURN ((LM_ERROR,
1058 ACE_TEXT ("%d online processors; should be <= %d\n"),
1059 number_processors_online,
1060 number_processors),
1061 -1);
1063 return 0;
1067 last_error_test (void)
1069 ACE_DEBUG ((LM_DEBUG,
1070 ACE_TEXT ("Testing last_error method\n")));
1072 ACE_OS::last_error (ETIME);
1074 int const l_error = ACE_OS::last_error ();
1075 if (l_error != ETIME)
1077 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Last error returned %d instead of ETIME"),
1078 l_error));
1079 return 1;
1082 ACE_OS::last_error (0);
1084 return 0;
1088 pagesize_test (void)
1090 ACE_DEBUG ((LM_DEBUG,
1091 ACE_TEXT ("Testing getpagesize method\n")));
1093 long const pagesize = ACE_OS::getpagesize ();
1094 if (pagesize <= 0)
1096 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, pagesize should return a value bigger ")
1097 ACE_TEXT ("then zero, it returned %d\n"), pagesize));
1098 return 1;
1100 else
1102 ACE_DEBUG ((LM_DEBUG,
1103 ACE_TEXT ("Pagesize returned %d\n"),
1104 pagesize));
1106 return 0;
1110 ace_ctype_test (void)
1112 ACE_DEBUG ((LM_DEBUG,
1113 ACE_TEXT ("Testing ace ctype methods\n")));
1115 int retval = 0;
1116 int result = ACE_OS::ace_isprint (ACE_TEXT('\t'));
1117 if (result != 0)
1119 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isprint should return 0 for tab ")
1120 ACE_TEXT ("but it returned %d\n"), result));
1121 ++retval;
1123 result = ACE_OS::ace_isblank (ACE_TEXT('\t'));
1124 if (result == 0)
1126 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isblank should return != 0 for tab ")
1127 ACE_TEXT ("but it returned %d\n"), result));
1128 ++retval;
1130 result = ACE_OS::ace_isblank (ACE_TEXT(' '));
1131 if (result == 0)
1133 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isblank should return != 0 for space ")
1134 ACE_TEXT ("but it returned %d\n"), result));
1135 ++retval;
1137 result = ACE_OS::ace_isalpha (ACE_TEXT('\t'));
1138 if (result != 0)
1140 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isalpha should return 0 for tab ")
1141 ACE_TEXT ("but it returned %d\n"), result));
1142 ++retval;
1144 result = ACE_OS::ace_isupper (ACE_TEXT('\t'));
1145 if (result != 0)
1147 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isupper should return 0 for tab ")
1148 ACE_TEXT ("but it returned %d\n"), result));
1149 ++retval;
1151 result = ACE_OS::ace_islower (ACE_TEXT('\t'));
1152 if (result != 0)
1154 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_islower should return 0 for tab ")
1155 ACE_TEXT ("but it returned %d\n"), result));
1156 ++retval;
1158 result = ACE_OS::ace_isdigit (ACE_TEXT('\t'));
1159 if (result != 0)
1161 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isdigit should return 0 for tab ")
1162 ACE_TEXT ("but it returned %d\n"), result));
1163 ++retval;
1165 result = ACE_OS::ace_isxdigit (ACE_TEXT('\t'));
1166 if (result != 0)
1168 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isxdigit should return 0 for tab ")
1169 ACE_TEXT ("but it returned %d\n"), result));
1170 ++retval;
1172 result = ACE_OS::ace_isspace (ACE_TEXT('\t'));
1173 if (result == 0)
1175 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isspace should return != 0 for tab ")
1176 ACE_TEXT ("but it returned %d\n"), result));
1177 ++retval;
1179 result = ACE_OS::ace_ispunct (ACE_TEXT('\t'));
1180 if (result != 0)
1182 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_ispunct should return 0 for tab ")
1183 ACE_TEXT ("but it returned %d\n"), result));
1184 ++retval;
1186 result = ACE_OS::ace_isalnum (ACE_TEXT('\t'));
1187 if (result != 0)
1189 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isalnum should return 0 for tab ")
1190 ACE_TEXT ("but it returned %d\n"), result));
1191 ++retval;
1193 result = ACE_OS::ace_isgraph (ACE_TEXT('\t'));
1194 if (result != 0)
1196 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isgraph should return 0 for tab ")
1197 ACE_TEXT ("but it returned %d\n"), result));
1198 ++retval;
1200 result = ACE_OS::ace_iscntrl (ACE_TEXT('\t'));
1201 if (result == 0)
1203 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_iscntrl should return != 0 for tab ")
1204 ACE_TEXT ("but it returned %d\n"), result));
1205 ++retval;
1207 result = ACE_OS::ace_isascii (ACE_TEXT('\t'));
1208 if (result == 0)
1210 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Error, ace_isascii should return != 0 for tab ")
1211 ACE_TEXT ("but it returned %d\n"), result));
1212 ++retval;
1215 return 0;
1219 ceilf_test (void)
1221 ACE_DEBUG ((LM_DEBUG,
1222 ACE_TEXT ("Testing ceilf method\n")));
1224 float const values[] = {-2.5, -1.5, 1.5, 2.5};
1225 float const results[] = {-2.0, -1.0, 2.0, 3.0};
1226 float result = 0.0;
1227 int error_count = 0;
1229 for (size_t i = 0 ; i < sizeof (values) / sizeof (float) ; i++)
1231 result = ACE_OS::ceil (values [i]);
1232 if (ACE::is_inequal(result, results[i]))
1234 ACE_ERROR ((LM_ERROR,
1235 ACE_TEXT ("ceilf error: input %.1F, output %1F, expected %1F\n"),
1236 values [i],
1237 result,
1238 results [i]));
1239 ++error_count;
1243 return error_count;
1247 floorf_test (void)
1249 ACE_DEBUG ((LM_DEBUG,
1250 ACE_TEXT ("Testing floorf method\n")));
1252 float const values[] = {-2.5, -1.5, 1.5, 2.5};
1253 float const results[] = {-3.0, -2.0, 1.0, 2.0};
1254 float result = 0.0;
1255 int error_count = 0;
1257 for (size_t i = 0 ; i < sizeof (values) / sizeof (float) ; i++)
1259 result = ACE_OS::floor (values [i]);
1260 if (ACE::is_inequal(result, results[i]))
1262 ACE_ERROR ((LM_ERROR,
1263 ACE_TEXT ("floorf error: input %.1F, output %1F, expected %1F\n"),
1264 values [i], result, results [i]));
1265 ++error_count;
1269 return error_count;
1273 ceil_test (void)
1275 ACE_DEBUG ((LM_DEBUG,
1276 ACE_TEXT ("Testing ceil method\n")));
1278 double const values[] = {-2.5, -1.5, 1.5, 2.5};
1279 double const results[] = {-2.0, -1.0, 2.0, 3.0};
1280 double result = 0.0;
1281 int error_count = 0;
1283 for (size_t i = 0 ; i < sizeof (values) / sizeof (double) ; i++)
1285 result = ACE_OS::ceil (values [i]);
1286 if (ACE::is_inequal(result, results[i]))
1288 ACE_ERROR ((LM_ERROR,
1289 ACE_TEXT ("ceil error: input %.1F, output %1F, expected %1F\n"),
1290 values [i],
1291 result,
1292 results [i]));
1293 ++error_count;
1297 return error_count;
1301 floor_test (void)
1303 ACE_DEBUG ((LM_DEBUG,
1304 ACE_TEXT ("Testing floor method\n")));
1306 double const values[] = {-2.5, -1.5, 1.5, 2.5};
1307 double const results[] = {-3.0, -2.0, 1.0, 2.0};
1308 double result = 0.0;
1309 int error_count = 0;
1311 for (size_t i = 0 ; i < sizeof (values) / sizeof (double) ; i++)
1313 result = ACE_OS::floor (values [i]);
1314 if (ACE::is_inequal(result, results[i]))
1316 ACE_ERROR ((LM_ERROR,
1317 ACE_TEXT ("floor error: input %.1F, output %1F, expected %1F\n"),
1318 values [i],
1319 result,
1320 results [i]));
1321 ++error_count;
1325 return error_count;
1329 ceill_test (void)
1331 ACE_DEBUG ((LM_DEBUG,
1332 ACE_TEXT ("Testing ceill method\n")));
1334 long double const values[] = {-2.5, -1.5, 1.5, 2.5};
1335 long double const results[] = {-2.0, -1.0, 2.0, 3.0};
1336 long double result = 0.0;
1337 int error_count = 0;
1339 for (size_t i = 0 ; i < sizeof (values) / sizeof (long double) ; i++)
1341 result = ACE_OS::ceil (values [i]);
1342 if (ACE::is_inequal(result, results[i]))
1344 ACE_ERROR ((LM_ERROR,
1345 ACE_TEXT ("ceil error: input %.1F, output %1F, expected %1F\n"),
1346 values [i],
1347 result,
1348 results [i]));
1349 ++error_count;
1353 return error_count;
1357 floorl_test (void)
1359 ACE_DEBUG ((LM_DEBUG,
1360 ACE_TEXT ("Testing floorl method\n")));
1362 long double const values[] = {-2.5, -1.5, 1.5, 2.5};
1363 long double const results[] = {-3.0, -2.0, 1.0, 2.0};
1364 long double result = 0.0;
1365 int error_count = 0;
1367 for (size_t i = 0 ; i < sizeof (values) / sizeof (long double) ; i++)
1369 result = ACE_OS::floor (values [i]);
1370 if (ACE::is_inequal(result, results[i]))
1372 ACE_ERROR ((LM_ERROR,
1373 ACE_TEXT ("floor error: input %.1F, output %1F, expected %1F\n"),
1374 values [i], result, results [i]));
1375 ++error_count;
1379 return error_count;
1383 log2_test (void)
1385 ACE_DEBUG ((LM_DEBUG,
1386 ACE_TEXT ("Testing log2 method\n")));
1388 double const values[] = {1.0, 2.0, 4.0, 8.0, 1048576.0};
1389 int const results[] = {0, 1, 2, 3, 20};
1390 int result = 0;
1391 int error_count = 0;
1393 for (size_t i = 0 ; i < sizeof (values) / sizeof (double) ; i++)
1395 result = static_cast<int> (ACE_OS::log2 (values [i]) + 0.5);
1396 if (result != results [i])
1398 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Log2 error: input %.1F, output %d, expected %d\n"), values [i], result, results [i]));
1399 ++error_count;
1403 return error_count;
1406 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1407 int snprintf_emulation (char *buf, size_t maxlen, const char *format, ...)
1409 va_list ap;
1410 va_start (ap, format);
1411 const int ret = ACE_OS::vsnprintf_emulation (buf, maxlen, format, ap);
1412 va_end (ap);
1413 return ret;
1416 #define TEST_STR_EQUAL(LHS, RHS) \
1417 if (ACE_OS::strcmp ((LHS), (RHS))) { \
1418 failed = true; \
1419 ACE_ERROR ((LM_ERROR, "Test assertion FAILED {%C} != {%C} at line %l\n", \
1420 (LHS), (RHS))); \
1423 #define TEST_INT_EQUAL(LHS, RHS) \
1424 if (!((LHS) == (RHS))) { \
1425 failed = true; \
1426 ACE_ERROR ((LM_ERROR, "Test assertion FAILED %d != %d at line %l\n", \
1427 (LHS), (RHS))); \
1430 #define EXPECTED_RESULT(STR) \
1431 TEST_INT_EQUAL (ACE_OS::strlen (STR), size_t (ret)) \
1432 TEST_STR_EQUAL (STR, buf)
1434 #define EXPECTED_RESULTS(STR_A, STR_B) \
1435 if (ACE_OS::strcmp ((STR_A), (buf)) && ACE_OS::strcmp ((STR_B), (buf))) { \
1436 failed = true; \
1437 ACE_ERROR ((LM_ERROR, "Test assertion FAILED {%C} != {%C} and " \
1438 "{%C} != {%C} at line %l\n", \
1439 (STR_A), (buf), (STR_B), (buf))); \
1442 #define EXPECTED_RESULT_LEN(STR, LEN) \
1443 TEST_INT_EQUAL (LEN, ret) \
1444 TEST_STR_EQUAL (STR, buf)
1446 #define LOG_RESULT(STR) \
1447 ACE_DEBUG ((LM_DEBUG, "Locale-dependent snprintf could be {%C}, was {%C}" \
1448 " at line %l\n", (STR), buf));
1450 int snprintf_emulation_test ()
1452 bool failed = false;
1453 char buf[BUFSIZ];
1455 int ret = snprintf_emulation (buf, sizeof buf, "[%d]", 314); EXPECTED_RESULT ("[314]");
1456 ret = snprintf_emulation (buf, sizeof buf, "[%i] %% [%u]", -314, 314); EXPECTED_RESULT ("[-314] % [314]");
1457 ret = snprintf_emulation (buf, sizeof buf, "%5d", 414); EXPECTED_RESULT (" 414");
1458 ret = snprintf_emulation (buf, sizeof buf, "%05d", 414); EXPECTED_RESULT ("00414");
1459 ret = snprintf_emulation (buf, sizeof buf, "%*d", 5, 414); EXPECTED_RESULT (" 414");
1460 ret = snprintf_emulation (buf, sizeof buf, "%-*d", 5, 414); EXPECTED_RESULT ("414 ");
1461 ret = snprintf_emulation (buf, sizeof buf, "%5i", -414); EXPECTED_RESULT (" -414");
1462 ret = snprintf_emulation (buf, sizeof buf, "%05i", -414); EXPECTED_RESULT ("-0414");
1463 ret = snprintf_emulation (buf, sizeof buf, "%2d", -414); EXPECTED_RESULT ("-414");
1464 ret = snprintf_emulation (buf, sizeof buf, "%.4d", -414); EXPECTED_RESULT ("-0414");
1465 ret = snprintf_emulation (buf, sizeof buf, "%6.4d", -314); EXPECTED_RESULT (" -0314");
1466 ret = snprintf_emulation (buf, sizeof buf, "%.4i", 314); EXPECTED_RESULT ("0314");
1467 ret = snprintf_emulation (buf, sizeof buf, "%6.4u", 414); EXPECTED_RESULT (" 0414");
1468 ret = snprintf_emulation (buf, sizeof buf, "%.d", 0); EXPECTED_RESULT ("");
1469 ret = snprintf_emulation (buf, sizeof buf, "% .0d", 0); EXPECTED_RESULT (" ");
1470 ret = snprintf_emulation (buf, sizeof buf, "%d", 0); EXPECTED_RESULT ("0");
1471 ret = snprintf_emulation (buf, sizeof buf, "%+d", 0); EXPECTED_RESULT ("+0");
1472 ret = snprintf_emulation (buf, sizeof buf, "% d", 0); EXPECTED_RESULT (" 0");
1474 ret = snprintf_emulation (buf, sizeof buf, "%04o", 0755); EXPECTED_RESULT ("0755");
1475 ret = snprintf_emulation (buf, sizeof buf, "%#o", 0644); EXPECTED_RESULT ("0644");
1476 ret = snprintf_emulation (buf, sizeof buf, "%#.o", 0); EXPECTED_RESULT ("0");
1477 ret = snprintf_emulation (buf, sizeof buf, "%#.5o", 0644); EXPECTED_RESULT ("00644");
1479 ret = snprintf_emulation (buf, sizeof buf, "%x", 0x987abc); EXPECTED_RESULT ("987abc");
1480 ret = snprintf_emulation (buf, sizeof buf, "%X", 0x987abc); EXPECTED_RESULT ("987ABC");
1481 ret = snprintf_emulation (buf, sizeof buf, "%02x", 0); EXPECTED_RESULT ("00");
1482 ret = snprintf_emulation (buf, sizeof buf, "%-#10x", 0x987abc); EXPECTED_RESULT ("0x987abc ");
1483 ret = snprintf_emulation (buf, sizeof buf, "%#10X", 0x987abc); EXPECTED_RESULT (" 0X987ABC");
1484 ret = snprintf_emulation (buf, sizeof buf, "%#X", 0); EXPECTED_RESULT ("0");
1485 ret = snprintf_emulation (buf, sizeof buf, "%#.X", 0); EXPECTED_RESULT ("");
1486 ret = snprintf_emulation (buf, sizeof buf, "%#05x", 20); EXPECTED_RESULT ("0x014");
1487 ret = snprintf_emulation (buf, sizeof buf, "%#.3X", 20); EXPECTED_RESULT ("0X014");
1488 ret = snprintf_emulation (buf, sizeof buf, "%#6.3X", 20); EXPECTED_RESULT (" 0X014");
1489 ret = snprintf_emulation (buf, sizeof buf, "%#-6.3X", 20); EXPECTED_RESULT ("0X014 ");
1491 ret = snprintf_emulation (buf, sizeof buf, "%c", 'a'); EXPECTED_RESULT ("a");
1492 ret = snprintf_emulation (buf, sizeof buf, "%2c", 'b'); EXPECTED_RESULT (" b");
1493 ret = snprintf_emulation (buf, sizeof buf, "%-2c", 'c'); EXPECTED_RESULT ("c ");
1494 ret = snprintf_emulation (buf, sizeof buf, "%-2s", "d"); EXPECTED_RESULT ("d ");
1495 ret = snprintf_emulation (buf, sizeof buf, "%2s", "e"); EXPECTED_RESULT (" e");
1496 ret = snprintf_emulation (buf, sizeof buf, "%2.1s", "fg"); EXPECTED_RESULT (" f");
1497 ret = snprintf_emulation (buf, sizeof buf, "%-2.1s", "gh"); EXPECTED_RESULT ("g ");
1498 ret = snprintf_emulation (buf, sizeof buf, "%.s", "x"); EXPECTED_RESULT ("");
1499 ret = snprintf_emulation (buf, sizeof buf, "%-4.9s", "hi"); EXPECTED_RESULT ("hi ");
1500 ret = snprintf_emulation (buf, sizeof buf, "%.s", "x"); EXPECTED_RESULT ("");
1502 int n;
1503 ret = snprintf_emulation (buf, sizeof buf, "%-5.2s%n %s", "jkl", &n, "lmn"); EXPECTED_RESULT ("jk lmn");
1504 ret = snprintf_emulation (buf, sizeof buf, "%0-3.2i", n); EXPECTED_RESULT ("05 ");
1506 ret = snprintf_emulation (buf, sizeof buf, "%p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT ("0x1234abc");
1507 ret = snprintf_emulation (buf, sizeof buf, "%12p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT (" 0x1234abc");
1508 ret = snprintf_emulation (buf, sizeof buf, "%-12p", reinterpret_cast<void *> (0x1234abc)); EXPECTED_RESULT ("0x1234abc ");
1510 ret = snprintf_emulation (buf, sizeof buf, "%hhu", 0x101); EXPECTED_RESULT ("1");
1511 ret = snprintf_emulation (buf, sizeof buf, "%hu", 0x10002); EXPECTED_RESULT ("2");
1512 ret = snprintf_emulation (buf, sizeof buf, "%#lx", 0x87654321ul); EXPECTED_RESULT ("0x87654321");
1513 ret = snprintf_emulation (buf, sizeof buf, "%llu", 612578912487901265ull); EXPECTED_RESULT ("612578912487901265");
1515 ret = snprintf_emulation (buf, sizeof buf, "%-+010.7d", 98765); EXPECTED_RESULT ("+0098765 ");
1516 ret = snprintf_emulation (buf, 10, "%-+010.7d", 98765); EXPECTED_RESULT_LEN ("+0098765 ", 10);
1518 ret = snprintf_emulation (buf, sizeof buf, "%f", 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, "%+-10F", 3.14); EXPECTED_RESULT ("+3.140000 ");
1521 ret = snprintf_emulation (buf, sizeof buf, "%010f", -3.14); EXPECTED_RESULT ("-03.140000");
1522 ret = snprintf_emulation (buf, sizeof buf, "% f", 3.14); EXPECTED_RESULT (" 3.140000");
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, "%#F", HUGE_VAL); EXPECTED_RESULT ("INF");
1526 ret = snprintf_emulation (buf, sizeof buf, "%5F", -HUGE_VAL); EXPECTED_RESULT (" -INF");
1527 #ifndef ACE_LYNXOS_MAJOR
1528 ret = snprintf_emulation (buf, sizeof buf, "%f", std::numeric_limits<double>::quiet_NaN ()); EXPECTED_RESULTS ("nan", "-nan");
1529 ret = snprintf_emulation (buf, sizeof buf, "%+F", std::numeric_limits<double>::quiet_NaN ()); EXPECTED_RESULTS ("+NAN", "-NAN");
1530 #endif
1531 ret = snprintf_emulation (buf, sizeof buf, "%.f", 2.17); EXPECTED_RESULT ("2");
1532 ret = snprintf_emulation (buf, sizeof buf, "%#.f", 2.17); EXPECTED_RESULT ("2.");
1533 ret = snprintf_emulation (buf, sizeof buf, "%.1f", 18.); EXPECTED_RESULT ("18.0");
1534 ret = snprintf_emulation (buf, sizeof buf, "%.1f", .9); EXPECTED_RESULT ("0.9");
1535 ret = snprintf_emulation (buf, sizeof buf, "%.2f", .01); EXPECTED_RESULT ("0.01");
1537 ret = snprintf_emulation (buf, sizeof buf, "%.2e", .01); EXPECTED_RESULT ("1.00e-02");
1538 ret = snprintf_emulation (buf, sizeof buf, "%#.E", .01); EXPECTED_RESULT ("1.E-02");
1539 ret = snprintf_emulation (buf, sizeof buf, "%+.E", .01); EXPECTED_RESULT ("+1E-02");
1540 ret = snprintf_emulation (buf, sizeof buf, "%e", 3.14159265); EXPECTED_RESULT ("3.141592e+00");
1541 ret = snprintf_emulation (buf, sizeof buf, "% .e", 0.); EXPECTED_RESULT (" 0e+00");
1542 ret = snprintf_emulation (buf, sizeof buf, "% -8.e", 0.); EXPECTED_RESULT (" 0e+00 ");
1544 #if !defined _MSC_VER || ACE_CC_MAJOR_VERSION > 7
1545 ret = snprintf_emulation (buf, sizeof buf, "% -11.2e", -0.); EXPECTED_RESULT ("-0.00e+00 ");
1546 #endif
1548 ret = snprintf_emulation (buf, sizeof buf, "%.E", 9e101); EXPECTED_RESULTS ("9E+101", "8E+101"); // could be rounded
1550 ret = snprintf_emulation (buf, sizeof buf, "%g", 3.); EXPECTED_RESULT ("3");
1551 ret = snprintf_emulation (buf, sizeof buf, "%g", 3.000001); EXPECTED_RESULT ("3");
1552 ret = snprintf_emulation (buf, sizeof buf, "%.6g", 3.000001); EXPECTED_RESULT ("3");
1553 ret = snprintf_emulation (buf, sizeof buf, "%G", 3000000.1); EXPECTED_RESULT ("3E+06");
1554 ret = snprintf_emulation (buf, sizeof buf, "%+#g", 3000000.1); EXPECTED_RESULT ("+3.00000e+06");
1555 ret = snprintf_emulation (buf, sizeof buf, "%G", -3000010.); EXPECTED_RESULTS ("-3.00001E+06", "-3E+06");
1556 ret = snprintf_emulation (buf, sizeof buf, "%g", .0001); EXPECTED_RESULT ("0.0001");
1557 ret = snprintf_emulation (buf, sizeof buf, "%- g", .00001); EXPECTED_RESULT (" 1e-05");
1559 ret = snprintf_emulation (buf, sizeof buf, "%a", 4.); EXPECTED_RESULT ("0x8p-1");
1560 ret = snprintf_emulation (buf, sizeof buf, "%#a", 4.); EXPECTED_RESULT ("0x8.p-1");
1561 ret = snprintf_emulation (buf, sizeof buf, "%A", -3.125); EXPECTED_RESULT ("-0XC.8P-2");
1562 ret = snprintf_emulation (buf, sizeof buf, "%+a", 0.); EXPECTED_RESULT ("+0x0p+0");
1563 ret = snprintf_emulation (buf, sizeof buf, "%+-10.1a", 0.); EXPECTED_RESULT ("+0x0.0p+0 ");
1564 ret = snprintf_emulation (buf, sizeof buf, "%0+10.1a", 0.); EXPECTED_RESULT ("+0x00.0p+0");
1565 ret = snprintf_emulation (buf, sizeof buf, "% 09A", 16.625); EXPECTED_RESULT (" 0X8.5P+1");
1566 ret = snprintf_emulation (buf, sizeof buf, "% 010a", 16.625); EXPECTED_RESULT (" 0x08.5p+1");
1568 ret = snprintf_emulation (buf, sizeof buf, "%%%d%#x", 1, 2); EXPECTED_RESULT ("%10x2");
1569 ret = snprintf_emulation (buf, sizeof buf, "foo %%%% bar"); EXPECTED_RESULT ("foo %% bar");
1570 ret = snprintf_emulation (buf, sizeof buf, ""); EXPECTED_RESULT ("");
1571 ret = snprintf_emulation (buf, sizeof buf, "foo"); EXPECTED_RESULT ("foo");
1573 ret = snprintf_emulation (buf, sizeof buf, "%'d", 12345); LOG_RESULT ("12,345");
1574 ret = snprintf_emulation (buf, sizeof buf, "%'d", 123456); LOG_RESULT ("123,456");
1575 ret = snprintf_emulation (buf, sizeof buf, "%'d", 1234567890); LOG_RESULT ("1,234,567,890");
1576 ret = snprintf_emulation (buf, sizeof buf, "%'.f", 12345.); LOG_RESULT ("12,345");
1577 ret = snprintf_emulation (buf, sizeof buf, "%'.f", 1234567890.); LOG_RESULT ("1,234,567,890");
1578 ret = snprintf_emulation (buf, sizeof buf, "%'.6d", 12345); LOG_RESULT ("012,345");
1579 ret = snprintf_emulation (buf, sizeof buf, "%0'8d", 12345); LOG_RESULT ("0012,345");
1581 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");
1582 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");
1583 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");
1584 ret = snprintf_emulation (buf, sizeof buf, "%2$#*1$x", -4, 10); EXPECTED_RESULT ("0xa ");
1586 return failed ? 1 : 0;
1588 #endif // ACE_HAS_VSNPRINTF_EMULATION
1591 swab_test (void)
1593 ACE_DEBUG ((LM_DEBUG,
1594 ACE_TEXT ("Testing swab method\n")));
1596 int error_count = 0;
1597 char const from[] = "BADCFEHGJILKNMPORQTSVUXWZY";
1598 char to[] = "..........................";
1599 char expect[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1601 ACE_OS::swab (from, to, sizeof (from));
1602 if (ACE_OS::strcmp (to, expect) != 0)
1604 ACE_ERROR ((LM_ERROR,
1605 ACE_TEXT ("swab error: %C, expected %C\n"),
1606 to, expect));
1607 ++error_count;
1610 return error_count;
1614 gai_strerror_test (void)
1616 ACE_DEBUG ((LM_DEBUG,
1617 ACE_TEXT ("Testing gai_strerror method\n")));
1619 const ACE_TCHAR* error_text = ACE_OS::gai_strerror (EAI_FAMILY);
1621 ACE_UNUSED_ARG (error_text);
1623 return 0;
1627 run_main (int, ACE_TCHAR *[])
1629 ACE_START_TEST (ACE_TEXT ("OS_Test"));
1631 // Enable a locale that has digit grouping so that snprintf's %'d is
1632 // different than %d. If the locale is not available the test won't
1633 // fail (log file needs to be examined to check formatting).
1634 #ifdef ACE_WIN32
1635 std::setlocale(LC_NUMERIC, "en-US");
1636 #elif defined ACE_LINUX
1637 std::setlocale(LC_NUMERIC, "en_US.utf8");
1638 #endif
1640 int status = 0;
1641 int result;
1643 if ((result = access_test ()) != 0)
1644 status = result;
1646 if ((result = rename_test ()) != 0)
1647 status = result;
1649 if ((result = string_emulation_test ()) != 0)
1650 status = result;
1652 if ((result = snprintf_test (ACE_OS::snprintf)) != 0)
1653 status = result;
1655 #if defined (ACE_HAS_VSNPRINTF_EMULATION)
1656 if ((result = snprintf_test (snprintf_emulation)) != 0)
1657 status = result;
1659 if ((result = snprintf_emulation_test ()) != 0)
1660 status = result;
1661 #endif
1663 if ((result = getpwnam_r_test ()) != 0)
1664 status = result;
1666 if ((result = ctime_r_test ()) != 0)
1667 status = result;
1669 if ((result = string_strsncpy_test ()) != 0)
1670 status = result;
1672 if ((result = strsignal_test ()) != 0)
1673 status = result;
1675 if ((result = cpu_info_test ()) != 0)
1676 status = result;
1678 if ((result = pagesize_test ()) != 0)
1679 status = result;
1681 if ((result = ceilf_test ()) != 0)
1682 status = result;
1684 if ((result = floorf_test ()) != 0)
1685 status = result;
1687 if ((result = ceil_test ()) != 0)
1688 status = result;
1690 if ((result = floor_test ()) != 0)
1691 status = result;
1693 if ((result = ceill_test ()) != 0)
1694 status = result;
1696 if ((result = floorl_test ()) != 0)
1697 status = result;
1699 if ((result = log2_test ()) != 0)
1700 status = result;
1702 if ((result = last_error_test ()) != 0)
1703 status = result;
1705 if ((result = ace_ctype_test ()) != 0)
1706 status = result;
1708 if ((result = swab_test ()) != 0)
1709 status = result;
1711 if ((result = compiler_test ()) != 0)
1712 status = result;
1714 if ((result = version_test ()) != 0)
1715 status = result;
1717 if ((result = gai_strerror_test ()) != 0)
1718 status = result;
1720 ACE_END_TEST;
1721 return status;
1723 #undef THIS_IS_NOT_AN_ASSERT_IT_IS_A_NON_DEBUG_TEST_AS_WELL