1# Copyright 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc.
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# This file is part of the gdb testsuite
18# file written by Elena Zannoni (ezannoni@cygnus.com)
19# rewritten by Michael Chastain (mec.gnu@mindspring.com)
20#
21# source files cttiadd.cc, cttiadd1.cc, cttiadd2.cc, cttiadd3.cc
22
23# Call to template instantiations.
24
25if $tracelevel then {
26    strace $tracelevel
27}
28
29if { [skip_cplus_tests] } { continue }
30
31set testfile "cttiadd"
32set srcfile  "${testfile}.cc"
33set srcfile1 "${testfile}1.cc"
34set srcfile2 "${testfile}2.cc"
35set srcfile3 "${testfile}3.cc"
36set objfile  "${testfile}.o"
37set objfile1 "${testfile}1.o"
38set objfile2 "${testfile}2.o"
39set objfile3 "${testfile}3.o"
40set binfile  "${objdir}/${subdir}/${testfile}"
41
42if { [gdb_compile "$srcdir/$subdir/$srcfile" "$objdir/$subdir/$objfile" object {debug c++}] != "" } {
43     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44}
45
46if { [gdb_compile "$srcdir/$subdir/$srcfile1" "$objdir/$subdir/$objfile1" object {debug c++}] != "" } {
47     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
48}
49
50if { [gdb_compile "$srcdir/$subdir/$srcfile2" "$objdir/$subdir/$objfile2" object {debug c++}] != "" } {
51     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
52}
53
54if { [gdb_compile "$srcdir/$subdir/$srcfile3" "$objdir/$subdir/$objfile3" object {debug c++}] != "" } {
55     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
56}
57
58if { [gdb_compile "$objdir/$subdir/$objfile $objdir/$subdir/$objfile1 $objdir/$subdir/$objfile2 $objdir/$subdir/$objfile3" "${binfile}" executable {debug c++}] != "" } {
59     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
60}
61
62if [get_compiler_info ${binfile} "c++"] {
63    return -1;
64}
65
66gdb_exit
67gdb_start
68gdb_reinitialize_dir $srcdir/$subdir
69gdb_load ${binfile}
70
71if ![runto_main] then {
72    perror "couldn't run to breakpoint"
73    continue
74}
75
76gdb_breakpoint [gdb_get_line_number "marker add1"]
77gdb_continue_to_breakpoint "marker add1"
78
79gdb_test "print c" "\\$\[0-9\]+ = 194 .*"
80gdb_test "print f" "\\$\[0-9\]+ = 9"
81gdb_test "print i" "\\$\[0-9\]+ = 4"
82
83# TODO: this needs more work before actually deploying it.
84# So bail out here.
85
86if { [ test_compiler_info gcc-*] } then { continue }
87
88gdb_test_multiple "print add<int>(2,2)" "print add<int>(2,2)" {
89    -re "\\$\[0-9\]+ = 4\r\n$gdb_prompt $" {
90	pass "print add<int>(2,2)"
91    }
92    -re "No symbol \"add<int>\" in current context.\r\n$gdb_prompt $" {
93	# TODO: kfail or xfail this
94	fail "print add<int>(2,2)"
95    }
96}
97
98# Note: 2.25 and 4.5 are exactly representable in IEEE-ish formats
99gdb_test_multiple "print add<float>(2.25,2.25)" "print add<float>(2.25,2.25)" {
100    -re "\\$\[0-9\]+ = 4\\.5\r\n$gdb_prompt $" {
101	pass "print add<float>(2.25,2.25)"
102    }
103    -re "No symbol \"add<float>\" in current context.\r\n$gdb_prompt $" {
104	# TODO: kfail or xfail this
105	fail "print add<float>(2.25,2.25)"
106    }
107}
108
109gdb_test_multiple "print add<unsigned char>('A','A')" "print add<unsigned char>('A','A')" {
110    -re "\\$\[0-9\]+ = -126 .*\r\n$gdb_prompt $" {
111	pass "print add<unsigned char>('A','A')"
112    }
113    -re "No symbol \"add<unsigned char>\" in current context.\r\n$gdb_prompt $" {
114	# TODO: kfail or xfail this
115	fail "print add<unsigned char>('A','A')"
116    }
117}
118
119gdb_test_multiple "print add2<int>(2,2)" "print add2<int>(2,2)" {
120    -re "\\$\[0-9\]+ = 4\r\n$gdb_prompt $" {
121	pass "print add2<int>(2,2)"
122    }
123    -re "No symbol \"add2<int>\" in current context.\r\n$gdb_prompt $" {
124	# TODO: kfail or xfail this
125	fail "print add2<int>(2,2)"
126    }
127}
128
129gdb_test_multiple "print add2<float>(2.25,2.25)" "print add2<float>(2.25,2.25)" {
130    -re "\\$\[0-9\]+ = 4\\.5\r\n$gdb_prompt $" {
131	pass "print add2<float>(2.25,2.25)"
132    }
133    -re "No symbol \"add2<float>\" in current context.\r\n$gdb_prompt $" {
134	# TODO: kfail or xfail this
135	fail "print add2<float>(2.25,2.25)"
136    }
137}
138
139gdb_test_multiple "print add2<unsigned char>('A','A')" "print add2<unsigned char>('A','A')" {
140    -re "\\$\[0-9]+ = -126 .*$gdb_prompt $" {
141	pass "print add2<unsigned char>('A','A')"
142    }
143    -re "No symbol \"add2<unsigned char>\" in current context.\r\n$gdb_prompt $" {
144	# TODO: kfail or xfail this
145	fail "print add2<unsigned char>('A','A')"
146    }
147}
148
149gdb_test_multiple "print add3<int>(2,2)" "print add3<int>(2,2)" {
150    -re "\\$\[0-9\]+ = 4\r\n$gdb_prompt $" {
151	pass "print add3<int>(2,2)"
152    }
153    -re "No symbol \"add3<int>\" in current context.\r\n$gdb_prompt $" {
154	# TODO: kfail or xfail this
155	fail "print add3<int>(2,2)"
156    }
157}
158
159gdb_test_multiple "print add3<float>(2.25,2.25)" "print add3<float>(2.25,2.25)" {
160    -re "\\$\[0-9\]+ = 4\\.5\r\n$gdb_prompt $" {
161	pass "print add3<float>(2.25,2.25)"
162    }
163    -re "No symbol \"add3<float>\" in current context.\r\n$gdb_prompt $" {
164	# TODO: kfail or xfail this
165	fail "print add3<float>(2.25,2.25)"
166    }
167}
168
169gdb_test_multiple "print add3<unsigned char>('A','A')" "print add3<unsigned char>('A','A')" {
170    -re "\\$\[0-9]+ = -126 .*$gdb_prompt $" {
171	pass "print add3<unsigned char>('A','A')"
172    }
173    -re "No symbol \"add3<unsigned char>\" in current context.\r\n$gdb_prompt $" {
174	# TODO: kfail or xfail this
175	fail "print add3<unsigned char>('A','A')"
176    }
177}
178
179gdb_test_multiple "print add4<int>(2,2)" "print add4<int>(2,2)" {
180    -re "\\$\[0-9\]+ = 4\r\n$gdb_prompt $" {
181	pass "print add4<int>(2,2)"
182    }
183    -re "No symbol \"add4<int>\" in current context.\r\n$gdb_prompt $" {
184	# TODO: kfail or xfail this
185	fail "print add4<int>(2,2)"
186    }
187}
188
189gdb_test_multiple "print add4<float>(2.25,2.25)" "print add4<float>(2.25,2.25)" {
190    -re "\\$\[0-9\]+ = 4\\.5\r\n$gdb_prompt $" {
191	pass "print add4<float>(2.25,2.25)"
192    }
193    -re "No symbol \"add4<float>\" in current context.\r\n$gdb_prompt $" {
194	# TODO: kfail or xfail this
195	fail "print add4<float>(2.25,2.25)"
196    }
197}
198
199gdb_test_multiple "print add4<unsigned char>('A','A')" "print add4<unsigned char>('A','A')" {
200    -re "\\$\[0-9]+ = -126 .*$gdb_prompt $" {
201	pass "print add4<unsigned char>('A','A')"
202    }
203    -re "No symbol \"add4<unsigned char>\" in current context.\r\n$gdb_prompt $" {
204	# TODO: kfail or xfail this
205	fail "print add4<unsigned char>('A','A')"
206    }
207}
208