summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorbala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-12-10 22:23:21 +0000
committerbala <bala@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2002-12-10 22:23:21 +0000
commit62a4408946cab06e10e479f1728497b5c6c4d88d (patch)
tree96c1ecc8ef992eaa85738c4df4173785e3079808 /tests
parentb97c27d48cf029b08c59da49a696d275c055ade4 (diff)
downloadATCD-62a4408946cab06e10e479f1728497b5c6c4d88d.tar.gz
ChangeLogTag: Tue Dec 10 17:19:06 2002 Balachandran Natarajan <bala@isis-server.isis.vanderbilt.edu>
Diffstat (limited to 'tests')
-rw-r--r--tests/OS_Test.cpp177
1 files changed, 118 insertions, 59 deletions
diff --git a/tests/OS_Test.cpp b/tests/OS_Test.cpp
index 12a3608b118..d6bd7de2f21 100644
--- a/tests/OS_Test.cpp
+++ b/tests/OS_Test.cpp
@@ -557,88 +557,147 @@ ctime_r_test (void)
return result;
}
+
int
string_strsncpy_test (void)
{
{
// Test strsncpy (char version)
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Testing strsncpy (char version)\n")));
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("Testing strsncpy (char version)\n")));
- char strsncpy1[] = "abcdefghijklmnopqrstuvwxyzabc";
- char strsncpy2[36];
+ char strsncpy1[] = "abcdefghijklmnopqrstuvwxyzabc";
+ char strsncpy2[36];
+
+ // strsncpy() where the max. length doesn't matter
+ ACE_ASSERT
+ (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy1,
+ 36),
+ strsncpy1) == 0);
- ACE_ASSERT
- (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ // strsncpy() where the max length does matter
+ ACE_ASSERT
+ (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
strsncpy1,
- 36),
- strsncpy1) == 0);
-
- ACE_ASSERT
- (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
- strsncpy1,
- 26),
- strsncpy1,
- 25) == 0);
- strsncpy1[25] = 0;
- strsncpy2[25] = 0;
-
- ACE_ASSERT (ACE_OS_String::strcmp (strsncpy2, strsncpy1) == 0);
-
- ACE_ASSERT
- (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
- strsncpy1,
- 2),
- strsncpy1,
- 1) == 0);
- ACE_ASSERT
- (ACE_OS_String::strlen (ACE_OS_String::strsncpy (strsncpy2,
+ 26),
+ strsncpy1,
+ 25) == 0);
+
+ // strsncpy1 and strsncpy2 are different size --> not equal
+ ACE_ASSERT (ACE_OS_String::strcmp (strsncpy2, strsncpy1) != 0);
+
+ // max. length == 2 --> 1 char available
+ ACE_ASSERT
+ (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
strsncpy1,
- 1)) == 0);
+ 2),
+ strsncpy1,
+ 1) == 0);
+
+ // max length == 1 --> empty string
+ ACE_ASSERT
+ (ACE_OS_String::strlen (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy1,
+ 1)) == 0);
+
+ // just preparation for the next assert
+ ACE_ASSERT
+ (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy1,
+ 36),
+ strsncpy1) == 0);
+
+ // A tricky one, if the max. length == 0 --> do nothing
+ // so the strsncpy2 shouldn't change
+ ACE_ASSERT
+ (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ "test",
+ 0),
+ strsncpy1) == 0);
+
+ // If src == dst --> truncate dst if needed!
+ ACE_ASSERT
+ (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy2,
+ 10),
+ strsncpy1,
+ 9) == 0);
+ // size should be 9 (+ '\0' char)
+ ACE_ASSERT(ACE_OS_String::strlen(strsncpy2) == 9);
}
#if defined (ACE_HAS_WCHAR)
{
- // Test strsncpy (wchar_t version)
+ // Test strsncpy (wchar_t version)
ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Testing strsncpy (wchar_t version)\n")));
+ ACE_TEXT ("Testing strsncpy (wchar_t version)\n")));
+
+ wchar_t strsncpy1[] = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyzabc");
+ wchar_t strsncpy2[36];
- wchar_t strsncpy1[] = ACE_TEXT_WIDE ("abcdefghijklmnopqrstuvwxyzabc");
- wchar_t strsncpy2[36];
+ // strsncpy() where the max. length doesn't matter
+ ACE_ASSERT
+ (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy1,
+ 36),
+ strsncpy1) == 0);
- ACE_ASSERT
- (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ // strsncpy() where the max length does matter
+ ACE_ASSERT
+ (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
strsncpy1,
- 36),
- strsncpy1) == 0);
- ACE_ASSERT
- (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
- strsncpy1,
- 26),
- strsncpy1,
- 25) == 0);
-
- strsncpy1[25] = 0;
- strsncpy2[25] = 0;
-
- ACE_ASSERT (ACE_OS_String::strcmp (strsncpy2, strsncpy1) == 0);
-
- ACE_ASSERT
- (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
- strsncpy1,
- 2),
- strsncpy1,
- 1) == 0);
- ACE_ASSERT
- (ACE_OS_String::strlen (ACE_OS_String::strsncpy (strsncpy2,
+ 26),
+ strsncpy1,
+ 25) == 0);
+
+ // strsncpy1 and strsncpy2 are different size --> not equal
+ ACE_ASSERT (ACE_OS_String::strcmp (strsncpy2, strsncpy1) != 0);
+
+ // max. length == 2 --> 1 char available
+ ACE_ASSERT
+ (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
strsncpy1,
- 1)) == 0);
+ 2),
+ strsncpy1,
+ 1) == 0);
+ // max length == 1 --> empty string
+ ACE_ASSERT
+ (ACE_OS_String::strlen (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy1,
+ 1)) == 0);
+
+ // just preparation for the next assert
+ ACE_ASSERT
+ (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy1,
+ 36),
+ strsncpy1) == 0);
+
+ // A tricky one, if the max. length == 0 --> do nothing
+ // so the strsncpy2 shouldn't change
+ ACE_ASSERT
+ (ACE_OS_String::strcmp (ACE_OS_String::strsncpy (strsncpy2,
+ ACE_TEXT_WIDE
+("test"),
+ 0),
+ strsncpy1) == 0);
+
+ // If src == dst --> truncate dst if needed!
+ ACE_ASSERT
+ (ACE_OS_String::strncmp (ACE_OS_String::strsncpy (strsncpy2,
+ strsncpy2,
+ 10),
+ strsncpy1,
+ 9) == 0);
+ // size should be 9 (+ '\0' char)
+ ACE_ASSERT(ACE_OS_String::strlen(strsncpy2) == 9);
}
#endif /* ACE_HAS_WCHAR */
- return 0;
+ return 0;
}
int