tizen 2.4 release
[external/binutils.git] / gdb / testsuite / gdb.gdb / observer.exp
1 # Copyright 2003-2014 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 3 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, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Joel Brobecker (brobecker@gnat.com), derived
17 # from xfullpath.exp.
18
19 load_lib selftest-support.exp
20
21 proc attach_first_observer { message } {
22     gdb_test_no_output "set \$first_obs = observer_attach_test_notification (&observer_test_first_notification_function)" \
23         "$message; attach first observer"
24 }
25
26 proc attach_second_observer { message } {
27     gdb_test_no_output "set \$second_obs = observer_attach_test_notification (&observer_test_second_notification_function)" \
28         "$message; attach second observer"
29 }
30
31 proc attach_third_observer { message } {
32     gdb_test_no_output "set \$third_obs = observer_attach_test_notification (&observer_test_third_notification_function)" \
33         "$message; attach third observer"
34 }
35
36 proc detach_first_observer { message } {
37     gdb_test_no_output "call observer_detach_test_notification (\$first_obs)" \
38         "$message; detach first observer"
39 }
40
41 proc detach_second_observer { message } {
42     gdb_test_no_output "call observer_detach_test_notification (\$second_obs)" \
43         "$message; detach second observer"
44 }
45
46 proc detach_third_observer { message } {
47     gdb_test_no_output "call observer_detach_test_notification (\$third_obs)" \
48         "$message; detach third observer"
49 }
50
51 proc check_counters { first second third message } {
52     gdb_test "print observer_test_first_observer" \
53         ".\[0-9\]+ =.*$first" \
54         "$message; check first observer counter value"
55     gdb_test "print observer_test_second_observer" \
56         ".\[0-9\]+ =.*$second" \
57         "$message; check second observer counter value"
58     gdb_test "print observer_test_third_observer" \
59         ".\[0-9\]+ =.*$third" \
60         "$message; check third observer counter value"
61 }
62
63 proc reset_counters { message } {
64     gdb_test_no_output "set variable observer_test_first_observer = 0" \
65         "$message; reset first observer counter"
66     gdb_test_no_output "set variable observer_test_second_observer = 0" \
67         "$message; reset second observer counter"
68     gdb_test_no_output "set variable observer_test_third_observer = 0" \
69         "$message; reset third observer counter"
70 }
71
72 proc test_notifications { first second third message args } {
73     # Do any initialization
74     for {set i 0} {$i < [llength $args]} {incr i} {
75         [lindex $args $i] $message
76     }
77     reset_counters $message
78     # Call observer_notify_test_notification.  Note that this procedure
79     # takes one argument, but this argument is ignored by the observer
80     # callbacks we have installed.  So we just pass an arbitrary value.
81     gdb_test_no_output "call observer_notify_test_notification (0)" \
82         "$message; sending notification"
83     check_counters $first $second $third $message
84 }
85
86 proc test_observer {} {
87     # First, try sending a notification without any observer attached.
88     test_notifications 0 0 0 "no observer attached"
89
90     # Now, attach one observer, and send a notification.
91     test_notifications 0 1 0 "second observer attached" \
92         attach_second_observer
93
94     # Remove the observer, and send a notification.
95     test_notifications 0 0 0 "second observer detached" \
96         detach_second_observer
97
98     # With a new observer.
99     test_notifications 1 0 0 "1st observer added" \
100         attach_first_observer
101
102     # With 2 observers.
103     test_notifications 1 1 0 "2nd observer added" \
104         attach_second_observer
105
106     # With 3 observers.
107     test_notifications 1 1 1 "3rd observer added" \
108         attach_third_observer
109
110     # Remove middle observer.
111     test_notifications 1 0 1 "2nd observer removed" \
112         detach_second_observer
113
114     # Remove first observer.
115     test_notifications 0 0 1 "1st observer removed" \
116         detach_first_observer
117
118     # Remove last observer.
119     test_notifications 0 0 0 "3rd observer removed" \
120         detach_third_observer
121
122     # Go back to 3 observers, and remove them in a different order...
123     test_notifications 1 1 1 "three observers added" \
124         attach_first_observer \
125         attach_second_observer \
126         attach_third_observer 
127
128     # Remove the third observer.
129     test_notifications 1 1 0 "third observer removed" \
130         detach_third_observer
131
132     # Remove the second observer.
133     test_notifications 1 0 0 "second observer removed" \
134         detach_second_observer
135
136     # Remove the first observer, no more observers.
137     test_notifications 0 0 0 "first observer removed" \
138         detach_first_observer
139
140     return 0
141 }
142
143 do_self_tests captured_main test_observer