Commit | Line | Data |
---|---|---|
4a1135b8 | 1 | # This testcase is part of GDB, the GNU debugger. |
b811d2c2 | 2 | # Copyright 1993-2020 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 | 19 | |
c906108c | 20 | |
4a1135b8 | 21 | # Start with a fresh gdb. |
c906108c | 22 | |
4a1135b8 MC |
23 | gdb_exit |
24 | gdb_start | |
c906108c | 25 | |
4a1135b8 | 26 | # Test input radices. |
c906108c | 27 | |
4a1135b8 MC |
28 | proc test_one_input { iradix input output } { |
29 | gdb_test "print $input" "$output" \ | |
30 | "print $input; expect $output; input radix $iradix" | |
c906108c SS |
31 | } |
32 | ||
4a1135b8 MC |
33 | proc test_input_radix { iradix iradixhex iradixoctal } { |
34 | # set input-radix = $iradix, output-radix = ten | |
c906108c SS |
35 | gdb_test "set radix" \ |
36 | "Input and output radices now set to decimal 10, hex a, octal 12." \ | |
4a1135b8 MC |
37 | "initialize radix, input radix $iradix" |
38 | gdb_test "set input-radix $iradix" \ | |
39 | "Input radix now set to decimal $iradix, hex $iradixhex, octal $iradixoctal." | |
40 | if { $iradix == 10 } then { | |
41 | gdb_test "show radix" \ | |
42 | "Input and output radices set to decimal 10, hex a, octal 12." \ | |
43 | "show radix, input radix $iradix" | |
44 | } else { | |
45 | gdb_test "show radix" \ | |
46 | "Input radix set to decimal $iradix, hex $iradixhex, octal $iradixoctal.\r\nOutput radix set to decimal 10, hex a, octal 12." \ | |
47 | "show radix, input radix $iradix" | |
48 | } | |
49 | ||
50 | # test constants with specific bases that do not use $iradix | |
51 | test_one_input $iradix "010" "8" | |
52 | test_one_input $iradix "20." "20" | |
53 | test_one_input $iradix "(int) 20." "20" | |
54 | test_one_input $iradix "0xf" "15" | |
55 | ||
56 | # test simple one-digit constants | |
57 | test_one_input $iradix "0" "0" | |
58 | test_one_input $iradix "1" "1" | |
59 | test_one_input $iradix "-1" "-1" | |
60 | ||
61 | # test simple two-digit constants | |
62 | test_one_input $iradix "10" [expr $iradix] | |
63 | test_one_input $iradix "11" [expr $iradix + 1] | |
64 | test_one_input $iradix "-10" [expr 0 - $iradix] | |
65 | test_one_input $iradix "-11" [expr 0 - $iradix - 1] | |
66 | ||
67 | # test simple three-digit constants | |
68 | test_one_input $iradix "100" [expr $iradix * $iradix] | |
69 | test_one_input $iradix "101" [expr $iradix * $iradix + 1] | |
70 | test_one_input $iradix "-100" [expr 0 - $iradix * $iradix] | |
71 | test_one_input $iradix "-101" [expr 0 - $iradix * $iradix - 1] | |
72 | ||
73 | # test a five-digit constant | |
74 | test_one_input $iradix "10101" \ | |
75 | [expr $iradix * $iradix * $iradix * $iradix + $iradix * $iradix + 1] | |
c906108c SS |
76 | } |
77 | ||
4a1135b8 MC |
78 | test_input_radix 2 "2" "2" |
79 | test_one_input 2 "4" "Invalid number \"4\"\\." | |
80 | test_one_input 2 "-2" "Invalid number \"2\"\\." | |
c906108c | 81 | |
4a1135b8 MC |
82 | test_input_radix 3 "3" "3" |
83 | test_one_input 3 "2" "2" | |
84 | test_one_input 3 "20" "6" | |
85 | test_one_input 3 "3" "Invalid number \"3\"\\." | |
86 | test_one_input 2 "30" "Invalid number \"30\"\\." | |
c906108c | 87 | |
4a1135b8 MC |
88 | test_input_radix 8 "8" "10" |
89 | test_one_input 8 "20" "16" | |
90 | test_one_input 8 "-20" "-16" | |
91 | test_one_input 8 "8" "Invalid number \"8\"." | |
92 | test_one_input 8 "-9" "Invalid number \"9\"." | |
93 | ||
94 | test_input_radix 10 "a" "12" | |
95 | test_one_input 10 "-12" "-12" | |
96 | ||
97 | test_input_radix 16 "10" "20" | |
98 | ||
99 | # Test output radices. | |
100 | ||
101 | proc test_one_output { oradix input output } { | |
102 | gdb_test "print $input" "$output" \ | |
103 | "print $input; expect $output; output radix $oradix" | |
c906108c SS |
104 | } |
105 | ||
4a1135b8 MC |
106 | proc test_output_radix { oradix oradixhex oradixoctal } { |
107 | # set input-radix = ten, output-radix = $oradix | |
c906108c SS |
108 | gdb_test "set radix" \ |
109 | "Input and output radices now set to decimal 10, hex a, octal 12." \ | |
4a1135b8 MC |
110 | "initialize radix, output radix $oradix" |
111 | gdb_test "set output-radix $oradix" \ | |
112 | "Output radix now set to decimal $oradix, hex $oradixhex, octal $oradixoctal." | |
113 | if { $oradix == 10 } then { | |
114 | gdb_test "show radix" \ | |
115 | "Input and output radices set to decimal 10, hex a, octal 12." \ | |
116 | "show radix, output radix $oradix" | |
117 | } else { | |
118 | gdb_test "show radix" \ | |
119 | "Input radix set to decimal 10, hex a, octal 12.\r\nOutput radix set to decimal $oradix, hex $oradixhex, octal $oradixoctal." \ | |
120 | "show radix, output radix $oradix" | |
121 | } | |
122 | ||
123 | # no standard tests for output radix | |
c906108c SS |
124 | } |
125 | ||
4a1135b8 MC |
126 | test_output_radix 8 "8" "10" |
127 | test_one_output 8 "010" "010" | |
128 | test_one_output 8 "0xf" "17" | |
129 | test_one_output 8 "10" "12" | |
130 | test_one_output 8 "100" "144" | |
bbc8b958 | 131 | setup_kfail "gdb/1715" *-*-* |
4a1135b8 MC |
132 | test_one_output 8 "20." "24" |
133 | test_one_output 8 "(int) 20." "24" | |
134 | ||
135 | test_output_radix 10 "a" "12" | |
136 | test_one_output 10 "010" "8" | |
137 | test_one_output 10 "0xf" "15" | |
138 | test_one_output 10 "10" "10" | |
139 | test_one_output 10 "100" "100" | |
140 | test_one_output 10 "20." "20" | |
141 | test_one_output 10 "(int) 20." "20" | |
142 | ||
143 | test_output_radix 16 "10" "20" | |
144 | test_one_output 16 "010" "8" | |
145 | test_one_output 16 "0xf" "f" | |
146 | test_one_output 16 "10" "a" | |
147 | test_one_output 16 "100" "64" | |
bbc8b958 | 148 | setup_kfail "gdb/1715" *-*-* |
4a1135b8 MC |
149 | test_one_output 16 "20." "14" |
150 | test_one_output 16 "(int) 20." "14" | |
09e6485f PA |
151 | |
152 | # Test rejecting invalid input radices and unsupported output radices | |
153 | # really rejects the radices, instead of just claiming so (PR 7536). | |
154 | ||
155 | gdb_test "set radix" \ | |
156 | "Input and output radices now set to decimal 10, hex a, octal 12\." \ | |
bb95117e | 157 | "reset radices" |
09e6485f | 158 | |
1e8fb976 PA |
159 | gdb_test "set input-radix 0" \ |
160 | "Nonsense input radix ``decimal 0''; input radix unchanged\\." \ | |
161 | "Reject input-radix 0" | |
162 | gdb_test "show input-radix" \ | |
163 | "Default input radix for entering numbers is 10\\." \ | |
bb95117e | 164 | "input radix unchanged after rejecting 0" |
1e8fb976 | 165 | |
09e6485f PA |
166 | gdb_test "set input-radix 1" \ |
167 | "Nonsense input radix ``decimal 1''; input radix unchanged\\." \ | |
168 | "Reject input-radix 1" | |
169 | gdb_test "show input-radix" \ | |
170 | "Default input radix for entering numbers is 10\\." \ | |
bb95117e | 171 | "input radix unchanged after rejecting 1" |
09e6485f | 172 | |
1e8fb976 PA |
173 | gdb_test "set output-radix 0" \ |
174 | "Unsupported output radix ``decimal 0''; output radix unchanged\\." \ | |
175 | "Reject output-radix 0" | |
176 | gdb_test "show output-radix" \ | |
177 | "Default output radix for printing of values is 10\\." \ | |
178 | "Output radix unchanged after rejecting 0" | |
09e6485f PA |
179 | gdb_test "set output-radix 1" \ |
180 | "Unsupported output radix ``decimal 1''; output radix unchanged\\." \ | |
181 | "Reject output-radix 1" | |
182 | gdb_test "show output-radix" \ | |
183 | "Default output radix for printing of values is 10\\." \ | |
bb95117e | 184 | "output radix unchanged after rejecting 1" |
09e6485f PA |
185 | |
186 | gdb_test "set radix 7" \ | |
187 | "Unsupported output radix ``decimal 7''; output radix unchanged\\." \ | |
188 | "set radix 7 rejected" | |
189 | gdb_test "show output-radix" \ | |
190 | "Default output radix for printing of values is 10\\." \ | |
bb95117e | 191 | "output radix unchanged after rejection through set radix command" |