]>
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, 2004, 2005
4 // Free Software Foundation, Inc.
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 2, or (at your option)
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.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // 21.1.1 Characher traits requirements
25 #include <testsuite_hooks.h>
29 bool test
__attribute__((unused
)) = true;
30 const std::wstring
str_01(L
"zuma beach");
31 const std::wstring
str_02(L
"montara and ocean beach");
33 // 21.1.1 character traits requirements
35 // Key for decoding what function signatures really mean:
36 // X == char_traits<_CharT>
38 // [p,q] == const _CharT*
43 // state == X::state_type
45 // void X::assign(wchar_t c, wchar_t d)
50 std::char_traits
<wchar_t>::assign(c1
,c2
);
53 // char* X::move(char* s, const char* p, size_t n)
54 // for each i in [0,n) performs X::assign(s[i], p[i]). Copies
55 // correctly even where p is in [s, s + n), and yields s.
56 wchar_t array1
[] = {L
'z', L
'u', L
'm', L
'a', L
' ', L
'b', L
'e', L
'a', L
'c', L
'h', 0};
57 const wchar_t str_lit1
[] = L
"montara and ocean beach";
58 const wchar_t str_lit2
[] = L
"boracay, philippines";
59 const int len1
= sizeof(str_lit1
)/sizeof(wchar_t);
60 const int len2
= sizeof(str_lit2
)/sizeof(wchar_t);
61 wchar_t array2
[len1
+ len2
- 1]; // two terminating chars
62 std::char_traits
<wchar_t>::copy(array2
, str_lit2
, len2
);
64 VERIFY( str_lit1
[0] == 'm' );
67 wchar_t c3
= array2
[1];
68 wchar_t c4
= str_lit1
[1];
69 std::char_traits
<wchar_t>::move(array2
, str_lit1
, 0);
70 VERIFY( array2
[0] == c1
);
71 VERIFY( str_lit1
[0] == c2
);
72 std::char_traits
<wchar_t>::move(array2
, str_lit1
, 1);
73 VERIFY( array2
[0] == c2
);
74 VERIFY( str_lit1
[0] == c2
);
75 VERIFY( array2
[1] == c3
);
76 VERIFY( str_lit1
[1] == c4
);
77 std::char_traits
<wchar_t>::move(array2
, str_lit1
, 2);
78 VERIFY( array2
[0] == c2
);
79 VERIFY( str_lit1
[0] == c2
);
80 VERIFY( array2
[1] == c4
);
81 VERIFY( str_lit1
[1] == c4
);
83 wchar_t* pc1
= array1
+ 1;
87 wchar_t* pc2
= std::char_traits
<wchar_t>::move(array1
, pc1
, 0);
92 VERIFY( pc2
== array1
);
97 pc2
= std::char_traits
<wchar_t>::move(array1
, pc1
, 10);
100 VERIFY( c1
!= c3
); // underlying wchar_t array changed.
102 VERIFY( pc2
== array1
);
103 VERIFY( pc3
== pc1
); // but pointers o-tay
104 c1
= *(str_01
.data());