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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [21_strings/] [basic_string/] [capacity/] [1.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// 1999-05-11 bkoz
2
 
3
// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
4
// Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// You should have received a copy of the GNU General Public License along
18
// with this library; see the file COPYING3.  If not see
19
// <http://www.gnu.org/licenses/>.
20
 
21
// 21.3.3 string capacity
22
 
23
#include <string>
24
#include <cstring>
25
#include <testsuite_hooks.h>
26
 
27
template<typename T>
28
  struct A { };
29
 
30
template<typename T>
31
  bool
32
  operator==(const A<T>&, const A<T>&) { return true; }
33
 
34
template<typename T>
35
  bool
36
  operator<(const A<T>&, const A<T>&) { return true; }
37
 
38
struct B { };
39
 
40
// char_traits specialization
41
namespace std
42
{
43
  template<>
44
    struct char_traits<A<B> >
45
    {
46
      typedef A<B>              char_type;
47
      // Unsigned as wint_t in unsigned.
48
      typedef unsigned long     int_type;
49
      typedef streampos         pos_type;
50
      typedef streamoff         off_type;
51
      typedef mbstate_t         state_type;
52
 
53
      static void
54
      assign(char_type& __c1, const char_type& __c2)
55
      { __c1 = __c2; }
56
 
57
      static bool
58
      eq(const char_type& __c1, const char_type& __c2)
59
      { return __c1 == __c2; }
60
 
61
      static bool
62
      lt(const char_type& __c1, const char_type& __c2)
63
      { return __c1 < __c2; }
64
 
65
      static int
66
      compare(const char_type* __s1, const char_type* __s2, size_t __n)
67
      {
68
        for (size_t __i = 0; __i < __n; ++__i)
69
          if (!eq(__s1[__i], __s2[__i]))
70
            return lt(__s1[__i], __s2[__i]) ? -1 : 1;
71
        return 0;
72
      }
73
 
74
      static size_t
75
      length(const char_type* __s)
76
      {
77
        const char_type* __p = __s;
78
        while (__p)
79
          ++__p;
80
        return (__p - __s);
81
      }
82
 
83
      static const char_type*
84
      find(const char_type* __s, size_t __n, const char_type& __a)
85
      {
86
        for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
87
          if (*__p == __a) return __p;
88
        return 0;
89
      }
90
 
91
      static char_type*
92
      move(char_type* __s1, const char_type* __s2, size_t __n)
93
      { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
94
 
95
      static char_type*
96
      copy(char_type* __s1, const char_type* __s2, size_t __n)
97
      { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
98
 
99
      static char_type*
100
      assign(char_type* __s, size_t __n, char_type __a)
101
      {
102
        for (char_type* __p = __s; __p < __s + __n; ++__p)
103
          assign(*__p, __a);
104
        return __s;
105
      }
106
 
107
      static char_type
108
      to_char_type(const int_type&)
109
      { return char_type(); }
110
 
111
      static int_type
112
      to_int_type(const char_type&) { return int_type(); }
113
 
114
      static bool
115
      eq_int_type(const int_type& __c1, const int_type& __c2)
116
      { return __c1 == __c2; }
117
 
118
      static int_type
119
      eof() { return static_cast<int_type>(-1); }
120
 
121
      static int_type
122
      not_eof(const int_type& __c)
123
      { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
124
    };
125
} // namespace std
126
 
127
void test01()
128
{
129
  bool test __attribute__((unused)) = true;
130
 
131
  // non POD types : resize, capacity, reserve
132
  std::basic_string< A<B> > str02;
133
  typedef std::basic_string< A<B> >::size_type size_type_o;
134
  size_type_o sz03;
135
  size_type_o sz04;
136
 
137
  sz03 = str02.capacity();
138
  str02.reserve(100);
139
  sz04 = str02.capacity();
140
  VERIFY( sz04 >= sz03 );
141
  VERIFY( sz04 >= 100 );
142
  str02.reserve();
143
  sz03 = str02.capacity();
144
  VERIFY( sz03 == 0 );
145
 
146
  sz03 = str02.size() + 5;
147
  str02.resize(sz03);
148
  sz04 = str02.size();
149
  VERIFY( sz03 == sz04 );
150
 
151
  sz03 = str02.size() - 5;
152
  str02.resize(sz03);
153
  sz04 = str02.size();
154
  VERIFY( sz03 == sz04 );
155
 
156
  A<B> inst_obj;
157
  std::basic_string<A<B> > str07(30, inst_obj);
158
  std::basic_string<A<B> > str08 = str07;
159
  str07 = str08 + str07;
160
  VERIFY( str07.capacity() >= str07.size() );
161
  VERIFY( str08.capacity() >= str08.size() );
162
 
163
  // non-POD types: size, length, max_size, clear(), empty()
164
  bool b01 = str02.empty();
165
  VERIFY( b01 == true );
166
  sz03 = str02.size();
167
  sz04 = str02.length();
168
  VERIFY( sz03 == sz04 );
169
  str02.c_str();
170
  sz03 = str02.size();
171
  sz04 = str02.length();
172
  VERIFY( sz03 == sz04 );
173
 
174
  sz03 = str02.max_size();
175
  VERIFY( sz03 >= sz04 );
176
 
177
  sz03 = str02.size();
178
  str02.clear();
179
  b01 = str02.empty();
180
  VERIFY( b01 == true );
181
  sz04 = str02.size();
182
  VERIFY( sz03 >= sz04 );
183
}
184
 
185
#if !__GXX_WEAK__
186
// Explicitly instantiate for systems with no COMDAT or weak support.
187
template
188
  const std::basic_string< A<B> >::size_type
189
  std::basic_string< A<B> >::_Rep::_S_max_size;
190
 
191
template
192
  const A<B>
193
  std::basic_string< A<B> >::_Rep::_S_terminal;
194
#endif
195
 
196
int main()
197
{
198
  test01();
199
  return 0;
200
}

powered by: WebSVN 2.1.0

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