]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/21_strings/char_traits/requirements/wchar_t/1.cc
Update copyright years.
[gcc.git] / libstdc++-v3 / testsuite / 21_strings / char_traits / requirements / wchar_t / 1.cc
CommitLineData
b2dad0e3
BK
1// 1999-06-03 bkoz
2
5624e564 3// Copyright (C) 1999-2015 Free Software Foundation, Inc.
b2dad0e3
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
b2dad0e3
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
b2dad0e3 19
b8f971fc 20// 21.1.1 Characher traits requirements
b2dad0e3
BK
21
22#include <string>
fe413112 23#include <testsuite_hooks.h>
b2dad0e3 24
61f1ed59 25void test02(void)
8445e42a 26{
11f10e6b 27 bool test __attribute__((unused)) = true;
8445e42a
SK
28 const std::wstring str_01(L"zuma beach");
29 const std::wstring str_02(L"montara and ocean beach");
30
31 // 21.1.1 character traits requirements
32
33 // Key for decoding what function signatures really mean:
a35f1a13 34 // X == char_traits<_CharT>
8445e42a
SK
35 // [c,d] == _CharT
36 // [p,q] == const _CharT*
a35f1a13 37 // s == _CharT*
8445e42a 38 // [n,i,j] == size_t
a35f1a13 39 // f == X::int_type
8445e42a
SK
40 // pos == X::pos_type
41 // state == X::state_type
42
43 // void X::assign(wchar_t c, wchar_t d)
44 // assigns c = d;
45 wchar_t c1 = L'z';
46 wchar_t c2 = L'u';
aa1b2f7d 47 VERIFY( c1 != c2 );
8445e42a 48 std::char_traits<wchar_t>::assign(c1,c2);
aa1b2f7d 49 VERIFY( c1 == L'u' );
b2dad0e3 50
8445e42a
SK
51 // char* X::move(char* s, const char* p, size_t n)
52 // for each i in [0,n) performs X::assign(s[i], p[i]). Copies
53 // correctly even where p is in [s, s + n), and yields s.
54 wchar_t array1[] = {L'z', L'u', L'm', L'a', L' ', L'b', L'e', L'a', L'c', L'h', 0};
55 const wchar_t str_lit1[] = L"montara and ocean beach";
a35f1a13
LL
56 const wchar_t str_lit2[] = L"boracay, philippines";
57 const int len1 = sizeof(str_lit1)/sizeof(wchar_t);
58 const int len2 = sizeof(str_lit2)/sizeof(wchar_t);
59 wchar_t array2[len1 + len2 - 1]; // two terminating chars
60 std::char_traits<wchar_t>::copy(array2, str_lit2, len2);
8445e42a 61
aa1b2f7d 62 VERIFY( str_lit1[0] == 'm' );
8445e42a
SK
63 c1 = array2[0];
64 c2 = str_lit1[0];
65 wchar_t c3 = array2[1];
66 wchar_t c4 = str_lit1[1];
67 std::char_traits<wchar_t>::move(array2, str_lit1, 0);
aa1b2f7d
BV
68 VERIFY( array2[0] == c1 );
69 VERIFY( str_lit1[0] == c2 );
8445e42a 70 std::char_traits<wchar_t>::move(array2, str_lit1, 1);
aa1b2f7d
BV
71 VERIFY( array2[0] == c2 );
72 VERIFY( str_lit1[0] == c2 );
73 VERIFY( array2[1] == c3 );
74 VERIFY( str_lit1[1] == c4 );
8445e42a 75 std::char_traits<wchar_t>::move(array2, str_lit1, 2);
aa1b2f7d
BV
76 VERIFY( array2[0] == c2 );
77 VERIFY( str_lit1[0] == c2 );
78 VERIFY( array2[1] == c4 );
79 VERIFY( str_lit1[1] == c4 );
8445e42a
SK
80
81 wchar_t* pc1 = array1 + 1;
82 c1 = pc1[0];
83 c2 = array1[0];
aa1b2f7d 84 VERIFY( c1 != c2 );
8445e42a
SK
85 wchar_t* pc2 = std::char_traits<wchar_t>::move(array1, pc1, 0);
86 c3 = pc1[0];
87 c4 = array1[0];
aa1b2f7d
BV
88 VERIFY( c1 == c3 );
89 VERIFY( c2 == c4 );
90 VERIFY( pc2 == array1 );
8445e42a
SK
91
92 c1 = pc1[0];
93 c2 = array1[0];
94 wchar_t* pc3 = pc1;
95 pc2 = std::char_traits<wchar_t>::move(array1, pc1, 10);
96 c3 = pc1[0];
97 c4 = array1[0];
aa1b2f7d
BV
98 VERIFY( c1 != c3 ); // underlying wchar_t array changed.
99 VERIFY( c4 != c3 );
100 VERIFY( pc2 == array1 );
101 VERIFY( pc3 == pc1 ); // but pointers o-tay
8445e42a
SK
102 c1 = *(str_01.data());
103 c2 = array1[0];
aa1b2f7d 104 VERIFY( c1 != c2 );
b2dad0e3
BK
105}
106
107int main()
108{
8445e42a 109 test02();
04d930e6 110 return 0;
b2dad0e3 111}
This page took 1.41357 seconds and 5 git commands to generate.