$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r84518 - in trunk: boost/utility libs/utility/test
From: andrey.semashev_at_[hidden]
Date: 2013-05-26 15:23:52
Author: andysem
Date: 2013-05-26 15:23:52 EDT (Sun, 26 May 2013)
New Revision: 84518
URL: http://svn.boost.org/trac/boost/changeset/84518
Log:
Removed constexpr from substr() as it doesn't work with BOOST_THROW_EXCEPTION. Added a test for streaming.
Added:
   trunk/libs/utility/test/string_ref_test_io.cpp   (contents, props changed)
Text files modified: 
   trunk/boost/utility/string_ref.hpp |     4 +---                                    
   trunk/libs/utility/test/Jamfile.v2 |     1 +                                       
   2 files changed, 2 insertions(+), 3 deletions(-)
Modified: trunk/boost/utility/string_ref.hpp
==============================================================================
--- trunk/boost/utility/string_ref.hpp	(original)
+++ trunk/boost/utility/string_ref.hpp	2013-05-26 15:23:52 EDT (Sun, 26 May 2013)
@@ -25,6 +25,7 @@
 #include <algorithm>
 #include <iterator>
 #include <string>
+#include <iosfwd>
 
 namespace boost {
 
@@ -135,10 +136,7 @@
 
 
         // basic_string_ref string operations
-        BOOST_CONSTEXPR
         basic_string_ref substr(size_type pos, size_type n=npos) const {
-            // Looks like msvc 8 and 9 have a codegen bug when one branch of
-            // a conditional operator is a throw expression. -EAN 2012/12/04
             if ( pos > size())
                 BOOST_THROW_EXCEPTION( std::out_of_range ( "string_ref::substr" ) );
             if ( n == npos || pos + n > size())
Modified: trunk/libs/utility/test/Jamfile.v2
==============================================================================
--- trunk/libs/utility/test/Jamfile.v2	(original)
+++ trunk/libs/utility/test/Jamfile.v2	2013-05-26 15:23:52 EDT (Sun, 26 May 2013)
@@ -38,6 +38,7 @@
         [ run ../shared_iterator_test.cpp ]
         [ run string_ref_test1.cpp unit_test_framework ]
         [ run string_ref_test2.cpp unit_test_framework ]
+        [ run string_ref_test_io.cpp unit_test_framework ]
         [ run ../value_init_test.cpp ]
         [ run ../value_init_workaround_test.cpp ]
         [ run ../initialized_test.cpp ]
Added: trunk/libs/utility/test/string_ref_test_io.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/utility/test/string_ref_test_io.cpp	2013-05-26 15:23:52 EDT (Sun, 26 May 2013)
@@ -0,0 +1,172 @@
+/*
+ *             Copyright Andrey Semashev 2013.
+ * Distributed under the Boost Software License, Version 1.0.
+ *    (See accompanying file LICENSE_1_0.txt or copy at
+ *          http://www.boost.org/LICENSE_1_0.txt)
+ */
+/*!
+ * \file   string_ref_test_io.cpp
+ * \author Andrey Semashev
+ * \date   26.05.2013
+ *
+ * \brief  This header contains tests for stream operations of \c basic_string_ref.
+ */
+
+#define BOOST_TEST_MODULE string_ref_test_io
+
+#include <boost/utility/string_ref.hpp>
+
+#include <iomanip>
+#include <sstream>
+#include <algorithm>
+#include <iterator>
+#include <string>
+
+#include <boost/config.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/test/unit_test.hpp>
+
+typedef boost::mpl::vector<
+    char
+#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_STD_WSTREAMBUF) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
+    , wchar_t
+#endif
+/* Current implementations seem to be missing codecvt facets to convert chars to char16_t and char32_t even though the types are available.
+#if !defined(BOOST_NO_CXX11_CHAR16_T)
+    , char16_t
+#endif
+#if !defined(BOOST_NO_CXX11_CHAR32_T)
+    , char32_t
+#endif
+*/
+>::type char_types;
+
+static const char* test_strings[] =
+{
+    "begin",
+    "abcd",
+    "end"
+};
+
+//! The context with test data for particular character type
+template< typename CharT >
+struct context
+{
+    typedef CharT char_type;
+    typedef std::basic_string< char_type > string_type;
+    typedef std::basic_ostringstream< char_type > ostream_type;
+
+    string_type begin, abcd, end;
+
+    context()
+    {
+        boost::string_ref str = test_strings[0];
+        std::copy(str.begin(), str.end(), std::back_inserter(begin));
+
+        str = test_strings[1];
+        std::copy(str.begin(), str.end(), std::back_inserter(abcd));
+
+        str = test_strings[2];
+        std::copy(str.begin(), str.end(), std::back_inserter(end));
+    }
+};
+
+// Test regular output
+BOOST_AUTO_TEST_CASE_TEMPLATE(string_ref_output, CharT, char_types)
+{
+    typedef CharT char_type;
+    typedef std::basic_string< char_type > string_type;
+    typedef std::basic_ostringstream< char_type > ostream_type;
+    typedef boost::basic_string_ref< char_type > string_ref_type;
+
+    context< char_type > ctx;
+
+    ostream_type strm;
+    strm << string_ref_type(ctx.abcd);
+    BOOST_CHECK(strm.str() == ctx.abcd);
+}
+
+// Test support for padding
+BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
+{
+    typedef CharT char_type;
+    typedef std::basic_string< char_type > string_type;
+    typedef std::basic_ostringstream< char_type > ostream_type;
+    typedef boost::basic_string_ref< char_type > string_ref_type;
+
+    context< char_type > ctx;
+
+    // Test for padding
+    {
+        ostream_type strm_ref;
+        strm_ref << ctx.begin << std::setw(8) << string_ref_type(ctx.abcd) << ctx.end;
+
+        ostream_type strm_correct;
+        strm_correct << ctx.begin << std::setw(8) << ctx.abcd << ctx.end;
+
+        BOOST_CHECK(strm_ref.str() == strm_correct.str());
+    }
+
+    // Test that short width does not truncate the string
+    {
+        ostream_type strm_ref;
+        strm_ref << ctx.begin << std::setw(1) << string_ref_type(ctx.abcd) << ctx.end;
+
+        ostream_type strm_correct;
+        strm_correct << ctx.begin << std::setw(1) << ctx.abcd << ctx.end;
+
+        BOOST_CHECK(strm_ref.str() == strm_correct.str());
+    }
+}
+
+// Test support for padding fill
+BOOST_AUTO_TEST_CASE_TEMPLATE(padding_fill, CharT, char_types)
+{
+    typedef CharT char_type;
+    typedef std::basic_string< char_type > string_type;
+    typedef std::basic_ostringstream< char_type > ostream_type;
+    typedef boost::basic_string_ref< char_type > string_ref_type;
+
+    context< char_type > ctx;
+
+    ostream_type strm_ref;
+    strm_ref << ctx.begin << std::setfill(static_cast< char_type >('x')) << std::setw(8) << string_ref_type(ctx.abcd) << ctx.end;
+
+    ostream_type strm_correct;
+    strm_correct << ctx.begin << std::setfill(static_cast< char_type >('x')) << std::setw(8) << ctx.abcd << ctx.end;
+
+    BOOST_CHECK(strm_ref.str() == strm_correct.str());
+}
+
+// Test support for alignment
+BOOST_AUTO_TEST_CASE_TEMPLATE(alignment, CharT, char_types)
+{
+    typedef CharT char_type;
+    typedef std::basic_string< char_type > string_type;
+    typedef std::basic_ostringstream< char_type > ostream_type;
+    typedef boost::basic_string_ref< char_type > string_ref_type;
+
+    context< char_type > ctx;
+
+    // Left alignment
+    {
+        ostream_type strm_ref;
+        strm_ref << ctx.begin << std::left << std::setw(8) << string_ref_type(ctx.abcd) << ctx.end;
+
+        ostream_type strm_correct;
+        strm_correct << ctx.begin << std::left << std::setw(8) << ctx.abcd << ctx.end;
+
+        BOOST_CHECK(strm_ref.str() == strm_correct.str());
+    }
+
+    // Right alignment
+    {
+        ostream_type strm_ref;
+        strm_ref << ctx.begin << std::right << std::setw(8) << string_ref_type(ctx.abcd) << ctx.end;
+
+        ostream_type strm_correct;
+        strm_correct << ctx.begin << std::right << std::setw(8) << ctx.abcd << ctx.end;
+
+        BOOST_CHECK(strm_ref.str() == strm_correct.str());
+    }
+}