]>
Commit | Line | Data |
---|---|---|
61f1ed59 PC |
1 | // 1999-05-11 bkoz |
2 | ||
8d9254fc | 3 | // Copyright (C) 1999-2020 Free Software Foundation, Inc. |
61f1ed59 PC |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
61f1ed59 PC |
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 | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
61f1ed59 PC |
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 | |
61f1ed59 PC |
28 | std::string str01; |
29 | typedef std::string::size_type size_type_s; | |
30 | ||
31 | size_type_s sz01 = str01.capacity(); | |
32 | str01.reserve(100); | |
33 | size_type_s sz02 = str01.capacity(); | |
34 | VERIFY( sz02 >= sz01 ); | |
35 | VERIFY( sz02 >= 100 ); | |
36 | str01.reserve(); | |
37 | sz01 = str01.capacity(); | |
34a2b755 JW |
38 | #if _GLIBCXX_USE_CXX11_ABI |
39 | VERIFY( sz01 < 100); | |
40 | #else | |
3dd50c74 | 41 | VERIFY( sz01 == 0 ); |
34a2b755 | 42 | #endif |
61f1ed59 PC |
43 | |
44 | sz01 = str01.size() + 5; | |
45 | str01.resize(sz01); | |
46 | sz02 = str01.size(); | |
47 | VERIFY( sz01 == sz02 ); | |
48 | ||
49 | sz01 = str01.size() - 5; | |
50 | str01.resize(sz01); | |
51 | sz02 = str01.size(); | |
52 | VERIFY( sz01 == sz02 ); | |
53 | ||
54 | std::string str05(30, 'q'); | |
55 | std::string str06 = str05; | |
56 | str05 = str06 + str05; | |
57 | VERIFY( str05.capacity() >= str05.size() ); | |
58 | VERIFY( str06.capacity() >= str06.size() ); | |
59 | ||
60 | // POD types: size, length, max_size, clear(), empty() | |
61 | bool b01; | |
62 | std::string str011; | |
63 | b01 = str01.empty(); | |
64 | VERIFY( b01 == true ); | |
65 | sz01 = str01.size(); | |
66 | sz02 = str01.length(); | |
67 | VERIFY( sz01 == sz02 ); | |
68 | str01.c_str(); | |
69 | sz01 = str01.size(); | |
70 | sz02 = str01.length(); | |
71 | VERIFY( sz01 == sz02 ); | |
72 | ||
73 | sz01 = str01.length(); | |
74 | str01.c_str(); | |
75 | str011 = str01 + "_addendum_"; | |
76 | str01.c_str(); | |
77 | sz02 = str01.length(); | |
78 | VERIFY( sz01 == sz02 ); | |
79 | sz02 = str011.length(); | |
80 | VERIFY( sz02 > sz01 ); | |
81 | ||
82 | // trickster allocator issues involved with these: | |
83 | std::string str3 = "8-chars_8-chars_"; | |
61f1ed59 | 84 | std::string str4 = str3 + "7-chars"; |
61f1ed59 PC |
85 | |
86 | sz01 = str01.size(); | |
87 | sz02 = str01.max_size(); | |
88 | VERIFY( sz02 >= sz01 ); | |
89 | ||
90 | sz01 = str01.size(); | |
91 | str01.clear(); | |
92 | b01 = str01.empty(); | |
93 | VERIFY( b01 == true ); | |
94 | sz02 = str01.size(); | |
95 | VERIFY( sz01 >= sz02 ); | |
96 | } | |
97 | ||
98 | int main() | |
99 | { | |
100 | test01(); | |
101 | return 0; | |
102 | } |