gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / charset.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3 Copyright 2001, 2004, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5
6 Contributed by Red Hat, originally written by Jim Blandy.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 Please email any bugs, comments, and/or additions to this file to:
22 bug-gdb@gnu.org */
23
24 /* X_string is a null-terminated string in the X charset whose
25 elements are as follows. X should be the name the `set charset'
26 command uses for the character set, in lower-case, with any
27 non-identifier characters replaced with underscores. Where a
28 character set doesn't have the given character, the string should
29 contain the character 'x'.
30
31 [0] --- the `alert' character, '\a'
32 [1] --- the `backspace' character, '\b'
33 [2] --- the `form feed' character, '\f'
34 [3] --- the `line feed' character, '\n'
35 [4] --- the `carriage return' character, '\r'
36 [5] --- the `horizontal tab' character, '\t'
37 [6] --- the `vertical tab' character, '\v'
38 [7 .. 32] --- the uppercase letters A-Z
39 [33 .. 58] --- the lowercase letters a-z
40 [59 .. 68] --- the digits 0-9
41 [69] --- the `cent' character
42 [70] --- a control character with no defined backslash escape
43
44 Feel free to extend these as you like. */
45
46 #define NUM_CHARS (71)
47
48 char ascii_string[NUM_CHARS];
49 char iso_8859_1_string[NUM_CHARS];
50 char ebcdic_us_string[NUM_CHARS];
51 char ibm1047_string[NUM_CHARS];
52
53 /* We make a phony wchar_t and then pretend that this platform uses
54 UTF-32 (or UTF-16, depending on the size -- same difference for the
55 purposes of this test). */
56 typedef unsigned int wchar_t;
57 wchar_t utf_32_string[NUM_CHARS];
58
59 /* We also define a couple phony types for testing the u'' and U''
60 support. It is ok if these have the wrong size on some platforms
61 -- the test case will skip the tests in that case. */
62 typedef unsigned short char16_t;
63 typedef unsigned int char32_t;
64
65 /* Make sure to use the typedefs. */
66 char16_t uvar;
67 char32_t Uvar;
68
69 char16_t *String16;
70 char32_t *String32;
71
72 /* A typedef to a typedef should also work. */
73 typedef wchar_t my_wchar_t;
74 my_wchar_t myvar;
75
76 void
77 init_string (char string[],
78 char x,
79 char alert, char backspace, char form_feed,
80 char line_feed, char carriage_return, char horizontal_tab,
81 char vertical_tab, char cent, char misc_ctrl)
82 {
83 int i;
84
85 for (i = 0; i < NUM_CHARS; ++i)
86 string[i] = x;
87 string[0] = alert;
88 string[1] = backspace;
89 string[2] = form_feed;
90 string[3] = line_feed;
91 string[4] = carriage_return;
92 string[5] = horizontal_tab;
93 string[6] = vertical_tab;
94 string[69] = cent;
95 string[70] = misc_ctrl;
96 }
97
98
99 void
100 fill_run (char string[], int start, int len, int first)
101 {
102 int i;
103
104 for (i = 0; i < len; i++)
105 string[start + i] = first + i;
106 }
107
108
109 void
110 init_utf32 ()
111 {
112 int i;
113
114 for (i = 0; i < NUM_CHARS; ++i)
115 utf_32_string[i] = iso_8859_1_string[i] & 0xff;
116 }
117
118 extern void malloc_stub (void);
119
120 int main ()
121 {
122 #ifdef usestubs
123 set_debug_traps();
124 breakpoint();
125 #endif
126
127 malloc_stub ();
128
129 /* Initialize ascii_string. */
130 init_string (ascii_string,
131 120,
132 7, 8, 12,
133 10, 13, 9,
134 11, 120, 17);
135 fill_run (ascii_string, 7, 26, 65);
136 fill_run (ascii_string, 33, 26, 97);
137 fill_run (ascii_string, 59, 10, 48);
138
139 /* Initialize iso_8859_1_string. */
140 init_string (iso_8859_1_string,
141 120,
142 7, 8, 12,
143 10, 13, 9,
144 11, 162, 17);
145 fill_run (iso_8859_1_string, 7, 26, 65);
146 fill_run (iso_8859_1_string, 33, 26, 97);
147 fill_run (iso_8859_1_string, 59, 10, 48);
148
149 /* Initialize ebcdic_us_string. */
150 init_string (ebcdic_us_string,
151 167,
152 47, 22, 12,
153 37, 13, 5,
154 11, 74, 17);
155 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
156 fill_run (ebcdic_us_string, 7, 9, 193);
157 fill_run (ebcdic_us_string, 16, 9, 209);
158 fill_run (ebcdic_us_string, 25, 8, 226);
159 /* The lower-case letters are, too. */
160 fill_run (ebcdic_us_string, 33, 9, 129);
161 fill_run (ebcdic_us_string, 42, 9, 145);
162 fill_run (ebcdic_us_string, 51, 8, 162);
163 /* The digits, at least, are contiguous. */
164 fill_run (ebcdic_us_string, 59, 10, 240);
165
166 /* Initialize ibm1047_string. */
167 init_string (ibm1047_string,
168 167,
169 47, 22, 12,
170 37, 13, 5,
171 11, 74, 17);
172 /* In EBCDIC, the upper-case letters are broken into three separate runs. */
173 fill_run (ibm1047_string, 7, 9, 193);
174 fill_run (ibm1047_string, 16, 9, 209);
175 fill_run (ibm1047_string, 25, 8, 226);
176 /* The lower-case letters are, too. */
177 fill_run (ibm1047_string, 33, 9, 129);
178 fill_run (ibm1047_string, 42, 9, 145);
179 fill_run (ibm1047_string, 51, 8, 162);
180 /* The digits, at least, are contiguous. */
181 fill_run (ibm1047_string, 59, 10, 240);
182
183 init_utf32 ();
184
185 myvar = utf_32_string[7];
186
187 return 0; /* all strings initialized */
188 }
This page took 0.046735 seconds and 4 git commands to generate.