stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r387379 - in /incubator/stdcxx/trunk/tests: include/rw_char.h self/0.char.cpp src/char.cpp
Date Tue, 21 Mar 2006 01:46:43 GMT
Author: sebor
Date: Mon Mar 20 17:46:41 2006
New Revision: 387379

URL: http://svn.apache.org/viewcvs?rev=387379&view=rev
Log:
2006-03-20  Martin Sebor  <sebor@roguewave.com>

	* rw_char.h (rw_narrow): Declared new testsuite helper(s).
	* char.cpp (rw_narrow): Implemented new testsuite helper(s).
	* 0.char.cpp (test_narrow): Exercised new testsuite helper(s).

Modified:
    incubator/stdcxx/trunk/tests/include/rw_char.h
    incubator/stdcxx/trunk/tests/self/0.char.cpp
    incubator/stdcxx/trunk/tests/src/char.cpp

Modified: incubator/stdcxx/trunk/tests/include/rw_char.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/rw_char.h?rev=387379&r1=387378&r2=387379&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/rw_char.h (original)
+++ incubator/stdcxx/trunk/tests/include/rw_char.h Mon Mar 20 17:46:41 2006
@@ -260,9 +260,9 @@
 };
 
 
-// widens the string src into the buffer dst; when (dst != 0) the last
-// character in the buffer is guaranteed to be NUL, regardless of the
-// value of str [len]
+// rw_widen() widens successive elements of src into the buffer dst
+// when (dst != 0) the last character in the buffer is guaranteed to be NUL,
+// regardless of the value of str [len]
 // when (len == SIZE_MAX && src != 0), computes len as if by evaluating
 // len = strlen(src)
 // when (src == 0 && len < SIZE_MAX), initializes the first len elements
@@ -274,14 +274,27 @@
                 const char*   /* src */,
                 _RWSTD_SIZE_T /* len */ = _RWSTD_SIZE_MAX);
 
