3 // Copyright (C) 1999-2013 Free Software Foundation, Inc.
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 3, or (at your option)
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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 21.1.1 Characher traits requirements
23 #include <testsuite_hooks.h>
27 bool test __attribute__((unused)) = true;
28 const std::string str_01("zuma beach");
29 const std::string str_02("montara and ocean beach");
31 // 21.1.1 character traits requirements
33 // Key for decoding what function signatures really mean:
34 // X == char_traits<_CharT>
36 // [p,q] == const _CharT*
41 // state == X::state_type
43 // void X::assign(char c, char d)
48 std::char_traits<char>::assign(c1,c2);
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 char array1[] = {'z', 'u', 'm', 'a', ' ', 'b', 'e', 'a', 'c', 'h', 0};
55 const char str_lit1[] = "montara and ocean beach";
56 const char str_lit2[] = "boracay, philippines";
57 const int len1 = sizeof(str_lit1)/sizeof(char);
58 const int len2 = sizeof(str_lit2)/sizeof(char);
59 char array2[len1 + len2 - 1]; // two terminating chars
60 std::char_traits<char>::copy(array2, str_lit2, len2);
62 VERIFY( str_lit1[0] == 'm' );
66 char c4 = str_lit1[1];
67 std::char_traits<char>::move(array2, str_lit1, 0);
68 VERIFY( array2[0] == c1 );
69 VERIFY( str_lit1[0] == c2 );
70 std::char_traits<char>::move(array2, str_lit1, 1);
71 VERIFY( array2[0] == c2 );
72 VERIFY( str_lit1[0] == c2 );
73 VERIFY( array2[1] == c3 );
74 VERIFY( str_lit1[1] == c4 );
75 std::char_traits<char>::move(array2, str_lit1, 2);
76 VERIFY( array2[0] == c2 );
77 VERIFY( str_lit1[0] == c2 );
78 VERIFY( array2[1] == c4 );
79 VERIFY( str_lit1[1] == c4 );
81 char* pc1 = array1 + 1;
85 char* pc2 = std::char_traits<char>::move(array1, pc1, 0);
90 VERIFY( pc2 == array1 );
95 pc2 = std::char_traits<char>::move(array1, pc1, 10);
98 VERIFY( c1 != c3 ); // underlying char array changed.
100 VERIFY( pc2 == array1 );
101 VERIFY( pc3 == pc1 ); // but pointers o-tay
102 c1 = *(str_01.data());