3 // Copyright (C) 1999-2013 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 21.3.1 basic_string constructors.
25 #include <testsuite_hooks.h>
29 bool test __attribute__((unused)) = true;
30 typedef std::wstring::size_type csize_type;
31 typedef std::wstring::iterator citerator;
32 csize_type npos = std::wstring::npos;
35 const wchar_t str_lit01[] = L"rodeo beach, marin";
36 const std::wstring str01(str_lit01);
37 const std::wstring str02(L"baker beach, san francisco");
39 // basic_string(const wstring&, size_type pos = 0, siz_type n = npos, alloc)
42 std::wstring str03(str01, csz01 + 1);
45 catch(std::out_of_range& fail) {
53 std::wstring str03(str01, csz01);
54 VERIFY( str03.size() == 0 );
55 VERIFY( str03.size() <= str03.capacity() );
61 // basic_string(const wchar_t* s, size_type n, alloc)
62 csz01 = str01.max_size();
63 // NB: As strlen(str_lit01) != csz01, this test is undefined. It
64 // should not crash, but what gets constructed is a bit arbitrary.
66 std::wstring str03(str_lit01, csz01 + 1);
69 catch(std::length_error& fail) {
76 // NB: As strlen(str_lit01) != csz01, this test is undefined. It
77 // should not crash, but what gets constructed is a bit arbitrary.
78 // The "maverick's" of all string objects.
80 std::wstring str04(str_lit01, npos);
83 catch(std::length_error& fail) {
90 // Build a maxsize - 1 lengthed string consisting of all A's
92 std::wstring str03(csz01 - 1, 'A');
93 VERIFY( str03.size() == csz01 - 1 );
94 VERIFY( str03.size() <= str03.capacity() );
96 // NB: bad_alloc is regrettable but entirely kosher for
97 // out-of-memory situations.
98 catch(std::bad_alloc& fail) {
105 // basic_string(const wchar_t* s, const allocator& a = allocator())
106 std::wstring str04(str_lit01);
107 VERIFY( str01 == str04 );
110 // basic_string(size_type n, char c, const allocator& a = allocator())
111 csz01 = str01.max_size();
113 std::wstring str03(csz01 + 1, L'z');
116 catch(std::length_error& fail) {
124 std::wstring str04(npos, L'b'); // the "maverick's" of all string objects.
127 catch(std::length_error& fail) {
135 std::wstring str03(csz01 - 1, L'z');
136 VERIFY( str03.size() != 0 );
137 VERIFY( str03.size() <= str03.capacity() );
139 // NB: bad_alloc is regrettable but entirely kosher for
140 // out-of-memory situations.
141 catch(std::bad_alloc& fail) {
149 // template<typename _InputIter>
150 // basic_string(_InputIter begin, _InputIter end, const allocator& a)
151 std::wstring str06(str01.begin(), str01.end());
152 VERIFY( str06 == str01 );
157 __gnu_test::set_memory_limits();