OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [libstdc++-v3/] [testsuite/] [21_strings/] [basic_string/] [element_access/] [wchar_t/] [2.cc] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// 1999-06-08 bkoz
2
 
3
// Copyright (C) 1999, 2003, 2009 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 3, 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 COPYING3.  If not see
18
// <http://www.gnu.org/licenses/>.
19
 
20
// 21.3 template class basic_string
21
 
22
#include <string>
23
#include <stdexcept>
24
#include <testsuite_hooks.h>
25
 
26
// Do a quick sanity check on known problems with element access and
27
// ref-counted strings. These should all pass, regardless of the
28
// underlying string implementation, of course.
29
bool test01(void)
30
{
31
  bool test __attribute__((unused)) = true;
32
  typedef std::wstring::size_type csize_type;
33
  typedef std::wstring::iterator siterator;
34
  typedef std::wstring::reverse_iterator sriterator;
35
  csize_type csz01, csz02;
36
  siterator it1;
37
  sriterator rit1;
38
 
39
  std::wstring str01(L"montara beach, half moon bay");
40
  const std::wstring str02(L"ocean beach, san francisco");
41
  std::wstring str03;
42
 
43
  // 21.3 p 5
44
 
45
  // References, pointers, and iterators referring to the elements of
46
  // a basic_string may be invalidated by the following uses of that
47
  // basic_string object:
48
 
49
  // ...
50
 
51
  // Susequent to any of the above uses except the forms of insert()
52
  // and erase() which return iterators, the first call to non-const
53
  // member functions operator[](), at(), begin(), rbegin(), end(), or
54
  // rend()
55
 
56
  str03 = str01;
57
  it1 = str01.begin();
58
  *it1 = L'x';
59
  VERIFY( str01[0] == L'x' );
60
  VERIFY( str03[0] == L'm' );
61
 
62
  str03 = str01;
63
  csz01 = str01.size();
64
  rit1 = str01.rbegin(); // NB: Pointing at one-past the end, so ...
65
  *rit1 = L'z';          // ... but it's taken care of here 
66
  VERIFY( str01[csz01 - 1] == L'z' );
67
  VERIFY( str03[csz01 - 1] == L'y' );
68
 
69
  str03 = str01;
70
  csz01 = str01.size();
71
  std::wstring::reference r1 = str01.at(csz01 - 2);
72
  VERIFY( str03 == str01 );
73
  r1 = L'd';
74
  VERIFY( str01[csz01 - 2] == L'd' );
75
  VERIFY( str03[csz01 - 2] == L'a' );
76
 
77
  str03 = str01;
78
  csz01 = str01.size();
79
  std::wstring::reference r2 = str01[csz01 - 3];
80
  VERIFY( str03 == str01 );
81
  r2 = L'w';
82
  VERIFY( str01[csz01 - 3] == L'w' );
83
  VERIFY( str03[csz01 - 3] == L'b' );
84
 
85
  str03 = str01;
86
  csz02 = str01.size();
87
  it1 = str01.end();
88
  VERIFY( str03 == str01 );
89
  --it1;
90
  *it1 = L'q';
91
  VERIFY( str01[csz02 - 1] == L'q' );
92
  VERIFY( str03[csz02 - 1] == L'z' );
93
 
94
  str03 = str01;
95
  rit1 = str01.rend();
96
  VERIFY( str03 == str01 );
97
  --rit1;
98
  *rit1 = L'p';
99
  VERIFY( str01[0] == L'p' );
100
  VERIFY( str03[0] == L'x' );
101
 
102
  // need to also test for const begin/const end
103
  VERIFY(test);
104
  return test;
105
}
106
 
107
int main()
108
{
109
  test01();
110
  return 0;
111
}

powered by: WebSVN 2.1.0

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