]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/ctype/to/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / ctype / to / wchar_t / 1.cc
1 // Copyright (C) 2000-2020 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 const char_type strlit00[] = L"manilla, cebu, tandag PHILIPPINES";
30 const char_type strlit01[] = L"MANILLA, CEBU, TANDAG PHILIPPINES";
31 const char_type strlit02[] = L"manilla, cebu, tandag philippines";
32 const char_type c00 = L'S';
33 const char_type c10 = L's';
34
35 gnu_ctype gctype;
36 char_type c100;
37 int len = std::char_traits<char_type>::length(strlit00);
38 char_type c_array[len + 1];
39
40 // sanity check ctype_base::mask members
41 int i01 = std::ctype_base::space;
42 int i02 = std::ctype_base::upper;
43 int i03 = std::ctype_base::lower;
44 int i04 = std::ctype_base::digit;
45 int i05 = std::ctype_base::punct;
46 int i06 = std::ctype_base::alpha;
47 int i07 = std::ctype_base::xdigit;
48 int i08 = std::ctype_base::alnum;
49 int i09 = std::ctype_base::graph;
50 int i10 = std::ctype_base::print;
51 int i11 = std::ctype_base::cntrl;
52 VERIFY ( i01 != i02);
53 VERIFY ( i02 != i03);
54 VERIFY ( i03 != i04);
55 VERIFY ( i04 != i05);
56 VERIFY ( i05 != i06);
57 VERIFY ( i06 != i07);
58 VERIFY ( i07 != i08);
59 VERIFY ( i08 != i09);
60 VERIFY ( i09 != i10);
61 VERIFY ( i10 != i11);
62 VERIFY ( i11 != i01);
63
64 // char_type toupper(char_type c) const
65 c100 = gctype.toupper(c10);
66 VERIFY( c100 == c00 );
67
68 // char_type tolower(char_type c) const
69 c100 = gctype.tolower(c00);
70 VERIFY( c100 == c10 );
71
72 // char_type toupper(char_type* low, const char_type* hi) const
73 std::char_traits<char_type>::copy(c_array, strlit02, len + 1);
74 gctype.toupper(c_array, c_array + len);
75 VERIFY( !std::char_traits<char_type>::compare(c_array, strlit01, len - 1) );
76
77 // char_type tolower(char_type* low, const char_type* hi) const
78 std::char_traits<char_type>::copy(c_array, strlit01, len + 1);
79 gctype.tolower(c_array, c_array + len);
80 VERIFY( !std::char_traits<char_type>::compare(c_array, strlit02, len - 1) );
81 }
82
83 int main()
84 {
85 test01();
86 return 0;
87 }