Debian Codegraph @

t/test.t

raw
1 #!/usr/bin/perl
2 # X11::GUITest ($Id: test.t 253 2026-08-19 22:37:51Z ctrondlp $)
3 # Note: Functions that might be too intrusive are not checked
4
5 BEGIN {
6 $| = 1;
7
8 # Is X info not available?
9 if (!defined($ENV{'DISPLAY'}) || length $ENV{'DISPLAY'} <= 0) {
10 warn "X11::GUITest - X Windows not running or DISPLAY not set.\n";
11 print "1..1\n";
12 print "ok 1\n";
13 exit(0);
14 }
15 # Testing too ambiguous for varied environments
16 if (defined($ENV{'AUTOMATED_TESTING'}) && $ENV{'AUTOMATED_TESTING'}) {
17 warn "X11::GUITest - Not performing extensive tests.\n";
18 print "1..1\n";
19 print "ok 1\n";
20 exit(0);
21 }
22
23 # Pre-checks ok, so plan on running the tests.
24 print "1..24\n";
25 }
26 END {
27 print "not ok 1\n" unless $loaded;
28 }
29
30 use X11::GUITest qw/
31 :ALL
32 /;
33 $loaded = 1;
34 print "ok 1\n";
35
36 use strict;
37 use warnings;
38
39 # Used for testing below
40 my $BadWinTitle = 'BadWindowNameNotToBeFound';
41 my $BadWinId = '898989899';
42 my @Windows = ();
43 my $HasWindows = 0;
44
45 # Determine if there are windows to use. If tester
46 # is using xvfb-run, we'll likely have 0 windows.
47 $HasWindows = (scalar FindWindowLike(".*"));
48
49
50 # FindWindowLike
51 if ($HasWindows) {
52 print "not " unless FindWindowLike(".*");
53 }
54 print "not " unless not FindWindowLike($BadWinTitle);
55 print "ok 2\n";
56
57 # WaitWindowClose
58 print "not " unless WaitWindowClose($BadWinId);
59 print "ok 3\n";
60
61 # WaitWindowLike
62 if ($HasWindows) {
63 print "not " unless WaitWindowLike(".*");
64 }
65 print "not " unless not WaitWindowLike($BadWinTitle, undef, 1);
66 print "ok 4\n";
67
68 # WaitWindowViewable
69 if ($HasWindows) {
70 print "not " unless WaitWindowViewable(".*");
71 }
72 print "not " unless not WaitWindowViewable($BadWinTitle, undef, 1);
73 print "ok 5\n";
74
75 # ClickWindow
76 # StartApp
77 # RunApp
78 # SetEventSendDelay
79 # GetEventSendDelay
80 # SetKeySendDelay
81 # GetKeySendDelay
82
83 # GetWindowName
84 my $WinName = '';
85 # Note: Only worry about windows that have a name
86 # RegExp: ".+" = one or more characters
87 foreach my $win (FindWindowLike(".+")) {
88 # If call fails, WinName will be set to undef
89 $WinName = GetWindowName($win);
90 if (not defined($WinName)) {
91 last;
92 }
93 }
94 print "not " unless defined($WinName);
95 print "ok 6\n";
96
97 # SetWindowName
98
99 # GetRootWindow
100 print "not " unless GetRootWindow();
101 print "ok 7\n";
102
103 # GetChildWindows
104 if ($HasWindows) {
105 print "not " unless GetChildWindows(GetRootWindow());
106 } else {
107 print "not " unless not GetChildWindows(GetRootWindow());
108 }
109 print "ok 8\n";
110
111 # MoveMouseAbs
112 print "not " unless MoveMouseAbs(2, 2);
113 print "ok 9\n";
114
115 # Give some respite to the X server
116 sleep 1;
117
118 # ClickMouseButton
119
120 # SendKeys
121
122 # IsWindow
123 print "not " unless IsWindow(GetRootWindow());
124 print "not " unless not IsWindow($BadWinId);
125 print "ok 10\n";
126
127 # IsWindowViewable
128 if ($HasWindows) {
129 @Windows = WaitWindowViewable(".*");
130 if (not IsWindow($Windows[0])) { # First window not viewable
131 $Windows[0] = GetRootWindow(); # Fall-back to root
132 }
133 print "not " unless IsWindowViewable($Windows[0]);
134 }
135 print "not " unless not IsWindowViewable($BadWinId);
136 print "ok 11\n";
137
138 # MoveWindow
139 # ResizeWindow
140 # IconifyWindow
141 # UnIconifyWindow
142 # Raise Window
143 # LowerWindow
144
145 # SetInputFocus
146
147 # GetInputFocus
148 print "not " unless GetInputFocus();
149 print "ok 12\n";
150
151 # GetWindowPos
152 my ($x, $y, $width, $height) = GetWindowPos(GetRootWindow());
153 print "not " unless (defined($x) and defined($y) and
154 defined($width) and defined($height));
155 print "ok 13\n";
156
157 # GetScreenRes
158 print "not " unless GetScreenRes();
159 print "ok 14\n";
160
161 # GetScreenDepth
162 print "not " unless GetScreenDepth();
163 print "ok 15\n";
164
165 # GetMousePos
166 my @coords = ();
167 print "not " unless ( @coords = GetMousePos() );
168 print "ok 16\n";
169
170 # IsChild
171 if ($HasWindows) {
172 print "not " unless ( @Windows = GetChildWindows(GetRootWindow()) );
173 # Note: Limiting check to a certain number of windows (10)
174 foreach my $win ( @Windows[0..(9 < $#Windows ? 9 : $#Windows)] ) {
175 if (!IsChild(GetRootWindow(), $win)) {
176 print "not ";
177 last;
178 }
179 }
180 }
181 print "ok 17\n";
182
183 # IsKeyPressed
184 # IsMouseButtonPressed
185
186 # QuoteStringForSendKeys
187 print "not " unless defined( QuoteStringForSendKeys('~!@#$%^&*()_+') );
188 print "ok 18\n";
189 print "not " unless (QSfSK('~!@#$%^&*()_+') eq '{~}!@#${%}{^}&*{(}{)}_{+}');
190 print "ok 19\n";
191 print "not " unless not defined ( QuoteStringForSendKeys(undef) );
192 print "ok 20\n";
193
194 # GetParentWindow
195 print "not " unless not GetParentWindow(GetRootWindow());
196 print "ok 21\n";
197 if ($HasWindows) {
198 print "not " unless GetParentWindow($Windows[0]);
199 }
200 print "ok 22\n";
201
202 # GetWindowFromPoint
203 # Note: Using invalid window position of (-1500 x -1500) for testing.
204 print "not " unless not GetWindowFromPoint(-1500, -1500);
205 print "ok 23\n";
206 if ($HasWindows) {
207 print "not " unless GetWindowFromPoint(0, 0);
208 }
209 print "ok 24\n";
210
211 # PressKey
212 # ReleaseKey
213 # PressReleaseKey
214 # PressMouseButton
215 # ReleaseMouseButton
216 # GetWindowPid
217 # GetWindowsFromPid
218