Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62994 - in trunk: boost/iostreams/filter libs/iostreams/test
From: steven_at_[hidden]
Date: 2010-06-15 15:54:46


Author: steven_watanabe
Date: 2010-06-15 15:54:45 EDT (Tue, 15 Jun 2010)
New Revision: 62994
URL: http://svn.boost.org/trac/boost/changeset/62994

Log:
Make aggregate_filter work with wide characters. Fixes #3851.
Text files modified:
   trunk/boost/iostreams/filter/aggregate.hpp | 6
   trunk/libs/iostreams/test/regex_filter_test.cpp | 154 +++++++++++++++++++++++++++++++++++++++
   2 files changed, 157 insertions(+), 3 deletions(-)

Modified: trunk/boost/iostreams/filter/aggregate.hpp
==============================================================================
--- trunk/boost/iostreams/filter/aggregate.hpp (original)
+++ trunk/boost/iostreams/filter/aggregate.hpp 2010-06-15 15:54:45 EDT (Tue, 15 Jun 2010)
@@ -126,7 +126,7 @@
     }
 
     template<typename Sink>
- void do_write(Sink& sink, const char* s, std::streamsize n)
+ void do_write(Sink& sink, const char_type* s, std::streamsize n)
     {
         typedef typename iostreams::category_of<Sink>::type category;
         typedef is_convertible<category, output> can_write;
@@ -134,11 +134,11 @@
     }
 
     template<typename Sink>
- void do_write(Sink& sink, const char* s, std::streamsize n, mpl::true_)
+ void do_write(Sink& sink, const char_type* s, std::streamsize n, mpl::true_)
     { iostreams::write(sink, s, n); }
 
     template<typename Sink>
