1# Copyright 1998, 1999, 2007, 2008, 2009, 2010, 2011
2# 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 3 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, see <http://www.gnu.org/licenses/>.
16
17# This file was written by Elena Zannoni (ezannoni@cygnus.com)
18
19# This file is part of the gdb testsuite
20#
21# tests for correctenss of relational operators, associativity and precedence
22# with integer type variables
23#
24
25if $tracelevel then {
26	strace $tracelevel
27	}
28
29#
30# test running programs
31#
32
33if { [prepare_for_testing relational.exp relational int-type.c {debug nowarnings}] } {
34    return -1
35}
36
37if [get_compiler_info not-used] {
38    return -1;
39}
40
41#
42# set it up at a breakpoint so we can play with the variable values
43#
44
45if ![runto_main] then {
46    perror "couldn't run to breakpoint"
47    continue
48}
49
50#
51# test expressions with "int" types
52#
53
54gdb_test_no_output "set variable x=14" "set variable x=14"
55gdb_test_no_output "set variable y=2" "set variable y=2"
56gdb_test_no_output "set variable z=2" "set variable z=2"
57gdb_test_no_output "set variable w=3" "set variable w=3"
58
59gdb_test "print x" " = 14" "print value of x"
60
61gdb_test "print y" " = 2" "print value of y"
62
63gdb_test "print z" " = 2" "print value of z"
64
65gdb_test "print w" " = 3" "print value of w"
66
67gdb_test "print x < y" "$false" "print value of x<y"
68
69gdb_test "print x <= y" "$false" "print value of x<=y"
70
71gdb_test "print x > y" "$true" "print value of x>y"
72
73gdb_test "print x >= y" "$true" "print value of x>=y"
74
75gdb_test "print x == y" "$false" "print value of x==y"
76
77gdb_test "print x != y" "$true" "print value of x!=y"
78
79
80# Test associativity of <, >, <=, >=, ==, !=
81
82gdb_test_no_output "set variable x=3" "set variable x"
83gdb_test_no_output "set variable y=5" "set variable y"
84gdb_test_no_output "set variable z=2" "set variable z"
85
86gdb_test "print x < y < z" "$true" "print value of x<y<z"
87
88gdb_test "print x <= y <= z" "$true" "print value of x<=y<=z"
89
90gdb_test "print x > y > z" "$false" "print value of x>y>z"
91
92gdb_test "print x >= y >= z" "$false" "print value of x>=y>=z"
93
94gdb_test_no_output "set variable x=2" "set variable x"
95gdb_test_no_output "set variable y=2" "set variable y"
96gdb_test_no_output "set variable z=1" "set variable z"
97
98gdb_test "print x == y == z" "$true" "print value of x==y==z"
99
100gdb_test_no_output "set variable z=0" "set variable z"
101
102gdb_test "print x != y != z" "$false" "print value of x!=y!=z"
103
104# test precedence rules on pairs of relational operators
105
106gdb_test_no_output "set variable x=0" "set variable x"
107gdb_test_no_output "set variable y=2" "set variable y"
108gdb_test_no_output "set variable z=2" "set variable z"
109
110gdb_test "print x < y == z" "$false" "print value of x<y==z"
111
112# 0  2  2
113gdb_test "print x < y != z" "$true" "print value of x<y!=z"
114
115gdb_test_no_output "set variable x=2" "set variable x"
116gdb_test_no_output "set variable y=3" "set variable y"
117gdb_test_no_output "set variable z=1" "set variable z"
118
119
120# 2 3 1
121gdb_test "print x < y <= z" "$true" "print value of x<y<=z"
122
123# 2 3 1
124gdb_test "print x < y >= z" "$true" "print value of x<y>=z"
125
126gdb_test_no_output "set variable z=0" " set variable z"
127
128# 2 3 0
129gdb_test "print x < y > z" "$true" "print value of x<y>z"
130
131gdb_test_no_output "set variable x=1" " set variable x"
132
133# 1 3 0
134gdb_test "print x > y >= z" "$true" "print value of x>y>=z"
135
136gdb_test_no_output "set variable z=2" " set variable z"
137
138# 1 3 2
139gdb_test "print x > y == z" "$false" "print value of x>y==z"
140
141gdb_test_no_output "set variable x=2" " set variable x"
142gdb_test_no_output "set variable z=0" " set variable z"
143
144# 2 3 0
145gdb_test "print x > y != z" "$false" "print value of x>y!=z"
146
147gdb_test_no_output "set variable x=4" "set x to 4"
148
149# 4 3 0
150gdb_test "print x > y <= z" "$false" "print value of x>y<=z"
151
152# 4 3 0
153gdb_test "print x >= y == z" "$false" "print value of x>=y==z"
154
155gdb_test_no_output "set variable x=2" " set variable x"
156
157# 2 3 0
158gdb_test "print x >= y != z" "$false" "print value of x>=y!=z"
159
160gdb_test_no_output "set variable x=0" " set variable x"
161gdb_test_no_output "set variable z=4" " set variable z"
162
163# 0 3 4
164gdb_test "print x >= y <= z" "$true" "print value of x>=y<=z"
165
166# 0 3 4
167gdb_test "print x <= y == z" "$false" "print value of x<=y==z"
168
169gdb_test_no_output "set variable x=2" " set variable x"
170
171# 2 3 4
172gdb_test "print x <= y != z" "$true" "print value of x<=y!=z"
173
174# 2 3 4
175gdb_test "print x == y != z" "$true" "print value of x==y!=z"
176
177
178
179# test use of parenthesis to enforce different order of evaluation
180
181gdb_test_no_output "set variable z=0" " set variable z"
182
183# 2 3 0
184gdb_test "print x >= (y < z)" "$true" "print value of x>=(y<z)"
185
186# 2 3 0
187gdb_test "print x >= (y != z)" "$true" "print value of x>=(y!=z)"
188
189# 2 3 0
190gdb_test "print x == (y == z)" "$false" "print value of x==(y==z)"
191
192gdb_test_no_output "set variable x=1" " set variable x"
193gdb_test_no_output "set variable z=4" " set variable z"
194
195# 1 3 4
196gdb_test "print (x == y) < z" "$true" "print value of (x==y)<z"
197
198