Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.

Commit message:
1. Improved catch() for unit tests.
2. Improved bpackfail() for streambufs.

Requested reviews:
  Paul J. Lucas (paul-lucas)

For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/141949

1. Improved catch() for unit tests.
2. Improved bpackfail() for streambufs.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/141949
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/internal/streambuf.h'
--- include/zorba/internal/streambuf.h	2012-06-15 17:01:01 +0000
+++ include/zorba/internal/streambuf.h	2013-01-04 16:16:32 +0000
@@ -20,12 +20,15 @@
 #include <streambuf>
 
 #include <zorba/config.h>
+#include <zorba/internal/proxy.h>
 
 namespace zorba {
 namespace internal {
 
 ///////////////////////////////////////////////////////////////////////////////
 
+typedef ztd::proxy<std::streambuf> proxy_streambuf;
+
 ZORBA_DLL_PUBLIC
 void dealloc_streambuf( std::streambuf* );
 

=== modified file 'include/zorba/transcode_stream.h'
--- include/zorba/transcode_stream.h	2012-09-19 21:16:15 +0000
+++ include/zorba/transcode_stream.h	2013-01-04 16:16:32 +0000
@@ -17,18 +17,11 @@
 #ifndef ZORBA_TRANSCODE_STREAM_API_H
 #define ZORBA_TRANSCODE_STREAM_API_H
 
-#include <stdexcept>
-#include <streambuf>
-
 #include <zorba/config.h>
-#include <zorba/internal/proxy.h>
 #include <zorba/internal/streambuf.h>
 #include <zorba/internal/unique_ptr.h>
 
 namespace zorba {
-
-typedef internal::ztd::proxy<std::streambuf> proxy_streambuf;
-
 namespace transcode {
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -108,7 +101,7 @@
   std::streamsize xsputn( char_type const*, std::streamsize );
 
 private:
-  std::unique_ptr<proxy_streambuf> proxy_buf_;
+  std::unique_ptr<internal::proxy_streambuf> proxy_buf_;
 
   // forbid
   streambuf( streambuf const& );

=== modified file 'modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp'
--- modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp	2012-09-19 21:16:15 +0000
+++ modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp	2013-01-04 16:16:32 +0000
@@ -13,11 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+#include <cassert>
 #include <cstring>
+#include <iostream>
+#include <sstream>
+#include <stdexcept>
 #include <string>
-#include <sstream>
-#include <assert.h>
-#include <iostream>
 
 #include <zorba/base64.h>
 #include <zorba/config.h>

=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
--- modules/org/expath/ns/file.xq.src/file.cpp	2012-09-19 21:16:15 +0000
+++ modules/org/expath/ns/file.xq.src/file.cpp	2013-01-04 16:16:32 +0000
@@ -16,9 +16,10 @@
 
 #include "file.h"
 
+#include <fstream>
 #include <memory>
-#include <fstream>
 #include <sstream>
+#include <stdexcept>
 
 #include <zorba/base64.h>
 #include <zorba/empty_sequence.h>

=== modified file 'src/api/base64_streambuf.cpp'
--- src/api/base64_streambuf.cpp	2012-06-15 23:02:52 +0000
+++ src/api/base64_streambuf.cpp	2013-01-04 16:16:32 +0000
@@ -110,9 +110,14 @@
 }
 
 streambuf::int_type streambuf::pbackfail( int_type c ) {
-  if ( gptr() > eback() )
-    gbump( -1 );
-  return orig_buf_->sputbackc( traits_type::to_char_type( c ) );
+  if ( !traits_type::eq_int_type( c, traits_type::eof() ) &&
+       gptr() > eback() ) {
+    c = orig_buf_->sputbackc( traits_type::to_char_type( c ) );
+    if ( !traits_type::eq_int_type( c, traits_type::eof() ) )
+      gbump( -1 );
+    return c;
+  }
+  return traits_type::eof();
 }
 
 streambuf::int_type streambuf::underflow() {

=== modified file 'src/api/transcode_streambuf.cpp'
--- src/api/transcode_streambuf.cpp	2012-09-19 21:16:15 +0000
+++ src/api/transcode_streambuf.cpp	2013-01-04 16:16:32 +0000
@@ -66,7 +66,8 @@
 }
 
 streambuf::int_type streambuf::pbackfail( int_type c ) {
-  return proxy_buf_->sputbackc( traits_type::to_char_type( c ) );
+  return  traits_type::eq_int_type( c, traits_type::eof() ) ?
+          c : proxy_buf_->sputbackc( traits_type::to_char_type( c ) );
 }
 
 streambuf::int_type streambuf::uflow() {

=== modified file 'src/unit_tests/memory_manager.cpp'
--- src/unit_tests/memory_manager.cpp	2012-09-19 21:16:15 +0000
+++ src/unit_tests/memory_manager.cpp	2013-01-04 16:16:32 +0000
@@ -39,20 +39,20 @@
 #define ASSERT_TRUE( EXPR ) assert_true( #EXPR, testName, !!(EXPR) )
 
 #define ASSERT_EXCEPTION( EXPR, EXCEPTION ) \
-  try { EXPR; assert_true( #EXPR, testName, false); } \
+  try { EXPR; assert_true( #EXPR, testName, false ); } \
   catch (EXCEPTION const& ) { } \
-  catch ( std::exception const &e ){ print_exception( #EXPR, testName, e ); } \
-  catch ( ... ) { assert_true ( #EXPR, testName, false ); }
+  catch ( std::exception const &e ) { print_exception( #EXPR, testName, e ); } \
+  catch ( ... ) { assert_true( #EXPR, testName, false ); }
 
 #define ASSERT_NO_EXCEPTION( EXPR ) \
-  try {EXPR; } \
-  catch ( std::exception const &e ){ print_exception( #EXPR, testName, e ); } \
-  catch ( ... ) { assert_true (#EXPR, testName, false ); }
+  try { EXPR; } \
+  catch ( std::exception const &e ) { print_exception( #EXPR, testName, e ); } \
+  catch ( ... ) { assert_true( #EXPR, testName, false ); }
 
 #define ASSERT_TRUE_AND_NO_EXCEPTION( EXPR ) \
   try { ASSERT_TRUE ( EXPR ); } \
   catch ( std::exception const &e ) { print_exception( #EXPR, testName, e ); } \
-  catch ( ... ) {assert_true( #EXPR, testName, false ); }
+  catch ( ... ) { assert_true( #EXPR, testName, false ); }
 
 #define TEST( TESTNAME ) \
 static void TESTNAME () { \

=== modified file 'src/unit_tests/test_base64.cpp'
--- src/unit_tests/test_base64.cpp	2012-09-19 21:16:15 +0000
+++ src/unit_tests/test_base64.cpp	2013-01-04 16:16:32 +0000
@@ -53,11 +53,13 @@
 
 #define ASSERT_NO_EXCEPTION( NO, EXPR ) \
   try { EXPR; } \
-  catch ( std::exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); }
+  catch ( exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); } \
+  catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
 
 #define ASSERT_EXCEPTION( NO, EXPR, EXCEPTION ) \
   try { EXPR; assert_true( NO, #EXPR, __LINE__, false ); } \
-  catch ( EXCEPTION const& ) { }
+  catch ( EXCEPTION const& ) { } \
+  catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
 
 ///////////////////////////////////////////////////////////////////////////////}
 

=== modified file 'src/unit_tests/test_base64_streambuf.cpp'
--- src/unit_tests/test_base64_streambuf.cpp	2012-06-15 17:01:01 +0000
+++ src/unit_tests/test_base64_streambuf.cpp	2013-01-04 16:16:32 +0000
@@ -51,7 +51,8 @@
 
 #define ASSERT_TRUE_AND_NO_EXCEPTION( NO, EXPR ) \
   try { ASSERT_TRUE( NO, EXPR ); } \
-  catch ( std::exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); }
+  catch ( exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); } \
+  catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
 
 ///////////////////////////////////////////////////////////////////////////////
 

=== modified file 'src/unit_tests/test_icu_streambuf.cpp'
--- src/unit_tests/test_icu_streambuf.cpp	2012-09-19 21:16:15 +0000
+++ src/unit_tests/test_icu_streambuf.cpp	2013-01-04 16:16:32 +0000
@@ -15,9 +15,11 @@
  */
 
 #include "stdafx.h"
+
 #include <fstream>
 #include <iostream>
 #include <sstream>
+#include <string>
 
 #include "util/transcode_streambuf.h"
 
@@ -71,7 +73,8 @@
 
 #define ASSERT_TRUE_AND_NO_EXCEPTION( NO, EXPR ) \
   try { ASSERT_TRUE( NO, EXPR ); } \
-  catch ( std::exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); }
+  catch ( exception const &e ) { print_exception( NO, #EXPR, __LINE__, e ); } \
+  catch ( ... ) { assert_true( NO, #EXPR, __LINE__, false ); }
 
 ///////////////////////////////////////////////////////////////////////////////
 

=== modified file 'src/unit_tests/test_json_parser.cpp'
--- src/unit_tests/test_json_parser.cpp	2012-09-19 21:16:15 +0000
+++ src/unit_tests/test_json_parser.cpp	2013-01-04 16:16:32 +0000
@@ -55,7 +55,8 @@
 
 #define ASSERT_EXCEPTION( EXPR, EXCEPTION ) \
   try { EXPR; assert_true( #EXPR, __LINE__, false ); } \
-  catch ( EXCEPTION const& ) { }
+  catch ( EXCEPTION const& ) { } \
+  catch ( ... ) { assert_true( #EXPR, __LINE__, false ); }
 
 #define ASSERT_NO_EXCEPTION( EXPR ) \
   try { EXPR; } \

=== modified file 'src/unit_tests/test_string.cpp'
--- src/unit_tests/test_string.cpp	2012-09-19 21:16:15 +0000
+++ src/unit_tests/test_string.cpp	2013-01-04 16:16:32 +0000
@@ -82,7 +82,8 @@
 
 #define ASSERT_EXCEPTION( EXPR, EXCEPTION ) \
   try { EXPR; assert_true( #EXPR, __LINE__, false ); } \
-  catch ( EXCEPTION const& ) { }
+  catch ( EXCEPTION const& ) { } \
+  catch ( ... ) { assert_true( #EXPR, __LINE__, false ); }
 
 #define ASSERT_NO_EXCEPTION( EXPR ) \
   try { EXPR; } \

=== modified file 'src/unit_tests/test_unordered_map.cpp'
--- src/unit_tests/test_unordered_map.cpp	2012-12-05 02:14:31 +0000
+++ src/unit_tests/test_unordered_map.cpp	2013-01-04 16:16:32 +0000
@@ -53,7 +53,8 @@
 
 #define ASSERT_EXCEPTION( EXPR, EXCEPTION ) \
   try { EXPR; assert_true( #EXPR, __LINE__, false ); } \
-  catch ( EXCEPTION const& ) { }
+  catch ( EXCEPTION const& ) { } \
+  catch ( ... ) { assert_true( #EXPR, __LINE__, false ); }
 
 ///////////////////////////////////////////////////////////////////////////////
 

=== modified file 'src/util/icu_streambuf.cpp'
--- src/util/icu_streambuf.cpp	2012-09-19 21:16:15 +0000
+++ src/util/icu_streambuf.cpp	2013-01-04 16:16:32 +0000
@@ -58,7 +58,7 @@
 }
 
 icu_streambuf::icu_streambuf( char const *charset, streambuf *orig ) :
-  proxy_streambuf( orig ),
+  internal::proxy_streambuf( orig ),
   no_conv_( !is_necessary( charset ) ),
   external_conv_( no_conv_ ? nullptr : create_conv( charset ) ),
   utf8_conv_( no_conv_ ? nullptr : create_conv( "UTF-8" ) )
@@ -151,7 +151,7 @@
 }
 
 icu_streambuf::int_type icu_streambuf::overflow( int_type c ) {
-#if ZORBA_DEBUG_ICU_STREAMBUF
+#ifdef ZORBA_DEBUG_ICU_STREAMBUF
   printf( "overflow()\n" );
 #endif
   if ( no_conv_ )
@@ -233,7 +233,7 @@
 #endif /* GCC_PRAGMA_DIAGNOSTIC_PUSH */
 
 icu_streambuf::int_type icu_streambuf::underflow() {
-#if ZORBA_DEBUG_ICU_STREAMBUF
+#ifdef ZORBA_DEBUG_ICU_STREAMBUF
   printf( "underflow()\n" );
 #endif
   if ( no_conv_ )
@@ -263,7 +263,7 @@
 }
 
 streamsize icu_streambuf::xsgetn( char_type *to, streamsize size ) {
-#if ZORBA_DEBUG_ICU_STREAMBUF
+#ifdef ZORBA_DEBUG_ICU_STREAMBUF
   printf( "xsgetn()\n" );
 #endif
   if ( no_conv_ )
@@ -301,7 +301,7 @@
 }
 
 streamsize icu_streambuf::xsputn( char_type const *from, streamsize size ) {
-#if ZORBA_DEBUG_ICU_STREAMBUF
+#ifdef ZORBA_DEBUG_ICU_STREAMBUF
   printf( "xsputn()\n" );
 #endif
   if ( no_conv_ )

=== modified file 'src/util/icu_streambuf.h'
--- src/util/icu_streambuf.h	2012-09-19 21:16:15 +0000
+++ src/util/icu_streambuf.h	2013-01-04 16:16:32 +0000
@@ -18,7 +18,7 @@
 #define ZORBA_ICU_STREAMBUF_H
 
 #include <unicode/ucnv.h>
-#include <zorba/transcode_stream.h>
+#include <zorba/internal/streambuf.h>
 
 #include "util/utf8_util.h"
 
@@ -38,7 +38,7 @@
  *  is.ios::rdbuf( &xbuf );
  * \endcode
  * Note that the %icu_streambuf must exist for as long as it's being used by
- * the stream.  If you are replacing the streabuf for a stream you did not
+ * the stream.  If you are replacing the streambuf for a stream you did not
  * create, you should set it back to the original streambuf:
  * \code
  *  void f( ostream &os ) {
@@ -58,7 +58,7 @@
  * While %icu_streambuf does support seeking, the positions are relative to the
  * original byte stream.
  */
-class icu_streambuf : public proxy_streambuf {
+class icu_streambuf : public internal::proxy_streambuf {
 public:
   /**
    * Constructs an %icu_streambuf.

=== modified file 'src/util/mem_streambuf.cpp'
--- src/util/mem_streambuf.cpp	2012-09-19 21:16:15 +0000
+++ src/util/mem_streambuf.cpp	2013-01-04 16:16:32 +0000
@@ -52,7 +52,7 @@
 
 mem_streambuf::int_type mem_streambuf::pbackfail( int_type c ) {
   if ( !traits_type::eq_int_type( c, traits_type::eof() ) ) {
-    *pptr() = traits_type::to_int_type( c );
+    *pptr() = traits_type::to_char_type( c );
     pbump( -1 );
   }
   return traits_type::to_int_type( *pptr() );

=== modified file 'src/util/oseparator.h'
--- src/util/oseparator.h	2012-09-19 21:16:15 +0000
+++ src/util/oseparator.h	2013-01-04 16:16:32 +0000
@@ -40,6 +40,14 @@
   }
 
   /**
+   * Constructs an %oseparator.
+   *
+   * @param sep The separator character.
+   */
+  explicit oseparator( char sep ) : sep_( 1, sep ), print_( false ) {
+  }
+
+  /**
    * Gets the printing state of this %oseparator.
    *
    * @return Returns \c true only if this %oseparator is currently printing.

=== modified file 'src/util/passthru_streambuf.cpp'
--- src/util/passthru_streambuf.cpp	2012-09-19 21:16:15 +0000
+++ src/util/passthru_streambuf.cpp	2013-01-04 16:16:32 +0000
@@ -84,7 +84,8 @@
 }
 
 passthru_streambuf::int_type passthru_streambuf::pbackfail( int_type c ) {
-  return original()->sputbackc( traits_type::to_char_type( c ) );
+  return  traits_type::eq_int_type( c, traits_type::eof() ) ?
+          c : proxy_buf_->sputbackc( traits_type::to_char_type( c ) );
 }
 
 passthru_streambuf::int_type passthru_streambuf::uflow() {

=== modified file 'src/util/transcode_streambuf.h'
--- src/util/transcode_streambuf.h	2012-09-19 21:16:15 +0000
+++ src/util/transcode_streambuf.h	2013-01-04 16:16:32 +0000
@@ -18,6 +18,7 @@
 #define ZORBA_TRANSCODE_STREAMBUF_H
 
 #include <zorba/config.h>
+#include <zorba/transcode_stream.h>
 
 ///////////////////////////////////////////////////////////////////////////////
 

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to