stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From far...@apache.org
Subject svn commit: r472092 - in /incubator/stdcxx/trunk/tests: self/0.printf.cpp src/fmt_defs.h src/printf.cpp
Date Tue, 07 Nov 2006 12:54:08 GMT
Author: faridz
Date: Tue Nov  7 04:54:08 2006
New Revision: 472092

URL: http://svn.apache.org/viewvc?view=rev&rev=472092
Log:
2006-11-07 Farid Zaripov <faridz@kyiv.vdiweb.com>

	* fmt_defs.h: Added definition of the DummyStruct
	* printf.cpp (rw_vasnprintf): Added checking for malformed directive
	(_rw_fmttm, _rw_fmtarray, _rw_fmtstrarray, _rw_fmtstr, _rw_fmtwstr):
	Third parameter of __rw::__rw_memattr() changed to -1
	(_rw_vasnprintf_ext): Ditto. Added "%{P}" formating directive to
	format the rw_pid_t value
	* 0.printf.cpp: #included rw_process.h for rw_pid_t
	(test_chararray): Added missing backslash in result string
	(test_stringarray): Added exercising of the "%{ As}" formatting
	directive
	(test_pid): New function exercising the "%{P}" formating directive
	(main): Added call to the test_pid()

Modified:
    incubator/stdcxx/trunk/tests/self/0.printf.cpp
    incubator/stdcxx/trunk/tests/src/fmt_defs.h
    incubator/stdcxx/trunk/tests/src/printf.cpp

Modified: incubator/stdcxx/trunk/tests/self/0.printf.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/self/0.printf.cpp?view=diff&rev=472092&r1=472091&r2=472092
==============================================================================
--- incubator/stdcxx/trunk/tests/self/0.printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/self/0.printf.cpp Tue Nov  7 04:54:08 2006
@@ -27,22 +27,23 @@
  **************************************************************************/
 
 #include <rw_printf.h>
-#include <environ.h>   // for rw_putenv()
+#include <rw_process.h> // for rw_pid_t
+#include <environ.h>    // for rw_putenv()
 
-#include <bitset>      // for bitset
-#include <ios>         // for ios::openmode, ios::seekdir
-#include <string>      // for string
-
-#include <assert.h>    // for assert()
-#include <ctype.h>     // for isdigit()
-#include <errno.h>     // for EXXX, errno
-#include <limits.h>    // for INT_MAX, ...
-#include <signal.h>    // for SIGABRT, ...
-#include <stdio.h>     // for printf(), ...
-#include <stdlib.h>    // for free(), size_t
-#include <string.h>    // for strcpy()
-#include <stdarg.h>    // for va_arg, ...
-#include <time.h>      // for struct tm
+#include <bitset>       // for bitset
+#include <ios>          // for ios::openmode, ios::seekdir
+#include <string>       // for string
+
+#include <assert.h>     // for assert()
+#include <ctype.h>      // for isdigit()
+#include <errno.h>      // for EXXX, errno
+#include <limits.h>     // for INT_MAX, ...
+#include <signal.h>     // for SIGABRT, ...
+#include <stdio.h>      // for printf(), ...
+#include <stdlib.h>     // for free(), size_t
+#include <string.h>     // for strcpy()
+#include <stdarg.h>     // for va_arg, ...
+#include <time.h>       // for struct tm
 
 
 // disable tests for function name in "%{lF}"
@@ -559,7 +560,7 @@
         TEST ("%{2Ac}", L"abc", 0, 0, "L\"abc\"");
 
         TEST ("%{2.0Ac}", L"",    0, 0, "L\"\"");
-        TEST ("%{2.1Ac}", L"",    0, 0, "L\"\0\"");
+        TEST ("%{2.1Ac}", L"",    0, 0, "L\"\\0\"");
 
         TEST ("%{2.0Ac}", L"a",   0, 0, "L\"\"");
         TEST ("%{2.1Ac}", L"a",   0, 0, "L\"a\"");
@@ -675,6 +676,17 @@
     TEST ("%{#As}", ARG ("abcd"),              0, 0, "\"abcd\"");
     TEST ("%{#As}", ARG ("abcd", "efg"),       0, 0, "\"abcd\",\"efg\"");
     TEST ("%{#As}", ARG ("abcd", "efg", "hi"), 0, 0, "\"abcd\",\"efg\",\"hi\"");
