Commit | Line | Data |
---|---|---|
6aba47ca | 1 | # Copyright 1998, 1999, 2007 Free Software Foundation, Inc. |
c906108c SS |
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 2 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, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Elena Zannoni (ezannoni@cygnus.com) | |
21 | ||
22 | # This file is part of the gdb testsuite | |
23 | ||
24 | # | |
25 | # test of evaluation of conditional expressions, with constants and | |
26 | # variables. Using the print and the whatis command | |
27 | # written with the only purpose in mind to cover the holes in the | |
28 | # eval.c file | |
29 | # | |
30 | # source file "int-type.c" | |
31 | # | |
32 | ||
33 | ||
34 | if $tracelevel then { | |
35 | strace $tracelevel | |
36 | } | |
37 | ||
38 | # Check to see if we have an executable to test. If not, then either we | |
39 | # haven't tried to compile one, or the compilation failed for some reason. | |
40 | # In either case, just notify the user and skip the tests in this file. | |
41 | ||
42 | set testfile "int-type" | |
43 | set srcfile ${testfile}.c | |
44 | set binfile ${objdir}/${subdir}/${testfile} | |
fc91c6c2 | 45 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug nowarnings}] != "" } { |
b60f0898 JB |
46 | untested cond-expr.exp |
47 | return -1 | |
c906108c SS |
48 | } |
49 | ||
50 | ||
51 | gdb_exit | |
52 | gdb_start | |
53 | gdb_reinitialize_dir $srcdir/$subdir | |
54 | gdb_load ${binfile} | |
55 | ||
56 | ||
57 | if ![runto_main] then { | |
58 | perror "couldn't run to breakpoint" | |
59 | continue | |
60 | } | |
61 | ||
62 | send_gdb "print (2 ? 3 : 4)\n" | |
63 | gdb_expect { | |
64 | -re ".\[0-9\]* = 3.*$gdb_prompt $" { | |
65 | pass "print value of cond expr (const true)" | |
66 | } | |
67 | -re ".*$gdb_prompt $" { fail "print value of cond expr (const true)" } | |
68 | timeout { fail "(timeout) print value of cond expr (const true)" } | |
69 | } | |
70 | ||
71 | send_gdb "print (0 ? 3 : 4)\n" | |
72 | gdb_expect { | |
73 | -re ".\[0-9\]* = 4.*$gdb_prompt $" { | |
74 | pass "print value of cond expr (const false)" | |
75 | } | |
76 | -re ".*$gdb_prompt $" { fail "print value of cond expr (const false)" } | |
77 | timeout { fail "(timeout) print value of cond expr (const false)" } | |
78 | } | |
79 | ||
80 | gdb_test "set variable x=14" "" "set variable x=14" | |
81 | gdb_test "set variable y=2" "" "set variable y=2" | |
82 | gdb_test "set variable z=3" "" "set variable z=3" | |
83 | ||
84 | send_gdb "print (x ? y : z)\n" | |
85 | gdb_expect { | |
86 | -re ".\[0-9\]* = 2.*$gdb_prompt $" { | |
87 | pass "print value of cond expr (var true)" | |
88 | } | |
89 | -re ".*$gdb_prompt $" { fail "print value of cond expr (var true)" } | |
90 | timeout { fail "(timeout) print value of cond expr (var true)" } | |
91 | } | |
92 | ||
93 | gdb_test "set variable x=0" "" "set variable x=0" | |
94 | ||
95 | send_gdb "print (x ? y : z)\n" | |
96 | gdb_expect { | |
97 | -re ".\[0-9\]* = 3.*$gdb_prompt $" { | |
98 | pass "print value of cond expr (var false)" | |
99 | } | |
100 | -re ".*$gdb_prompt $" { fail "print value of cond expr (var false)" } | |
101 | timeout { fail "(timeout) print value of cond expr (var false)" } | |
102 | } | |
103 | ||
104 | ||
105 | send_gdb "whatis (0 ? 3 : 4)\n" | |
106 | gdb_expect { | |
107 | -re "type = int.*$gdb_prompt $" { | |
108 | pass "print whatis of cond expr" | |
109 | } | |
110 | -re ".*$gdb_prompt $" { fail "print whatis of cond expr" } | |
111 | timeout { fail "(timeout) print whatis of cond expr" } | |
112 | } | |
113 | ||
114 | ||
115 | ||
116 | ||
117 | ||
118 | ||
119 | ||
120 | ||
121 | ||
122 | ||
123 |