Commit | Line | Data |
---|---|---|
d4f3574e | 1 | # Tests of overloaded operators resolution. |
6e19e2bf | 2 | # Copyright 1998, 1999, 2002, 2004 Free Software Foundation, Inc. |
c906108c SS |
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 2 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, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
c906108c SS |
18 | # written by Elena Zannoni (ezannoni@cygnus.com) |
19 | # | |
c906108c SS |
20 | # source file "userdef.cc" |
21 | # | |
22 | ||
c906108c SS |
23 | if $tracelevel then { |
24 | strace $tracelevel | |
25 | } | |
26 | ||
d4f3574e | 27 | if { [skip_cplus_tests] } { continue } |
c906108c SS |
28 | |
29 | set testfile "userdef" | |
30 | set srcfile ${testfile}.cc | |
31 | set binfile ${objdir}/${subdir}/${testfile} | |
32 | ||
33 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
34 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
35 | } | |
36 | ||
37 | ||
38 | gdb_exit | |
39 | gdb_start | |
40 | gdb_reinitialize_dir $srcdir/$subdir | |
41 | gdb_load ${binfile} | |
42 | ||
43 | ||
44 | if ![runto_main] then { | |
45 | perror "couldn't run to breakpoint" | |
46 | continue | |
47 | } | |
48 | ||
49 | send_gdb "break marker1\n" ; gdb_expect -re ".*$gdb_prompt $" | |
50 | send_gdb "cont\n" | |
51 | gdb_expect { | |
5178b9d6 | 52 | -re "Break.* marker1(\\(\\)|) \\(\\) at .*:$decimal.*$gdb_prompt $" { |
c906108c SS |
53 | send_gdb "up\n" |
54 | gdb_expect { | |
55 | -re ".*$gdb_prompt $" { pass "up from marker1" } | |
56 | timeout { fail "up from marker1" } | |
57 | } | |
58 | } | |
59 | -re "$gdb_prompt $" { fail "continue to marker1" } | |
60 | timeout { fail "(timeout) continue to marker1" } | |
61 | } | |
62 | ||
63 | ||
fb8acdcc DJ |
64 | gdb_test "print one + two" "\\\$\[0-9\]* = {x = 6, y = 8}" |
65 | ||
5624293a JB |
66 | # If GDB fails to restore the selected frame properly after the |
67 | # inferior function call above (see GDB PR 1155 for an explanation of | |
68 | # why this might happen), all the subsequent tests will fail. We | |
69 | # should detect report that failure, but let the marker call finish so | |
70 | # that the rest of the tests can run undisturbed. | |
71 | gdb_test_multiple "frame" "re-selected 'main' frame after inferior call" { | |
72 | -re "#0 marker1.*$gdb_prompt $" { | |
73 | setup_kfail "gdb/1155" s390-*-linux-gnu | |
74 | fail "re-selected 'main' frame after inferior call" | |
93201743 | 75 | gdb_test "finish" ".*main.*at .*userdef.cc:.*// marker1-returns-here.*" \ |
5624293a JB |
76 | "finish call to marker1" |
77 | } | |
78 | -re "#1 ($hex in )?main.*$gdb_prompt $" { | |
79 | pass "re-selected 'main' frame after inferior call" | |
80 | } | |
81 | } | |
82 | ||
fb8acdcc DJ |
83 | gdb_test "print one - two" "\\\$\[0-9\]* = {x = -2, y = -2}" |
84 | ||
85 | gdb_test "print one * two" "\\\$\[0-9\]* = {x = 8, y = 15}" | |
86 | ||
87 | gdb_test "print one / two" "\\\$\[0-9\]* = {x = 0, y = 0}" | |
88 | ||
89 | gdb_test "print one % two" "\\\$\[0-9\]* = {x = 2, y = 3}" | |
90 | ||
91 | gdb_test "print one && two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
92 | ||
93 | gdb_test "print one || two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
94 | ||
95 | gdb_test "print one & two" "\\\$\[0-9\]* = {x = 0, y = 1}" | |
96 | ||
97 | gdb_test "print one | two" "\\\$\[0-9\]* = {x = 6, y = 7}" | |
98 | ||
99 | gdb_test "print one ^ two" "\\\$\[0-9\]* = {x = 6, y = 6}" | |
100 | ||
101 | gdb_test "print one < two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
102 | ||
103 | gdb_test "print one <= two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
104 | ||
105 | gdb_test "print one > two" "\\\$\[0-9\]* = 0\[\r\n\]" | |
106 | ||
107 | gdb_test "print one >= two" "\\\$\[0-9\]* = 0\[\r\n\]" | |
108 | ||
109 | gdb_test "print one == two" "\\\$\[0-9\]* = 0\[\r\n\]" | |
110 | ||
111 | gdb_test "print one != two" "\\\$\[0-9\]* = 1\[\r\n\]" | |
112 | ||
113 | # Can't really check the output of this one without knowing | |
114 | # target integer width. Make sure we don't try to call | |
115 | # the iostreams operator instead, though. | |
116 | gdb_test "print one << 31" "\\\$\[0-9\]* = {x = -?\[0-9\]*, y = -?\[0-9\]*}" | |
117 | ||
118 | # Should be fine even on < 32-bit targets. | |
119 | gdb_test "print one >> 31" "\\\$\[0-9\]* = {x = 0, y = 0}" | |
120 | ||
121 | gdb_test "print !one" "\\\$\[0-9\]* = 0\[\r\n\]" | |
122 | ||
123 | # Assumes 2's complement. So does everything... | |
36e9969c NS |
124 | gdb_test "print +one" "\\\$\[0-9\]* = {x = 2, y = 3}" |
125 | ||
fb8acdcc DJ |
126 | gdb_test "print ~one" "\\\$\[0-9\]* = {x = -3, y = -4}" |
127 | ||
128 | gdb_test "print -one" "\\\$\[0-9\]* = {x = -2, y = -3}" | |
129 | ||
130 | gdb_test "print one++" "\\\$\[0-9\]* = {x = 2, y = 4}" | |
131 | ||
132 | gdb_test "print ++one" "\\\$\[0-9\]* = {x = 3, y = 4}" | |
133 | ||
134 | gdb_test "print one--" "\\\$\[0-9\]* = {x = 3, y = 3}" | |
135 | ||
136 | gdb_test "print --one" "\\\$\[0-9\]* = {x = 2, y = 3}" | |
137 | ||
138 | gdb_test "print one += 7" "\\\$\[0-9\]* = {x = 9, y = 10}" | |
139 | ||
140 | gdb_test "print two = one" "\\\$\[0-9\]* = {x = 9, y = 10}" | |
c906108c | 141 | |
13b57657 | 142 | # Check that GDB tolerates whitespace in operator names. |
36e9969c NS |
143 | gdb_test "break A2::'operator+'" ".*Breakpoint $decimal at.*" |
144 | gdb_test "break A2::'operator +'" ".*Breakpoint $decimal at.*" | |
13b57657 | 145 | |
c906108c SS |
146 | gdb_exit |
147 | return 0 |