1# This testcase is part of GDB, the GNU debugger. 2# Copyright 1993, 1997, 2004 Free Software Foundation, Inc. 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 6# the Free Software Foundation; either version 2 of the License, or 7# (at your option) any later version. 8# 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. 13# 14# You should have received a copy of the GNU General Public License 15# along with this program; if not, write to the Free Software 16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18# This file was written by Fred Fish. (fnf@cygnus.com) 19# And rewritten by Michael Chastain (mec.gnu@mindspring.com) 20 21if $tracelevel then { 22 strace $tracelevel 23} 24 25set prms_id 0 26set bug_id 0 27 28# Start with a fresh gdb. 29 30gdb_exit 31gdb_start 32 33# Test input radices. 34 35proc test_one_input { iradix input output } { 36 gdb_test "print $input" "$output" \ 37 "print $input; expect $output; input radix $iradix" 38} 39 40proc test_input_radix { iradix iradixhex iradixoctal } { 41 # set input-radix = $iradix, output-radix = ten 42 gdb_test "set radix" \ 43 "Input and output radices now set to decimal 10, hex a, octal 12." \ 44 "initialize radix, input radix $iradix" 45 gdb_test "set input-radix $iradix" \ 46 "Input radix now set to decimal $iradix, hex $iradixhex, octal $iradixoctal." 47 if { $iradix == 10 } then { 48 gdb_test "show radix" \ 49 "Input and output radices set to decimal 10, hex a, octal 12." \ 50 "show radix, input radix $iradix" 51 } else { 52 gdb_test "show radix" \ 53 "Input radix set to decimal $iradix, hex $iradixhex, octal $iradixoctal.\r\nOutput radix set to decimal 10, hex a, octal 12." \ 54 "show radix, input radix $iradix" 55 } 56 57 # test constants with specific bases that do not use $iradix 58 test_one_input $iradix "010" "8" 59 test_one_input $iradix "20." "20" 60 test_one_input $iradix "(int) 20." "20" 61 test_one_input $iradix "0xf" "15" 62 63 # test simple one-digit constants 64 test_one_input $iradix "0" "0" 65 test_one_input $iradix "1" "1" 66 test_one_input $iradix "-1" "-1" 67 68 # test simple two-digit constants 69 test_one_input $iradix "10" [expr $iradix] 70 test_one_input $iradix "11" [expr $iradix + 1] 71 test_one_input $iradix "-10" [expr 0 - $iradix] 72 test_one_input $iradix "-11" [expr 0 - $iradix - 1] 73 74 # test simple three-digit constants 75 test_one_input $iradix "100" [expr $iradix * $iradix] 76 test_one_input $iradix "101" [expr $iradix * $iradix + 1] 77 test_one_input $iradix "-100" [expr 0 - $iradix * $iradix] 78 test_one_input $iradix "-101" [expr 0 - $iradix * $iradix - 1] 79 80 # test a five-digit constant 81 test_one_input $iradix "10101" \ 82 [expr $iradix * $iradix * $iradix * $iradix + $iradix * $iradix + 1] 83} 84 85test_input_radix 2 "2" "2" 86 test_one_input 2 "4" "Invalid number \"4\"\\." 87 test_one_input 2 "-2" "Invalid number \"2\"\\." 88 89test_input_radix 3 "3" "3" 90 test_one_input 3 "2" "2" 91 test_one_input 3 "20" "6" 92 test_one_input 3 "3" "Invalid number \"3\"\\." 93 test_one_input 2 "30" "Invalid number \"30\"\\." 94 95test_input_radix 8 "8" "10" 96 test_one_input 8 "20" "16" 97 test_one_input 8 "-20" "-16" 98 test_one_input 8 "8" "Invalid number \"8\"." 99 test_one_input 8 "-9" "Invalid number \"9\"." 100 101test_input_radix 10 "a" "12" 102 test_one_input 10 "-12" "-12" 103 104test_input_radix 16 "10" "20" 105 106# Test output radices. 107 108proc test_one_output { oradix input output } { 109 gdb_test "print $input" "$output" \ 110 "print $input; expect $output; output radix $oradix" 111} 112 113proc test_output_radix { oradix oradixhex oradixoctal } { 114 # set input-radix = ten, output-radix = $oradix 115 gdb_test "set radix" \ 116 "Input and output radices now set to decimal 10, hex a, octal 12." \ 117 "initialize radix, output radix $oradix" 118 gdb_test "set output-radix $oradix" \ 119 "Output radix now set to decimal $oradix, hex $oradixhex, octal $oradixoctal." 120 if { $oradix == 10 } then { 121 gdb_test "show radix" \ 122 "Input and output radices set to decimal 10, hex a, octal 12." \ 123 "show radix, output radix $oradix" 124 } else { 125 gdb_test "show radix" \ 126 "Input radix set to decimal 10, hex a, octal 12.\r\nOutput radix set to decimal $oradix, hex $oradixhex, octal $oradixoctal." \ 127 "show radix, output radix $oradix" 128 } 129 130 # no standard tests for output radix 131} 132 133test_output_radix 8 "8" "10" 134 test_one_output 8 "010" "010" 135 test_one_output 8 "0xf" "17" 136 test_one_output 8 "10" "12" 137 test_one_output 8 "100" "144" 138 setup_kfail *-*-* "gdb/1715" 139 test_one_output 8 "20." "24" 140 test_one_output 8 "(int) 20." "24" 141 142test_output_radix 10 "a" "12" 143 test_one_output 10 "010" "8" 144 test_one_output 10 "0xf" "15" 145 test_one_output 10 "10" "10" 146 test_one_output 10 "100" "100" 147 test_one_output 10 "20." "20" 148 test_one_output 10 "(int) 20." "20" 149 150test_output_radix 16 "10" "20" 151 test_one_output 16 "010" "8" 152 test_one_output 16 "0xf" "f" 153 test_one_output 16 "10" "a" 154 test_one_output 16 "100" "64" 155 setup_kfail *-*-* "gdb/1715" 156 test_one_output 16 "20." "14" 157 test_one_output 16 "(int) 20." "14" 158