1// Copyright (C) 2000, 2001, 2002 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 2, 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 COPYING.  If not, write to the Free
16// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17// USA.
18
19// As a special exception, you may use this file as part of a free software
20// library without restriction.  Specifically, if other files instantiate
21// templates or use macros or inline functions from this file, or you compile
22// this file and link it with other files to produce an executable, this
23// file does not by itself cause the resulting executable to be covered by
24// the GNU General Public License.  This exception does not however
25// invalidate any other reasons why the executable file might be covered by
26// the GNU General Public License.
27
28// 22.2.1.3.2 ctype<char> members
29
30#include <locale>
31#include <testsuite_hooks.h>
32
33typedef char char_type;
34class gnu_ctype: public std::ctype<char_type> { };
35
36void test01()
37{
38  bool test = true;
39  const char_type strlit00[] = "manilla, cebu, tandag PHILIPPINES";
40  const char_type strlit01[] = "MANILLA, CEBU, TANDAG PHILIPPINES";
41  const char_type strlit02[] = "manilla, cebu, tandag philippines";
42  const char_type c00 = 'S';
43  const char_type c10 = 's';
44  const char_type c20 = '9';
45  const char_type c30 = ' ';
46  const char_type c40 = '!';
47  const char_type c50 = 'F';
48  const char_type c60 = 'f';
49  const char_type c70 = 'X';
50  const char_type c80 = 'x';
51
52  gnu_ctype gctype;
53  char_type c100;
54  int len = std::char_traits<char_type>::length(strlit00);
55  char_type c_array[len + 1];
56
57  // sanity check ctype_base::mask members
58  int i01 = std::ctype_base::space;
59  int i02 = std::ctype_base::upper;
60  int i03 = std::ctype_base::lower;
61  int i04 = std::ctype_base::digit;
62  int i05 = std::ctype_base::punct;
63  int i06 = std::ctype_base::alpha;
64  int i07 = std::ctype_base::xdigit;
65  int i08 = std::ctype_base::alnum;
66  int i09 = std::ctype_base::graph;
67  int i10 = std::ctype_base::print;
68  int i11 = std::ctype_base::cntrl;
69  int i12 = sizeof(std::ctype_base::mask);
70  VERIFY ( i01 != i02);
71  VERIFY ( i02 != i03);
72  VERIFY ( i03 != i04);
73  VERIFY ( i04 != i05);
74  VERIFY ( i05 != i06);
75  VERIFY ( i06 != i07);
76  VERIFY ( i07 != i08);
77  VERIFY ( i08 != i09);
78  VERIFY ( i09 != i10);
79  VERIFY ( i10 != i11);
80  VERIFY ( i11 != i01);
81
82  // char_type toupper(char_type c) const
83  c100 = gctype.toupper(c10);
84  VERIFY( c100 == c00 );
85
86  // char_type tolower(char_type c) const
87  c100 = gctype.tolower(c00);
88  VERIFY( c100 == c10 );
89
90  // char_type toupper(char_type* low, const char_type* hi) const
91  std::char_traits<char_type>::copy(c_array, strlit02, len + 1);
92  gctype.toupper(c_array, c_array + len);
93  VERIFY( !std::char_traits<char_type>::compare(c_array, strlit01, len - 1) );
94
95  // char_type tolower(char_type* low, const char_type* hi) const
96  std::char_traits<char_type>::copy(c_array, strlit01, len + 1);
97  gctype.tolower(c_array, c_array + len);
98  VERIFY( !std::char_traits<char_type>::compare(c_array, strlit02, len - 1) );
99}
100
101// libstdc++/5280
102void test04()
103{
104#ifdef _GLIBCPP_HAVE_SETENV
105  // Set the global locale to non-"C".
106  std::locale loc_de("de_DE");
107  std::locale::global(loc_de);
108
109  // Set LANG environment variable to de_DE.
110  const char* oldLANG = getenv("LANG");
111  if (!setenv("LANG", "de_DE", 1))
112    {
113      test01();
114      setenv("LANG", oldLANG ? oldLANG : "", 1);
115    }
116#endif
117}
118
119// http://gcc.gnu.org/ml/libstdc++/2002-05/msg00038.html
120void test05()
121{
122  bool test = true;
123
124  const char* tentLANG = std::setlocale(LC_ALL, "ja_JP.eucjp");
125  if (tentLANG != NULL)
126    {
127      std::string preLANG = tentLANG;
128      test01();
129      std::string postLANG = std::setlocale(LC_ALL, NULL);
130      VERIFY( preLANG == postLANG );
131    }
132}
133
134int main()
135{
136  test01();
137  test04();
138  test05();
139  return 0;
140}
141