Author: vitek
Date: Mon Aug  4 13:49:15 2008
New Revision: 682503

URL: http://svn.apache.org/viewvc?rev=682503&view=rev
Log:
2008-08-04  Travis Vitek  <[EMAIL PROTECTED]>

        Merge r677461 from branches/4.2.x


        2008-07-16  Martin Sebor  <[EMAIL PROTECTED]>

        * tests/self/0.printf.cpp (<rw_value.h>): #included for UserClass.
        (test_userclass_format): New function to exercise the "%{X=}"
        formatting directive for arrays of UserClass objects.
        (main): Called it.
        * tests/src/value.cpp (_rw_fmtxarrayv): Corrected and simplified
        cursor positioning.


Modified:
    stdcxx/trunk/tests/self/0.printf.cpp
    stdcxx/trunk/tests/src/value.cpp

Modified: stdcxx/trunk/tests/self/0.printf.cpp
URL: 
http://svn.apache.org/viewvc/stdcxx/trunk/tests/self/0.printf.cpp?rev=682503&r1=682502&r2=682503&view=diff
==============================================================================
--- stdcxx/trunk/tests/self/0.printf.cpp (original)
+++ stdcxx/trunk/tests/self/0.printf.cpp Mon Aug  4 13:49:15 2008
@@ -30,9 +30,10 @@
 // but not in the compiler's pure C++ libc headers)
 #undef __PURE_CNAME
 
+#include <rw_environ.h> // for rw_putenv()
 #include <rw_printf.h>
 #include <rw_process.h> // for rw_pid_t
-#include <rw_environ.h> // for rw_putenv()
+#include <rw_value.h>   // for UserClass
 
 #include <bitset>       // for bitset
 #include <ios>          // for ios::iostate, ios::openmode, ios::seekdir
@@ -813,7 +814,6 @@
     const int bad  = std::ios_base::badbit;
     const int eof  = std::ios_base::eofbit;
     const int fail = std::ios_base::failbit;
-    const int good = std::ios_base::goodbit;
 
     TEST ("[%{Is}]", 0,                0, 0, "[goodbit]");
     TEST ("[%{Is}]", bad,              0, 0, "[badbit]");
@@ -2924,6 +2924,84 @@
 
 /***********************************************************************/
 
