OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [ext/] [codecvt/] [wchar_t.cc] - Blame information for rev 742

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// { dg-require-iconv "UCS-2BE" }
2
// { dg-require-iconv "UCS-4BE" }
3
 
4
// 2000-08-23 Benjamin Kosnik <bkoz@cygnus.com>
5
 
6
// Copyright (C) 2000, 2001, 2002, 2003, 2007, 2009, 2010, 2011
7
// Free Software Foundation
8
//
9
// This file is part of the GNU ISO C++ Library.  This library is free
10
// software; you can redistribute it and/or modify it under the
11
// terms of the GNU General Public License as published by the
12
// Free Software Foundation; either version 3, or (at your option)
13
// any later version.
14
 
15
// This library is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
// GNU General Public License for more details.
19
 
20
// You should have received a copy of the GNU General Public License along
21
// with this library; see the file COPYING3.  If not see
22
// <http://www.gnu.org/licenses/>.
23
 
24
// 22.2.1.5 - Template class codecvt [lib.locale.codecvt]
25
 
26
#include <locale>
27
#include <testsuite_hooks.h>
28
#include <ext/codecvt_specializations.h>
29
 
30
// Partial specialization using encoding_state.
31
// codecvt<unicode_t, wchar_t, encoding_state>
32
void test01()
33
{
34
  using namespace std;
35
  typedef codecvt_base::result                  result;
36
  typedef unsigned short                        int_type;
37
  typedef wchar_t                               ext_type;
38
  typedef __gnu_cxx::encoding_state                     state_type;
39
  typedef codecvt<int_type, ext_type, state_type>       unicode_codecvt;
40
  typedef char_traits<int_type>                 int_traits;
41
  typedef char_traits<ext_type>                 ext_traits;
42
 
43
  bool test __attribute__((unused)) = true;
44
  int                   size = 23;
45
  char  e_lit_base[96] __attribute__((aligned(__alignof__(ext_type)))) =
46
  {
47
    char(0x00), char(0x00), char(0x00), char(0x62), char(0x00), char(0x00),
48
    char(0x00), char(0x6c), char(0x00), char(0x00), char(0x00), char(0x61),
49
    char(0x00), char(0x00), char(0x00), char(0x63), char(0x00), char(0x00),
50
    char(0x00), char(0x6b), char(0x00), char(0x00), char(0x00), char(0x20),
51
    char(0x00), char(0x00), char(0x00), char(0x70), char(0x00), char(0x00),
52
    char(0x00), char(0x65), char(0x00), char(0x00), char(0x00), char(0x61),
53
    char(0x00), char(0x00), char(0x00), char(0x72), char(0x00), char(0x00),
54
    char(0x00), char(0x6c), char(0x00), char(0x00), char(0x00), char(0x20),
55
    char(0x00), char(0x00), char(0x00), char(0x6a), char(0x00), char(0x00),
56
    char(0x00), char(0x61), char(0x00), char(0x00), char(0x00), char(0x73),
57
    char(0x00), char(0x00), char(0x00), char(0x6d), char(0x00), char(0x00),
58
    char(0x00), char(0x69), char(0x00), char(0x00), char(0x00), char(0x6e),
59
    char(0x00), char(0x00), char(0x00), char(0x65), char(0x00), char(0x00),
60
    char(0x00), char(0x20), char(0x00), char(0x00), char(0x00), char(0x74),
61
    char(0x00), char(0x00), char(0x00), char(0x65), char(0x00), char(0x00),
62
    char(0x00), char(0x61), char(0x00), char(0x00), char(0x00), char(0xa0)
63
  };
64
  const ext_type*       e_lit = reinterpret_cast<ext_type*>(e_lit_base);
65
 
66
  char  i_lit_base[48] __attribute__((aligned(__alignof__(int_type)))) =
67
  {
68
    char(0x00), char(0x62), char(0x00), char(0x6c), char(0x00), char(0x61),
69
    char(0x00), char(0x63), char(0x00), char(0x6b), char(0x00), char(0x20),
70
    char(0x00), char(0x70), char(0x00), char(0x65), char(0x00), char(0x61),
71
    char(0x00), char(0x72), char(0x00), char(0x6c), char(0x00), char(0x20),
72
    char(0x00), char(0x6a), char(0x00), char(0x61), char(0x00), char(0x73),
73
    char(0x00), char(0x6d), char(0x00), char(0x69), char(0x00), char(0x6e),
74
    char(0x00), char(0x65), char(0x00), char(0x20), char(0x00), char(0x74),
75
    char(0x00), char(0x65), char(0x00), char(0x61), char(0x00), char(0xa0)
76
  };
77
  const int_type*       i_lit = reinterpret_cast<int_type*>(i_lit_base);
78
 
79
  const ext_type*       efrom_next;
80
  const int_type*       ifrom_next;
81
  ext_type*             e_arr = new ext_type[size + 1];
82
  ext_type*             eto_next;
83
  int_type*             i_arr = new int_type[size + 1];
84
  int_type*             ito_next;
85
 
86
  // construct a locale object with the specialized facet.
87
  locale                loc(locale::classic(), new unicode_codecvt);
88
  // sanity check the constructed locale has the specialized facet.
89
  VERIFY( has_facet<unicode_codecvt>(loc) );
90
  const unicode_codecvt& cvt = use_facet<unicode_codecvt>(loc);
91
 
92
  // in
93
  //  unicode_codecvt::state_type state01("UCS-2BE", "UCS-4BE", 0xfeff, 0);
94
  unicode_codecvt::state_type state01("UCS-2BE", "UCS-4BE", 0, 0);
95
  result r1 = cvt.in(state01, e_lit, e_lit + size, efrom_next,
96
                     i_arr, i_arr + size + 1, ito_next);
97
  VERIFY( r1 == codecvt_base::ok );
98
  VERIFY( !int_traits::compare(i_arr, i_lit, size) );
99
  VERIFY( efrom_next == e_lit + size );
100
  VERIFY( ito_next == i_arr + size );
101
 
102
  // out
103
  unicode_codecvt::state_type state02("UCS-2BE", "UCS-4BE", 0, 0);
104
  result r2 = cvt.out(state02, i_lit, i_lit + size, ifrom_next,
105
                       e_arr, e_arr + size, eto_next);
106
  VERIFY( r2 == codecvt_base::ok ); // XXX?
107
  VERIFY( !ext_traits::compare(e_arr, e_lit, size) );
108
  VERIFY( ifrom_next == i_lit + size );
109
  VERIFY( eto_next == e_arr + size );
110
 
111
  // unshift
112
  ext_traits::copy(e_arr, e_lit, size);
113
  unicode_codecvt::state_type state03("UCS-2BE", "UCS-4BE", 0, 0);
114
  result r3 = cvt.unshift(state03, e_arr, e_arr + size, eto_next);
115
  VERIFY( r3 == codecvt_base::noconv );
116
  VERIFY( !ext_traits::compare(e_arr, e_lit, size) );
117
  VERIFY( eto_next == e_arr );
118
 
119
  int i = cvt.encoding();
120
  VERIFY( i == 0 );
121
 
122
  VERIFY( !cvt.always_noconv() );
123
 
124
  unicode_codecvt::state_type state04("UCS-2BE", "UCS-4BE", 0, 0);
125
  int j = cvt.length(state03, e_lit, e_lit + size, 5);
126
  VERIFY( j == 5 );
127
 
128
  int k = cvt.max_length();
129
  VERIFY( k == 1 );
130
 
131
  delete [] e_arr;
132
  delete [] i_arr;
133
}
134
 
135
int main ()
136
{
137
  test01();
138
  return 0;
139
}
140
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.