1// 1999-06-03 bkoz 2 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. 11 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. 16 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. 21 22// 21.1.1 Characher traits requirements 23 24#include <string> 25#include <testsuite_hooks.h> 26 27void test01(void) 28{ 29 bool test __attribute__((unused)) = true; 30 const std::string str_01("zuma beach"); 31 const std::string str_02("montara and ocean beach"); 32 33 // 21.1.1 character traits requirements 34 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 44 45 // void X::assign(char c, char d) 46 // assigns c = d; 47 char c1 = 'z'; 48 char c2 = 'u'; 49 VERIFY( c1 != c2 ); 50 std::char_traits<char>::assign(c1,c2); 51 VERIFY( c1 == 'u' ); 52 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 char array1[] = {'z', 'u', 'm', 'a', ' ', 'b', 'e', 'a', 'c', 'h', 0}; 57 const char str_lit1[] = "montara and ocean beach"; 58 const char str_lit2[] = "boracay, philippines"; 59 const int len1 = sizeof(str_lit1)/sizeof(char); 60 const int len2 = sizeof(str_lit2)/sizeof(char); 61 char array2[len1 + len2 - 1]; // two terminating chars 62 std::char_traits<char>::copy(array2, str_lit2, len2); 63 64 VERIFY( str_lit1[0] == 'm' ); 65 c1 = array2[0]; 66 c2 = str_lit1[0]; 67 char c3 = array2[1]; 68 char c4 = str_lit1[1]; 69 std::char_traits<char>::move(array2, str_lit1, 0); 70 VERIFY( array2[0] == c1 ); 71 VERIFY( str_lit1[0] == c2 ); 72 std::char_traits<char>::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<char>::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 ); 82 83 char* pc1 = array1 + 1; 84 c1 = pc1[0]; 85 c2 = array1[0]; 86 VERIFY( c1 != c2 ); 87 char* pc2 = std::char_traits<char>::move(array1, pc1, 0); 88 c3 = pc1[0]; 89 c4 = array1[0]; 90 VERIFY( c1 == c3 ); 91 VERIFY( c2 == c4 ); 92 VERIFY( pc2 == array1 ); 93 94 c1 = pc1[0]; 95 c2 = array1[0]; 96 char* pc3 = pc1; 97 pc2 = std::char_traits<char>::move(array1, pc1, 10); 98 c3 = pc1[0]; 99 c4 = array1[0]; 100 VERIFY( c1 != c3 ); // underlying char 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 ); 107} 108 109int main() 110{ 111 test01(); 112 return 0; 113} 114