1// 1999-06-03 bkoz
2
3// Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 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.1.1 Characher traits requirements
22
23#include <string>
24#include <testsuite_hooks.h>
25
26void test02(void)
27{
28  bool test __attribute__((unused)) = true;
29  const std::wstring str_01(L"zuma beach");
30  const std::wstring str_02(L"montara and ocean beach");
31
32  // 21.1.1 character traits requirements
33
34  // Key for decoding what function signatures really mean:
35  // X        == char_traits<_CharT>
36  // [c,d]    == _CharT
37  // [p,q]    == const _CharT*
38  // s        == _CharT*
39  // [n,i,j]  == size_t
40  // f        == X::int_type
41  // pos      == X::pos_type
42  // state    == X::state_type
43
44  // void X::assign(wchar_t c, wchar_t d)
45  // assigns c = d;
46  wchar_t c1 = L'z';
47  wchar_t c2 = L'u';
48  VERIFY( c1 != c2 );
49  std::char_traits<wchar_t>::assign(c1,c2);
50  VERIFY( c1 == L'u' );
51
52  // char* X::move(char* s, const char* p, size_t n)
53  // for each i in [0,n) performs X::assign(s[i], p[i]). Copies
54  // correctly even where p is in [s, s + n), and yields s.
55  wchar_t array1[] = {L'z', L'u', L'm', L'a', L' ', L'b', L'e', L'a', L'c', L'h',  0};
56  const wchar_t str_lit1[] = L"montara and ocean beach";
57  const wchar_t str_lit2[] = L"boracay, philippines";
58  const int len1 = sizeof(str_lit1)/sizeof(wchar_t);
59  const int len2 = sizeof(str_lit2)/sizeof(wchar_t);
60  wchar_t array2[len1 + len2 - 1]; // two terminating chars
61  std::char_traits<wchar_t>::copy(array2, str_lit2, len2);
62
63  VERIFY( str_lit1[0] == 'm' );
64  c1 = array2[0];
65  c2 = str_lit1[0];
66  wchar_t c3 = array2[1];
67  wchar_t c4 = str_lit1[1];
68  std::char_traits<wchar_t>::move(array2, str_lit1, 0);
69  VERIFY( array2[0] == c1 );
70  VERIFY( str_lit1[0] == c2 );
71  std::char_traits<wchar_t>::move(array2, str_lit1, 1);
72  VERIFY( array2[0] == c2 );
73  VERIFY( str_lit1[0] == c2 );
74  VERIFY( array2[1] == c3 );
75  VERIFY( str_lit1[1] == c4 );
76  std::char_traits<wchar_t>::move(array2, str_lit1, 2);
77  VERIFY( array2[0] == c2 );
78  VERIFY( str_lit1[0] == c2 );
79  VERIFY( array2[1] == c4 );
80  VERIFY( str_lit1[1] == c4 );
81
82  wchar_t* pc1 = array1 + 1;
83  c1 = pc1[0];
84  c2 = array1[0];
85  VERIFY( c1 != c2 );
86  wchar_t* pc2 = std::char_traits<wchar_t>::move(array1, pc1, 0);
87  c3 = pc1[0];
88  c4 = array1[0];
89  VERIFY( c1 == c3 );
90  VERIFY( c2 == c4 );
91  VERIFY( pc2 == array1 );
92
93  c1 = pc1[0];
94  c2 = array1[0];
95  wchar_t* pc3 = pc1;
96  pc2 = std::char_traits<wchar_t>::move(array1, pc1, 10);
97  c3 = pc1[0];
98  c4 = array1[0];
99  VERIFY( c1 != c3 ); // underlying wchar_t array changed.
100  VERIFY( c4 != c3 );
101  VERIFY( pc2 == array1 );
102  VERIFY( pc3 == pc1 ); // but pointers o-tay
103  c1 = *(str_01.data());
104  c2 = array1[0];
105  VERIFY( c1 != c2 );
106}
107
108int main()
109{
110  test02();
111  return 0;
112}
113