← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba

 

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.
3. locale template function additions.

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

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

1. Improved catch() for unit tests.
2. Improved bpackfail() for streambufs.
3. locale template function additions.
-- 
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/142005
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-01-03 20:25:05 +0000
+++ ChangeLog	2013-01-05 08:10:26 +0000
@@ -5,8 +5,8 @@
 
 New Features:
   * (bug #1039284) Implemented jn:json-doc().
-  * (bug #867363) Added http-uri-resolution feature to disable HTTP
-	when resolving URIs.
+  * (bug #867363) Added http-uri-resolution feature to disable HTTP when
+    resolving URIs.
   * Can now specify jsoniq-strip-top-level-array option to parse-json() to
     strip the top-level array from JSON streams.
   * New info-extraction module for querying concepts and entities in
@@ -44,8 +44,8 @@
   * Fixed bug #1021492 (while computeing the "sources" of a prolog var, skip
     any var-setting exprs that appear in non-used (and non-optimized) functions).
   * Fixed bug #1070551 (zerr:ZOSE0003 stream read failure)
-  * Fixed bug #992304 (Compiling library modules could load data from
-	wrong source)
+  * Fixed bug #992304 (Compiling library modules could load data from wrong
+    source)
   * Fixed bugs related to casting to user-defined types.
 
 

=== 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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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/CMakeLists.txt'
--- src/unit_tests/CMakeLists.txt	2012-11-12 21:17:32 +0000
+++ src/unit_tests/CMakeLists.txt	2013-01-05 08:10:26 +0000
@@ -17,15 +17,12 @@
   test_base64.cpp
   test_base64_streambuf.cpp
   test_fs_iterator.cpp
+  test_hashmaps.cpp
   test_json_parser.cpp
   test_string.cpp
   test_uri.cpp
   test_uuid.cpp
   unit_tests.cpp
-  test_uri.cpp
-  test_json_parser.cpp
-  test_fs_iterator.cpp
-  test_hashmaps.cpp
 )
 
 IF (NOT ZORBA_NO_FULL_TEXT)

=== 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-05 08:10:26 +0000
@@ -30,7 +30,7 @@
 }
 
 static void print_exception( char const *expr, char const *testName,
-        std::exception const &e ) {
+                             std::exception const &e ) {
     std::cout << "FAILED " << testName << ": exception: " << e.what() <<
         std::endl;
   ++failures;
@@ -40,19 +40,19 @@
 
 #define ASSERT_EXCEPTION( EXPR, EXCEPTION ) \
   try { EXPR; assert_true( #EXPR, testName, false); } \
-  catch (EXCEPTION const& ) { } \
-  catch ( std::exception const &e ){ print_exception( #EXPR, testName, e ); } \
+  catch ( EXCEPTION const& ) { } \
+  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 ); } \
+  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 () { \
@@ -177,9 +177,11 @@
   ASSERT_TRUE(hugePage == mem);
 END_TEST
 
-namespace zorba { namespace UnitTests{
-
 ///////////////////////////////////////////////////////////////////////////////
+
+namespace zorba {
+namespace UnitTests {
+
 int test_mem_manager( int, char*[] )
 {
   PageCreationAllocatesMemoryDeletionFreesIt();
@@ -201,4 +203,7 @@
   return failures ? 1 : 0;
 }
 
-}} //namespace zorba::UnitTests
+} // namespace UnitTests
+} // namespace zorba
+
+/* vim:set et sw=2 ts=2: */

=== 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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +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-05 08:10:26 +0000
@@ -18,6 +18,7 @@
 #define ZORBA_TRANSCODE_STREAMBUF_H
 
 #include <zorba/config.h>
+#include <zorba/transcode_stream.h>
 
 ///////////////////////////////////////////////////////////////////////////////
 

=== modified file 'src/zorbautils/locale.h'
--- src/zorbautils/locale.h	2012-09-19 21:16:15 +0000
+++ src/zorbautils/locale.h	2013-01-05 08:10:26 +0000
@@ -21,6 +21,7 @@
 
 #include <zorba/locale.h>
 
+#include "util/string_util.h"
 namespace zorba {
   namespace locale {
 
@@ -297,7 +298,19 @@
        * @return Returns said enumeration or \c unknown.
        */
       type find( char const *country );
-    }
+
+      //
+      // Template version of find().
+      //
+      template<class StringType> inline
+      typename std::enable_if<
+        ztd::has_c_str<StringType,char const* (StringType::*)() const>::value,
+        type
+      >::type
+      find( StringType const &country ) {
+        return find( country.c_str() );
+      }
+    } // namespace iso3166_1
 
     /////////////////////////////////////////////////////////////////////////// 
 
@@ -322,7 +335,19 @@
        * @return Returns said enumeration or \c unknown.
        */
       type find( char const *lang );
-    }
+
+      //
+      // Template version of find().
+      //
+      template<class StringType> inline
+      typename std::enable_if<
+        ztd::has_c_str<StringType,char const* (StringType::*)() const>::value,
+        type
+      >::type
+      find( StringType const &lang ) {
+        return find( lang.c_str() );
+      }
+    } // namespace iso639_1
 
     /////////////////////////////////////////////////////////////////////////// 
 
@@ -474,7 +499,19 @@
        * @return Returns said enumeration or \c unknown.
        */
       type find( char const *lang );
-    }
+
+      //
+      // Template version of find().
+      //
+      template<class StringType> inline
+      typename std::enable_if<
+        ztd::has_c_str<StringType,char const* (StringType::*)() const>::value,
+        type
+      >::type
+      find( StringType const &lang ) {
+        return find( lang.c_str() );
+      }
+    } // namespace iso639_2
 
     /////////////////////////////////////////////////////////////////////////// 
 
@@ -486,6 +523,18 @@
      */
     iso639_1::type find_lang( char const *lang );
 
+    //
+    // Template version of find_lang().
+    //
+    template<class StringType> inline
+    typename std::enable_if<
+      ztd::has_c_str<StringType,char const* (StringType::*)() const>::value,
+      iso639_1::type
+    >::type
+    find_lang( StringType const &lang ) {
+      return find_lang( lang.c_str() );
+    }
+
     /**
      * Gets the ISO 3166-1 country code enumeration for the host system.
      *
@@ -505,7 +554,5 @@
   } // namespace locale
 } // namespace zorba
 
-#undef DEF_OSTREAM_INSERT_OPERATOR
-
 #endif  /* ZORBA_CORE_LOCALE_H */
 /* vim:set et sw=2 ts=2: */


Follow ups