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