OSDN Git Service

2000-04-21 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 22_locale / ctype_char_members.cc
1 // 2000-02-16 bkoz
2
3 // Copyright (C) 2000 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 // 22.2.1.3.2 ctype<char> members
31
32 #include <locale>
33 // NB: Don't include any other headers in this file.
34 #ifdef DEBUG_ASSERT
35 #include <assert.h>
36 #endif
37
38 class gnu_ctype: public std::ctype<char> {};
39
40 void test01()
41 {
42   bool test = true;
43   const char strlit00[] = "manilla, cebu, tandag PHILIPPINES";
44   const char strlit01[] = "MANILLA, CEBU, TANDAG PHILIPPINES";
45   const char strlit02[] = "manilla, cebu, tandag philippines";
46   const char c00 = 'S';
47   const char c10 = 's';
48   const char c20 = '9';
49   const char c30 = ' ';
50   const char c40 = '!';
51   const char c50 = 'F';
52   const char c60 = 'f';
53   const char c70 = 'X';
54   const char c80 = 'x';
55
56   gnu_ctype gctype;
57   char c100;
58   int len = std::char_traits<char>::length(strlit00);
59   char c_array[len + 1];
60
61   // bool is(mask m, char c) const;
62   test &= gctype.is(std::ctype_base::space, c30);
63   test &= gctype.is(std::ctype_base::upper, c00);
64   test &= gctype.is(std::ctype_base::lower, c10);
65   test &= gctype.is(std::ctype_base::digit, c20);
66   test &= gctype.is(std::ctype_base::punct, c40);
67   test &= gctype.is(std::ctype_base::alpha, c50);
68   test &= gctype.is(std::ctype_base::alpha, c60);
69   test &= gctype.is(std::ctype_base::xdigit, c20);
70   test &= !gctype.is(std::ctype_base::xdigit, c80);
71   test &= gctype.is(std::ctype_base::alnum, c50);
72   test &= gctype.is(std::ctype_base::alnum, c20);
73   test &= gctype.is(std::ctype_base::graph, c40);
74   test &= gctype.is(std::ctype_base::graph, c20);
75
76   // char toupper(char c) const
77   c100 = gctype.toupper(c10);
78   test &= c100 == c00;
79
80   // char tolower(char c) const
81   c100 = gctype.tolower(c00);
82   test &= c100 == c10;
83
84   // char toupper(char* low, const char* hi) const
85   std::char_traits<char>::copy(c_array, strlit02, len + 1);
86   gctype.toupper(c_array, c_array + len);
87   test &= !std::char_traits<char>::compare(c_array, strlit01, len - 1);
88
89   // char tolower(char* low, const char* hi) const
90   std::char_traits<char>::copy(c_array, strlit01, len + 1);
91   gctype.tolower(c_array, c_array + len);
92   test &= !std::char_traits<char>::compare(c_array, strlit02, len - 1);
93
94
95 #ifdef DEBUG_ASSERT
96   assert(test);
97 #endif
98 }
99
100 int main() {
101   test01();
102   return 0;
103 }
104
105