1 // (C) Copyright Gennadiy Rozental 2003-2008.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : unit test for class properties facility
13 // ***************************************************************************
16 #include <boost/test/unit_test.hpp>
17 #include <boost/test/utils/class_properties.hpp>
18 #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
19 #include <boost/test/utils/algorithm.hpp>
20 namespace utf = boost::unit_test;
21 using utf::const_string;
27 # ifdef BOOST_NO_STDC_NAMESPACE
28 namespace std { using ::toupper; }
31 //____________________________________________________________________________//
33 bool predicate( char c1, char c2 ) { return (std::toupper)( c1 ) == (std::toupper)( c2 ); }
35 //____________________________________________________________________________//
39 const_string cs1( "test_string" );
40 const_string cs2( "test_stream" );
42 BOOST_CHECK_EQUAL( utf::mismatch( cs1.begin(), cs1.end(), cs2.begin(), cs2.end() ).first - cs1.begin(), 8 );
45 BOOST_CHECK_EQUAL( utf::mismatch( cs1.begin(), cs1.end(), cs2.begin(), cs2.end() ).first - cs1.begin(), 1 );
47 cs2 = "test_string_klmn";
48 BOOST_CHECK_EQUAL( utf::mismatch( cs1.begin(), cs1.end(), cs2.begin(), cs2.end() ).first - cs1.begin(), 11 );
52 utf::mismatch( cs1.begin(), cs1.end(), cs2.begin(), cs2.end(), std::ptr_fun( predicate ) ).first - cs1.begin(),
56 //____________________________________________________________________________//
58 void test_find_first_not_of()
60 const_string cs( "test_string" );
61 const_string another( "tes" );
63 BOOST_CHECK_EQUAL( utf::find_first_not_of( cs.begin(), cs.end(), another.begin(), another.end() ) - cs.begin(), 4 );
67 utf::find_first_not_of( cs.begin(), cs.end(), another.begin(), another.end(), std::ptr_fun( predicate ) ) - cs.begin(),
71 BOOST_CHECK( utf::find_last_not_of( cs.begin(), cs.end(), another.begin(), another.end() ) == cs.end() );
74 //____________________________________________________________________________//
76 void test_find_last_of()
78 const_string cs( "test_string" );
79 const_string another( "tes" );
81 BOOST_CHECK_EQUAL( utf::find_last_of( cs.begin(), cs.end(), another.begin(), another.end() ) - cs.begin(), 6 );
85 utf::find_last_of( cs.begin(), cs.end(), another.begin(), another.end(), std::ptr_fun( predicate ) ) - cs.begin(),
89 BOOST_CHECK( utf::find_last_of( cs.begin(), cs.end(), another.begin(), another.end() ) == cs.end() );
92 BOOST_CHECK_EQUAL( utf::find_last_of( cs.begin(), cs.end(), another.begin(), another.end() ) - cs.begin(), 0 );
95 //____________________________________________________________________________//
97 void test_find_last_not_of()
99 const_string cs( "test_string" );
100 const_string another( "string" );
102 BOOST_CHECK_EQUAL( utf::find_last_not_of( cs.begin(), cs.end(), another.begin(), another.end() ) - cs.begin(), 4 );
106 utf::find_last_not_of( cs.begin(), cs.end(), another.begin(), another.end(), std::ptr_fun( predicate ) ) - cs.begin(),
109 another = "e_string";
110 BOOST_CHECK( utf::find_last_not_of( cs.begin(), cs.end(), another.begin(), another.end() ) == cs.end() );
113 //____________________________________________________________________________//
116 init_unit_test_suite( int /* argc */, char* /* argv */ [] )
118 utf::test_suite* test= BOOST_TEST_SUITE("Algorithms test");
120 test->add( BOOST_TEST_CASE( test_mismatch ) );
121 test->add( BOOST_TEST_CASE( test_find_first_not_of ) );
122 test->add( BOOST_TEST_CASE( test_find_last_of ) );
123 test->add( BOOST_TEST_CASE( test_find_last_not_of ) );
128 //____________________________________________________________________________//