+// rw_narrow() narrows successive elements of src into the buffer dst
+// (see rw_widen() for details)
+_TEST_EXPORT
+char* rw_narrow (char*         /* dst */,
+                 const char*   /* src */,
+                 _RWSTD_SIZE_T /* len */ = _RWSTD_SIZE_MAX);
+
 #ifndef _RWSTD_WCHAR_T
 
 _TEST_EXPORT
 wchar_t* rw_widen (wchar_t*, const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
 
+_TEST_EXPORT
+char* rw_narrow (char*, const wchar_t*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
+
 #endif   // _RWSTD_WCHAR_T
 
 _TEST_EXPORT
 UserChar* rw_widen (UserChar*, const char*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
+
+_TEST_EXPORT
+char* rw_narrow (char*, const UserChar*, _RWSTD_SIZE_T = _RWSTD_SIZE_MAX);
 
 #endif   // RW_CHAR_INCLUDED

Modified: incubator/stdcxx/trunk/tests/self/0.char.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/self/0.char.cpp?rev=387379&r1=387378&r2=387379&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/self/0.char.cpp (original)
+++ incubator/stdcxx/trunk/tests/self/0.char.cpp Mon Mar 20 17:46:41 2006
@@ -467,7 +467,7 @@
             rw_widen (udst, src, i) : rw_widen (udst, src);
 
         rw_assert (udst == ret, 0, __LINE__,
-                   "rw_widen(wchar_t*, %{#s}%{?}, %zu%{;})",
+                   "rw_widen(UserChar*, %{#s}%{?}, %zu%{;})",
                    src, i < nsrc, i);
 
         rw_assert (   0 == memcmp (udst, usrc, i * sizeof *udst)
@@ -487,11 +487,120 @@
 
 /***********************************************************************/
 
+static void
+test_narrow ()
+{
+    //////////////////////////////////////////////////////////////////
+    rw_info (0, 0, 0, "rw_narrow(char*, const char*, size_t)");
+
+    static const char   src []  = "abcdefgh";
+    static const size_t nsrc = sizeof src;
+    static const char   null [nsrc + 1] = "";
+    char                cdst [nsrc + 1];
+
+    for (size_t i = 0; i != nsrc + 1; ++i) {
+
+        memset (cdst, 0, sizeof cdst);
+
+        const char* const ret = i < nsrc ?
+            rw_narrow (cdst, src, i) : rw_narrow (cdst, src);
+
+        rw_assert (cdst == ret, 0, __LINE__,
+                   "rw_narrow(char*, %{#s}%{?}, %zu%{;})",
+                   src, i < nsrc);
+
+        rw_assert (0 == memcmp (cdst, src, i) && '\0' == cdst [i],
+                   0, __LINE__,
+                   "rw_narrow(char*, %{#s}%{?}, %zu%{;}) == %{#*s}, got %{#*s}",
+                   src, i < nsrc, i, int (i), src, int (i + 1), cdst);
+    }
+
+    memset (cdst, '@', sizeof cdst);
+    rw_narrow (cdst, (const char*)0, sizeof cdst);
+
+    rw_assert (0 == memcmp (cdst, null, sizeof cdst), 0, __LINE__,
+               "rw_narrow(char*, %{#s}, %zu) == %{#*s}, got %{#*s}",
+               0, sizeof cdst, int (sizeof cdst), null,
+               int (sizeof cdst), cdst);
+               
+
+#ifndef _RWSTD_NO_WCHAR_T
+
+    //////////////////////////////////////////////////////////////////
+    rw_info (0, 0, 0, "rw_narrow(wchar_t*, const wchar_t*, size_t)");
+
+    static const wchar_t wsrc [] = L"abcdefgh";
+
+    for (size_t i = 0; i != nsrc + 1; ++i) {
+
+        memset (cdst, 0, sizeof cdst);
+
+        const char* const ret = i < nsrc ?
+            rw_narrow (cdst, wsrc, i) : rw_narrow (cdst, wsrc);
+
+        rw_assert (cdst == ret, 0, __LINE__,
+                   "rw_narrow(char*, %{#s}%{?}, %zu%{;})",
+                   src, i < nsrc, i);
+
+        rw_assert (0 == memcmp (cdst, src, i) && '\0' == cdst [i],
+                   0, __LINE__,
+                   "rw_narrow(char*, L%{#*ls}%{?}, %zu%{;}) == %{#*s}, "
+                   "got %{#*s}",
+                   src, i < nsrc, i, int (i), wsrc, int (i + 1), cdst);
+    }
+
+    memset (cdst, '@', sizeof cdst);
+    rw_narrow (cdst, (const wchar_t*)0, sizeof cdst);
+
+    rw_assert (0 == memcmp (cdst, null, nsrc + 1), 0, __LINE__,
+               "rw_narrow(char*, %{#s}, %zu) == %{#*s}, got %{#*s}",
+               0, sizeof cdst, int (sizeof null), null,
+               int (sizeof cdst), cdst);
+
+#endif   // _RWSTD_NO_WCHAR_T
+
+    //////////////////////////////////////////////////////////////////
+    rw_info (0, 0, 0, "rw_narrow(char*, const UserChar*, size_t)");
+
+    static const UserChar usrc [] = {
+        { 0, 'a' }, { 0, 'b' }, { 0, 'c' }, { 0, 'd' },
+        { 0, 'e' }, { 0, 'f' }, { 0, 'g' }, { 0, 'h' },
+        { 0, '\0' }
+    };
+
+    for (size_t i = 0; i != nsrc + 1; ++i) {
+
+        memset (cdst, 0, sizeof cdst);
+
+        const char* const ret = i < nsrc ?
+            rw_narrow (cdst, usrc, i) : rw_narrow (cdst, usrc);
+
+        rw_assert (cdst == ret, 0, __LINE__,
+                   "rw_narrow(char*, %{#s}%{?}, %zu%{;})",
+                   src, i < nsrc, i);
+
+        rw_assert (0 == memcmp (cdst, src, i) && 0 == cdst [i],
+                   0, __LINE__,
+                   "rw_narrow(char*, %{#s}%{?}, %zu%{;})",
+                   src, i < nsrc, i);
+    }
+
+    memset (cdst, '@', sizeof cdst);
+    rw_narrow (cdst, (const UserChar*)0, sizeof cdst);
+
+    rw_assert (0 == memcmp (cdst, null, nsrc + 1), 0, __LINE__,
+               "rw_narrow(char*, %{#s}, %zu)",
+               0, sizeof cdst);
+}
+
+/***********************************************************************/
+
 static int no_user_traits;
 static int no_user_traits_char;
 static int no_user_traits_wchar_t;
 static int no_user_traits_user_char;
 static int no_rw_widen;
+static int no_rw_narrow;
 
 
 static int
@@ -530,6 +639,13 @@
         test_widen ();
     }
 
+    if (no_rw_narrow) {
+        rw_note (0, 0, 0, "rw_narrow() tests disabled");
+    }
+    else {
+        test_narrow ();
+    }
+
     return 0;
 }
 
@@ -545,10 +661,13 @@
                     "|-no-UserTraits<char># "
                     "|-no-UserTraits<wchar_t># "
                     "|-no-UserTraits<UserChar># "
-                    "|-no-rw_widen#",
+                    "|-no-rw_widen# "
+                    "|-no-rw_narrow#",
                     &no_user_traits,
                     &no_user_traits_char,
                     &no_user_traits_wchar_t,
                     &no_user_traits_user_char,
-                    &no_rw_widen);
+                    &no_rw_widen,
+                    &no_rw_narrow,
+                    0);
 }

