Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56323 - in sandbox/explore: boost/explore libs/explore/test
From: jeff_at_[hidden]
Date: 2009-09-20 15:00:32


Author: jefffaust
Date: 2009-09-20 15:00:31 EDT (Sun, 20 Sep 2009)
New Revision: 56323
URL: http://svn.boost.org/trac/boost/changeset/56323

Log:
Make work with copyfmt. Add stream tests.
Added:
   sandbox/explore/libs/explore/test/std_stream.cpp (contents, props changed)
Text files modified:
   sandbox/explore/boost/explore/manipulators.hpp | 6 ------
   sandbox/explore/boost/explore/stream_state.hpp | 31 +++++++++++++++++++++++++------
   sandbox/explore/libs/explore/test/Jamfile.v2 | 1 +
   3 files changed, 26 insertions(+), 12 deletions(-)

Modified: sandbox/explore/boost/explore/manipulators.hpp
==============================================================================
--- sandbox/explore/boost/explore/manipulators.hpp (original)
+++ sandbox/explore/boost/explore/manipulators.hpp 2009-09-20 15:00:31 EDT (Sun, 20 Sep 2009)
@@ -255,12 +255,6 @@
     {
         return detail::manipfunc<std::size_t>(&detail::levelFn, l);
     }
-
- template<typename Elem, typename Tr>
- std::size_t get_level(std::basic_ostream<Elem, Tr>& ostr)
- {
- return explore::get_stream_state<container_common_stream_state>(ostr)->level();
- }
 
     detail::manipfunc<std::size_t> cols(std::size_t sz)
     {

Modified: sandbox/explore/boost/explore/stream_state.hpp
==============================================================================
--- sandbox/explore/boost/explore/stream_state.hpp (original)
+++ sandbox/explore/boost/explore/stream_state.hpp 2009-09-20 15:00:31 EDT (Sun, 20 Sep 2009)
@@ -32,14 +32,33 @@
             return index;
         }
 
- // deletion callback for extra state
+ // callback for extra state events
         template<typename T>
- void delete_extra_state(std::ios_base::event e, std::ios_base& stream, int arg)
+ void extra_state_callback(std::ios_base::event e, std::ios_base& stream, int arg)
         {
- if( std::ios_base::erase_event == e && arg == get_stream_state_index<T>() )
+ if( arg == get_stream_state_index<T>() )
             {
- delete get_stream_state<T>(stream);
- stream.pword(arg) = 0;
+ switch( e )
+ {
+ case std::ios_base::erase_event:
+ delete get_stream_state<T>(stream);
+ stream.pword(arg) = 0;
+ break;
+ case std::ios_base::copyfmt_event:
+ {
+ // format has been copied. Make an actual copy instead of using the same
+ // pointer. Prevents deleting memory twice.
+ T* state = get_stream_state<T>(stream);
+
+ // first set to 0 in case allocation fails. Although copyfmt will have failed,
+ // we at least won't crash when we won't delete the same memory twice
+ stream.pword(arg) = 0;
+ stream.pword(arg) = new T(*state);
+ break;
+ }
+ case std::ios_base::imbue_event:
+ break;
+ }
             }
         }
     }
@@ -61,7 +80,7 @@
             // both creating a new T and registering the callback allocate memory. Use
             // auto_ptr to satisfy the strong exception guarantee.
             std::auto_ptr<T> pt(new T(&stream));
- stream.register_callback(detail::delete_extra_state<T>, index);
+ stream.register_callback(detail::extra_state_callback<T>, index);
             state = pt.release();
         }
         return state;

Modified: sandbox/explore/libs/explore/test/Jamfile.v2
==============================================================================
--- sandbox/explore/libs/explore/test/Jamfile.v2 (original)
+++ sandbox/explore/libs/explore/test/Jamfile.v2 2009-09-20 15:00:31 EDT (Sun, 20 Sep 2009)
@@ -28,6 +28,7 @@
   [ run std_map.cpp ]
   [ run std_set.cpp ]
   [ run std_pair.cpp ]
+ [ run std_stream.cpp ]
 
   [ run boost_array.cpp ]
   [ run boost_tuple.cpp ]

