1 # Copyright 1998, 1999, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18 # This file is part of the gdb testsuite
20 # tests for correctenss of relational operators, associativity and precedence
21 # with integer type variables
29 # test running programs
32 if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
36 if [get_compiler_info not-used] {
41 # set it up at a breakpoint so we can play with the variable values
44 if ![runto_main] then {
45 perror "couldn't run to breakpoint"
50 # test expressions with "int" types
53 gdb_test_no_output "set variable x=14" "set variable x=14"
54 gdb_test_no_output "set variable y=2" "set variable y=2"
55 gdb_test_no_output "set variable z=2" "set variable z=2"
56 gdb_test_no_output "set variable w=3" "set variable w=3"
58 gdb_test "print x" " = 14" "print value of x"
60 gdb_test "print y" " = 2" "print value of y"
62 gdb_test "print z" " = 2" "print value of z"
64 gdb_test "print w" " = 3" "print value of w"
66 gdb_test "print x < y" "$false" "print value of x<y"
68 gdb_test "print x <= y" "$false" "print value of x<=y"
70 gdb_test "print x > y" "$true" "print value of x>y"
72 gdb_test "print x >= y" "$true" "print value of x>=y"
74 gdb_test "print x == y" "$false" "print value of x==y"
76 gdb_test "print x != y" "$true" "print value of x!=y"
79 # Test associativity of <, >, <=, >=, ==, !=
81 gdb_test_no_output "set variable x=3" "set variable x"
82 gdb_test_no_output "set variable y=5" "set variable y"
83 gdb_test_no_output "set variable z=2" "set variable z"
85 gdb_test "print x < y < z" "$true" "print value of x<y<z"
87 gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
89 gdb_test "print x > y > z" "$false" "print value of x>y>z"
91 gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
93 gdb_test_no_output "set variable x=2" "set variable x"
94 gdb_test_no_output "set variable y=2" "set variable y"
95 gdb_test_no_output "set variable z=1" "set variable z"
97 gdb_test "print x == y == z" "$true" "print value of x==y==z"
99 gdb_test_no_output "set variable z=0" "set variable z"
101 gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
103 # test precedence rules on pairs of relational operators
105 gdb_test_no_output "set variable x=0" "set variable x"
106 gdb_test_no_output "set variable y=2" "set variable y"
107 gdb_test_no_output "set variable z=2" "set variable z"
109 gdb_test "print x < y == z" "$false" "print value of x<y==z"
112 gdb_test "print x < y != z" "$true" "print value of x<y!=z"
114 gdb_test_no_output "set variable x=2" "set variable x"
115 gdb_test_no_output "set variable y=3" "set variable y"
116 gdb_test_no_output "set variable z=1" "set variable z"
120 gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
123 gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
125 gdb_test_no_output "set variable z=0" " set variable z"
128 gdb_test "print x < y > z" "$true" "print value of x<y>z"
130 gdb_test_no_output "set variable x=1" " set variable x"
133 gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
135 gdb_test_no_output "set variable z=2" " set variable z"
138 gdb_test "print x > y == z" "$false" "print value of x>y==z"
140 gdb_test_no_output "set variable x=2" " set variable x"
141 gdb_test_no_output "set variable z=0" " set variable z"
144 gdb_test "print x > y != z" "$false" "print value of x>y!=z"
146 gdb_test_no_output "set variable x=4" "set x to 4"
149 gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
152 gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
154 gdb_test_no_output "set variable x=2" " set variable x"
157 gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
159 gdb_test_no_output "set variable x=0" " set variable x"
160 gdb_test_no_output "set variable z=4" " set variable z"
163 gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
166 gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
168 gdb_test_no_output "set variable x=2" " set variable x"
171 gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
174 gdb_test "print x == y != z" "$true" "print value of x==y!=z"
178 # test use of parenthesis to enforce different order of evaluation
180 gdb_test_no_output "set variable z=0" " set variable z"
183 gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
186 gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
189 gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
191 gdb_test_no_output "set variable x=1" " set variable x"
192 gdb_test_no_output "set variable z=4" " set variable z"
195 gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"