2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 21_strings / char_traits / requirements / wchar_t / 1.cc
blobd4a64ae4a10bbb4bc7946d0a1a690d68a0a7250d
1 // 1999-06-03 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
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,
19 // USA.
21 // 21.1.1 Characher traits requirements
23 #include <string>
24 #include <testsuite_hooks.h>
26 void test02(void)
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>
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
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' );
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
58 wchar_t array2[len];
60 VERIFY( str_lit1[0] == 'm' );
61 c1 = array2[0];
62 c2 = str_lit1[0];
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;
80 c1 = pc1[0];
81 c2 = array1[0];
82 VERIFY( c1 != c2 );
83 wchar_t* pc2 = std::char_traits<wchar_t>::move(array1, pc1, 0);
84 c3 = pc1[0];
85 c4 = array1[0];
86 VERIFY( c1 == c3 );
87 VERIFY( c2 == c4 );
88 VERIFY( pc2 == array1 );
90 c1 = pc1[0];
91 c2 = array1[0];
92 wchar_t* pc3 = pc1;
93 pc2 = std::char_traits<wchar_t>::move(array1, pc1, 10);
94 c3 = pc1[0];
95 c4 = array1[0];
96 VERIFY( c1 != c3 ); // underlying wchar_t array changed.
97 VERIFY( c4 != c3 );
98 VERIFY( pc2 == array1 );
99 VERIFY( pc3 == pc1 ); // but pointers o-tay
100 c1 = *(str_01.data());
101 c2 = array1[0];
102 VERIFY( c1 != c2 );
105 int main()
107 test02();
108 return 0;