Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / 21_strings / char_traits / requirements / wchar_t / 1.cc
blob3a8a20cf88dc618f3972dbf06695caa7f073a54f
1 // 1999-06-03 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005
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 2, or (at your option)
10 // any later version.
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,
20 // USA.
22 // 21.1.1 Characher traits requirements
24 #include <string>
25 #include <testsuite_hooks.h>
27 void test02(void)
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>
37 // [c,d] == _CharT
38 // [p,q] == const _CharT*
39 // s == _CharT*
40 // [n,i,j] == size_t
41 // f == X::int_type
42 // pos == X::pos_type
43 // state == X::state_type
45 // void X::assign(wchar_t c, wchar_t d)
46 // assigns c = d;
47 wchar_t c1 = L'z';
48 wchar_t c2 = L'u';
49 VERIFY( c1 != c2 );
50 std::char_traits<wchar_t>::assign(c1,c2);
51 VERIFY( c1 == L'u' );
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' );
65 c1 = array2[0];
66 c2 = str_lit1[0];
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;
84 c1 = pc1[0];
85 c2 = array1[0];
86 VERIFY( c1 != c2 );
87 wchar_t* pc2 = std::char_traits<wchar_t>::move(array1, pc1, 0);
88 c3 = pc1[0];
89 c4 = array1[0];
90 VERIFY( c1 == c3 );
91 VERIFY( c2 == c4 );
92 VERIFY( pc2 == array1 );
94 c1 = pc1[0];
95 c2 = array1[0];
96 wchar_t* pc3 = pc1;
97 pc2 = std::char_traits<wchar_t>::move(array1, pc1, 10);
98 c3 = pc1[0];
99 c4 = array1[0];
100 VERIFY( c1 != c3 ); // underlying wchar_t array changed.
101 VERIFY( c4 != c3 );
102 VERIFY( pc2 == array1 );
103 VERIFY( pc3 == pc1 ); // but pointers o-tay
104 c1 = *(str_01.data());
105 c2 = array1[0];
106 VERIFY( c1 != c2 );
109 int main()
111 test02();
112 return 0;