Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55241 - in trunk/libs/spirit/test: . karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-30 14:44:22


Author: hkaiser
Date: 2009-07-28 15:08:05 EDT (Tue, 28 Jul 2009)
New Revision: 55241
URL: http://svn.boost.org/trac/boost/changeset/55241

Log:
Spirit: added test case for formatting containers holding pointers
Added:
   trunk/libs/spirit/test/karma/format_pointer_container.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/test/CMakeLists.txt | 10 +++-------
   trunk/libs/spirit/test/Jamfile | 1 +
   2 files changed, 4 insertions(+), 7 deletions(-)

Modified: trunk/libs/spirit/test/CMakeLists.txt
==============================================================================
--- trunk/libs/spirit/test/CMakeLists.txt (original)
+++ trunk/libs/spirit/test/CMakeLists.txt 2009-07-28 15:08:05 EDT (Tue, 28 Jul 2009)
@@ -1,15 +1,10 @@
 #
 # Copyright Troy D. Straszheim
+# Copyright (c) 2001-2009 Joel de Guzman
+# Copyright (c) 2001-2009 Hartmut Kaiser
 #
 # Distributed under the Boost Software License, Version 1.0.
 # See http://www.boost.org/LICENSE_1_0.txt
-#
-# Copyright (c) 2001-2009 Joel de Guzman
-# Copyright (c) 2001-2009 Hartmut Kaiser
-#
-# 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)
 #==============================================================================
 
 include_directories(.)
@@ -79,6 +74,7 @@
 boost_test_run(karma_eps karma/eps.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_format_manip karma/format_manip.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_format_manip_attr karma/format_manip_attr.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(karma_format_pointer_container karma/format_pointer_container.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_generate_attr karma/generate_attr.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_grammar karma/grammar.cpp COMPILE_FLAGS ${test_compile_flags})
 boost_test_run(karma_int_numerics karma/int_numerics.cpp COMPILE_FLAGS ${test_compile_flags})

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2009-07-28 15:08:05 EDT (Tue, 28 Jul 2009)
@@ -79,6 +79,7 @@
     [ run karma/eps.cpp : : : : karma_eps ]
     [ run karma/format_manip.cpp : : : : ]
     [ run karma/format_manip_attr.cpp : : : : ]
+ [ run karma/format_pointer_container.cpp : : : : ]
     [ run karma/generate_attr.cpp : : : : ]
     [ run karma/grammar.cpp : : : : karma_grammar ]
     [ run karma/int_numerics.cpp : : : : ]

Added: trunk/libs/spirit/test/karma/format_pointer_container.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/format_pointer_container.cpp 2009-07-28 15:08:05 EDT (Tue, 28 Jul 2009)
@@ -0,0 +1,59 @@
+// Copyright (c) 2009 Matthias Vallentin
+//
+// 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)
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/iterator/indirect_iterator.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/spirit/include/karma.hpp>
+#include <boost/spirit/include/karma_stream.hpp>
+
+#include <sstream>
+#include <string>
+#include <vector>
+
+struct foo : boost::noncopyable
+{
+ foo()
+ : str("foo")
+ {
+ }
+
+ std::string str;
+};
+
+template <typename Stream>
+Stream& operator<<(Stream& out, const foo& f)
+{
+ out << f.str;
+ return out;
+};
+
+int main()
+{
+ using namespace boost::spirit;
+
+ typedef boost::shared_ptr<foo> foo_ptr;
+ std::vector<foo_ptr> v;
+
+ std::size_t i = 10;
+ while (i--)
+ v.push_back(boost::make_shared<foo>());
+
+ typedef boost::indirect_iterator<std::vector<foo_ptr>::const_iterator>
+ iterator_type;
+
+ std::stringstream strm;
+ strm
+ << karma::format(stream % ',',
+ boost::iterator_range<iterator_type>(
+ iterator_type(v.begin()), iterator_type(v.end())
+ )
+ );
+ BOOST_TEST(strm.str() == "foo,foo,foo,foo,foo,foo,foo,foo,foo,foo");
+
+ return boost::report_errors();
+}


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