1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1998, 1999, 2004 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21 # Tests for correctenss of logical operators, associativity and
22 # precedence with integer type variables
30 # test running programs
35 set testfile "int-type"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } {
44 if [get_compiler_info ${binfile}] {
50 gdb_reinitialize_dir $srcdir/$subdir
55 # set it up at a breakpoint so we can play with the variable values
58 if ![runto_main] then {
59 perror "couldn't run to breakpoint"
63 proc evaluate { vars ops } {
64 for {set vari 0} {$vari < [llength $vars]} {incr vari} {
65 set var [lindex $vars $vari]
66 for {set opi 0} {$opi < [llength $ops]} {incr opi} {
67 set op [lindex [lindex $ops $opi] 0]
68 set val [lindex [lindex $ops $opi] [expr $vari + 1]]
69 gdb_test "print $var, $op" " = $val" "evaluate $op; variables $var; expecting $val"
87 {x = 0, y = 0} {x = 0, y = 1} {x = 1, y = 0} {x = 1, y = 1}
92 { {!x && !y} 1 0 0 0 }
97 { {!x || !y} 1 1 1 0 }
107 # Full table of &&, || combinations, followed by random mix of unary ops
110 {x = 0, y = 0, z = 0} {x = 0, y = 0, z = 1} {x = 0, y = 1, z = 0} {x = 0, y = 1, z = 1}
111 {x = 1, y = 0, z = 0} {x = 1, y = 0, z = 1} {x = 1, y = 1, z = 0} {x = 1, y = 1, z = 1}
113 { {x && y && z} 0 0 0 0 0 0 0 1 }
114 { {x || y && z} 0 0 0 1 1 1 1 1 }
115 { {x && y || z} 0 1 0 1 0 1 1 1 }
116 { {x || y || z} 0 1 1 1 1 1 1 1 }
118 { {x || !y && z} 0 1 0 0 1 1 1 1 }
119 { {!x || y && z} 1 1 1 1 0 0 0 1 }
120 { {!x || y && !z} 1 1 1 1 0 0 1 0 }
123 # More complex operations
126 {x = 1, y = 2, w = 3, z = 3}
127 {x = 1, y = 2, w = 1, z = 3}
128 {x = 2, y = 2, w = 2, z = 3}
130 { {x > y || w == z} 1 0 0 }
131 { {x >= y && w != z} 0 0 1 }
132 { {! x > y || w + z} 1 1 1 }