]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/rfind.cc
std_fstream.h: Remove duplicate typdefs for ofstream and wofstream...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / rfind.cc
CommitLineData
913c27bf
BV
1// 2000-06-22 -=dbv=- (shamelessy copied from bkoz' find.cc)
2
3// Copyright (C) 2000 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21#include <string>
22#include <stdexcept>
23#ifdef DEBUG_ASSERT
24#include <assert.h>
25#endif
26
27// 21.3.6.2 basic_string rfind
28bool test01(void)
29{
30 bool test = true;
31 typedef std::string::size_type csize_type;
32 typedef std::string::const_reference cref;
33 typedef std::string::reference ref;
34 csize_type npos = std::string::npos;
35 csize_type csz01, csz02;
36
37 const char str_lit01[] = "mave";
38 const std::string str01("mavericks, santa cruz");
39 std::string str02(str_lit01);
40 std::string str03("s, s");
41 std::string str04;
42
43 // size_type rfind(const string&, size_type pos = 0) const;
44 csz01 = str01.rfind(str01);
45 test &= csz01 == 0;
46 csz01 = str01.rfind(str01, 4);
47 test &= csz01 == 0;
48 csz01 = str01.rfind(str02,3);
49 test &= csz01 == 0;
50 csz01 = str01.rfind(str02);
51 test &= csz01 == 0;
52 csz01 = str01.rfind(str03);
53 test &= csz01 == 8;
54 csz01 = str01.rfind(str03, 3);
55 test &= csz01 == npos;
56 csz01 = str01.rfind(str03, 12);
57 test &= csz01 == 8;
58
59 // An empty string consists of no characters
60 // therefore it should be found at every point in a string,
61 // except beyond the end
62 csz01 = str01.rfind(str04, 0);
63 test &= csz01 == 0;
64 csz01 = str01.rfind(str04, 5);
65 test &= csz01 == 5;
66 csz01 = str01.rfind(str04, str01.size());
67 test &= csz01 == str01.size();
68 csz01 = str01.rfind(str04, str01.size()+1);
69 test &= csz01 == str01.size();
70
71 // size_type rfind(const char* s, size_type pos, size_type n) const;
72 csz01 = str01.rfind(str_lit01, 0, 3);
73 test &= csz01 == 0;
74 csz01 = str01.rfind(str_lit01, 3, 0);
75 test &= csz01 == 3;
76
77 // size_type rfind(const char* s, size_type pos = 0) const;
78 csz01 = str01.rfind(str_lit01);
79 test &= csz01 == 0;
80 csz01 = str01.rfind(str_lit01, 3);
81 test &= csz01 == 0;
82
83 // size_type rfind(char c, size_type pos = 0) const;
84 csz01 = str01.rfind('z');
85 csz02 = str01.size() - 1;
86 test &= csz01 == csz02;
87 csz01 = str01.rfind('/');
88 test &= csz01 == npos;
89
90#ifdef DEBUG_ASSERT
91 assert(test);
92#endif
93 return test;
94}
95
96// 21.3.6.4 basic_string::find_last_of
97bool test02()
98{
99 bool test = true;
100
101 // test find_last_of
102
103#ifdef DEBUG_ASSERT
104 assert(test);
105#endif
106 return test;
107}
108
109// 21.3.6.6 basic_string::find_last_not_of
110bool test03()
111{
112 bool test = true;
113
114 // test find_last_not_of
115
116#ifdef DEBUG_ASSERT
117 assert(test);
118#endif
119 return test;
120}
121int main()
122{
123 test01();
124 test02();
125 test03();
126}