]>
Commit | Line | Data |
---|---|---|
61f1ed59 PC |
1 | // 1999-05-11 bkoz |
2 | ||
aa118a03 | 3 | // Copyright (C) 1999-2014 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 | |
11f10e6b | 28 | bool test __attribute__((unused)) = true; |
61f1ed59 PC |
29 | std::string str01; |
30 | typedef std::string::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(); | |
3dd50c74 | 39 | VERIFY( sz01 == 0 ); |
61f1ed59 PC |
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::string str05(30, 'q'); | |
52 | std::string 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::string 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 + "_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::string str3 = "8-chars_8-chars_"; | |
61f1ed59 | 81 | std::string str4 = str3 + "7-chars"; |
61f1ed59 PC |
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 | } |