From f162b8dafd14c261c4bc00623af628081b2409fe Mon Sep 17 00:00:00 2001 From: Gennadiy Rozental Date: Sat, 5 Jun 2004 11:04:50 +0000 Subject: [PATCH] no message [SVN r23029] --- test/Jamfile | 1 + test/basic_cstring_test.cpp | 22 +-- test/ifstream_line_iterator_test.cpp | 52 ++++--- test/output_test_stream_test.cpp | 17 ++- test/token_iterator_test.cpp | 197 +++++++++++++++++++++++++++ 5 files changed, 244 insertions(+), 45 deletions(-) create mode 100644 test/token_iterator_test.cpp diff --git a/test/Jamfile b/test/Jamfile index b628f177..a31c456f 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -69,4 +69,5 @@ test-suite "unit_test_framework_test" [ test-btl-lib run : fixed_mapping_test : boost_unit_test_framework ] [ test-btl-lib run : ifstream_line_iterator_test : boost_unit_test_framework ] [ test-btl-lib run : algorithms_test : boost_unit_test_framework ] + [ test-btl-lib run : token_iterator_test : boost_unit_test_framework ] ; diff --git a/test/basic_cstring_test.cpp b/test/basic_cstring_test.cpp index 65c85313..a8e2580c 100644 --- a/test/basic_cstring_test.cpp +++ b/test/basic_cstring_test.cpp @@ -38,6 +38,7 @@ using utf::const_string; namespace mpl = boost::mpl; +typedef mpl::list base_const_char_types; typedef mpl::list mutable_char_types; typedef mpl::transform >::type const_char_types; typedef mpl::joint_view char_types; @@ -126,7 +127,7 @@ BOOST_META_FUNC_TEST_CASE( constructors_test ); //____________________________________________________________________________// template -void constructors_const_test( CharT* = 0 ) +void constructors_std_string_test( CharT* = 0 ) { typedef typename utf::basic_cstring::traits_type traits; @@ -139,7 +140,7 @@ void constructors_const_test( CharT* = 0 ) } -BOOST_META_FUNC_TEST_CASE( constructors_const_test ); +BOOST_META_FUNC_TEST_CASE( constructors_std_string_test ); //____________________________________________________________________________// @@ -249,7 +250,7 @@ BOOST_META_FUNC_TEST_CASE( asignment_test ); //____________________________________________________________________________// template -void asignment_const_test( CharT* = 0 ) +void asignment_std_string_test( CharT* = 0 ) { typedef typename utf::basic_cstring::traits_type traits_type; @@ -266,7 +267,7 @@ void asignment_const_test( CharT* = 0 ) BOOST_CHECK_EQUAL( traits_type::compare( bcs1.begin(), LITERAL( "es" ), bcs1.size() ), 0 ); } -BOOST_META_FUNC_TEST_CASE( asignment_const_test ); +BOOST_META_FUNC_TEST_CASE( asignment_std_string_test ); //____________________________________________________________________________// @@ -297,7 +298,7 @@ BOOST_META_FUNC_TEST_CASE( comparison_test ); //____________________________________________________________________________// template -void comparison_const_test( CharT* = 0 ) +void comparison_std_string_test( CharT* = 0 ) { utf::basic_cstring bcs1( TEST_STRING ); typename utf::basic_cstring::std_string l( TEST_STRING ); @@ -315,7 +316,7 @@ void comparison_const_test( CharT* = 0 ) #endif } -BOOST_META_FUNC_TEST_CASE( comparison_const_test ); +BOOST_META_FUNC_TEST_CASE( comparison_std_string_test ); //____________________________________________________________________________// @@ -469,9 +470,9 @@ init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( constructors_test, char_types ) ); #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( constructors_const_test, const_char_types ) ); - test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( asignment_const_test, const_char_types ) ); - test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( comparison_const_test, const_char_types ) ); + test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( constructors_std_string_test, base_const_char_types ) ); + test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( asignment_std_string_test, base_const_char_types ) ); + test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( comparison_std_string_test, base_const_char_types ) ); #endif test->add( BOOST_TEST_CASE( array_construction_test ) ); test->add( BOOST_FUNC_TEMPLATE_TEST_CASE( data_access_test, char_types ) ); @@ -491,6 +492,9 @@ init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) // History : // // $Log$ +// Revision 1.4 2004/06/05 11:04:17 rogeeff +// no message +// // Revision 1.3 2004/05/27 06:30:48 rogeeff // no message // diff --git a/test/ifstream_line_iterator_test.cpp b/test/ifstream_line_iterator_test.cpp index fbed7110..455b4ad0 100644 --- a/test/ifstream_line_iterator_test.cpp +++ b/test/ifstream_line_iterator_test.cpp @@ -16,59 +16,50 @@ #include #include -#include -#include namespace utf = boost::unit_test; -namespace tt = boost::test_tools; -using utf::const_string; //____________________________________________________________________________// void test_default_delimeter() { - { - utf::ifstream_line_iterator it( "./test_files/ifstream_line_iterator.tst1" ); + utf::ifstream_line_iterator it( "./test_files/ifstream_line_iterator.tst1" ); - BOOST_CHECK( it != utf::ifstream_line_iterator() ); + BOOST_CHECK( it != utf::ifstream_line_iterator() ); - BOOST_CHECK_EQUAL( *it, "acv ffg" ); - ++it; + BOOST_CHECK_EQUAL( *it, "acv ffg" ); + ++it; - BOOST_CHECK_EQUAL( *it, "" ); - ++it; + BOOST_CHECK_EQUAL( *it, "" ); + ++it; - BOOST_CHECK_EQUAL( *it, " " ); - ++it; + BOOST_CHECK_EQUAL( *it, " " ); + ++it; - BOOST_CHECK_EQUAL( *it, "1" ); - ++it; + BOOST_CHECK_EQUAL( *it, "1" ); + ++it; - BOOST_CHECK( it == utf::ifstream_line_iterator() ); - } + BOOST_CHECK( it == utf::ifstream_line_iterator() ); } //____________________________________________________________________________// void test_custom_delimeter() { + utf::ifstream_line_iterator it( "./test_files/ifstream_line_iterator.tst2", '}' ); - { - utf::ifstream_line_iterator it( "./test_files/ifstream_line_iterator.tst2", '}' ); + BOOST_CHECK( it != utf::ifstream_line_iterator() ); - BOOST_CHECK( it != utf::ifstream_line_iterator() ); + BOOST_CHECK_EQUAL( *it, "{ abc d " ); + ++it; - BOOST_CHECK_EQUAL( *it, "{ abc d " ); - ++it; + BOOST_CHECK_EQUAL( *it, "\n{ d \n dsfg\n" ); + ++it; - BOOST_CHECK_EQUAL( *it, "\n{ d \n dsfg\n" ); - ++it; + BOOST_CHECK_EQUAL( *it, "\n" ); + ++it; - BOOST_CHECK_EQUAL( *it, "\n" ); - ++it; - - BOOST_CHECK( it == utf::ifstream_line_iterator() ); - } + BOOST_CHECK( it == utf::ifstream_line_iterator() ); } @@ -91,6 +82,9 @@ init_unit_test_suite( int argc, char* argv[] ) // History : // // $Log$ +// Revision 1.3 2004/06/05 11:04:17 rogeeff +// no message +// // Revision 1.2 2004/05/27 06:30:48 rogeeff // no message // diff --git a/test/output_test_stream_test.cpp b/test/output_test_stream_test.cpp index cebc5d33..7835dd0d 100644 --- a/test/output_test_stream_test.cpp +++ b/test/output_test_stream_test.cpp @@ -46,17 +46,17 @@ test_constructor() BOOST_CHECK( output.is_empty() ); } { - output_test_stream output( "./test_files/pattern.temp" ); + output_test_stream output( "pattern.temp" ); BOOST_CHECK( !output.match_pattern() ); BOOST_CHECK( output.is_empty() ); } { - output_test_stream output( "./test_files/pattern.temp2", false ); + output_test_stream output( "pattern.temp2", false ); BOOST_CHECK( output.match_pattern() ); BOOST_CHECK( output.is_empty() ); } { - output_test_stream output( "./test_files/pattern.temp2" ); + output_test_stream output( "pattern.temp2" ); BOOST_CHECK( output.match_pattern() ); BOOST_CHECK( output.is_empty() ); } @@ -153,7 +153,7 @@ void test_match_pattern() { { - output_test_stream output( "./test_files/pattern.test", false ); + output_test_stream output( "pattern.test", false ); output << "text1\n"; BOOST_CHECK( output.match_pattern() ); @@ -163,7 +163,7 @@ test_match_pattern() BOOST_CHECK( output.match_pattern() ); } { - output_test_stream output( "./test_files/pattern.test" ); + output_test_stream output( "pattern.test" ); output << "text1\n"; BOOST_CHECK( output.match_pattern() ); @@ -173,7 +173,7 @@ test_match_pattern() BOOST_CHECK( output.match_pattern() ); } { - output_test_stream output( "./test_files/pattern.test" ); + output_test_stream output( "pattern.test" ); output << "text4\n"; BOOST_CHECK( !output.match_pattern() ); @@ -183,7 +183,7 @@ test_match_pattern() BOOST_CHECK( output.match_pattern() ); } { - output_test_stream output( "./test_files/pattern.test" ); + output_test_stream output( "pattern.test" ); output << "text\n"; BOOST_CHECK( !output.match_pattern() ); @@ -215,6 +215,9 @@ init_unit_test_suite( int /*argc*/, char* /*argv*/[] ) { // Revision History : // // $Log$ +// Revision 1.18 2004/06/05 11:04:17 rogeeff +// no message +// // Revision 1.17 2004/05/27 06:30:48 rogeeff // no message // diff --git a/test/token_iterator_test.cpp b/test/token_iterator_test.cpp new file mode 100644 index 00000000..9d63c997 --- /dev/null +++ b/test/token_iterator_test.cpp @@ -0,0 +1,197 @@ +// (C) Copyright Gennadiy Rozental 2001-2004. +// 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) + +// See http://www.boost.org/libs/test for the library home page. +// +// File : $RCSfile$ +// +// Version : $Revision$ +// +// Description : string_token_iterator unit test +// ***************************************************************************** + +// Boost.Test +#include + +#include +#include + +namespace utf = boost::unit_test; + +#include +#include +#include + +#ifdef BOOST_NO_STDC_NAMESPACE +namespace std{ using ::toupper; using ::tolower; } +#endif + +//____________________________________________________________________________// + +static utf::string_token_iterator sti_end; +static utf::wstring_token_iterator wsti_end; +void test_default_delim_policy() +{ + utf::string_token_iterator tit( "This is\n, a \ttest" ); + char const* res[] = { "This", "is", ",", "a", "test" }; + + BOOST_CHECK_EQUAL_COLLECTIONS( tit, sti_end, res ); +} + +//____________________________________________________________________________// + +void test_wide() +{ + utf::wstring_token_iterator tit( L"Почему бы и нет" ); + wchar_t const* res[4] = { L"Почему", L"бы", L"и", L"нет" }; + + BOOST_CHECK_EQUAL_COLLECTIONS( tit, wsti_end, res ); +} + +//____________________________________________________________________________// + +void test_custom_drop_delim() +{ + utf::string_token_iterator tit( "My:-:\t: :string, :", utf::dropped_delimeters = ":" ); + char const* res[] = { "My", "-", "\t", " ", "string", ",", " " }; + + BOOST_CHECK_EQUAL_COLLECTIONS( tit, sti_end, res ); +} + +//____________________________________________________________________________// + +void test_custom_keep_delim() +{ + utf::string_token_iterator tit( "abc = \t\t 123, int", utf::kept_delimeters = "=," ); + char const* res[] = { "abc", "=", "123", ",", "int" }; + + BOOST_CHECK_EQUAL_COLLECTIONS( tit, sti_end, res ); +} + +//____________________________________________________________________________// + +void test_keep_empty_tokens() +{ + utf::string_token_iterator tit( "fld,, 456,a=4,", + utf::dropped_delimeters = " ,", + utf::kept_delimeters = "=", + utf::keep_empty_tokens ); + char const* res[] = { "fld", "", "", "456", "a", "=", "4", "" }; + + BOOST_CHECK_EQUAL_COLLECTIONS( tit, sti_end, res ); +} + +//____________________________________________________________________________// + +struct ci_comp { + bool operator()( char c1, char c2 ) + { + return (std::toupper)( c1 ) == (std::toupper)( c2 ); + } +}; + +void test_custom_compare() +{ + typedef utf::basic_string_token_iterator my_token_iterator; + + my_token_iterator tit( "093514T120104", utf::dropped_delimeters = "t" ); + char const* res[] = { "093514", "120104" }; + + my_token_iterator end; + BOOST_CHECK_EQUAL_COLLECTIONS( tit, end, res ); +} + +//____________________________________________________________________________// + +void test_range_token_iterator() +{ + typedef utf::range_token_iterator::iterator> my_token_iterator; + + std::list l; + char const* pattern = "a bc , cd"; + std::copy( pattern, pattern+9, std::back_inserter( l ) ); + + my_token_iterator tit( l.begin(), l.end() ); + char const* res[] = { "a", "bc", ",", "cd" }; + + my_token_iterator end; + BOOST_CHECK_EQUAL_COLLECTIONS( tit, end, res ); +} + +//____________________________________________________________________________// + +void test_istream_token_iterator() +{ + typedef utf::range_token_iterator > my_token_iterator; + + std::istream_iterator in_it( std::cin ); + + my_token_iterator tit( in_it, std::istream_iterator(), utf::dropped_delimeters = ":" ); + + while( tit != my_token_iterator() ) { + std::cout << '<' << *tit << '>'; + ++tit; + } +} + +//____________________________________________________________________________// + +template +void moo( Iter b ) +{ + char const* res[] = { "ABC", "SDF", " ", "SD", "FG", " " }; + + Iter end; + BOOST_CHECK_EQUAL_COLLECTIONS( b, end, res ); +} + +template +void foo( Iter b, Iter e ) +{ + moo( utf::make_range_token_iterator( b, e, utf::kept_delimeters = utf::use_isspace, utf::dropped_delimeters = "2" ) ); +} + +inline char loo( char c ) { return (std::toupper)( c ); } + +void test_make_range_token_iterator() +{ + char const* str = "Abc22sdf sd2fg "; + + foo( boost::make_transform_iterator( str, loo ), + boost::make_transform_iterator( str+15, loo ) ); +} + +//____________________________________________________________________________// + +utf::test_suite* +init_unit_test_suite( int argc, char* argv[] ) +{ + utf::test_suite* test= BOOST_TEST_SUITE( "token iterator unit test" ); + + test->add( BOOST_TEST_CASE( &test_default_delim_policy ) ); + test->add( BOOST_TEST_CASE( &test_wide ) ); + test->add( BOOST_TEST_CASE( &test_custom_drop_delim ) ); + test->add( BOOST_TEST_CASE( &test_custom_keep_delim ) ); + test->add( BOOST_TEST_CASE( &test_keep_empty_tokens ) ); + test->add( BOOST_TEST_CASE( &test_custom_compare ) ); + test->add( BOOST_TEST_CASE( &test_range_token_iterator ) ); +// test->add( BOOST_TEST_CASE( &test_istream_token_iterator ) ); + test->add( BOOST_TEST_CASE( &test_make_range_token_iterator ) ); + + return test; +} + +//____________________________________________________________________________// + +// ***************************************************************************** +// History : +// +// $Log$ +// Revision 1.1 2004/06/05 11:04:50 rogeeff +// no message +// +// ***************************************************************************** + +// EOF