+
+    TEST ("%{ As}", 0,                              0, 0, "(null)");
+    TEST ("%{ As}", ARG ("a"),                      0, 0, "a");
+    TEST ("%{ As}", ARG ("a", "bc"),                0, 0, "a bc");
+    TEST ("%{ As}", ARG ("a", "bc", "def"),         0, 0, "a bc def");
+    TEST ("%{ As}", ARG ("a", "bc", "def", "ghij"), 0, 0, "a bc def ghij");
+
+    TEST ("%{ #As}", 0,                        0, 0, "(null)");
+    TEST ("%{ #As}", ARG ("abc"),              0, 0, "\"abc\"");
+    TEST ("%{ #As}", ARG ("abc", "efg"),       0, 0, "\"abc\" \"efg\"");
+    TEST ("%{ #As}", ARG ("abc", "efg", "hi"), 0, 0, "\"abc\" \"efg\" \"hi\"");
 }
 
 /***********************************************************************/
@@ -2234,6 +2246,27 @@
 
 /***********************************************************************/
 
+static void
+test_pid ()
+{
+    //////////////////////////////////////////////////////////////////
+    printf ("%s\n", "extension: \"%P\": rw_pid_t");
+
+    const rw_pid_t pid = 12345;
+
+    TEST ("%{P}", pid, 0, 0, "12345");
+
+    TEST ("[%{10P}]",    pid, 0, 0, "[     12345]");
+    TEST ("[%{+10P}]",   pid, 0, 0, "[     12345]");
+    TEST ("[%{-10P}]",   pid, 0, 0, "[12345     ]");
+    TEST ("[%{.3P}]",    pid, 0, 0, "[12345]");
+    TEST ("[%{10.3P}]",  pid, 0, 0, "[     12345]");
+    TEST ("[%{+10.3P}]", pid, 0, 0, "[     12345]");
+    TEST ("[%{-10.3P}]", pid, 0, 0, "[12345     ]");
+}
+
+/***********************************************************************/
+
 static const tm*
 make_tm (int sec = 0,            // [0,60]
          int min = 0,            // [0,59]
@@ -2822,6 +2855,7 @@
     test_memptr ();
     test_errno ();
     test_signal ();
+    test_pid ();
 
     test_basic_string ();
 

Modified: incubator/stdcxx/trunk/tests/src/fmt_defs.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/fmt_defs.h?view=diff&rev=472092&r1=472091&r2=472092
==============================================================================
--- incubator/stdcxx/trunk/tests/src/fmt_defs.h (original)
+++ incubator/stdcxx/trunk/tests/src/fmt_defs.h Tue Nov  7 04:54:08 2006
@@ -48,7 +48,7 @@
 
 typedef void (*funptr_t)();
 
-struct DummyStruct;
+struct DummyStruct { };
 typedef void (DummyStruct::*memptr_t)() const;
 
 /********************************************************************/

Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/printf.cpp?view=diff&rev=472092&r1=472091&r2=472092
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Tue Nov  7 04:54:08 2006
@@ -790,7 +790,7 @@
         if ('{' == *fc) {
             const char* const endbrace = strchr (++fc, '}');
 
-            if (0 == endbrace) {
+            if (0 == endbrace || fc == endbrace) {
                 const size_t flen = strlen (fc -= 2);
                 next = _rw_bufcat (buf, fc, flen);
                 if (0 == next)
@@ -1670,7 +1670,7 @@
 static int
 _rw_fmttm (const FmtSpec &spec, Buffer &buf, const tm *tmb)
 {
-    if (   0 == tmb || 0 > _RW::__rw_memattr (tmb, sizeof *tmb, 0)
+    if (   0 == tmb || 0 > _RW::__rw_memattr (tmb, sizeof *tmb, -1)
         || (size_t)tmb & (sizeof (int) - 1)) {
         return _rw_fmtbadaddr (spec, buf, tmb, sizeof (int));
     }
@@ -1897,7 +1897,7 @@
 {
     RW_ASSERT (0 != buf.pbuf);
 
-    if (   0 == array || 0 > _RW::__rw_memattr (array, _RWSTD_SIZE_MAX, 0)
+    if (   0 == array || 0 > _RW::__rw_memattr (array, _RWSTD_SIZE_MAX, -1)
         || ((size_t)array & (sizeof *array - 1))) {
         // qualify the name of the static function in order to
         // allow it to be found when referenced from a template
@@ -2234,7 +2234,7 @@
 
     int len = 0;
 
-    if (0 == argv || 0 > _RW::__rw_memattr (argv, sizeof *argv, 0))
+    if (0 == argv || 0 > _RW::__rw_memattr (argv, sizeof *argv, -1))
         return _rw_fmtbadaddr (spec, buf, argv);
 
     size_t argc = spec.prec;
@@ -2333,7 +2333,7 @@
     if (spec.fl_pound)
         return _rw_fmtarray (spec, buf, str, len, A_CHAR | A_ESC);
 
-    if (0 == str || 0 > _RW::__rw_memattr (str, _RWSTD_SIZE_MAX, 0))
+    if (0 == str || 0 > _RW::__rw_memattr (str, _RWSTD_SIZE_MAX, -1))
         return _rw_fmtbadaddr (spec, buf, str);
 
     if (_RWSTD_SIZE_MAX == len)
@@ -2404,7 +2404,7 @@
         return _rw_fmtarray (spec, buf, wstr, len, flags);
     }
 
-    if (   0 == wstr || 0 > _RW::__rw_memattr (wstr, _RWSTD_SIZE_MAX, 0)
+    if (   0 == wstr || 0 > _RW::__rw_memattr (wstr, _RWSTD_SIZE_MAX, -1)
         || ((size_t)wstr & (sizeof *wstr - 1)))
         return _rw_fmtbadaddr (spec, buf, wstr, sizeof *wstr);
 
@@ -2597,7 +2597,7 @@
         // std::bitset
         spec.param.ptr_ = PARAM (ptr_);
         if (   0 == spec.param.ptr_
-            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, 0))
+            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, -1))
             len = _rw_fmtbadaddr (spec, buf, spec.param.ptr_, sizeof (long));
         else
             len = _rw_fmtbits (spec, buf, spec.param.ptr_, sizeof (long));
@@ -2606,7 +2606,7 @@
     case 'b':   // %{b}
         spec.param.ptr_ = PARAM (ptr_);
         if (   0 == spec.param.ptr_
-            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, 0))
+            || 0 > _RW::__rw_memattr (spec.param.ptr_, spec.prec, -1))
             len = _rw_fmtbadaddr (spec, buf, spec.param.ptr_);
         else
             len = _rw_fmtbits (spec, buf, spec.param.ptr_, 1);
@@ -2806,6 +2806,12 @@
         break;
     }
 
+    case 'P':   // %{P}
+        // rw_pid_t is _RWSTD_SSIZE_T which is equal to _RWSTD_PTRDIFF_T
+        spec.param.diff_ = PARAM (diff_);
+        len = rw_fmtinteger (spec, buf, spec.param.diff_);
+        break;
+
     case 's':   // %{s}, %{As}, %{Is}, %{ls}
         if (spec.mod == spec.mod_ext_A) {   // array of strings
             spec.param.ptr_ = PARAM (ptr_);
@@ -2840,7 +2846,7 @@
 
             const std::wstring* const pstr = (std::wstring*)spec.param.ptr_;
 
-            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, 0)
+            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, -1)
                 || (size_t)pstr & (sizeof (pstr) - 1)) {
                 len = _rw_fmtbadaddr (spec, buf, pstr, sizeof pstr);
             }
@@ -2857,7 +2863,7 @@
 
             const std::string* const pstr = (std::string*)spec.param.ptr_;
 
-            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, 0)
+            if (   0 == pstr || 0 > _RW::__rw_memattr (pstr, sizeof *pstr, -1)
                 || (size_t)pstr & (sizeof (pstr) - 1)) {
                 len = _rw_fmtbadaddr (spec, buf, pstr, sizeof pstr);
             }



Mime
View raw message