os2_process.t
[p5sagit/p5-mst-13.2.git] / os2 / OS2 / Process / t / os2_process.t
1 #! /usr/bin/perl -w
2
3 #END {
4 #  sleep 10;
5 #}
6
7 sub propagate_INC {
8   my $inc = $ENV{PERL5LIB};
9   $inc = $ENV{PERLLIB} unless defined $inc;
10   $inc = '' unless defined $inc;
11   $ENV{PERL5LIB} = join ';', @INC, split /;/, $inc;
12 }
13
14 my $separate_session;
15 BEGIN {                 # Remap I/O to the parent's window
16  $separate_session = $ENV{OS2_PROCESS_TEST_SEPARATE_SESSION};
17  propagate_INC, return unless $separate_session; # done by the parent
18  my @fn = split " ", $ENV{NEW_FD};
19  my @fh = (*STDOUT, *STDERR);
20  my @how = qw( > > );
21  # warn $_ for @fn;
22  open $fh[$_], "$how[$_]&=$fn[$_]"
23    or warn "Cannot reopen $fh[$_], $how[$_]&=$fn[$_]: $!" for 0..1;
24 }
25
26 use strict;
27 use Test::More tests => 232;
28 use OS2::Process;
29
30 sub SWP_flags ($) {
31   my @nkpos = WindowPos shift;
32   $nkpos[2];
33 }
34
35 my $interactive_wait = @ARGV && $ARGV[0] eq 'wait';
36
37 my @l = OS2::Process::process_entry();
38 ok(@l == 11, 'all the fields of the process_entry() are there');
39
40 # 1: FS 2: Window-VIO 
41 ok( ($l[9] == 1 or $l[9] == 2), 'we are FS or Windowed-VIO');
42
43 #print "# $_\n" for @l;
44
45 eval <<'EOE' or die;
46 #use OS2::Process qw(WM_SYSCOMMAND WM_DBCSLAST FID_CLIENT HWND_DESKTOP);
47 use OS2::Process qw(WM_SYSCOMMAND WM_DBCSLAST HWND_DESKTOP);
48
49 ok( WM_SYSCOMMAND == 0x0021, 'correct WM_SYSCOMMAND' );
50 ok( WM_DBCSLAST   == 0x00cf,  'correct WM_DBCSLAST' );
51 #ok( FID_CLIENT    == 0x8008 );
52 ok( HWND_DESKTOP  == 0x0001,  'correct HWND_DESKTOP' );
53 1;
54 EOE
55
56 my $t = Title;
57 my $wint = winTitle;
58
59 ok($t, 'got session title');
60 ok($wint, 'got titlebar text');
61
62 my $newt = "test OS2::Process $$";
63 ok(Title_set($newt), 'successfully set Title');
64 is(Title, $newt, 'correctly set Title');
65 my $wt = winTitle or warn "winTitle: $!, $^E";
66 is(winTitle, $newt, 'winTitle changed its value too');
67 ok(Title_set $t, 'successfully set Title back');
68 is(Title, $t, 'correctly set Title back');
69 is(winTitle, $wint, 'winTitle restored its value too');
70
71 $newt = "test OS2::Process both-$$";
72 ok(bothTitle_set($newt), 'successfully set both titles via Win* API');
73 is(Title, $newt, 'session title correctly set');
74 is(winTitle, $newt, 'winTitle correctly set');
75 ok(bothTitle_set($t), 'successfully reset both titles via Win* API');
76 is(Title, $t, 'session title correctly reset');
77 is(winTitle, $wint, 'winTitle correctly reset');
78
79 $newt = "test OS2::Process win-$$";
80 ok(winTitle_set($newt), 'successfully set titlebar title via Win* API');
81 is(Title, $t, 'session title remained the same');
82 is(winTitle, $newt, 'winTitle changed value');
83 ok(winTitle_set($wint), 'successfully reset titlebar title via Win* API');
84 is(Title, $t, 'session title remained the same');
85 is(winTitle, $wint, 'winTitle restored value');
86
87 $newt = "test OS2::Process sw-$$";
88 ok(swTitle_set($newt), 'successfully set session title via Win* API');
89 is(Title, $newt, 'session title correctly set');
90 is(winTitle, $wint, 'winTitle has unchanged value');
91 ok(swTitle_set($t), 'successfully reset session title via Win* API');
92 is(Title, $t, 'session title correctly set');
93 is(winTitle, $wint, 'winTitle has unchanged value');
94
95 $newt = "test OS2::Process again-$$";
96 ok(Title_set($newt), 'successfully set Title again');
97 is(Title, $newt, 'correctly set Title again');
98 is(winTitle, $newt, 'winTitle changed its value too again');
99 ok(Title_set($t), 'successfully set Title back');
100 is(Title, $t, 'correctly set Title back');
101 is(winTitle, $wint, 'winTitle restored its value too again');
102
103 my $hwnd = process_hwnd;
104 ok($hwnd, 'found session owner hwnd');
105 my $c_subhwnd = WindowFromId $hwnd, 0x8008;     # FID_CLIENT;
106 ok($c_subhwnd, 'found client hwnd');
107 my $a_subhwnd = ActiveWindow $hwnd;     # or $^E and warn $^E;
108 ok((not $a_subhwnd and not $^E), 'No active subwindow in a VIO frame');
109
110 my $ahwnd = ActiveWindow;
111 ok($ahwnd, 'found active window');
112 my $fhwnd = FocusWindow;
113 ok($fhwnd, 'found focus window');
114
115 # This call without morphing results in VIO window with active highlight, but
116 # no keyboard focus (even after Alt-Tabbing to it; you cannot Alt-Tab off it!)
117
118 # Interestingly, Desktop is active on the switch list, but the
119 # switch list is not acting on keyboard events.
120
121 # Give up focus
122 { my $force_PM = OS2::localMorphPM->new(0);
123   ok $force_PM, 'morphed to PM locally';
124   ok FocusWindow_set(1), 'set focus to DESKTOP';        # HWND_DESKTOP
125 }
126 my $dtop = DesktopWindow;
127 ok($dtop, 'found the desktop window');
128
129 #OS2::Process::ResetWinError;                   # XXXX Should not be needed!
130 $ahwnd = ActiveWindow or $^E and warn $^E;
131 ok( (not $ahwnd and not $^E), 'desktop is not active');
132 $fhwnd = FocusWindow;
133 ok($fhwnd, 'there is a focus window');
134 is($fhwnd, $dtop, 'which is the desktop');
135
136 # XXXX Well, no need to skip it now...
137 SKIP: {
138   skip 'We already have focus', 4 if $hwnd == $ahwnd;
139   my $force_PM = OS2::localMorphPM->new(0);
140   ok $force_PM, 'morphed to PM locally again';
141   ok FocusWindow_set($c_subhwnd), 'set focus to the client of the session owner';
142   # If we do not morph, then when the focus is in another VIO frame,
143   # we get two VIO frames with activated titlebars.
144   # The only (?) way to take the activated state from another frame
145   # is to switch to it via the switch list
146   $ahwnd = ActiveWindow;
147   ok($ahwnd, 'there is an active window');
148   $fhwnd = FocusWindow;
149   ok($fhwnd, 'there is a focus window');
150   is($hwnd, $ahwnd, 'the active window is the session owner');
151   is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner');
152 }
153
154 # Give up focus again
155 { my $force_PM = OS2::localMorphPM->new(0);
156   ok $force_PM, 'morphed to PM locally again';
157   ok FocusWindow_set(1), 'set focus to DESKTOP again';  # HWND_DESKTOP
158 }
159
160 $ahwnd = ActiveWindow or $^E and warn $^E;
161 ok( (not $ahwnd and not $^E), 'desktop is not active again');
162 $fhwnd = FocusWindow;
163 ok($fhwnd, 'there is a focus window');
164 is($fhwnd, $dtop, 'which is the desktop');
165
166 # XXXX Well, no need to skip it now...
167 SKIP: {
168   skip 'We already have focus', 4 if $hwnd == $ahwnd;
169   my $force_PM = OS2::localMorphPM->new(0);
170   ok $force_PM, 'morphed to PM locally again';
171   ok ActiveWindow_set($hwnd), 'activate the session owner';
172   $ahwnd = ActiveWindow;
173   ok($ahwnd, 'there is an active window');
174   $fhwnd = FocusWindow;
175   ok($fhwnd, 'there is a focus window');
176   is($hwnd, $ahwnd, 'the active window is the session owner');
177 }
178
179 # XXXX Well, no need to skip it now...
180 SKIP: {
181   skip 'Tests assume we have focus', 1 unless $hwnd == $ahwnd;
182   # We have focus
183   # is($fhwnd, $ahwnd);
184   # is($a_subhwnd, $c_subhwnd);
185   is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner');
186 }
187
188 # Check enumeration of switch entries:
189 my $skid_title = "temporary s-kid ppid=$$";
190 my $spid = system P_SESSION, $^X, '-wle', "END {sleep 25} use OS2::Process; eval {Title_set '$skid_title'} or warn \$@; \$SIG{TERM} = sub {exit 0}";
191 ok ($spid, 'start the new VIO session with unique title');
192 sleep 1;
193 my @sw = grep $_->{title} eq $skid_title, process_hentries;
194 sleep 1000 unless @sw;
195 is(scalar @sw, 1, 'exactly one session with this title');
196 my $sw = $sw[0];
197 ok $sw, 'have the data about the session';
198 is($sw->{owner_pid}, $spid, 'session has a correct pid');
199 my $k_hwnd = $sw->{owner_hwnd};
200 ok $k_hwnd, 'found the session window handle';
201 is sidOf($spid), $sw->{owner_sid}, 'we know sid of the session';
202
203 # Give up focus again
204 { my $force_PM = OS2::localMorphPM->new(0);
205   ok $force_PM, 'morphed to PM locally again';
206   ok FocusWindow_set($k_hwnd), 'set focus to kid session window';
207 }
208
209 $ahwnd = ActiveWindow;
210 ok $ahwnd, 'there is an active window';
211 is $ahwnd, $k_hwnd, 'after focusing the active window is the owner_hwnd';
212 $fhwnd = FocusWindow;
213 ok $fhwnd, 'there is a focus window';
214 my $c_sub_ahwnd = WindowFromId $ahwnd, 0x8008;  # FID_CLIENT;
215 ok $c_sub_ahwnd, 'the active window has a FID_CLIENT';
216 is($fhwnd, $ahwnd, 'the focus window = the active window');
217
218 ok hWindowPos_set({behind => 3}, $k_hwnd),      # HWND_TOP
219   'put kid to the front';
220
221 is((hWindowPos $k_hwnd)->{behind}, 3, 'kis is at front');
222
223 my ($enum_handle, $first_zorder);
224 { my $force_PM = OS2::localMorphPM->new(0);
225   ok $force_PM, 'morphed to PM locally again';
226   $enum_handle = BeginEnumWindows 1;            # HWND_DESKTOP
227   ok $enum_handle, 'start enumeration';
228   $first_zorder = GetNextWindow $enum_handle;
229   ok $first_zorder, 'GetNextWindow works';
230   ok EndEnumWindows($enum_handle), 'end enumeration';
231 }
232 is ($first_zorder, $k_hwnd, 'kid is the first in z-order enumeration');
233
234 ok hWindowPos_set({behind => 4}, $k_hwnd),      # HWND_BOTTOM
235   'put kid to the back';
236
237 # This does not work, the result is the handle of "Window List"
238 # is((hWindowPos $k_hwnd)->{behind}, 4, 'kis is at back');
239
240 my (@list, $next, @list1);
241 { my $force_PM = OS2::localMorphPM->new(0);
242   ok $force_PM, 'morphed to PM locally again';
243   $enum_handle = BeginEnumWindows 1;            # HWND_DESKTOP
244   ok $enum_handle, 'start enumeration';
245   push @list, $next while $next = GetNextWindow $enum_handle;
246   @list1 = ChildWindows;
247   ok 1, 'embedded ChildWindows()';
248   ok EndEnumWindows($enum_handle), 'end enumeration';
249
250   is_deeply \@list, \@list1, 'Manual list same as by ChildWindows()';
251   # Apparently, the 'Desktop' window is still behind us;
252   # Note that this window is *not* what is returned by DesktopWindow
253   pop @list if WindowText($list[-1]) eq 'Desktop';
254 }
255 is ($list[-1], $k_hwnd, 'kid is the last in z-order enumeration');
256 # print "# kid=$k_hwnd in @list\n";
257 @list = ChildWindows;
258 is_deeply \@list, \@list1, 'Other ChildWindows(), same result';
259 ok scalar @list, 'ChildWindows works';
260 is $list[-2], $k_hwnd, 'kid is the last but one in ChildWindows';
261
262 ok hWindowPos_set({behind => 3}, $k_hwnd),      # HWND_TOP
263   'put kid to the front again';
264
265 is((hWindowPos $k_hwnd)->{behind}, 3, 'kis is at front again');
266 sleep 5 if $interactive_wait;
267
268 ok IsWindow($k_hwnd), 'IsWindow works';
269 #print "# win=$k_hwnd => err=$^E\n";
270 my $c_sub_khwnd = WindowFromId $k_hwnd, 0x8008; # FID_CLIENT
271 ok $c_sub_khwnd, 'have kids client window';
272 ok IsWindow($c_sub_khwnd), 'IsWindow works on the client';
273 #print "# win=$c_sub_khwnd => IsWindow err=$^E\n";
274 my ($pkid,$tkid) = WindowProcess $c_sub_khwnd;
275 my ($pkid1,$tkid1) = WindowProcess $hwnd;
276 ok($pkid1 > 0, 'our window has a governing process');
277 ok($tkid1 > 0, 'our window has a governing thread');
278 is($pkid, $pkid1, 'kid\'s window is governed by the same process as our (PMSHELL:1)');
279 is($tkid, $tkid1, 'likewise for threads');
280 is $pkid, ppidOf($spid), 'the governer is the parent of the kid session';
281
282 my $my_pos = hWindowPos($hwnd);
283 ok $my_pos, 'got my position';
284 { my $force_PM = OS2::localMorphPM->new(0);
285   ok $force_PM, 'morphed to PM locally again';
286   my @pos = WindowPos $hwnd;
287   my @ppos = WindowPos $k_hwnd;
288   # ok hWindowPos_set({%$my_pos, behind => $hwnd}, $k_hwnd), 'hide the kid behind us';
289   # Hide it completely behind our window
290   ok hWindowPos_set({x => $my_pos->{x}, y => $my_pos->{y}, behind => $hwnd,
291                      width => $my_pos->{width}, height => $my_pos->{height}},
292                     $k_hwnd), 'hide the kid behind us';
293   # ok WindowPos_set($k_hwnd, $pos[0], $pos[1]), 'hide the kid behind us';
294   my @kpos = WindowPos $k_hwnd;
295   # print "# kidpos=@ppos\n";
296   # print "#  mypos=@pos\n";
297   # print "# kidpos=@kpos\n";
298 # kidpos=252 630 4111 808 478 3 66518088 502482793
299 #  mypos=276 78 4111 491 149 2147484137 66518060 502532977
300 # kidpos=276 78 4111 491 149 2147484255 1392374582 213000
301   print "# Before window position\n" if $interactive_wait;
302   sleep 5 if $interactive_wait;
303
304   my $w_at = WindowFromPoint($kpos[0] + 5, $kpos[0] + 5, 1, 0); # HWND_DESKTOP, no grandchildren
305   ok $w_at, 'got window near LL corner of the kid';
306   print "# we=$hwnd, our client=$c_subhwnd, kid=$k_hwnd, kid's client=$c_sub_khwnd\n";
307   #is $w_at, $c_sub_khwnd, 'it is the kids client';
308   #is $w_at, $k_hwnd, 'it is the kids frame';
309   # Apparently, this result is accidental only...
310 #  is $w_at, $hwnd, 'it is our frame - is on top, but no focus';
311   #is $w_at, $c_subhwnd, 'it is our client';
312   print "# text: `", WindowText $w_at, "'.\n";
313   $w_at = WindowFromPoint($kpos[0] + 5, $kpos[0] + 5); # HWND_DESKTOP, grandchildren too
314   ok $w_at, 'got grandkid window near LL corner of the kid';
315   # Apparently, this result is accidental only...
316 #  is $w_at, $c_subhwnd, 'it is our client';
317   print "# text: `", WindowText $w_at, "'.\n";
318   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
319   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
320   ok IsWindowShowing $hwnd, 'we are showing';
321   ok ((not IsWindowShowing $k_hwnd), 'kid is not showing');
322   ok ((not eval { IsWindowShowing 12; 1 }), 'wrong kid causes errors');
323   is $^E+0, 0x1001, 'error is 0x1001';
324   like $@, qr/\Q[Win]IsWindowShowing/, 'error message shows function';
325   like $@, qr/SYS4097\b/, 'error message shows error number';
326   like $@, qr/\b0x1001\b/, 'error message shows error number in hex';
327
328   ok WindowPos_set($k_hwnd, @ppos[0..5]), 'restore the kid position';
329   my @nkpos = WindowPos $k_hwnd;
330   my $fl = $nkpos[2];
331   is_deeply([@ppos[0..5]], [@nkpos[0..5]], 'position restored');
332   ok IsWindowShowing $k_hwnd, 'kid is showing';
333   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
334   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
335   sleep 5 if $interactive_wait;
336   ok EnableWindow($k_hwnd, 0), 'disable the kid';
337   ok IsWindowShowing $k_hwnd, 'kid is showing';
338   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
339   ok !IsWindowEnabled $k_hwnd, 'kid is flaged as not enabled';
340   ok EnableWindow($k_hwnd), 'enable the kid';
341   ok IsWindowShowing $k_hwnd, 'kid is showing';
342   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
343   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
344   ok ShowWindow($k_hwnd, 0), 'hide the kid';
345   ok !IsWindowShowing $k_hwnd, 'kid is not showing';
346   ok !IsWindowVisible $k_hwnd, 'kid is flaged as not visible';
347   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
348   ok ShowWindow($k_hwnd), 'show the kid';
349   ok IsWindowShowing $k_hwnd, 'kid is showing';
350   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
351   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
352   ok( ($fl & 0x1800), 'window is maximized or restored'); # SWP_MAXIMIZE SWP_RESTORE
353   ok( ($fl & 0x1800) != 0x1800, 'window is not maximized AND restored'); # SWP_MAXIMIZE SWP_RESTORE
354
355   ok PostMsg( $k_hwnd, 0x21,    # WM_SYSCOMMAND, SC_MINIMIZE
356               OS2::Process::MPFROMSHORT 0x8002), 'post minimize message';
357   sleep 1;
358   ok !IsWindowShowing $k_hwnd, 'kid is not showing';
359   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
360   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
361   is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE
362
363   ok PostMsg($k_hwnd, 0x21,     # WM_SYSCOMMAND, SC_RESTORE
364              OS2::Process::MPFROMSHORT 0x8008), 'post restore message';
365   sleep 1;
366   ok IsWindowShowing $k_hwnd, 'kid is showing';
367   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
368   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
369   is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE
370
371   ok PostMsg($k_hwnd, 0x21,     # WM_SYSCOMMAND, SC_MAXIMIZE
372             OS2::Process::MPFROMSHORT 0x8003), 'post maximize message';
373   sleep 1;
374   ok IsWindowShowing $k_hwnd, 'kid is showing';
375   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
376   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
377   is 0x1c00 & SWP_flags $k_hwnd, 0x800, 'kid is maximized'; # SWP_MAXIMIZE
378
379   ok PostMsg( $k_hwnd, 0x21,    # WM_SYSCOMMAND, SC_MINIMIZE
380               OS2::Process::MPFROMSHORT 0x8002), 'post minimize message again';
381   sleep 1;
382   ok !IsWindowShowing $k_hwnd, 'kid is not showing';
383   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
384   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
385   is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE
386
387   ok PostMsg($k_hwnd, 0x21,     # WM_SYSCOMMAND, SC_RESTORE
388              OS2::Process::MPFROMSHORT 0x8008), 'post restore message again';
389   sleep 1;
390   ok IsWindowShowing $k_hwnd, 'kid is showing';
391   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
392   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
393   is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE
394
395   ok PostMsg( $k_hwnd, 0x21,    # WM_SYSCOMMAND, SC_MINIMIZE
396               OS2::Process::MPFROMSHORT 0x8002), 'post minimize message again';
397   sleep 1;
398   ok !IsWindowShowing $k_hwnd, 'kid is not showing';
399   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
400   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
401   is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE
402
403   ok PostMsg($k_hwnd, 0x21,     # WM_SYSCOMMAND, SC_RESTORE
404              OS2::Process::MPFROMSHORT (($fl & 0x800) ? 0x8003 : 0x8008)), # SWP_MAXIMIZE
405         'return back to the initial MAXIMIZE/RESTORE state';
406   sleep 1;
407   ok IsWindowShowing $k_hwnd, 'kid is showing';
408   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
409   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
410   SKIP: {
411     skip 'if defaultVIO=MAXIMIZED, new windows are shifted, but maximize to UL corner', 1 unless $fl & 0x800;
412     ok hWindowPos_set({x => $ppos[0], y => $ppos[1]}, $k_hwnd), 'x,y-restore for de-minimization of MAXIMIZED';
413   }
414   @nkpos = WindowPos $k_hwnd;
415   is_deeply([@ppos[0..5]], [@nkpos[0..5]], 'position restored');
416
417
418   # Now the other way
419   ok hWindowPos_set( {flags => 0x400}, $k_hwnd), 'set to minimized';
420   ok !IsWindowShowing $k_hwnd, 'kid is not showing';
421   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
422   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
423   is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE
424
425   ok hWindowPos_set( {flags => 0x1000}, $k_hwnd), 'set to restore';
426   ok IsWindowShowing $k_hwnd, 'kid is showing';
427   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
428   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
429   is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE
430
431   ok hWindowPos_set( {flags => 0x800}, $k_hwnd), 'set to maximized';
432   ok IsWindowShowing $k_hwnd, 'kid is showing';
433   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
434   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
435   is 0x1c00 & SWP_flags $k_hwnd, 0x800, 'kid is maximized'; # SWP_MAXIMIZE
436
437   ok hWindowPos_set( {flags => 0x400}, $k_hwnd), 'set to minimized again';
438   ok !IsWindowShowing $k_hwnd, 'kid is not showing';
439   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
440   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
441   is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE
442
443   ok hWindowPos_set( {flags => 0x1000}, $k_hwnd), 'set to restore again';
444   ok IsWindowShowing $k_hwnd, 'kid is showing';
445   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
446   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
447   is 0x1c00 & SWP_flags $k_hwnd, 0x1000, 'kid is restored'; # SWP_RESTORE
448
449   ok hWindowPos_set( {flags => 0x400}, $k_hwnd), 'set to minimized again';
450   ok !IsWindowShowing $k_hwnd, 'kid is not showing';
451   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
452   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
453   is 0x1c00 & SWP_flags $k_hwnd, 0x400, 'kid is minimized'; # SWP_MINIMIZE
454
455   ok hWindowPos_set( {flags => ($fl & 0x1800)}, $k_hwnd),
456         'set back to the initial MAXIMIZE/RESTORE state';
457   ok IsWindowShowing $k_hwnd, 'kid is showing';
458   ok IsWindowVisible $k_hwnd, 'kid is flaged as visible';
459   ok IsWindowEnabled $k_hwnd, 'kid is flaged as enabled';
460   SKIP: {
461     skip 'if defaultVIO=MAXIMIZED, new windows are shifted, but maximize to UL corner', 1 unless $fl & 0x800;
462     ok hWindowPos_set({x => $ppos[0], y => $ppos[1]}, $k_hwnd), 'x,y-restore for de-minimization of MAXIMIZED';
463   }
464   @nkpos = WindowPos $k_hwnd;
465   is_deeply([@ppos[0..5]], [@nkpos[0..5]], 'position restored');
466
467 }
468
469 # XXXX Well, no need to skip it now...
470 SKIP: {
471   skip 'We already have focus', 4 if $hwnd == $ahwnd;
472   my $force_PM = OS2::localMorphPM->new(0);
473   ok($force_PM, 'morphed to catch focus again');
474   ok FocusWindow_set($c_subhwnd), 'set focus to the client of the session owner';
475   # If we do not morph, then when the focus is in another VIO frame,
476   # we get two VIO frames with activated titlebars.
477   # The only (?) way to take the activated state from another frame
478   # is to switch to it via the switch list
479   $ahwnd = ActiveWindow;
480   ok($ahwnd, 'there is an active window');
481   $fhwnd = FocusWindow;
482   ok($fhwnd, 'there is a focus window');
483   is($hwnd, $ahwnd, 'the active window is the session owner');
484   is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner');
485 }
486
487 SKIP: {
488   skip 'Potentially destructive session modifications, done in a separate session only',
489     12, unless $separate_session;
490   # Manipulate process' hentry
491   my $he = process_hentry;
492   ok($he, 'got process hentry');
493   ok($he->{visible}, 'session switch is visible');# 4? Assume nobody manipulated it...
494
495   ok change_entryh($he), 'can change it (without modifications)';
496   my $nhe = process_hentry;
497   ok $nhe, 'could refetch the process hentry';
498   is_deeply($nhe, $he, 'it did not change');
499
500   sleep 5 if $interactive_wait;
501   # Try removing the process entry from the switch list
502   $nhe->{visible} = 0;
503   ok change_entryh($nhe), 'can change it to be invisible';
504   my $nnhe = process_hentry;
505   ok($nnhe, 'could refetch the process hentry');
506   is_deeply($nnhe, $nhe, 'it is modified as expected');
507   is($nnhe->{visible}, 0, 'it is not visible');
508
509   sleep 5 if $interactive_wait;
510
511   $nhe->{visible} = 1;
512   ok change_entryh ($nhe), 'can change it to be visible';
513   $nnhe = process_hentry;
514   ok($nnhe, 'could refetch the process hentry');
515   ok($nnhe->{visible}, 'it is visible');
516   sleep 5 if $interactive_wait;
517 }