1# Copyright (C) 1994-2014 Free Software Foundation, Inc. 2 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 3 of the License, or 6# (at your option) any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16# This file was adapted from old Chill tests by Stan Shebs 17# (shebs@cygnus.com). 18 19load_lib "fortran.exp" 20 21if { [skip_fortran_tests] } { continue } 22 23proc test_integer_literals_accepted {} { 24 global gdb_prompt 25 26 # Test various decimal values. 27 28 gdb_test "p 123" " = 123" 29 gdb_test "p -123" " = -123" 30} 31 32proc test_character_literals_accepted {} { 33 global gdb_prompt 34 35 # Test various character values. 36 37 gdb_test "p 'a'" " = 'a'" 38 39 # Test various substring expression. 40 gdb_test "p 'abcdefg'(2:4)" " = 'bcd'" 41 gdb_test "p 'abcdefg'(:3)" " = 'abc'" 42 gdb_test "p 'abcdefg'(5:)" " = 'efg'" 43 gdb_test "p 'abcdefg'(:)" " = 'abcdefg'" 44 45} 46 47proc test_integer_literals_rejected {} { 48 global gdb_prompt 49 50 test_print_reject "p _" 51} 52 53proc test_logical_literals_accepted {} { 54 global gdb_prompt 55 56 # Test the only possible values for a logical, TRUE and FALSE. 57 58 gdb_test "p .TRUE." " = .TRUE." 59 gdb_test "p .FALSE." " = .FALSE." 60} 61 62proc test_float_literals_accepted {} { 63 global gdb_prompt 64 65 # Test various floating point formats 66 67 gdb_test "p .44 .LT. .45" " = .TRUE." 68 gdb_test "p .44 .GT. .45" " = .FALSE." 69 gdb_test "p 0.44 .LT. 0.45" " = .TRUE." 70 gdb_test "p 0.44 .GT. 0.45" " = .FALSE." 71 gdb_test "p 44. .LT. 45." " = .TRUE." 72 gdb_test "p 44. .GT. 45." " = .FALSE." 73 gdb_test "p 44.0 .LT. 45.0" " = .TRUE." 74 gdb_test "p 44.0 .GT. 45.0" " = .FALSE." 75 gdb_test "p 10D20 .LT. 10D21" " = .TRUE." 76 gdb_test "p 10D20 .GT. 10D21" " = .FALSE." 77 gdb_test "p 10d20 .LT. 10d21" " = .TRUE." 78 gdb_test "p 10d20 .GT. 10d21" " = .FALSE." 79 gdb_test "p 10E20 .LT. 10E21" " = .TRUE." 80 gdb_test "p 10E20 .GT. 10E21" " = .FALSE." 81 gdb_test "p 10e20 .LT. 10e21" " = .TRUE." 82 gdb_test "p 10e20 .GT. 10e21" " = .FALSE." 83 gdb_test "p 10.D20 .LT. 10.D21" " = .TRUE." 84 gdb_test "p 10.D20 .GT. 10.D21" " = .FALSE." 85 gdb_test "p 10.d20 .LT. 10.d21" " = .TRUE." 86 gdb_test "p 10.d20 .GT. 10.d21" " = .FALSE." 87 gdb_test "p 10.E20 .LT. 10.E21" " = .TRUE." 88 gdb_test "p 10.E20 .GT. 10.E21" " = .FALSE." 89 gdb_test "p 10.e20 .LT. 10.e21" " = .TRUE." 90 gdb_test "p 10.e20 .GT. 10.e21" " = .FALSE." 91 gdb_test "p 10.0D20 .LT. 10.0D21" " = .TRUE." 92 gdb_test "p 10.0D20 .GT. 10.0D21" " = .FALSE." 93 gdb_test "p 10.0d20 .LT. 10.0d21" " = .TRUE." 94 gdb_test "p 10.0d20 .GT. 10.0d21" " = .FALSE." 95 gdb_test "p 10.0E20 .LT. 10.0E21" " = .TRUE." 96 gdb_test "p 10.0E20 .GT. 10.0E21" " = .FALSE." 97 gdb_test "p 10.0e20 .LT. 10.0e21" " = .TRUE." 98 gdb_test "p 10.0e20 .GT. 10.0e21" " = .FALSE." 99 gdb_test "p 10.0D+20 .LT. 10.0D+21" " = .TRUE." 100 gdb_test "p 10.0D+20 .GT. 10.0D+21" " = .FALSE." 101 gdb_test "p 10.0d+20 .LT. 10.0d+21" " = .TRUE." 102 gdb_test "p 10.0d+20 .GT. 10.0d+21" " = .FALSE." 103 gdb_test "p 10.0E+20 .LT. 10.0E+21" " = .TRUE." 104 gdb_test "p 10.0E+20 .GT. 10.0E+21" " = .FALSE." 105 gdb_test "p 10.0e+20 .LT. 10.0e+21" " = .TRUE." 106 gdb_test "p 10.0e+20 .GT. 10.0e+21" " = .FALSE." 107 gdb_test "p 10.0D-11 .LT. 10.0D-10" " = .TRUE." 108 gdb_test "p 10.0D-11 .GT. 10.0D-10" " = .FALSE." 109 gdb_test "p 10.0d-11 .LT. 10.0d-10" " = .TRUE." 110 gdb_test "p 10.0d-11 .GT. 10.0d-10" " = .FALSE." 111 gdb_test "p 10.0E-11 .LT. 10.0E-10" " = .TRUE." 112 gdb_test "p 10.0E-11 .GT. 10.0E-10" " = .FALSE." 113 gdb_test "p 10.0e-11 .LT. 10.0e-10" " = .TRUE." 114 gdb_test "p 10.0e-11 .GT. 10.0e-10" " = .FALSE." 115} 116 117proc test_convenience_variables {} { 118 global gdb_prompt 119 120 gdb_test "set \$foo = 101" " = 101\[\r\n\]*" \ 121 "Set a new convenience variable" 122 123 gdb_test "print \$foo" " = 101" \ 124 "Print contents of new convenience variable" 125 126 gdb_test "set \$foo = 301" " = 301\[\r\n\]*" \ 127 "Set convenience variable to a new value" 128 129 gdb_test "print \$foo" " = 301" \ 130 "Print new contents of convenience variable" 131 132 gdb_test "set \$_ = 11" " = 11\[\r\n\]*" \ 133 "Set convenience variable \$_" 134 135 gdb_test "print \$_" " = 11" \ 136 "Print contents of convenience variable \$_" 137 138 gdb_test "print \$foo + 10" " = 311" \ 139 "Use convenience variable in arithmetic expression" 140 141 gdb_test "print (\$foo = 32) + 4" " = 36" \ 142 "Use convenience variable assignment in arithmetic expression" 143 144 gdb_test "print \$bar" " = VOID" \ 145 "Print contents of uninitialized convenience variable" 146} 147 148proc test_value_history {} { 149 global gdb_prompt 150 151 gdb_test "print 101" "\\\$1 = 101" \ 152 "Set value-history\[1\] using \$1" 153 154 gdb_test "print 102" "\\\$2 = 102" \ 155 "Set value-history\[2\] using \$2" 156 157 gdb_test "print 103" "\\\$3 = 103" \ 158 "Set value-history\[3\] using \$3" 159 160 gdb_test "print \$\$" "\\\$4 = 102" \ 161 "Print value-history\[MAX-1\] using inplicit index \$\$" 162 163 gdb_test "print \$\$" "\\\$5 = 103" \ 164 "Print value-history\[MAX-1\] again using implicit index \$\$" 165 166 gdb_test "print \$" "\\\$6 = 103" \ 167 "Print value-history\[MAX\] using implicit index \$" 168 169 gdb_test "print \$\$2" "\\\$7 = 102" \ 170 "Print value-history\[MAX-2\] using explicit index \$\$2" 171 172 gdb_test "print \$0" "\\\$8 = 102" \ 173 "Print value-history\[MAX\] using explicit index \$0" 174 175 gdb_test "print 108" "\\\$9 = 108" "" 176 177 gdb_test "print \$\$0" "\\\$10 = 108" \ 178 "Print value-history\[MAX\] using explicit index \$\$0" 179 180 gdb_test "print \$1" "\\\$11 = 101" \ 181 "Print value-history\[1\] using explicit index \$1" 182 183 gdb_test "print \$2" "\\\$12 = 102" \ 184 "Print value-history\[2\] using explicit index \$2" 185 186 gdb_test "print \$3" "\\\$13 = 103" \ 187 "Print value-history\[3\] using explicit index \$3" 188 189 gdb_test "print \$-3" "\\\$14 = 100" \ 190 "Print (value-history\[MAX\] - 3) using implicit index \$" 191 192 gdb_test "print \$1 + 3" "\\\$15 = 104" \ 193 "Use value-history element in arithmetic expression" 194} 195 196proc test_arithmetic_expressions {} { 197 global gdb_prompt 198 199 # Test unary minus with various operands 200 201# gdb_test "p -(TRUE)" " = -1" "unary minus applied to bool" 202# gdb_test "p -('a')" " = xxx" "unary minus applied to char" 203 gdb_test "p -(1)" " = -1" "unary minus applied to int" 204 gdb_test "p -(1.0)" " = -1" "unary minus applied to real" 205 206 # Test addition with various operands 207 208 gdb_test "p .TRUE. + 1" " = 2" "bool plus int" 209 gdb_test "p 1 + 1" " = 2" "int plus int" 210 gdb_test "p 1.0 + 1" " = 2" "real plus int" 211 gdb_test "p 1.0 + 2.0" " = 3" "real plus real" 212 213 # Test subtraction with various operands 214 215 gdb_test "p .TRUE. - 1" " = 0" "bool minus int" 216 gdb_test "p 3 - 1" " = 2" "int minus int" 217 gdb_test "p 3.0 - 1" " = 2" "real minus int" 218 gdb_test "p 5.0 - 2.0" " = 3" "real minus real" 219 220 # Test multiplication with various operands 221 222 gdb_test "p .TRUE. * 1" " = 1" "bool times int" 223 gdb_test "p 2 * 3" " = 6" "int times int" 224 gdb_test "p 2.0 * 3" " = 6" "real times int" 225 gdb_test "p 2.0 * 3.0" " = 6" "real times real" 226 227 # Test division with various operands 228 229 gdb_test "p .TRUE. / 1" " = 1" "bool divided by int" 230 gdb_test "p 6 / 3" " = 2" "int divided by int" 231 gdb_test "p 6.0 / 3" " = 2" "real divided by int" 232 gdb_test "p 6.0 / 3.0" " = 2" "real divided by real" 233 234 # Test exponentiation with various operands 235 236 gdb_test "p 2 ** 3" " = 8" "int powered by int" 237 gdb_test "p 2 ** 2 ** 3" " = 256" "combined exponentiation expression" 238 gdb_test "p (2 ** 2) ** 3" " = 64" "combined exponentiation expression in specified order" 239 gdb_test "p 4 ** 0.5" " = 2" "int powered by real" 240 gdb_test "p 4.0 ** 0.5" " = 2" "real powered by real" 241 242} 243 244# Start with a fresh gdb. 245 246gdb_exit 247gdb_start 248gdb_reinitialize_dir $srcdir/$subdir 249 250gdb_test "set print sevenbit-strings" "" 251 252if [set_lang_fortran] then { 253 test_value_history 254 test_convenience_variables 255 test_integer_literals_accepted 256 test_integer_literals_rejected 257 test_logical_literals_accepted 258 test_character_literals_accepted 259 test_float_literals_accepted 260 test_arithmetic_expressions 261} else { 262 warning "$test_name tests suppressed." 0 263} 264