diff options
author | Olli Savia <ops@iki.fi> | 2006-11-24 13:06:45 +0000 |
---|---|---|
committer | Olli Savia <ops@iki.fi> | 2006-11-24 13:06:45 +0000 |
commit | 290b270989b890ccf64dbde68696c47a3e2c7e56 (patch) | |
tree | 928b613cf1858e9c6fac69726fea6f3ef5b5f8da | |
parent | fcd1533f47df16af4c2d8760de56297f97f6e43d (diff) | |
download | ATCD-290b270989b890ccf64dbde68696c47a3e2c7e56.tar.gz |
ChangeLogTag: Fri Nov 24 13:05:01 UTC 2006 Olli Savia <ops@iki.fi>
-rw-r--r-- | ACE/ChangeLog | 5 | ||||
-rw-r--r-- | ACE/tests/OS_Test.cpp | 71 |
2 files changed, 76 insertions, 0 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 65e204bf536..c3a3bd26f4c 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,8 @@ +Fri Nov 24 13:05:01 UTC 2006 Olli Savia <ops@iki.fi> + + * tests/OS_Test.cpp: + Added ACE_OS::snprintf test. + Fri Nov 24 10:08:12 UTC 2006 Johnny Willemsen <jwillemsen@remedy.nl> * ace/Sock_Connect.cpp: diff --git a/ACE/tests/OS_Test.cpp b/ACE/tests/OS_Test.cpp index fa7b058e4e4..5d108bafc4f 100644 --- a/ACE/tests/OS_Test.cpp +++ b/ACE/tests/OS_Test.cpp @@ -524,6 +524,74 @@ string_emulation_test (void) return 0; } +// Test ACE_OS::snprintf +int +snprintf_test (void) +{ + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing snprintf\n"))); + + int error_count = 0; + const int BUFSIZE = 4; + char buf[2*BUFSIZE]; + int retval; + + ACE_OS::memset(buf, 0xab, 2*BUFSIZE); + retval = ACE_OS::snprintf (buf, BUFSIZE, "%d", 123); + if (retval != 3) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("[1] ACE_OS::snprintf() returns %d, should be 3\n"), + retval)); + ++error_count; + } + + ACE_OS::memset(buf, 0xab, 2*BUFSIZE); + retval = ACE_OS::snprintf (buf, BUFSIZE, "%d", 1234); + if (retval != 4) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("[2] ACE_OS::snprintf() returns %d, should be 4\n"), + retval)); + ++error_count; + } + + if (buf[3] != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("[3] ACE_OS::snprintf() doesn't terminate string correctly\n"))); + ++error_count; + } + else if (ACE_OS::strcmp(buf, "123") != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("[4] ACE_OS::snprintf() incorrect output\n"))); + ++error_count; + } + + ACE_OS::memset(buf, 0xab, 2*BUFSIZE); + retval = ACE_OS::snprintf (buf, BUFSIZE, "%d", 12345); + if (retval != 5) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("[5] ACE_OS::snprintf() returns %d, should be 5\n"), + retval)); + ++error_count; + } + else if (buf[3] != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("[6] ACE_OS::snprintf() doesn't terminate string correctly\n"))); + ++error_count; + } + else if (ACE_OS::strcmp(buf, "123") != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("[6] ACE_OS::snprintf() incorrect output\n"))); + ++error_count; + } + + return error_count; +} static int ctime_r_test (void) @@ -839,6 +907,9 @@ run_main (int, ACE_TCHAR *[]) if ((result = string_emulation_test ()) != 0) status = result; + if ((result = snprintf_test ()) != 0) + status = result; + if ((result = ctime_r_test ()) != 0) status = result; |