]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/ctype/is/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / ctype / is / wchar_t / 1.cc
1 // Copyright (C) 2000-2016 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18
19 // 22.2.1.3.2 ctype<char> members
20
21 #include <locale>
22 #include <testsuite_hooks.h>
23
24 typedef wchar_t char_type;
25 class gnu_ctype: public std::ctype<char_type> { };
26
27 void test01()
28 {
29 bool test __attribute__((unused)) = true;
30 const char_type strlit00[] = L"manilla, cebu, tandag PHILIPPINES";
31 const char_type strlit01[] = L"MANILLA, CEBU, TANDAG PHILIPPINES";
32 const char_type c00 = L'S';
33 const char_type c10 = L's';
34 const char_type c20 = L'9';
35 const char_type c30 = L' ';
36 const char_type c40 = L'!';
37 const char_type c50 = L'F';
38 const char_type c60 = L'f';
39 const char_type c80 = L'x';
40
41 gnu_ctype gctype;
42
43 // sanity check ctype_base::mask members
44 int i01 = std::ctype_base::space;
45 int i02 = std::ctype_base::upper;
46 int i03 = std::ctype_base::lower;
47 int i04 = std::ctype_base::digit;
48 int i05 = std::ctype_base::punct;
49 int i06 = std::ctype_base::alpha;
50 int i07 = std::ctype_base::xdigit;
51 int i08 = std::ctype_base::alnum;
52 int i09 = std::ctype_base::graph;
53 int i10 = std::ctype_base::print;
54 int i11 = std::ctype_base::cntrl;
55 VERIFY ( i01 != i02);
56 VERIFY ( i02 != i03);
57 VERIFY ( i03 != i04);
58 VERIFY ( i04 != i05);
59 VERIFY ( i05 != i06);
60 VERIFY ( i06 != i07);
61 VERIFY ( i07 != i08);
62 VERIFY ( i08 != i09);
63 VERIFY ( i09 != i10);
64 VERIFY ( i10 != i11);
65 VERIFY ( i11 != i01);
66
67 // bool is(mask m, char_type c) const;
68 VERIFY( gctype.is(std::ctype_base::space, c30) );
69 VERIFY( gctype.is(std::ctype_base::upper, c00) );
70 VERIFY( gctype.is(std::ctype_base::lower, c10) );
71 VERIFY( gctype.is(std::ctype_base::digit, c20) );
72 VERIFY( gctype.is(std::ctype_base::punct, c40) );
73 VERIFY( gctype.is(std::ctype_base::alpha, c50) );
74 VERIFY( gctype.is(std::ctype_base::alpha, c60) );
75 VERIFY( gctype.is(std::ctype_base::xdigit, c20) );
76 VERIFY( !gctype.is(std::ctype_base::xdigit, c80) );
77 VERIFY( gctype.is(std::ctype_base::alnum, c50) );
78 VERIFY( gctype.is(std::ctype_base::alnum, c20) );
79 VERIFY( gctype.is(std::ctype_base::graph, c40) );
80 VERIFY( gctype.is(std::ctype_base::graph, c20) );
81
82 // const char* is(const char* low, const char* high, mask* vec) const
83 std::ctype_base::mask m00 = static_cast<std::ctype_base::mask>(0);
84 std::ctype_base::mask m01[3];
85 std::ctype_base::mask m02[13];
86 const char_type* cc0 = strlit00;
87 const char_type* cc1 = 0;
88 const char_type* cc2 = 0;
89
90 cc0 = strlit00;
91 for (std::size_t i = 0; i < 3; ++i)
92 m01[i] = m00;
93 cc1 = gctype.is(cc0, cc0, m01);
94 VERIFY( cc1 == strlit00 );
95 VERIFY( m01[0] == m00 );
96 VERIFY( m01[1] == m00 );
97 VERIFY( m01[2] == m00 );
98
99 cc0 = strlit00;
100 for (std::size_t i = 0; i < 3; ++i)
101 m01[i] = m00;
102 cc2 = gctype.is(cc0, cc0 + 3, m01);
103 VERIFY( cc2 == strlit00 + 3);
104 VERIFY( m01[0] != m00 );
105 VERIFY( m01[1] != m00 );
106 VERIFY( m01[2] != m00 );
107 VERIFY( gctype.is(m01[0], cc0[0]) );
108 VERIFY( gctype.is(m01[1], cc0[1]) );
109 VERIFY( gctype.is(m01[2], cc0[2]) );
110
111 cc0 = strlit01;
112 for (std::size_t i = 0; i < 13; ++i)
113 m02[i] = m00;
114 cc1 = gctype.is(cc0, cc0 + 13, m02);
115 VERIFY( cc1 == strlit01 + 13);
116 VERIFY( m02[6] != m00 );
117 VERIFY( m02[7] != m00 );
118 VERIFY( m02[8] != m00 );
119 VERIFY( m02[8] != m02[6] );
120 VERIFY( m02[6] != m02[7] );
121 VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alnum) );
122 VERIFY( static_cast<bool>(m02[6] & std::ctype_base::upper) );
123 VERIFY( static_cast<bool>(m02[6] & std::ctype_base::alpha) );
124 VERIFY( static_cast<bool>(m02[7] & std::ctype_base::punct) );
125 VERIFY( static_cast<bool>(m02[8] & std::ctype_base::space) );
126 VERIFY( gctype.is(m02[6], cc0[6]) );
127 VERIFY( gctype.is(m02[7], cc0[7]) );
128 VERIFY( gctype.is(m02[8], cc0[8]) );
129 }
130
131 int main()
132 {
133 test01();
134 return 0;
135 }