+static void
+test_userclass_format ()
+{
+    // %{X=} directive syntax:
+    //
+    //   "X=" [ '#' ] [ '+' ] [ '*' | <n> ] [ '.' [ '*' | '@' | <n> ] ]
+    //
+    // where
+    //   '#' causes UserClass::id_ to be included in output
+    //   '+' forces UserClass::data_.val_ to be formatted as an int
+    //       otherwise it is formatted as an (optionally escaped)
+    //       char
+    //   '*' or <n> is the number of elements in the sequence
+    //       (the first occurrence)
+    //   '*', <n> is the offset of the cursor within the sequence
+    //            (where the cursor is a pair of pointy brackets
+    //            surrounding the element, e.g., >123<)
+    //   '@' is the pointer to the element to be surrended by the
+    //       pair of pointy brackets
+
+    UserClass* const x = UserClass::from_char ("abcdef");
+
+    TEST ("[%{X=*}]", 0, x, 0, "[]");
+    TEST ("[%{X=*}]", 1, x, 0, "[a]");
+    TEST ("[%{X=*}]", 2, x, 0, "[ab]");
+    TEST ("[%{X=*}]", 3, x, 0, "[abc]");
+    TEST ("[%{X=*}]", 4, x, 0, "[abcd]");
+    TEST ("[%{X=*}]", 5, x, 0, "[abcde]");
+    TEST ("[%{X=*}]", 6, x, 0, "[abcdef]");
+
+    TEST ("[%{X=#*}]", 0, x, 0, "[]");
+    TEST ("[%{X=#*}]", 1, x, 0, "[1:a]");
+    TEST ("[%{X=#*}]", 2, x, 0, "[1:a2:b]");
+    TEST ("[%{X=#*}]", 3, x, 0, "[1:a2:b3:c]");
+    TEST ("[%{X=#*}]", 4, x, 0, "[1:a2:b3:c4:d]");
+    TEST ("[%{X=#*}]", 5, x, 0, "[1:a2:b3:c4:d5:e]");
+    TEST ("[%{X=#*}]", 6, x, 0, "[1:a2:b3:c4:d5:e6:f]");
+
+    TEST ("[%{X=+*}]", 0, x, 0, "[]");
+    TEST ("[%{X=+*}]", 1, x, 0, "[97]");
+    TEST ("[%{X=+*}]", 2, x, 0, "[97,98]");
+    TEST ("[%{X=+*}]", 3, x, 0, "[97,98,99]");
+    TEST ("[%{X=+*}]", 4, x, 0, "[97,98,99,100]");
+    TEST ("[%{X=+*}]", 5, x, 0, "[97,98,99,100,101]");
+    TEST ("[%{X=+*}]", 6, x, 0, "[97,98,99,100,101,102]");
+
+    TEST ("[%{X=+*.0}]", 0, x, 0, "[]");
+
+    TEST ("[%{X=+*.0}]", 1, x, 0, "[>97<]");
+
+    TEST ("[%{X=+*.*}]", 2, 0, x, "[>97<,98]");
+    TEST ("[%{X=+*.1}]", 2, x, 0, "[97,>98<]");
+
+    TEST ("[%{X=+*.0}]", 3, x, 0, "[>97<,98,99]");
+    TEST ("[%{X=+*.*}]", 3, 1, x, "[97,>98<,99]");
+    TEST ("[%{X=+*.*}]", 3, 2, x, "[97,98,>99<]");
+
+    TEST ("[%{X=+*.*}]", 4, 0, x, "[>97<,98,99,100]");
+    TEST ("[%{X=+*.*}]", 4, 1, x, "[97,>98<,99,100]");
+    TEST ("[%{X=+*.*}]", 4, 2, x, "[97,98,>99<,100]");
+    TEST ("[%{X=+*.*}]", 4, 3, x, "[97,98,99,>100<]");
+
+    TEST ("[EMAIL PROTECTED]", 4, x + 3, x, "[97,98,99,>100<]");
+    TEST ("[EMAIL PROTECTED]", 4, x + 2, x, "[97,98,>99<,100]");
+    TEST ("[EMAIL PROTECTED]", 4, x + 1, x, "[97,>98<,99,100]");
+    TEST ("[EMAIL PROTECTED]", 4, x + 0, x, "[>97<,98,99,100]");
+
+    TEST ("[%{X=+#5.*}]", 0, x, 0, "[>1:97<,2:98,3:99,4:100,5:101]");
+    TEST ("[%{X=+#5.*}]", 1, x, 0, "[1:97,>2:98<,3:99,4:100,5:101]");
+    TEST ("[%{X=+#5.*}]", 2, x, 0, "[1:97,2:98,>3:99<,4:100,5:101]");
+    TEST ("[%{X=+#5.*}]", 3, x, 0, "[1:97,2:98,3:99,>4:100<,5:101]");
+    TEST ("[%{X=+#5.*}]", 4, x, 0, "[1:97,2:98,3:99,4:100,>5:101<]");
+
+    delete[] x;
+}
+
+/***********************************************************************/
+
 static int
 user_fun_va (const char *fun_name,   // name of calling function
              char      **pbuf,       // pointer to a buffer
@@ -3319,6 +3397,9 @@
 
     test_conditional ();
 
+    // must be exercised before user-defined formatting
+    test_userclass_format ();
+
     test_user_defined_formatting ();
 
     test_bufsize ();

Modified: stdcxx/trunk/tests/src/value.cpp
URL: 
http://svn.apache.org/viewvc/stdcxx/trunk/tests/src/value.cpp?rev=682503&r1=682502&r2=682503&view=diff
==============================================================================
--- stdcxx/trunk/tests/src/value.cpp (original)
+++ stdcxx/trunk/tests/src/value.cpp Mon Aug  4 13:49:15 2008
@@ -687,13 +687,13 @@
     RW_ASSERT (0 != pbufsize);
     RW_ASSERT (0 != fmt);
 
-    va_list* pva      =  0;
+    va_list* pva      =  0;   // pointer to rw_vsnprintf's va_list
     bool     fl_plus  =  false;
     bool     fl_pound =  false;
     int      nelems   = -1;
     int      cursor   = -1;
 
-    const UserClass* pelem    = 0;
+    const UserClass* pelem = 0;
 
     // directive syntax:
     // "X=" [ '#' ] [ '+' ] [ '*' | <n> ] [ '.' [ '*' | '@' | <n> ] ]
@@ -819,19 +819,31 @@
     // value returned from rw_asnprintf() (i.e., the number of
     // bytes appended) back to the caller
 
+    const char* pointer [2];
+
     for (const UserClass *px = xbeg; px != xbeg + nelems; ++px) {
+
+        if (px == pelem) {
+            pointer [0] = ">";
+            pointer [1] = "<";
+        }
+        else {
+            pointer [0] = "";
+            pointer [1] = "";
+        }
+
         const int n =
             rw_asnprintf (pbuf, pbufsize,
-                          "%{+}%{?}>%{;}"
+                          "%{+}%s"                        // '>'
                           "%{?}%d:%{;}"
-                          "%{?}%d%{?},%{;}%{:}%{lc}%{;}"
-                          "%{?}<%{;}",
-                          px == pelem,                    // '>'
+                          "%{?}%d%s%{?},%{;}%{:}%{lc}%{;}",
+                          pointer [0],                    // ">" or ""
                           fl_pound, px->id_,              // "<id>:"
                           fl_plus, px->data_.val_,        // <val>
+                          pointer [1],                    // "<" or ""
                           px + 1 < xbeg + nelems,         // ','
                           px->data_.val_,                 // <val>
-                          px == pelem);                   // '<'
+                          pointer [1]);                   // "<" or ""
         if (n < 0)
             return n;
 


Reply via email to