]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / capacity / char / 1.cc
CommitLineData
61f1ed59
PC
1// 1999-05-11 bkoz
2
5624e564 3// Copyright (C) 1999-2015 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
25void 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();
34a2b755
JW
39#if _GLIBCXX_USE_CXX11_ABI
40 VERIFY( sz01 < 100);
41#else
3dd50c74 42 VERIFY( sz01 == 0 );
34a2b755 43#endif
61f1ed59
PC
44
45 sz01 = str01.size() + 5;
46 str01.resize(sz01);
47 sz02 = str01.size();
48 VERIFY( sz01 == sz02 );
49
50 sz01 = str01.size() - 5;
51 str01.resize(sz01);
52 sz02 = str01.size();
53 VERIFY( sz01 == sz02 );
54
55 std::string str05(30, 'q');
56 std::string str06 = str05;
57 str05 = str06 + str05;
58 VERIFY( str05.capacity() >= str05.size() );
59 VERIFY( str06.capacity() >= str06.size() );
60
61 // POD types: size, length, max_size, clear(), empty()
62 bool b01;
63 std::string str011;
64 b01 = str01.empty();
65 VERIFY( b01 == true );
66 sz01 = str01.size();
67 sz02 = str01.length();
68 VERIFY( sz01 == sz02 );
69 str01.c_str();
70 sz01 = str01.size();
71 sz02 = str01.length();
72 VERIFY( sz01 == sz02 );
73
74 sz01 = str01.length();
75 str01.c_str();
76 str011 = str01 + "_addendum_";
77 str01.c_str();
78 sz02 = str01.length();
79 VERIFY( sz01 == sz02 );
80 sz02 = str011.length();
81 VERIFY( sz02 > sz01 );
82
83 // trickster allocator issues involved with these:
84 std::string str3 = "8-chars_8-chars_";
61f1ed59 85 std::string str4 = str3 + "7-chars";
61f1ed59
PC
86
87 sz01 = str01.size();
88 sz02 = str01.max_size();
89 VERIFY( sz02 >= sz01 );
90
91 sz01 = str01.size();
92 str01.clear();
93 b01 = str01.empty();
94 VERIFY( b01 == true );
95 sz02 = str01.size();
96 VERIFY( sz01 >= sz02 );
97}
98
99int main()
100{
101 test01();
102 return 0;
103}