Modified: incubator/stdcxx/trunk/tests/src/char.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/char.cpp?rev=387379&r1=387378&r2=387379&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/char.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/char.cpp Mon Mar 20 17:46:41 2006
@@ -229,7 +229,7 @@
 
 _TEST_EXPORT
 char*
-rw_widen (char *dst, const char *src, size_t len)
+rw_widen (char *dst, const char *src, size_t len /* = SIZE_MAX */)
 {
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
@@ -254,11 +254,18 @@
 }
 
 
+_TEST_EXPORT
+char* rw_narrow (char *dst, const char *src, size_t len /* = SIZE_MAX */)
+{
+    return rw_widen (dst, src, len);
+}
+
+
 #ifndef _RWSTD_WCHAR_T
 
 _TEST_EXPORT
 wchar_t*
-rw_widen (wchar_t *dst, const char *src, size_t len)
+rw_widen (wchar_t *dst, const char *src, size_t len /* = SIZE_MAX */)
 {
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
@@ -290,12 +297,52 @@
     return dst;
 }
 
+
+_TEST_EXPORT
+char*
+rw_narrow (char *dst, const wchar_t *src, size_t len /* = SIZE_MAX */)
+{
+    // compute the length of src if not specified
+    if (_RWSTD_SIZE_MAX == len) {
+        if (src) {
+            for (len = 0; src [len]; ++len);
+        }
+        else
+            len = 0;
+    }
+
+    // if len is non-zero dst must be non-0 as well
+    RW_ASSERT (0 == len || 0 != dst);
+
+    if (dst) {
+        if (src) {
+            // narrow src into dst one element at a time
+            for (size_t i = 0; ; ++i) {
+                typedef unsigned char UChar;
+
+                if (i == len) {
+                    dst [i] = '\0';
+                    break;
+                }
+
+                dst [i] = char (UChar (src [i]));
+            }
+        }
+        else {
+            // set dst to all NUL
+            memset (dst, 0, len);
+        }
+    }
+
+    return dst;
+}
+
 #endif   // _RWSTD_WCHAR_T
 
 
 _TEST_EXPORT
 UserChar*
-rw_widen (UserChar *dst, const char *src, size_t len)
+rw_widen (UserChar *dst, const char *src, size_t len /* = SIZE_MAX */)
 {
     // compute the length of src if not specified
     if (_RWSTD_SIZE_MAX == len)
@@ -322,6 +369,46 @@
         else {
             // set dst to all NUL
             memset (dst, 0, len * sizeof *dst);
+        }
+    }
+
+    return dst;
+}
+
+
+_TEST_EXPORT
+char*
+rw_narrow (char *dst, const UserChar *src, size_t len /* = SIZE_MAX */)
+{
+    // compute the length of src if not specified
+    if (_RWSTD_SIZE_MAX == len) {
+        if (src) {
+            for (len = 0; src [len].f || src [len].c; ++len);
+        }
+        else
+            len = 0;
+    }
+
+    // if len is non-zero dst must be non-0 as well
+    RW_ASSERT (0 == len || 0 != dst);
+
+    if (dst) {
+        if (src) {
+            // narrow src into dst one element at a time
+            for (size_t i = 0; ; ++i) {
+                typedef unsigned char UChar;
+
+                if (i == len) {
+                    dst [i] = '\0';
+                    break;
+                }
+
+                dst [i] = char (src [i].c);
+            }
+        }
+        else {
+            // set dst to all NUL
+            memset (dst, 0, len);
         }
     }
 



Mime
View raw message