- void do_write(Sink&, const char*, std::streamsize, mpl::false_) { }
+ void do_write(Sink&, const char_type*, std::streamsize, mpl::false_) { }
 
     void close_impl()
     {

Modified: trunk/libs/iostreams/test/regex_filter_test.cpp
==============================================================================
--- trunk/libs/iostreams/test/regex_filter_test.cpp (original)
+++ trunk/libs/iostreams/test/regex_filter_test.cpp 2010-06-15 15:54:45 EDT (Tue, 15 Jun 2010)
@@ -22,6 +22,10 @@
 struct replace_lower {
     std::string operator() (const boost::match_results<const char*>&)
     { return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
+#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
+ std::wstring operator() (const boost::match_results<const wchar_t*>&)
+ { return L"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
+#endif
 };
 
 void regex_filter_test()
@@ -167,9 +171,159 @@
     }
 }
 
+#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
+
+void wregex_filter_test()
+{
+ // Note: Given the basic stream and filter tests, two regex tests
+ // are probably sufficient: reading with a filter based on a function,
+ // and writing with a filter based on a format string.
+
+ test_file test;
+ uppercase_file upper;
+
+ boost::wregex match_lower(L"[a-z]+");
+ std::wstring fmt = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ {
+ // Note: the ifstream second is placed in a nested scope because
+ // closing and reopening a single ifstream failed for CW 9.4 on Windows.
+
+ // Test reading from a regex filter based on a function in chars.
+ filtering_wistream
+ first(boost::iostreams::wregex_filter(match_lower, replace_lower()));
+ first.push(wfile_source(test.name(), in_mode));
+ {
+ wifstream second(upper.name().c_str(), in_mode);
+ BOOST_CHECK_MESSAGE(
+ compare_streams_in_chars(first, second),
+ "failed reading from function-based regex_filter in chars"
+ );
+ }
+ first.pop();
+
+ // Test reading from a regex filter based on a function in chunks.
+ // (Also tests reusing the regex filter.)
+ first.push(wfile_source(test.name(), in_mode));
+ {
+ wifstream second(upper.name().c_str(), in_mode);
+ BOOST_CHECK_MESSAGE(
+ compare_streams_in_chunks(first, second),
+ "failed reading from function-based regex_filter in chunks"
+ );
+ }
+ }
+
+ {
+ // Note: the ifstream second is placed in a nested scope because
+ // closing and reopening a single ifstream failed for CW 9.4 on Windows.
+
+ // Test reading from a regex filter based on a format string in chars.
+ filtering_wistream
+ first(boost::iostreams::wregex_filter(match_lower, fmt));
+ first.push(wfile_source(test.name(), in_mode));
+ {
+ wifstream second(upper.name().c_str(), in_mode);
+ BOOST_CHECK_MESSAGE(
+ compare_streams_in_chars(first, second),
+ "failed reading from format-string-based regex_filter in chars"
+ );
+ }
+ first.pop();
+
+ // Test reading from a regex filter based on a format string in chunks.
+ // (Also tests reusing the regex filter.)
+ first.push(wfile_source(test.name(), in_mode));
+ {
+ wifstream second(upper.name().c_str(), in_mode);
+ BOOST_CHECK_MESSAGE(
+ compare_streams_in_chars(first, second),
+ "failed reading from format-string-based regex_filter in chunks"
+ );
+ }
+ }
+
+ {
+ test_file dest1;
+ test_file dest2;
+
+ // Test writing to a regex filter based on a function in chars.
+ filtering_wostream
+ out(boost::iostreams::wregex_filter(match_lower, replace_lower()));
+ out.push(wfile_sink(dest1.name(), out_mode));
+ write_data_in_chars(out);
+ out.pop();
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest1.name(), upper.name()),
+ "failed writing to function-based regex_filter in chars"
+ );
+
+ // Test writing to a regex filter based on a function in chunks.
+ // (Also tests reusing the regex filter.)
+ out.push(wfile_sink(dest2.name(), out_mode));
+ write_data_in_chunks(out);
+ out.pop();
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest2.name(), upper.name()),
+ "failed writing to function-based regex_filter in chunks"
+ );
+ }
+
+ {
+ test_file dest1;
+ test_file dest2;
+
+ // Test writing to a regex filter based on a format string in chars.
+ filtering_wostream
+ out(boost::iostreams::wregex_filter(match_lower, fmt));
+ out.push(wfile_sink(dest1.name(), out_mode));
+ write_data_in_chars(out);
+ out.pop();
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest1.name(), upper.name()),
+ "failed writing to format-string-based regex_filter in chars"
+ );
+
+ // Test writing to a regex filter based on a format string in chunks.
+ // (Also tests reusing the regex filter.)
+ out.push(wfile_sink(dest2.name(), out_mode));
+ write_data_in_chunks(out);
+ out.pop();
+ BOOST_CHECK_MESSAGE(
+ compare_files(dest2.name(), upper.name()),
+ "failed writing to format-string-based regex_filter in chunks"
+ );
+ }
+
+ {
+ // Note: the ifstream second is placed in a nested scope because
+ // closing and reopening a single ifstream failed for CW 9.4 on Windows.
+
+ // Test reading from a regex filter with no matches; this checks that
+ // Ticket #1139 is fixed
+ boost::wregex match_xxx(L"xxx");
+ test_file test2;
+ filtering_wistream
+ first(boost::iostreams::wregex_filter(match_xxx, replace_lower()));
+ first.push(wfile_source(test.name(), in_mode));
+ {
+ wifstream second(test2.name().c_str(), in_mode);
+ BOOST_CHECK_MESSAGE(
+ compare_streams_in_chars(first, second),
+ "failed reading from a regex filter with no matches"
+ );
+ }
+ }
+}
+
+#endif
+
 test_suite* init_unit_test_suite(int, char* [])
 {
     test_suite* test = BOOST_TEST_SUITE("regex_filter test");
     test->add(BOOST_TEST_CASE(&regex_filter_test));
+#ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
+ test->add(BOOST_TEST_CASE(&wregex_filter_test));
+#endif
     return test;
 }


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