]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/1.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / capacity / wchar_t / 1.cc
1 // 1999-05-11 bkoz
2
3 // Copyright (C) 1999-2014 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 21.3.3 string capacity
21
22 #include <string>
23 #include <testsuite_hooks.h>
24
25 void test01()
26 {
27 // POD types : resize, capacity, reserve
28 bool test __attribute__((unused)) = true;
29 std::wstring str01;
30 typedef std::wstring::size_type size_type_s;
31
32 size_type_s sz01 = str01.capacity();
33 str01.reserve(100);
34 size_type_s sz02 = str01.capacity();
35 VERIFY( sz02 >= sz01 );
36 VERIFY( sz02 >= 100 );
37 str01.reserve();
38 sz01 = str01.capacity();
39 VERIFY( sz01 == 0 );
40
41 sz01 = str01.size() + 5;
42 str01.resize(sz01);
43 sz02 = str01.size();
44 VERIFY( sz01 == sz02 );
45
46 sz01 = str01.size() - 5;
47 str01.resize(sz01);
48 sz02 = str01.size();
49 VERIFY( sz01 == sz02 );
50
51 std::wstring str05(30, L'q');
52 std::wstring str06 = str05;
53 str05 = str06 + str05;
54 VERIFY( str05.capacity() >= str05.size() );
55 VERIFY( str06.capacity() >= str06.size() );
56
57 // POD types: size, length, max_size, clear(), empty()
58 bool b01;
59 std::wstring str011;
60 b01 = str01.empty();
61 VERIFY( b01 == true );
62 sz01 = str01.size();
63 sz02 = str01.length();
64 VERIFY( sz01 == sz02 );
65 str01.c_str();
66 sz01 = str01.size();
67 sz02 = str01.length();
68 VERIFY( sz01 == sz02 );
69
70 sz01 = str01.length();
71 str01.c_str();
72 str011 = str01 + L"_addendum_";
73 str01.c_str();
74 sz02 = str01.length();
75 VERIFY( sz01 == sz02 );
76 sz02 = str011.length();
77 VERIFY( sz02 > sz01 );
78
79 // trickster allocator issues involved with these:
80 std::wstring str3 = L"8-chars_8-chars_";
81 std::wstring str4 = str3 + L"7-chars";
82
83 sz01 = str01.size();
84 sz02 = str01.max_size();
85 VERIFY( sz02 >= sz01 );
86
87 sz01 = str01.size();
88 str01.clear();
89 b01 = str01.empty();
90 VERIFY( b01 == true );
91 sz02 = str01.size();
92 VERIFY( sz01 >= sz02 );
93 }
94
95 int main()
96 {
97 test01();
98 return 0;
99 }