2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / capacity / char / 1.cc
blob9cdc4f0457cf63408ced184a8ad757ee11a2bd46
1 // 1999-05-11 bkoz
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.
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.
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.
21 // 21.3.3 string capacity
23 #include <string>
24 #include <testsuite_hooks.h>
26 void test01()
28 // POD types : resize, capacity, reserve
29 bool test __attribute__((unused)) = true;
30 std::string str01;
31 typedef std::string::size_type size_type_s;
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 );
42 sz01 = str01.size() + 5;
43 str01.resize(sz01);
44 sz02 = str01.size();
45 VERIFY( sz01 == sz02 );
47 sz01 = str01.size() - 5;
48 str01.resize(sz01);
49 sz02 = str01.size();
50 VERIFY( sz01 == sz02 );
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() );
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 );
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 );
80 // trickster allocator issues involved with these:
81 std::string str3 = "8-chars_8-chars_";
82 std::string str4 = str3 + "7-chars";
84 sz01 = str01.size();
85 sz02 = str01.max_size();
86 VERIFY( sz02 >= sz01 );
88 sz01 = str01.size();
89 str01.clear();
90 b01 = str01.empty();
91 VERIFY( b01 == true );
92 sz02 = str01.size();
93 VERIFY( sz01 >= sz02 );
96 int main()
98 test01();
99 return 0;