]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/char_traits/requirements/wchar_t/1.cc
3 // Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
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)
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,
21 // 21.1.1 Characher traits requirements
24 #include <testsuite_hooks.h>
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");
32 // 21.1.1 character traits requirements
34 // Key for decoding what function signatures really mean:
35 // X == char_traits<_CharT>
37 // [p,q] == const _CharT*
42 // state == X::state_type
44 // void X::assign(wchar_t c, wchar_t d)
49 std::char_traits
<wchar_t>::assign(c1
,c2
);
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 int len
= sizeof(str_lit1
) + sizeof(array1
) - 1; // two terminating chars
60 VERIFY( str_lit1
[0] == 'm' );
63 wchar_t c3
= array2
[1];
64 wchar_t c4
= str_lit1
[1];
65 std::char_traits
<wchar_t>::move(array2
, str_lit1
, 0);
66 VERIFY( array2
[0] == c1
);
67 VERIFY( str_lit1
[0] == c2
);
68 std::char_traits
<wchar_t>::move(array2
, str_lit1
, 1);
69 VERIFY( array2
[0] == c2
);
70 VERIFY( str_lit1
[0] == c2
);
71 VERIFY( array2
[1] == c3
);
72 VERIFY( str_lit1
[1] == c4
);
73 std::char_traits
<wchar_t>::move(array2
, str_lit1
, 2);
74 VERIFY( array2
[0] == c2
);
75 VERIFY( str_lit1
[0] == c2
);
76 VERIFY( array2
[1] == c4
);
77 VERIFY( str_lit1
[1] == c4
);
79 wchar_t* pc1
= array1
+ 1;
83 wchar_t* pc2
= std::char_traits
<wchar_t>::move(array1
, pc1
, 0);
88 VERIFY( pc2
== array1
);
93 pc2
= std::char_traits
<wchar_t>::move(array1
, pc1
, 10);
96 VERIFY( c1
!= c3
); // underlying wchar_t array changed.
98 VERIFY( pc2
== array1
);
99 VERIFY( pc3
== pc1
); // but pointers o-tay
100 c1
= *(str_01
.data());