2 // 2003-07-22 Matt Austern
4 // Copyright (C) 1999, 2000, 2001, 2003 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // 21.1.1 Character traits requirements
23 // Make sure we can instantiate char_traits and basic_string for
24 // charT = 'short', and make sure the char_traits memeber functions
25 // satisfy the requirements of 21.1.1.
28 #include <testsuite_hooks.h>
32 bool test
__attribute__((unused
)) = true;
34 // 21.1.1 character traits requirements
36 // Key for decoding what function signatures really mean:
37 // X == char_traits<_CharT>
39 // [p,q] == const _CharT*
44 // state == X::state_type
46 // void X::assign(short c, short d)
51 std::char_traits
<short>::assign(c1
,c2
);
54 // bool X::eq(short c, short d)
57 VERIFY ( !std::char_traits
<short>::eq(c1
, c2
) );
58 VERIFY ( std::char_traits
<short>::eq(c1
, c1
) );
59 VERIFY ( std::char_traits
<short>::eq(c2
, c2
) );
61 // bool X::lt(short c, short d)
64 VERIFY ( std::char_traits
<short>::lt(c2
, c1
) );
65 VERIFY ( !std::char_traits
<short>::lt(c1
, c2
) );
66 VERIFY ( !std::char_traits
<short>::lt(c1
, c1
) );
67 VERIFY ( !std::char_traits
<short>::lt(c2
, c2
) );
69 // short* X::move(short* s, const short* p, size_t n)
70 // for each i in [0,n) performs X::assign(s[i], p[i]). Copies
71 // correctly even where p is in [s, s + n), and yields s.
72 short array1
[] = {'z', 'u', 'm', 'a', ' ', 'b', 'e', 'a', 'c', 'h', 0};
73 const std::basic_string
<short> str_01(array1
+ 0, array1
+ 10);
75 const short str_lit1
[] = {'m', 'o', 'n', 't', 'a', 'r', 'a', ' ', 'a', 'n', 'd', ' ', 'o', 'c', 'e', 'a', 'n', ' ', 'b', 'e', 'a', 'c', 'h', 0};
77 int len
= sizeof(str_lit1
)/sizeof(short) + sizeof(array1
)/sizeof(short) - 1;
78 // two terminating chars
81 VERIFY( str_lit1
[0] == 'm' );
85 short c4
= str_lit1
[1];
86 std::char_traits
<short>::move(array2
, str_lit1
, 0);
87 VERIFY( array2
[0] == c1
);
88 VERIFY( str_lit1
[0] == c2
);
89 std::char_traits
<short>::move(array2
, str_lit1
, 1);
90 VERIFY( array2
[0] == c2
);
91 VERIFY( str_lit1
[0] == c2
);
92 VERIFY( array2
[1] == c3
);
93 VERIFY( str_lit1
[1] == c4
);
94 std::char_traits
<short>::move(array2
, str_lit1
, 2);
95 VERIFY( array2
[0] == c2
);
96 VERIFY( str_lit1
[0] == c2
);
97 VERIFY( array2
[1] == c4
);
98 VERIFY( str_lit1
[1] == c4
);
100 short* pc1
= array1
+ 1;
104 short* pc2
= std::char_traits
<short>::move(array1
, pc1
, 0);
109 VERIFY( pc2
== array1
);
114 pc2
= std::char_traits
<short>::move(array1
, pc1
, 10);
117 VERIFY( c1
!= c3
); // underlying short array changed.
119 VERIFY( pc2
== array1
);
120 VERIFY( pc3
== pc1
); // but pointers o-tay
121 c1
= *(str_01
.data());
125 // size_t X::length(const short* p)
126 len
= std::char_traits
<short>::length(str_lit1
);
127 VERIFY( len
== sizeof(str_lit1
) / sizeof(short) - 1 );
129 // const short* X::find(const short* s, size_t n, short c)
130 const int N4
= sizeof(str_lit1
) / sizeof(short);
131 const short* pc4
= std::char_traits
<short>::find(str_lit1
, N4
, 'a');
133 VERIFY( *pc4
== 'a' );
135 pc4
= std::char_traits
<short>::find(str_lit1
, N4
, 0x0a73);
138 // short* X::assign(short* s, size_t n, short c)
139 len
= sizeof(array2
) / sizeof(short);
140 memset(array2
, 0xaf, len
* sizeof(short));
141 VERIFY( array2
[0] != 0x15a8 );
143 pc1
= std::char_traits
<short>::assign (array2
, len
, 0x15a8);
144 VERIFY( pc1
== array2
);
145 for (int i
= 0; i
< len
; ++i
)
146 VERIFY( array2
[i
] == 0x15a8 );
148 // short* X::copy(short* s, const short* p, size_t n)
149 int n1
= sizeof(str_lit1
) / sizeof(short);
150 pc1
= std::char_traits
<short>::copy(array2
, str_lit1
, n1
);
151 len
= std::char_traits
<short>::length(array2
);
152 VERIFY( len
== n1
- 1 );
153 for (int i
= 0; i
< len
; ++i
)
154 VERIFY( str_lit1
[i
] == array2
[i
] );
156 // int X::compare(const short* p, const short* q, size_t n)
157 const short* pconst1
= str_01
.data();
158 const short* pconst2
= str_lit1
;
160 VERIFY( std::char_traits
<short>::compare(pconst1
, pconst2
, 10) > 0 );
161 VERIFY( std::char_traits
<short>::compare(pconst2
, pconst1
, 10) < 0 );
162 VERIFY( std::char_traits
<short>::compare(pconst1
, pconst1
, 10) == 0 );
163 VERIFY( std::char_traits
<short>::compare(pconst2
, pconst2
, 10) == 0 );