1// Boost string_algo library conv_test.cpp file ---------------------------//
2
3// Copyright Pavol Droba 2002-2003. Use, modification and
4// distribution is subject to the Boost Software License, Version
5// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7
8// See http://www.boost.org for updates, documentation, and revision history.
9
10#include <boost/algorithm/string/case_conv.hpp>
11
12// Include unit test framework
13#define BOOST_TEST_MAIN
14#include <boost/test/unit_test.hpp>
15
16#include <string>
17#include <iostream>
18#include <algorithm>
19#include <boost/test/test_tools.hpp>
20
21using namespace std;
22using namespace boost;
23
24void conv_test()
25{
26 string str1("AbCdEfG 123 xxxYYYzZzZ");
27 string str2("AbCdEfG 123 xxxYYYzZzZ");
28 string str3("");
29 const char pch[]="AbCdEfG 123 xxxYYYzZzZ";
30 unsigned int pchlen=sizeof(pch);
31
32 char* pch1=new char[pchlen];
33 std::copy(pch, pch+pchlen, pch1);
34 char* pch2=new char[pchlen];
35 std::copy(pch, pch+pchlen, pch2);
36
37 // *** iterator tests *** //
38
39 string strout;
40 to_lower_copy( back_inserter(strout), str1 );
41 BOOST_CHECK( strout=="abcdefg 123 xxxyyyzzzz" );
42 strout.clear();
43 to_upper_copy( back_inserter(strout), str1 );
44 BOOST_CHECK( strout=="ABCDEFG 123 XXXYYYZZZZ" );
45
46 strout.clear();
47 to_lower_copy( back_inserter(strout), "AbCdEfG 123 xxxYYYzZzZ" );
48 BOOST_CHECK( strout=="abcdefg 123 xxxyyyzzzz" );
49 strout.clear();
50 to_upper_copy( back_inserter(strout), "AbCdEfG 123 xxxYYYzZzZ" );
51 BOOST_CHECK( strout=="ABCDEFG 123 XXXYYYZZZZ" );
52
53 strout.clear();
54 to_lower_copy( back_inserter(strout), pch1 );
55 BOOST_CHECK( strout=="abcdefg 123 xxxyyyzzzz" );
56 strout.clear();
57 to_upper_copy( back_inserter(strout), pch1 );
58 BOOST_CHECK( strout=="ABCDEFG 123 XXXYYYZZZZ" );
59
60 // *** value passing tests *** //
61
62 BOOST_CHECK( to_lower_copy( str1 )=="abcdefg 123 xxxyyyzzzz" );
63 BOOST_CHECK( to_upper_copy( str1 )=="ABCDEFG 123 XXXYYYZZZZ" );
64
65 BOOST_CHECK( to_lower_copy( str3 )=="" );
66 BOOST_CHECK( to_upper_copy( str3 )=="" );
67
68 // *** inplace tests *** //
69
70 to_lower( str1 );
71 BOOST_CHECK( str1=="abcdefg 123 xxxyyyzzzz" );
72 to_upper( str2 );
73 BOOST_CHECK( str2=="ABCDEFG 123 XXXYYYZZZZ" );
74
75 // c-string modification
76 to_lower( pch1 );
77 BOOST_CHECK( string(pch1)=="abcdefg 123 xxxyyyzzzz" );
78 to_upper( pch2 );
79 BOOST_CHECK( string(pch2)=="ABCDEFG 123 XXXYYYZZZZ" );
80
81 to_lower( str3 );
82 BOOST_CHECK( str3=="" );
83 to_upper( str3 );
84 BOOST_CHECK( str3=="" );
85
86 delete[] pch1;
87 delete[] pch2;
88}
89
90// test main
91BOOST_AUTO_TEST_CASE( test_main )
92{
93 conv_test();
94}
95