Added: sandbox/explore/libs/explore/test/std_stream.cpp
==============================================================================
--- (empty file)
+++ sandbox/explore/libs/explore/test/std_stream.cpp 2009-09-20 15:00:31 EDT (Sun, 20 Sep 2009)
@@ -0,0 +1,111 @@
+// Boost.Explore library
+
+// Copyright Jeffrey Faust 2009. Use, modification and
+// distribution is subject to 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)
+
+// Tests explore against other standard stream functionality
+
+// For more information, see http://www.boost.org
+
+#define BOOST_TEST_MODULE PrintLib
+#include <boost/test/unit_test.hpp>
+#include <boost/explore/vector.hpp>
+#include "boost_explore_test_tools.hpp"
+
+#include <iomanip>
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( std_fill, C, test_types )
+{
+ using namespace boost::explore;
+ typename test_traits<C>::stream_type str_out;
+
+ std::vector<int> vi;
+ vi.push_back(1);
+ vi.push_back(100);
+ vi.push_back(1000);
+
+ str_out << std::setfill(C('x')) << vi;
+ BOOST_CHECK_EQUAL(output(str_out), "[1, 100, 1000]");
+
+ reset(str_out);
+
+ str_out << std::setfill(C('x')) << item_width(5) << vi;
+ BOOST_CHECK_EQUAL(output(str_out), "[xxxx1, xx100, x1000]");
+
+ reset(str_out);
+
+ str_out << std::setfill(C('x')) << item_width(5) << separator(str_to<C>(",")) << vi;
+ BOOST_CHECK_EQUAL(output(str_out), "[xxxx1,xx100,x1000]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( std_boolalpha, C, test_types )
+{
+ using namespace boost::explore;
+ typename test_traits<C>::stream_type str_out;
+
+ std::vector<bool> vb;
+ vb.push_back(true);
+ vb.push_back(false);
+ vb.push_back(true);
+
+ str_out << std::boolalpha << vb;
+ BOOST_CHECK_EQUAL(output(str_out), "[true, false, true]");
+
+ reset(str_out);
+
+ str_out << std::noboolalpha << vb;
+ BOOST_CHECK_EQUAL(output(str_out), "[1, 0, 1]");
+
+ reset(str_out);
+
+ str_out << std::boolalpha << item_width(7) << separator(str_to<C>(",")) << vb;
+ BOOST_CHECK_EQUAL(output(str_out), "[ true, false, true]");
+
+ reset(str_out);
+
+ str_out << std::noboolalpha << item_width(7) << separator(str_to<C>(",")) << vb;
+ BOOST_CHECK_EQUAL(output(str_out), "[ 1, 0, 1]");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( std_copy_fmt, C, test_types )
+{
+ using namespace boost::explore;
+ typename test_traits<C>::stream_type str_out1;
+ typename test_traits<C>::stream_type str_out2;
+
+ std::vector<int> vi;
+ vi.push_back(1);
+ vi.push_back(100);
+ vi.push_back(1000);
+
+ str_out1 << item_width(10) << delimiters(str_to<C>("<"), str_to<C>("-"), str_to<C>(">"));
+ str_out2.copyfmt(str_out1);
+
+ str_out1 << vi;
+ str_out2 << vi;
+
+ BOOST_CHECK_EQUAL(output(str_out1), "< 1- 100- 1000>");
+ BOOST_CHECK_EQUAL(output(str_out2), "< 1- 100- 1000>");
+}
+
+BOOST_AUTO_TEST_CASE_TEMPLATE( std_imbue, C, test_types )
+{
+ using namespace boost::explore;
+ typename test_traits<C>::stream_type str_out;
+
+ std::vector<double> vd;
+ vd.push_back(1.2);
+ vd.push_back(2.3);
+ vd.push_back(3.4);
+
+ str_out << vd;
+ BOOST_CHECK_EQUAL(output(str_out), "[1.2, 2.3, 3.4]");
+
+ reset(str_out);
+
+ str_out.imbue(std::locale("german_Germany"));
+ str_out << vd;
+ BOOST_CHECK_EQUAL(output(str_out), "[1,2, 2,3, 3,4]");
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk