OSDN Git Service

a1bae8cc530f04530498786518bac54e96daf5d2
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.gdbtk / srcwin.test
1 #   Copyright (C) 1999, 2001 Red Hat, 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 was written by Martin Hunt (hunt@cygnus.com)
18
19 # Read in the standard defs file
20
21 if {![gdbtk_read_defs]} {
22   break
23 }
24
25 global objdir srcdir
26
27
28 # move the pointer to the center of the bbox relative to $win
29 proc move_mouse_to {win bbox} {
30   if {[llength $bbox] != 4} {
31     return 0
32   }
33   set x [expr [lindex $bbox 0] + [lindex $bbox 2] / 2]
34   set y [expr [lindex $bbox 1] + [lindex $bbox 3] / 2]
35   warp_pointer . [winfo rootx $win] [winfo rooty $win]
36
37   set nx 0
38   set ny 0
39
40   while {$nx != $x || $ny != $y} {
41     if {$nx < $x} {incr nx}
42     if {$ny < $y} {incr ny}
43     warp_pointer $win $nx $ny
44   }
45   return 1
46 }
47
48 proc click {win bbox bnum} {
49   if {![move_mouse_to $win $bbox]} {
50     return 0
51   }
52   update
53
54   set x [expr [lindex $bbox 0] + [lindex $bbox 2] / 2]
55   set y [expr [lindex $bbox 1] + [lindex $bbox 3] / 2]
56
57   if {[catch {event generate $win <Button-$bnum> -x $x -y $y} result]} {
58     return 0
59   }
60   if {[catch {event generate $win <ButtonRelease-$bnum> -x $x -y $y} result]} {
61     return 0
62   }
63   return 1
64 }
65
66
67 #####                 #####
68 #                         #
69 #  SECTION 1: Mode Tests  #
70 #                         #
71 #####                 #####
72
73 # Load the test executable
74 set program [file join $objdir list]
75 if {[catch {gdbtk_test_file $program} t]} {
76   # This isn't a test case, since if this fails, we're hosed.
77   gdbtk_test_error "loading \"$program\": $t"
78 }
79
80 set srcwin [ManagedWin::open SrcWin]
81 set stw [$srcwin test_get twin]
82 set twin [$stw test_get twin]
83
84 # get things started
85 gdb_cmd "break main"
86 gdbtk_test_run
87
88 # Test: srcwin-1.1
89 # Desc: Check for something in source window
90 gdbtk_test srcwin-1.1 "source window has contents" {
91   set file1(source) [$twin get 1.0 end]
92   expr {![string compare $file1(source) ""]}
93 } {0}
94
95
96 # Test: srcwin-1.2
97 # Desc: source->assembly mode change
98 gdbtk_test srcwin-1.2 "source->assembly mode change" {
99   $srcwin mode "" ASSEMBLY
100   set twin [$stw test_get twin]
101   set file1(assembly) [$twin get 1.0 end]
102   expr {![string compare $file1(source) $file1(assembly)]}
103 } {0}
104
105 # Test: srcwin-1.3
106 # Desc: assembly->mixed mode change
107 gdbtk_test srcwin-1.3 "assembly->mixed mode change" {
108   $srcwin mode "" MIXED
109   set twin [$stw test_get twin]
110   set file1(mixed) [$twin get 1.0 end]
111   expr {![string compare $file1(mixed) $file1(assembly)]}
112 } {0}
113
114 # Test: srcwin-1.4
115 # Desc: mixed->src+asm mode change
116 gdbtk_test srcwin-1.4 "mixed->src+asm mode change" {
117   $srcwin mode "" SRC+ASM
118   set twin [$stw test_get twin]
119   set bwin [$stw test_get bwin]
120   set s [$twin get 1.0 end]
121   set a [$bwin get 1.0 end]
122   list [string compare $a $file1(assembly)] [string compare $s $file1(source)] [winfo ismapped $bwin]
123 } {0 0 1}
124
125 # Test: srcwin-1.5
126 # Desc: src+asm->source mode change
127 gdbtk_test srcwin-1.5 "src+asm->source mode change" {
128   $srcwin mode "" SOURCE
129   set twin [$stw test_get twin]
130   set a [$twin get 1.0 end]
131   set bwin [$stw test_get bwin]
132   list [string compare $file1(source) $a] [winfo ismapped $bwin]
133 } {0 0}
134
135 # Test: srcwin-1.6
136 # Desc: source->mixed mode change
137 gdbtk_test srcwin-1.6 "source->mixed mode change" {
138   $srcwin mode "" MIXED
139   set twin [$stw test_get twin]
140   set a [$twin get 1.0 end]
141   string compare $file1(mixed) $a
142 } {0}
143
144 # Test: srcwin-1.7
145 # Desc: mixed->source mode change
146 gdbtk_test srcwin-1.7 "mixed->source mode change" {
147   $srcwin mode "" SOURCE
148   set twin [$stw test_get twin]
149   set a [$twin get 1.0 end]
150   string compare $file1(source) $a
151 } {0}
152
153 # Test: srcwin-1.8
154 # Desc: source->src+asm mode change
155 gdbtk_test srcwin-1.8 "source->src+asm mode change" {
156   $srcwin mode "" SRC+ASM
157   set twin [$stw test_get twin]
158   set bwin [$stw test_get bwin]
159   set s [$twin get 1.0 end]
160   set a [$bwin get 1.0 end]
161   list [string compare $a $file1(assembly)] [string compare $s $file1(source)] [winfo ismapped $bwin]
162 } {0 0 1}
163
164 # Test: srcwin-1.9
165 # Desc: src+asm->assembly mode change
166 gdbtk_test srcwin-1.9 "src+asm->assembly mode change" {
167   $srcwin mode "" ASSEMBLY
168   set twin [$stw test_get twin]
169   set a [$twin get 1.0 end]
170   string compare $file1(assembly) $a
171 } {0}
172
173 # Test: srcwin-1.10
174 # Desc: assembly->src+asm mode change
175 gdbtk_test srcwin-1.10 "assembly->src+asm mode change" {
176   $srcwin mode "" SRC+ASM
177   set twin [$stw test_get twin]
178   set bwin [$stw test_get bwin]
179   set s [$twin get 1.0 end]
180   set a [$bwin get 1.0 end]
181   list [string compare $a $file1(assembly)] [string compare $s $file1(source)] [winfo ismapped $bwin]
182 } {0 0 1}
183
184 # Test: srcwin-1.11
185 # Desc: src+asm->mixed mode change
186 gdbtk_test srcwin-1.11 "src+asm->mixed mode change" {
187   $srcwin mode "" MIXED
188   set twin [$stw test_get twin]
189   set a [$twin get 1.0 end]
190   set bwin [$stw test_get bwin]
191   expr {[string compare $file1(mixed) $a] ||
192         [winfo ismapped $bwin]}
193 } {0}
194
195 # Test: srcwin-1.12
196 # Desc: mixed->assembly mode change
197 gdbtk_test srcwin-1.12 "mixed->assembly mode change" {
198   $srcwin mode "" ASSEMBLY
199   set twin [$stw test_get twin]
200   set a [$twin get 1.0 end]
201   string compare $file1(assembly) $a
202 } {0}
203
204 # Test: srcwin-1.13
205 # Desc: assembly->source mode change
206 gdbtk_test srcwin-1.13 "assembly->source mode change" {
207   $srcwin mode "" SOURCE
208   set twin [$stw test_get twin]
209   set a [$twin get 1.0 end]
210   string compare $file1(source) $a
211 } {0}
212
213
214 #####                       #####
215 #                               #
216 #  SECTION 2: Basic Operations  #
217 #                               #
218 #####                       #####
219
220 # Test: srcwin-2.1
221 # Desc: check contents of filename combobox
222 gdbtk_test srcwin-2.1 "check contents of filename combobox" {
223   set statbar [$srcwin test_get _statbar]
224   set names [$statbar.name list get 0 end]
225   set r 0
226   foreach f {list0.c list1.c} {
227     if {[lsearch $names $f] != -1} {
228       incr r
229     }
230   }
231   set r
232 } {2}
233
234 # Test: srcwin-2.2
235 # Desc: check contents of function combobox
236 gdbtk_test srcwin-2.2 "check contents of function combobox" {
237   set names [$statbar.func list get 0 end]
238   set r 0
239   foreach f {main foo unused} {
240     if {[lsearch $names $f] != -1} {
241       incr r
242     }
243   }
244   set r
245 } {3}
246
247 # Test: srcwin-2.3
248 # Desc: goto filename
249 gdbtk_test srcwin-2.3 "goto filename" {
250   set func [$srcwin test_get _name 1]
251   $func "" list1.c
252   set twin [$stw test_get twin]
253   set file2(source) [$twin get 1.0 end]
254   expr {![string compare $file1(source) $file2(source)]}
255 } {0}
256
257 # Test: srcwin-2.4
258 # Desc: check contents of function combobox
259 gdbtk_test srcwin-2.4 "check contents of function combobox" {
260   set names [$statbar.func list get 0 end]
261   set r 0
262   foreach f {bar long_line oof unused} {
263     if {[lsearch $names $f] != -1} {
264       incr r
265     }
266   }
267   set r
268 } {4}
269
270 # Test: srcwin-2.5
271 # Desc: function combobox entry field should be empty after switching to a new file
272 gdbtk_test srcwin-2.5 "function combobox entry field should be empty" {
273   set names [$statbar.func get]
274   string length $names
275 } {0}
276
277 # Test: srcwin-2.6
278 # Desc: goto function
279 gdbtk_test srcwin-2.6 "goto function bar" {
280   $srcwin goto_func "" bar
281   set r 0
282
283   # now get a dump of all tags and check that only one line is
284   # marked BROWSE_TAG and no lines are STACK_TAG or PC_TAG.
285
286   # We know that list1.c should have BROWSE_TAG set at index 5.2
287   # for function "bar".  If list1.c is changed or the layout of the source
288   # window is changed, this must be updated.
289   if {![catch {set z [$twin dump -tag 1.0 end]}]} {
290     foreach {k v i} $z {
291       if {$k == "tagon"} {
292         if {$v == "BROWSE_TAG"} {
293           if {$i == "10.2"} {
294             incr r
295           } else {
296             incr r 5
297           }
298         }
299         if {$v == "STACK_TAG"} { incr r 10}
300         if {$v == "PC_TAG"} { incr r 100}
301       }
302     }
303   } else {
304     set r -1
305   }
306
307   if {$r == 1} {
308     # things are OK so far, so just verify the function name is displayed
309     # in the combobox entry field.
310     set names [$statbar.func get]
311     if {[string compare $names "bar"]} {set r -2}
312   }
313   set r
314 } {1}
315
316 # Test: srcwin-2.7
317 # Desc: goto function "oof". This tests that the correct line is highlighted
318 # with BROWSE_TAG and no other lines are highlighted. It also checks that
319 # the combobox has the correct function name in it.  Finally, list1.c
320 # has an extremely long line, line 32, that breaks some functions.  We verify 
321 # that the GDBtk has the correct line number.
322
323 gdbtk_test srcwin-2.7 "goto function oof" {
324   $srcwin goto_func "" oof
325   set r 0
326
327   # now get a dump of all tags and check that only one line is
328   # marked BROWSE_TAG and no lines are STACK_TAG or PC_TAG.
329
330   # We know that list1.c should have BROWSE_TAG set at index 32.2
331   # for function "oof".  If list1.c is changed or the layout of the source
332   # window is changed, this must be updated.
333   if {![catch {set z [$twin dump -tag 1.0 end]}]} {
334     foreach {k v i} $z {
335       if {$k == "tagon"} {
336         if {$v == "BROWSE_TAG"} {
337           if {$i == "38.2"} {
338             set line_number [$twin get "$i wordstart" "$i wordend"]
339             if {$line_number == "38"} {
340               incr r
341             } else {
342               incr r -100
343             }
344           } else {
345             incr r 5
346           }
347         }
348         if {$v == "STACK_TAG"} {incr r 10}
349         if {$v == "PC_TAG"} {incr r 100}
350       }
351     }
352   } else {
353     set r -1
354   }
355
356   if {$r == 1} {
357     # things are OK so far, so just verify the function name is displayed
358     # in the combobox entry field.
359     set names [$statbar.func get]
360     if {[string compare $names "oof"]} {set r -2}
361   }
362   set r
363 } {1}
364
365 # Test: srcwin-2.8
366 # Desc: This test issues a next command while browsing list1.c.
367 # It should display list0.c and highlight the correct line.
368 gdbtk_test srcwin-2.8 "step while browsing" {
369   gdb_immediate "next" 1
370   set r 0
371   set name [$statbar.name get]
372   set func [$statbar.func get]
373
374   # check contents of name and function comboboxes
375   if {$name != "list0.c"} {set r -1}
376   if {$func != "main"} {set r -2}
377
378   # check that correct file is displayed
379   set twin [$stw test_get twin]
380   set a [$twin get 1.0 end]
381   if {[string compare $file1(source) $a]} {set r -3}
382
383   # check for PC_TAG on correct line
384   if {$r == 0} {
385     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
386       foreach {k v i} $z {
387         if {$k == "tagon"} {
388           if {$v == "PC_TAG"} {
389             if {$i == "11.2"} {
390               incr r
391             } else {
392               incr r 5
393             }
394           }
395           if {$v == "STACK_TAG"} {incr r 10}
396           if {$v == "BROWSE_TAG"} {incr r 100}
397         }
398       }
399     } else {
400       set r -4
401     }
402   }
403   set r
404 } {1}
405
406 # Test: srcwin-2.9
407 # Desc: This test issues a next command while the current
408 # PC is ready to call a function.  It should not go into the function and
409 # should update the PC highlight correctly.
410 gdbtk_test srcwin-2.9 "next" {
411   gdb_immediate "next" 1
412   set r 0
413   set name [$statbar.name get]
414   set func [$statbar.func get]
415
416   # check contents of name and function comboboxes
417   if {$name != "list0.c"} {set r -1}
418   if {$func != "main"} {set r -2}
419
420   # check that correct file is displayed
421   set twin [$stw test_get twin]
422   set a [$twin get 1.0 end]
423   if {[string compare $file1(source) $a]} {set r -3}
424
425   # check for PC_TAG on correct line
426   if {$r == 0} {
427     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
428       foreach {k v i} $z {
429         if {$k == "tagon"} {
430           if {$v == "PC_TAG"} {
431             if {$i == "12.2"} {
432               incr r
433             } else {
434               incr r 5
435             }
436           }
437           if {$v == "STACK_TAG"} {incr r 10}
438           if {$v == "BROWSE_TAG"} {incr r 100}
439         }
440       }
441     } else {
442       set r -4
443     }
444   }
445   set r
446 } {1}
447
448 # Test: srcwin-2.10
449 # Desc: This test issues a step command while the current
450 # PC is ready to call a function.  It should step into the function.
451 gdbtk_test srcwin-2.10 "step" {
452   gdb_immediate "step" 1
453   set r 0
454   set name [$statbar.name get]
455   set func [$statbar.func get]
456
457   # check contents of name and function comboboxes
458   if {$name != "list0.h"} {set r -1}
459   if {$func != "foo"} {set r -2}
460
461   # check that a new file is displayed
462   set twin [$stw test_get twin]
463   set file3(source) [$twin get 1.0 end]
464   if {![string compare $file1(source) $file3(source)]} {set r -3}
465
466   # check for PC_TAG on correct line
467   if {$r == 0} {
468     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
469       foreach {k v i} $z {
470         if {$k == "tagon"} {
471           if {$v == "PC_TAG"} {
472             if {$i == "9.2"} {
473               incr r
474             } else {
475               incr r 5
476             }
477           }
478           if {$v == "STACK_TAG"} {incr r 10}
479           if {$v == "BROWSE_TAG"} {incr r 100}
480         }
481       }
482     } else {
483       set r -4
484     }
485   }
486   set r
487 } {1}
488
489 # Test: srcwin-2.11
490 # Desc: This test issues a break and a continue
491 gdbtk_test srcwin-2.11 "set BP and continue" {
492   gdb_immediate "break oof" 1
493   gdb_immediate "continue" 1
494   set r 0
495   set name [$statbar.name get]
496   set func [$statbar.func get]
497
498   # check contents of name and function comboboxes
499   if {$name != "list1.c"} {set r -1}
500   if {$func != "oof"} {set r -2}
501
502   # check that the correct file is displayed
503   # we must clear the breakpoint first so it doesn't mess up the
504   # comparison...
505   gdb_immediate "clear oof" 1  
506   set twin [$stw test_get twin]
507   set a [$twin get 1.0 end]
508   if {[string compare $file2(source) $a]} {set r -3}
509   
510   # check for PC_TAG on correct line
511   if {$r == 0} {
512     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
513       foreach {k v i} $z {
514         if {$k == "tagon"} {
515           if {$v == "PC_TAG"} {
516             if {$i == "38.2"} {
517               incr r
518             } else {
519               incr r 5
520             }
521           }
522           if {$v == "STACK_TAG"} {incr r 10}
523           if {$v == "BROWSE_TAG"} {incr r 100}
524         }
525       }
526     } else {
527       set r -4
528     }
529   }
530   set r
531 } {1}
532
533 #####                       #####
534 #                               #
535 #  SECTION 3: Stack Operations  #
536 #                               #
537 #####                       #####
538
539 # Test: srcwin-3.1
540 # Desc: This tests "stack up" 
541 gdbtk_test srcwin-3.1 "stack up (1)" {
542   $srcwin stack up
543   set r 0
544   set name [$statbar.name get]
545   set func [$statbar.func get]
546
547   # check contents of name and function comboboxes
548   if {$name != "list1.c"} {set r -1}
549   if {$func != "long_line"} {set r -2}
550
551   # check that the correct file is displayed
552   set twin [$stw test_get twin]
553   set a [$twin get 1.0 end]
554   if {[string compare $file2(source) $a]} {set r -3}
555   
556   # check for PC_TAG and STACK_TAG on correct lines
557   if {$r == 0} {
558     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
559       foreach {k v i} $z {
560         if {$k == "tagon"} {
561           if {$v == "PC_TAG"} {
562             # return n + 1;
563             if {$i == "38.2"} {
564               incr r
565             } else {
566               incr r 5
567             }
568           }
569           if {$v == "STACK_TAG"} {
570             # oof (67);
571             if {$i == "26.2"} {
572               incr r
573             } else {
574               incr r 10
575             }
576           }
577           if {$v == "BROWSE_TAG"} {incr r 100}
578         }
579       }
580     } else {
581       set r -4
582     }
583   }
584   set r
585 } {2}
586
587 # Test: srcwin-3.2
588 # Desc: Another "stack up"  test
589 gdbtk_test srcwin-3.2 "stack up (2)" {
590   $srcwin stack up
591   set r 0
592   set name [$statbar.name get]
593   set func [$statbar.func get]
594
595   # check contents of name and function comboboxes
596   if {$name != "list1.c"} {set r -1}
597   if {$func != "bar"} {set r -2}
598
599   # check that the correct file is displayed
600   set twin [$stw test_get twin]
601   set a [$twin get 1.0 end]
602   if {[string compare $file2(source) $a]} {set r -3}
603   
604   # check for PC_TAG and STACK_TAG on correct lines
605   if {$r == 0} {
606     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
607       foreach {k v i} $z {
608         if {$k == "tagon"} {
609           if {$v == "PC_TAG"} {
610             # return n + 1;
611             if {$i == "38.2"} {
612               incr r
613             } else {
614               incr r 5
615             }
616           }
617           if {$v == "STACK_TAG"} {
618             # long_line ();
619             if {$i == "12.2"} {
620               incr r
621             } else {
622               incr r 10
623             }
624           }
625           if {$v == "BROWSE_TAG"} {incr r 100}
626         }
627       }
628     } else {
629       set r -4
630     }
631   }
632   set r
633 } {2}
634
635 # Test: srcwin-3.3
636 # Desc: Another "stack up"  test
637 gdbtk_test srcwin-3.3 "stack up (3)" {
638   $srcwin stack up
639   set r 0
640   set name [$statbar.name get]
641   set func [$statbar.func get]
642
643   # check contents of name and function comboboxes
644   if {$name != "list0.h"} {set r -1}
645   if {$func != "foo"} {set r -2}
646
647   # check that the correct file is displayed
648   set twin [$stw test_get twin]
649   set a [$twin get 1.0 end]
650   if {![string compare $file2(source) $a]} {set r -3}
651   
652   # check for PC_TAG and STACK_TAG on correct lines
653   if {$r == 0} {
654     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
655       foreach {k v i} $z {
656         if {$k == "tagon"} {
657           if {$v == "STACK_TAG"} {
658             if {$i == "9.2"} {
659               incr r
660             } else {
661               incr r 5
662             }
663           }
664           if {$v == "PC_TAG"} {incr r 10}
665           if {$v == "BROWSE_TAG"} {incr r 100}
666         }
667       }
668     } else {
669       set r -4
670     }
671   }
672   set r
673 } {1}
674
675 # Test: srcwin-3.4
676 # Desc: Another "stack up"  test
677 gdbtk_test srcwin-3.4 "stack up (4)" {
678   $srcwin stack up
679   set r 0
680   set name [$statbar.name get]
681   set func [$statbar.func get]
682
683   # check contents of name and function comboboxes
684   if {$name != "list0.c"} {set r -1}
685   if {$func != "main"} {set r -2}
686
687   # check that the correct file is displayed
688   set twin [$stw test_get twin]
689   set a [$twin get 1.0 end]
690   if {[string compare $file1(source) $a]} {set r -3}
691   
692   # check for PC_TAG and STACK_TAG on correct lines
693   if {$r == 0} {
694     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
695       foreach {k v i} $z {
696         if {$k == "tagon"} {
697           if {$v == "STACK_TAG"} {
698             if {$i == "12.2"} {
699               incr r
700             } else {
701               incr r 5
702             }
703           }
704           if {$v == "PC_TAG"} {incr r 10}
705           if {$v == "BROWSE_TAG"} {incr r 100}
706         }
707       }
708     } else {
709       set r -4
710     }
711   }
712   set r
713 } {1}
714
715 # Disabled for now because there are different correct results.
716 # Test should be rewritten to include those.
717 # Test: srcwin-3.5
718 # Desc: "stack up" when we are at the top
719 #gdbtk_test srcwin-3.5 "stack up when at the top" {
720 #  $srcwin stack up
721 #  set r 0
722 #  set name [$statbar.name get]
723 #  set func [$statbar.func get]
724 #
725   # check contents of name and function comboboxes
726 #  if {$name != "list0.c"} {set r -1}
727 #  if {$func != "main"} {set r -2}
728
729   # check that the correct file is displayed
730 #  set twin [$stw test_get twin]
731 #  set a [$twin get 1.0 end]
732 #  if {[string compare $file1(source) $a]} {set r -3}
733   
734   # check for PC_TAG and STACK_TAG on correct lines
735 #  if {$r == 0} {
736 #    if {![catch {set z [$twin dump -tag 1.0 end]}]} {
737 #      foreach {k v i} $z {
738 #       if {$k == "tagon"} {
739 #         if {$v == "STACK_TAG"} {
740 #           if {$i == "12.2"} {
741 #             incr r
742 #           } else {
743 #             incr r 5
744 #           }
745 #         }
746 #         if {$v == "PC_TAG"} {incr r 10}
747 #         if {$v == "BROWSE_TAG"} {incr r 100}
748 #       }
749 #      }
750 #    } else {
751 #      set r -4
752 #    }
753 #  }
754 #  set r
755 #} {1}
756
757 # Test: srcwin-3.6
758 # Desc: "stack down"  test
759 gdbtk_test srcwin-3.6 "stack down" {
760   $srcwin stack down
761   set r 0
762   set name [$statbar.name get]
763   set func [$statbar.func get]
764
765   # check contents of name and function comboboxes
766   if {$name != "list0.h"} {set r -1}
767   if {$func != "foo"} {set r -2}
768
769   # check that the correct file is displayed
770   set twin [$stw test_get twin]
771   set a [$twin get 1.0 end]
772   if {![string compare $file2(source) $a]} {set r -3}
773   
774   # check for PC_TAG and STACK_TAG on correct lines
775   if {$r == 0} {
776     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
777       foreach {k v i} $z {
778         if {$k == "tagon"} {
779           if {$v == "STACK_TAG"} {
780             if {$i == "9.2"} {
781               incr r
782             } else {
783               incr r 5
784             }
785           }
786           if {$v == "PC_TAG"} {incr r 10}
787           if {$v == "BROWSE_TAG"} {incr r 100}
788         }
789       }
790     } else {
791       set r -4
792     }
793   }
794   set r
795 } {1}
796
797 # Test: srcwin-3.7
798 # Desc: "stack bottom"  test
799 gdbtk_test srcwin-3.7 "stack bottom" {
800   $srcwin stack bottom
801   set r 0
802   set name [$statbar.name get]
803   set func [$statbar.func get]
804
805   # check contents of name and function comboboxes
806   if {$name != "list1.c"} {set r -1}
807   if {$func != "oof"} {set r -2}
808
809   # check that the correct file is displayed
810   set twin [$stw test_get twin]
811   set a [$twin get 1.0 end]
812   if {[string compare $file2(source) $a]} {set r -3}
813   
814   # check for PC_TAG on correct line
815   if {$r == 0} {
816     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
817       foreach {k v i} $z {
818         if {$k == "tagon"} {
819           if {$v == "PC_TAG"} {
820             if {$i == "38.2"} {
821               incr r
822             } else {
823               incr r 5
824             }
825           }
826           if {$v == "STACK_TAG"} {incr r 10}
827           if {$v == "BROWSE_TAG"} {incr r 100}
828         }
829       }
830     } else {
831       set r -4
832     }
833   }
834   set r
835 } {1}
836
837 # Test: srcwin-3.8
838 # Desc: "stack down" when at bottom
839 gdbtk_test srcwin-3.8 "stack down when at bottom" {
840   $srcwin stack down
841   set r 0
842   set name [$statbar.name get]
843   set func [$statbar.func get]
844
845   # check contents of name and function comboboxes
846   if {$name != "list1.c"} {set r -1}
847   if {$func != "oof"} {set r -2}
848
849   # check that the correct file is displayed
850   set twin [$stw test_get twin]
851   set a [$twin get 1.0 end]
852   if {[string compare $file2(source) $a]} {set r -3}
853   
854   # check for PC_TAG on correct line
855   if {$r == 0} {
856     if {![catch {set z [$twin dump -tag 1.0 end]}]} {
857       foreach {k v i} $z {
858         if {$k == "tagon"} {
859           if {$v == "PC_TAG"} {
860             if {$i == "38.2"} {
861               incr r
862             } else {
863               incr r 5
864             }
865           }
866           if {$v == "STACK_TAG"} {incr r 10}
867           if {$v == "BROWSE_TAG"} {incr r 100}
868         }
869       }
870     } else {
871       set r -4
872     }
873   }
874   set r
875 } {1}
876
877 # 4 -  BREAKPOINTS
878
879 # Test: srcwin-4.1
880 # Desc: Set BP in another file. Tests bp and cache functions
881 gdbtk_test srcwin-4.1 "set BP in another file" {
882   gdb_immediate "break foo" 1
883   $srcwin goto_func "" foo
884   set r 0
885   set name [$statbar.name get]
886   set func [$statbar.func get]
887
888   # check contents of name and function comboboxes
889   if {$name != "list0.h"} {set r -1}
890   if {$func != "foo"} {set r -2}
891
892   set twin [$stw test_get twin]
893   
894   # check for BROWSE_TAG and BP image on correct line
895   if {$r == 0} {
896     if {![catch {set z [$twin dump 1.0 end]}]} {
897       foreach {k v i} $z {
898         if {$k == "tagon"} {
899           if {$v == "BROWSE_TAG"} {
900             if {$i == "9.2"} {
901               incr r
902             } else {
903               incr r 5
904             }
905           }
906           if {$v == "STACK_TAG"} {incr r 10}
907           if {$v == "PC_TAG"} {incr r 100}
908         } elseif {$k == "image"} {
909           if {$i == "9.0"} {
910             incr r
911           } else {
912             set r -200
913           }
914         }
915       }
916     } else {
917       set r -4
918     }
919   }
920   
921   if {$r == 2} {
922     # clear BP and compare with previous contents. This should succeed,
923     gdb_immediate "clear foo" 1
924     set a [$twin get 1.0 end]
925     if {[string compare $file3(source) $a]} {set r -3}
926   }
927   
928   set r
929 } {2}
930
931 # Test: srcwin-4.2
932 # Desc: Test temporary BP
933 gdbtk_test srcwin-4.2 "temporary BP" {
934   set r 0
935   if {[catch {gdb_immediate "tbreak foo" 1} msg]} {
936     set r -500
937   }
938   set name [$statbar.name get]
939   set func [$statbar.func get]
940   
941   # check contents of name and function comboboxes
942   if {$name != "list0.h"} {set r -1}
943   if {$func != "foo"} {set r -2}
944
945   set twin [$stw test_get twin]
946   
947   # check for BROWSE_TAG and BP image on correct line
948   if {$r == 0} {
949     if {![catch {set z [$twin dump 1.0 end]}]} {
950       foreach {k v i} $z {
951         if {$k == "tagon"} {
952           if {$v == "BROWSE_TAG"} {
953             if {$i == "9.2"} {
954               incr r
955             } else {
956               incr r 5
957             }
958           }
959           if {$v == "STACK_TAG"} {incr r 10}
960           if {$v == "PC_TAG"} {incr r 100}
961         } elseif {$k == "image"} {
962           if {$i == "9.0"} {
963             incr r
964           } else {
965             set r -200
966           }
967         }
968       }
969     } else {
970       set r -4
971     }
972   }
973   
974   gdb_immediate "continue" 1
975   
976   # now check for PC_TAG and no image
977   if {$r == 2} {
978     if {![catch {set z [$twin dump 1.0 end]}]} {
979       foreach {k v i} $z {
980         if {$k == "tagon"} {
981           if {$v == "PC_TAG"} {
982             if {$i == "9.2"} {
983               incr r
984             } else {
985               incr r 5
986             }
987           }
988           if {$v == "STACK_TAG"} {incr r 10}
989           if {$v == "BROWSE_TAG"} {incr r 100}
990         } elseif {$k == "image"} {
991           set r -200
992         }
993       }
994     } else {
995       set r -4
996     }
997   }
998   
999   set r
1000 } {3}
1001
1002 # Test: srcwin-4.3
1003 # Desc: Test BP balloons
1004 gdbtk_test srcwin-4.3 "BP Balloons" {
1005   # move pointer out of the way
1006   warp_pointer . 0 0 
1007   set r 0
1008   gdb_immediate "break 10" 1
1009   gdb_immediate "tbreak 10" 1
1010
1011   set twin [$stw test_get twin]
1012   
1013   # check for BROWSE_TAG and BP image on correct line
1014   if {$r == 0} {
1015     if {![catch {set z [$twin dump 1.0 end]}]} {
1016       foreach {k v i} $z {
1017         if {$k == "tagon"} {
1018           if {$v == "PC_TAG"} {
1019             if {$i == "9.2"} {
1020               incr r
1021             } else {
1022               incr r 5
1023             }
1024           }
1025           if {$v == "STACK_TAG"} {incr r 10}
1026           if {$v == "BROWSE_TAG"} {incr r 100}
1027         } elseif {$k == "image"} {
1028           if {$i == "10.0"} {
1029             incr r
1030             # we found the bp image, now we will test the bp balloon messages
1031             set balloon [winfo toplevel [namespace tail $srcwin]].__balloon
1032             # shouldn't be mapped yet
1033             if {[winfo ismapped $balloon]} {
1034               set r -3000
1035               break
1036             }
1037             move_mouse_to $twin [$twin bbox $i]
1038             #wait a second for the balloon message to appear
1039             sleep 1
1040             if {![winfo ismapped $balloon]} {
1041               set r -4000
1042               break
1043             }
1044             # read the contents of the balloon and parse it into lines
1045             set a [split [$balloon.label cget -text] \n]
1046             set i 0
1047             # foreach line parse it and check the type and make sure it is enabled
1048             foreach line $a {
1049               if {[lindex $line 0] == "breakpoint"} {continue}
1050               incr i
1051               set enabled [lindex $line 0]
1052               set bptype [lindex $line 2]
1053               switch $i {
1054                 1 {
1055                   if {$bptype != "donttouch"} {set r -1000}
1056                 }
1057                 2 {
1058                   if {$bptype != "delete"} {set r -2000}
1059                 }
1060               }
1061             }
1062           } else {
1063             set r -200
1064           }
1065         }
1066       }
1067     } else {
1068       set r -4
1069     }
1070   }
1071   set r
1072 } {2}
1073
1074 #ManagedWin::open DebugWin
1075
1076 # Test: srcwin-4.4
1077 # Desc: Click on line to set BP
1078 gdbtk_test srcwin-4.4 "Click on line to set BP" {
1079   set r 0
1080
1081   # click mouse button 1 at index 20.1
1082   if {![click $twin [$twin bbox 20.1] 1]} {
1083     set r "Click failed on line 20.1"
1084   } else {
1085
1086     # now look for BP at line 20
1087     foreach bpnum [gdb_get_breakpoint_list] {
1088       set bpinfo [gdb_get_breakpoint_info $bpnum]
1089       lassign $bpinfo file func line pc type enabled disposition \
1090         ignore_count commands cond thread hit_count
1091       set file [lindex [file split $file] end]
1092       if {$file == "list0.h"} {
1093         if {$line == "20"} {
1094           if {$enabled == "1"} {incr r}
1095           if {$func == "foo"} {incr r}
1096           if {$type == "breakpoint"} {incr r}
1097           if {$disposition == "donttouch"} {incr r}
1098         }
1099       }
1100     }
1101   }
1102   set r
1103 } {4}
1104
1105
1106 # Test: srcwin-4.5
1107 # Desc: Continue till here popup
1108 gdbtk_test srcwin-4.5 "Continue till here popup" {
1109   set twin [$stw test_get twin]
1110
1111   # Get coordinates of line 16
1112   set b [$twin bbox 16.1]
1113   set y [expr {[lindex $b 1] + ([lindex $b 3] / 2)}]
1114
1115   # Continue to here
1116   $stw continue_to_here $twin $y
1117
1118   # Where is the PC_TAG?
1119   set pcs {}
1120   set tags [$twin tag ranges PC_TAG]
1121   foreach {start end} $tags {
1122     lappend pcs [expr {int($start)}]
1123   }
1124
1125   # Where are breakpoints?
1126   set bps {}
1127   set imgs [$twin dump -image 1.0 end]
1128   foreach {foo bar line} $imgs {
1129     lappend bps $line
1130   }
1131
1132   list $pcs $bps
1133 } {16 {10.0 20.0}}
1134
1135 # 5.1 balloon variables
1136 # Test: srcwin-5.1
1137 # Desc: variable balloon test
1138 # continues to BP at line 20 and checks to see that value was updated
1139 gdbtk_test srcwin-5.1 "variable balloon test" {
1140   # move pointer out of the way
1141   warp_pointer . 0 0 
1142   set r 0
1143   set twin [$stw test_get twin]
1144
1145   # move pointer to variable "x" and check balloon
1146   set index [string first "x++" [$twin get 20.0 20.end]]
1147   move_mouse_to $twin [$twin bbox 20.$index]
1148   sleep 1
1149   if {[winfo ismapped $balloon]} {
1150     if {![string compare "x=9" [$balloon.label cget -text]]} {incr r}
1151     gdb_immediate "continue" 1
1152     sleep 1
1153     if {![string compare "x=13" [$balloon.label cget -text]]} {incr r}
1154   } else {
1155     set r -1
1156   }
1157
1158   set r
1159 } {2}
1160
1161 # 6.1 mixed mode disassembly of include file
1162 # Test: srcwin-6.1
1163 # Desc: Some versions of GDBtk can't do mixed-mode disassembly of a function
1164 # that is in an include file. PR# mi/1101
1165
1166 gdbtk_test srcwin-6.1 "mixed mode disassembly of include file (mi/1101)" {
1167   set r 0
1168   $srcwin mode "" MIXED
1169
1170   # check contents of name and function comboboxes
1171   set name [$statbar.name get]
1172   set func [$statbar.func get]
1173   if {$name != "list0.h"} {set r -1}
1174   if {$func != "foo"} {set r -2}
1175   
1176   # check contents of source window
1177   set twin [$stw test_get twin]
1178   set text [$twin get 1.0 end]
1179   # Is it correct? I don't know.  Guess we look for some pieces of source...
1180   if {[string first "static void" $text] != -1 &&
1181       [string first "foo (x)" $text] != -1 &&
1182       [string first "bar (x++);" $text] != -1} {
1183     set r 1
1184   }
1185   
1186   set r
1187 } {1}
1188
1189 gdbtk_test_done