]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/ctor_copy_dtor.cc
3 // Copyright (C) 1999, 2000 Free Software Foundation, Inc.
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)
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.
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,
21 // 21.3.1 basic_string constructors.
26 #include <debug_assert.h>
31 typedef std::string::size_type csize_type
;
32 typedef std::string::iterator citerator
;
33 csize_type npos
= std::string::npos
;
34 csize_type csz01
, csz02
;
36 const char str_lit01
[] = "rodeo beach, marin";
37 const std::string
str01(str_lit01
);
38 const std::string
str02("baker beach, san francisco");
40 // basic_string(const string&, size_type pos = 0, siz_type n = npos, alloc)
43 std::string
str03(str01
, csz01
+ 1);
46 catch(std::out_of_range
& fail
) {
54 std::string
str03(str01
, csz01
);
55 VERIFY( str03
.size() == 0 );
56 VERIFY( str03
.size() <= str03
.capacity() );
63 // XXX These tests have been temporarily disabled.
64 //http://gcc.gnu.org/ml/libstdc++/2000-10/msg00033.html
65 // basic_string(const char* s, size_type n, alloc)
66 csz01
= str01
.max_size();
67 // NB: As strlen(str_lit01) != csz01, this test is undefined. It
68 // should not crash, but what gets constructed is a bit arbitrary.
70 std::string
str03(str_lit01
, csz01
+ 1);
73 catch(std::length_error
& fail
) {
80 // NB: As strlen(str_lit01) != csz01, this test is undefined. It
81 // should not crash, but what gets constructed is a bit arbitrary.
82 // The "maverick's" of all string objects.
84 std::string
str04(str_lit01
, npos
);
87 catch(std::length_error
& fail
) {
94 // Build a maxsize - 1 lengthed string consisting of all A's
96 std::string
str03(csz01
- 1, 'A');
97 VERIFY( str03
.size() == csz01
- 1 );
98 VERIFY( str03
.size() <= str03
.capacity() );
100 // NB: bad_alloc is regrettable but entirely kosher for
101 // out-of-memory situations.
102 catch(std::bad_alloc
& fail
) {
110 // basic_string(const char* s, const allocator& a = allocator())
111 std::string
str04(str_lit01
);
112 VERIFY( str01
== str04
);
115 // basic_string(size_type n, char c, const allocator& a = allocator())
116 csz01
= str01
.max_size();
118 std::string
str03(csz01
+ 1, 'z');
121 catch(std::length_error
& fail
) {
129 std::string
str04(npos
, 'b'); // the "maverick's" of all string objects.
132 catch(std::length_error
& fail
) {
140 std::string
str03(csz01
- 1, 'z');
141 VERIFY( str03
.size() != 0 );
142 VERIFY( str03
.size() <= str03
.capacity() );
144 // NB: bad_alloc is regrettable but entirely kosher for
145 // out-of-memory situations.
146 catch(std::bad_alloc
& fail
) {
154 // template<typename _InputIter>
155 // basic_string(_InputIter begin, _InputIter end, const allocator& a)
156 std::string
str06(str01
.begin(), str01
.end());
157 VERIFY( str06
== str01
);
169 // template<typename _InputIter>
170 // basic_string(_InputIter begin, _InputIter end, const allocator& a)
171 // where _InputIter is integral [21.3.1 para 15]
173 VERIFY( s
.size() == 10 );