]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc
Reshuffle 21_strings testsuite.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / capacity / char / 1.cc
CommitLineData
61f1ed59
PC
1// 1999-05-11 bkoz
2
3// Copyright (C) 1999, 2002, 2003 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 2, 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 COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// 21.3.3 string capacity
22
23#include <string>
24#include <testsuite_hooks.h>
25
26void test01()
27{
28 // POD types : resize, capacity, reserve
29 bool test = true;
30 std::string str01;
31 typedef std::string::size_type size_type_s;
32
33 size_type_s sz01 = str01.capacity();
34 str01.reserve(100);
35 size_type_s sz02 = str01.capacity();
36 VERIFY( sz02 >= sz01 );
37 VERIFY( sz02 >= 100 );
38 str01.reserve();
39 sz01 = str01.capacity();
40 VERIFY( sz01 >= 0 );
41
42 sz01 = str01.size() + 5;
43 str01.resize(sz01);
44 sz02 = str01.size();
45 VERIFY( sz01 == sz02 );
46
47 sz01 = str01.size() - 5;
48 str01.resize(sz01);
49 sz02 = str01.size();
50 VERIFY( sz01 == sz02 );
51
52 std::string str05(30, 'q');
53 std::string str06 = str05;
54 str05 = str06 + str05;
55 VERIFY( str05.capacity() >= str05.size() );
56 VERIFY( str06.capacity() >= str06.size() );
57
58 // POD types: size, length, max_size, clear(), empty()
59 bool b01;
60 std::string str011;
61 b01 = str01.empty();
62 VERIFY( b01 == true );
63 sz01 = str01.size();
64 sz02 = str01.length();
65 VERIFY( sz01 == sz02 );
66 str01.c_str();
67 sz01 = str01.size();
68 sz02 = str01.length();
69 VERIFY( sz01 == sz02 );
70
71 sz01 = str01.length();
72 str01.c_str();
73 str011 = str01 + "_addendum_";
74 str01.c_str();
75 sz02 = str01.length();
76 VERIFY( sz01 == sz02 );
77 sz02 = str011.length();
78 VERIFY( sz02 > sz01 );
79
80 // trickster allocator issues involved with these:
81 std::string str3 = "8-chars_8-chars_";
82 const char* p3 = str3.c_str();
83 std::string str4 = str3 + "7-chars";
84 const char* p4 = str3.c_str();
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
98int main()
99{
100 test01();
101 return 0;
102}