summaryrefslogtreecommitdiff
path: root/ACE/tests/OS_Test.cpp
diff options
context:
space:
mode:
authorolli <olli@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2006-11-24 13:06:45 +0000
committerolli <olli@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2006-11-24 13:06:45 +0000
commitfc7bef54aeed581f36e6822fb8f57665a35751b5 (patch)
tree928b613cf1858e9c6fac69726fea6f3ef5b5f8da /ACE/tests/OS_Test.cpp
parent4ff167c5e48be2d970e9a0b4d29487230e134d51 (diff)
downloadATCD-fc7bef54aeed581f36e6822fb8f57665a35751b5.tar.gz
ChangeLogTag: Fri Nov 24 13:05:01 UTC 2006 Olli Savia <ops@iki.fi>
Diffstat (limited to 'ACE/tests/OS_Test.cpp')
-rw-r--r--ACE/tests/OS_Test.cpp71
1 files changed, 71 insertions, 0 deletions
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;