Author: sebor
Date: Wed Jul 16 15:58:25 2008
New Revision: 677461
URL: http://svn.apache.org/viewvc?rev=677461&view=rev
Log:
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/branches/4.2.x/tests/self/0.printf.cpp
stdcxx/branches/4.2.x/tests/src/value.cpp
Modified: stdcxx/branches/4.2.x/tests/self/0.printf.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/self/0.printf.cpp?rev=677461&r1=677460&r2=677461&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/tests/self/0.printf.cpp (original)
+++ stdcxx/branches/4.2.x/tests/self/0.printf.cpp Wed Jul 16 15:58:25 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
@@ -814,7 +815,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]");
@@ -2925,6 +2925,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
@@ -3320,6 +3398,9 @@
test_conditional ();
+ // must be exercised before user-defined formatting
+ test_userclass_format ();
+
test_user_defined_formatting ();
test_bufsize ();
Modified: stdcxx/branches/4.2.x/tests/src/value.cpp
URL:
http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/src/value.cpp?rev=677461&r1=677460&r2=677461&view=diff
==============================================================================
--- stdcxx/branches/4.2.x/tests/src/value.cpp (original)
+++ stdcxx/branches/4.2.x/tests/src/value.cpp Wed Jul 16 15:58:25 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;