2009-07-01 Tristan Gingold <gingold@adacore.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / radix.exp
CommitLineData
4a1135b8 1# This testcase is part of GDB, the GNU debugger.
0fb0cc75 2# Copyright 1993, 1997, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
9# This program 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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c 17# This file was written by Fred Fish. (fnf@cygnus.com)
4a1135b8 18# And rewritten by Michael Chastain (mec.gnu@mindspring.com)
c906108c
SS
19
20if $tracelevel then {
21 strace $tracelevel
22}
23
24set prms_id 0
25set bug_id 0
26
4a1135b8 27# Start with a fresh gdb.
c906108c 28
4a1135b8
MC
29gdb_exit
30gdb_start
c906108c 31
4a1135b8 32# Test input radices.
c906108c 33
4a1135b8
MC
34proc test_one_input { iradix input output } {
35 gdb_test "print $input" "$output" \
36 "print $input; expect $output; input radix $iradix"
c906108c
SS
37}
38
4a1135b8
MC
39proc test_input_radix { iradix iradixhex iradixoctal } {
40 # set input-radix = $iradix, output-radix = ten
c906108c
SS
41 gdb_test "set radix" \
42 "Input and output radices now set to decimal 10, hex a, octal 12." \
4a1135b8
MC
43 "initialize radix, input radix $iradix"
44 gdb_test "set input-radix $iradix" \
45 "Input radix now set to decimal $iradix, hex $iradixhex, octal $iradixoctal."
46 if { $iradix == 10 } then {
47 gdb_test "show radix" \
48 "Input and output radices set to decimal 10, hex a, octal 12." \
49 "show radix, input radix $iradix"
50 } else {
51 gdb_test "show radix" \
52 "Input radix set to decimal $iradix, hex $iradixhex, octal $iradixoctal.\r\nOutput radix set to decimal 10, hex a, octal 12." \
53 "show radix, input radix $iradix"
54 }
55
56 # test constants with specific bases that do not use $iradix
57 test_one_input $iradix "010" "8"
58 test_one_input $iradix "20." "20"
59 test_one_input $iradix "(int) 20." "20"
60 test_one_input $iradix "0xf" "15"
61
62 # test simple one-digit constants
63 test_one_input $iradix "0" "0"
64 test_one_input $iradix "1" "1"
65 test_one_input $iradix "-1" "-1"
66
67 # test simple two-digit constants
68 test_one_input $iradix "10" [expr $iradix]
69 test_one_input $iradix "11" [expr $iradix + 1]
70 test_one_input $iradix "-10" [expr 0 - $iradix]
71 test_one_input $iradix "-11" [expr 0 - $iradix - 1]
72
73 # test simple three-digit constants
74 test_one_input $iradix "100" [expr $iradix * $iradix]
75 test_one_input $iradix "101" [expr $iradix * $iradix + 1]
76 test_one_input $iradix "-100" [expr 0 - $iradix * $iradix]
77 test_one_input $iradix "-101" [expr 0 - $iradix * $iradix - 1]
78
79 # test a five-digit constant
80 test_one_input $iradix "10101" \
81 [expr $iradix * $iradix * $iradix * $iradix + $iradix * $iradix + 1]
c906108c
SS
82}
83
4a1135b8
MC
84test_input_radix 2 "2" "2"
85 test_one_input 2 "4" "Invalid number \"4\"\\."
86 test_one_input 2 "-2" "Invalid number \"2\"\\."
c906108c 87
4a1135b8
MC
88test_input_radix 3 "3" "3"
89 test_one_input 3 "2" "2"
90 test_one_input 3 "20" "6"
91 test_one_input 3 "3" "Invalid number \"3\"\\."
92 test_one_input 2 "30" "Invalid number \"30\"\\."
c906108c 93
4a1135b8
MC
94test_input_radix 8 "8" "10"
95 test_one_input 8 "20" "16"
96 test_one_input 8 "-20" "-16"
97 test_one_input 8 "8" "Invalid number \"8\"."
98 test_one_input 8 "-9" "Invalid number \"9\"."
99
100test_input_radix 10 "a" "12"
101 test_one_input 10 "-12" "-12"
102
103test_input_radix 16 "10" "20"
104
105# Test output radices.
106
107proc test_one_output { oradix input output } {
108 gdb_test "print $input" "$output" \
109 "print $input; expect $output; output radix $oradix"
c906108c
SS
110}
111
4a1135b8
MC
112proc test_output_radix { oradix oradixhex oradixoctal } {
113 # set input-radix = ten, output-radix = $oradix
c906108c
SS
114 gdb_test "set radix" \
115 "Input and output radices now set to decimal 10, hex a, octal 12." \
4a1135b8
MC
116 "initialize radix, output radix $oradix"
117 gdb_test "set output-radix $oradix" \
118 "Output radix now set to decimal $oradix, hex $oradixhex, octal $oradixoctal."
119 if { $oradix == 10 } then {
120 gdb_test "show radix" \
121 "Input and output radices set to decimal 10, hex a, octal 12." \
122 "show radix, output radix $oradix"
123 } else {
124 gdb_test "show radix" \
125 "Input radix set to decimal 10, hex a, octal 12.\r\nOutput radix set to decimal $oradix, hex $oradixhex, octal $oradixoctal." \
126 "show radix, output radix $oradix"
127 }
128
129 # no standard tests for output radix
c906108c
SS
130}
131
4a1135b8
MC
132test_output_radix 8 "8" "10"
133 test_one_output 8 "010" "010"
134 test_one_output 8 "0xf" "17"
135 test_one_output 8 "10" "12"
136 test_one_output 8 "100" "144"
137 setup_kfail *-*-* "gdb/1715"
138 test_one_output 8 "20." "24"
139 test_one_output 8 "(int) 20." "24"
140
141test_output_radix 10 "a" "12"
142 test_one_output 10 "010" "8"
143 test_one_output 10 "0xf" "15"
144 test_one_output 10 "10" "10"
145 test_one_output 10 "100" "100"
146 test_one_output 10 "20." "20"
147 test_one_output 10 "(int) 20." "20"
148
149test_output_radix 16 "10" "20"
150 test_one_output 16 "010" "8"
151 test_one_output 16 "0xf" "f"
152 test_one_output 16 "10" "a"
153 test_one_output 16 "100" "64"
154 setup_kfail *-*-* "gdb/1715"
155 test_one_output 16 "20." "14"
156 test_one_output 16 "(int) 20." "14"
09e6485f
PA
157
158# Test rejecting invalid input radices and unsupported output radices
159# really rejects the radices, instead of just claiming so (PR 7536).
160
161gdb_test "set radix" \
162 "Input and output radices now set to decimal 10, hex a, octal 12\." \
163 "Reset radices"
164
1e8fb976
PA
165gdb_test "set input-radix 0" \
166 "Nonsense input radix ``decimal 0''; input radix unchanged\\." \
167 "Reject input-radix 0"
168gdb_test "show input-radix" \
169 "Default input radix for entering numbers is 10\\." \
170 "Input radix unchanged after rejecting 0"
171
09e6485f
PA
172gdb_test "set input-radix 1" \
173 "Nonsense input radix ``decimal 1''; input radix unchanged\\." \
174 "Reject input-radix 1"
175gdb_test "show input-radix" \
176 "Default input radix for entering numbers is 10\\." \
1e8fb976 177 "Input radix unchanged after rejecting 1"
09e6485f 178
1e8fb976
PA
179gdb_test "set output-radix 0" \
180 "Unsupported output radix ``decimal 0''; output radix unchanged\\." \
181 "Reject output-radix 0"
182gdb_test "show output-radix" \
183 "Default output radix for printing of values is 10\\." \
184 "Output radix unchanged after rejecting 0"
09e6485f
PA
185gdb_test "set output-radix 1" \
186 "Unsupported output radix ``decimal 1''; output radix unchanged\\." \
187 "Reject output-radix 1"
188gdb_test "show output-radix" \
189 "Default output radix for printing of values is 10\\." \
1e8fb976 190 "Output radix unchanged after rejecting 1"
09e6485f
PA
191
192gdb_test "set radix 7" \
193 "Unsupported output radix ``decimal 7''; output radix unchanged\\." \
194 "set radix 7 rejected"
195gdb_test "show output-radix" \
196 "Default output radix for printing of values is 10\\." \
197 "Output radix unchanged after rejection through set radix command"
This page took 0.892827 seconds and 4 git commands to generate.