OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [21_strings/] [basic_string/] [capacity/] [char/] [1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 1999-05-11 bkoz
2
 
3
// Copyright (C) 1999, 2002, 2003, 2004 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// 21.3.3 string capacity
22
 
23
#include <string>
24
#include <testsuite_hooks.h>
25
 
26
void test01()
27
{
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;
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
  std::string str4 = str3 + "7-chars";
83
 
84
  sz01 = str01.size();
85
  sz02 = str01.max_size();
86
  VERIFY( sz02 >= sz01 );
87
 
88
  sz01 = str01.size();
89
  str01.clear();
90
  b01 = str01.empty();
91
  VERIFY( b01 == true );
92
  sz02 = str01.size();
93
  VERIFY( sz01 >= sz02 );
94
}
95
 
96
int main()
97
{
98
  test01();
99
  return 0;
100
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.