⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 os2_process.t

📁 source of perl for linux application,
💻 T
📖 第 1 页 / 共 2 页
字号:
#! /usr/bin/perl -w#END {#  sleep 10;#}sub propagate_INC {  my $inc = $ENV{PERL5LIB};  $inc = $ENV{PERLLIB} unless defined $inc;  $inc = '' unless defined $inc;  $ENV{PERL5LIB} = join ';', @INC, split /;/, $inc;}my $separate_session;BEGIN {			# Remap I/O to the parent's window $separate_session = $ENV{OS2_PROCESS_TEST_SEPARATE_SESSION}; propagate_INC, return unless $separate_session; # done by the parent my @fn = split " ", $ENV{NEW_FD}; my @fh = (*STDOUT, *STDERR); my @how = qw( > > ); # warn $_ for @fn; open $fh[$_], "$how[$_]&=$fn[$_]"   or warn "Cannot reopen $fh[$_], $how[$_]&=$fn[$_]: $!" for 0..1;}use strict;use Test::More tests => 235;use OS2::Process;sub SWP_flags ($) {  my @nkpos = WindowPos shift;  $nkpos[2];}my $interactive_wait = @ARGV && $ARGV[0] eq 'wait';my @l = OS2::Process::process_entry();ok(@l == 11, 'all the fields of the process_entry() are there');# 1: FS 2: Window-VIO ok( ($l[9] == 1 or $l[9] == 2), 'we are FS or Windowed-VIO');#print "# $_\n" for @l;eval <<'EOE' or die;#use OS2::Process qw(WM_SYSCOMMAND WM_DBCSLAST FID_CLIENT HWND_DESKTOP);use OS2::Process qw(WM_SYSCOMMAND WM_DBCSLAST HWND_DESKTOP);ok( WM_SYSCOMMAND == 0x0021, 'correct WM_SYSCOMMAND' );ok( WM_DBCSLAST   == 0x00cf,  'correct WM_DBCSLAST' );#ok( FID_CLIENT    == 0x8008 );ok( HWND_DESKTOP  == 0x0001,  'correct HWND_DESKTOP' );1;EOEmy $t = Title;my $wint = winTitle;ok($t, 'got session title');ok($wint, 'got titlebar text');my $newt = "test OS2::Process $$";ok(Title_set($newt), 'successfully set Title');is(Title, $newt, 'correctly set Title');my $wt = winTitle or warn "winTitle: $!, $^E";is(winTitle, $newt, 'winTitle changed its value too');ok(Title_set $t, 'successfully set Title back');is(Title, $t, 'correctly set Title back');is(winTitle, $wint, 'winTitle restored its value too');$newt = "test OS2::Process both-$$";ok(bothTitle_set($newt), 'successfully set both titles via Win* API');is(Title, $newt, 'session title correctly set');is(winTitle, $newt, 'winTitle correctly set');ok(bothTitle_set($t), 'successfully reset both titles via Win* API');is(Title, $t, 'session title correctly reset');is(winTitle, $wint, 'winTitle correctly reset');$newt = "test OS2::Process win-$$";ok(winTitle_set($newt), 'successfully set titlebar title via Win* API');is(Title, $t, 'session title remained the same');is(winTitle, $newt, 'winTitle changed value');ok(winTitle_set($wint), 'successfully reset titlebar title via Win* API');is(Title, $t, 'session title remained the same');is(winTitle, $wint, 'winTitle restored value');$newt = "test OS2::Process sw-$$";ok(swTitle_set($newt), 'successfully set session title via Win* API');is(Title, $newt, 'session title correctly set');is(winTitle, $wint, 'winTitle has unchanged value');ok(swTitle_set($t), 'successfully reset session title via Win* API');is(Title, $t, 'session title correctly set');is(winTitle, $wint, 'winTitle has unchanged value');$newt = "test OS2::Process again-$$";ok(Title_set($newt), 'successfully set Title again');is(Title, $newt, 'correctly set Title again');is(winTitle, $newt, 'winTitle changed its value too again');ok(Title_set($t), 'successfully set Title back');is(Title, $t, 'correctly set Title back');is(winTitle, $wint, 'winTitle restored its value too again');my $hwnd = process_hwnd;ok($hwnd, 'found session owner hwnd');my $c_subhwnd = WindowFromId $hwnd, 0x8008;	# FID_CLIENT;ok($c_subhwnd, 'found client hwnd');my $a_subhwnd = ActiveWindow $hwnd;	# or $^E and warn $^E;ok((not $a_subhwnd and not $^E), 'No active subwindow in a VIO frame');my $ahwnd = ActiveWindow;ok($ahwnd, 'found active window');my $fhwnd = FocusWindow;ok($fhwnd, 'found focus window');# This call without morphing results in VIO window with active highlight, but# no keyboard focus (even after Alt-Tabbing to it; you cannot Alt-Tab off it!)# Interestingly, Desktop is active on the switch list, but the# switch list is not acting on keyboard events.# Give up focus{ my $force_PM = OS2::localMorphPM->new(0);  ok $force_PM, 'morphed to PM locally';  ok FocusWindow_set(1), 'set focus to DESKTOP';	# HWND_DESKTOP}my $dtop = DesktopWindow;ok($dtop, 'found the desktop window');#OS2::Process::ResetWinError;			# XXXX Should not be needed!$ahwnd = ActiveWindow or $^E and warn $^E;ok( (not $ahwnd and not $^E), 'desktop is not active');$fhwnd = FocusWindow;ok($fhwnd, 'there is a focus window');is($fhwnd, $dtop, 'which is the desktop');# XXXX Well, no need to skip it now...SKIP: {  skip 'We already have focus', 4 if $hwnd == $ahwnd;  my $force_PM = OS2::localMorphPM->new(0);  ok $force_PM, 'morphed to PM locally again';  ok FocusWindow_set($c_subhwnd), 'set focus to the client of the session owner';  # If we do not morph, then when the focus is in another VIO frame,  # we get two VIO frames with activated titlebars.  # The only (?) way to take the activated state from another frame  # is to switch to it via the switch list  $ahwnd = ActiveWindow;  ok($ahwnd, 'there is an active window');  $fhwnd = FocusWindow;  ok($fhwnd, 'there is a focus window');  is($hwnd, $ahwnd, 'the active window is the session owner');  is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner');}# Give up focus again{ my $force_PM = OS2::localMorphPM->new(0);  ok $force_PM, 'morphed to PM locally again';  ok FocusWindow_set(1), 'set focus to DESKTOP again';	# HWND_DESKTOP}$ahwnd = ActiveWindow or $^E and warn $^E;ok( (not $ahwnd and not $^E), 'desktop is not active again');$fhwnd = FocusWindow;ok($fhwnd, 'there is a focus window');is($fhwnd, $dtop, 'which is the desktop');# XXXX Well, no need to skip it now...SKIP: {  skip 'We already have focus', 4 if $hwnd == $ahwnd;  my $force_PM = OS2::localMorphPM->new(0);  ok $force_PM, 'morphed to PM locally again';  ok ActiveWindow_set($hwnd), 'activate the session owner';  $ahwnd = ActiveWindow;  ok($ahwnd, 'there is an active window');  $fhwnd = FocusWindow;  ok($fhwnd, 'there is a focus window');  is($hwnd, $ahwnd, 'the active window is the session owner');}# XXXX Well, no need to skip it now...SKIP: {  skip 'Tests assume we have focus', 1 unless $hwnd == $ahwnd;  # We have focus  # is($fhwnd, $ahwnd);  # is($a_subhwnd, $c_subhwnd);  is($fhwnd, $c_subhwnd, 'the focus window is the client of the session owner');}# Check enumeration of switch entries:my $skid_title = "temporary s-kid ppid=$$";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}";ok ($spid, 'start the new VIO session with unique title');sleep 1;my @sw = grep $_->{title} eq $skid_title, process_hentries;sleep 1000 unless @sw;is(scalar @sw, 1, 'exactly one session with this title');my $sw = $sw[0];ok $sw, 'have the data about the session';is($sw->{owner_pid}, $spid, 'session has a correct pid');my $k_hwnd = $sw->{owner_hwnd};ok $k_hwnd, 'found the session window handle';is sidOf($spid), $sw->{owner_sid}, 'we know sid of the session';# Give up focus again{ my $force_PM = OS2::localMorphPM->new(0);  ok $force_PM, 'morphed to PM locally again';  ok FocusWindow_set($k_hwnd), 'set focus to kid session window';}$ahwnd = ActiveWindow;ok $ahwnd, 'there is an active window';is $ahwnd, $k_hwnd, 'after focusing the active window is the owner_hwnd';$fhwnd = FocusWindow;ok $fhwnd, 'there is a focus window';my $c_sub_ahwnd = WindowFromId $ahwnd, 0x8008;	# FID_CLIENT;ok $c_sub_ahwnd, 'the active window has a FID_CLIENT';is($fhwnd, $ahwnd, 'the focus window = the active window');ok hWindowPos_set({behind => 3}, $k_hwnd),	# HWND_TOP  'put kid to the front';# After Alt-Tab a WS_TOPMOST, WS_DISABLED window of class 'AltTabWindow' existsmy $top = (hWindowPos $k_hwnd)->{behind};ok(($top == 3 or WindowStyle($top) & 0x200000),	# HWND_TOP, WS_TOPMOST   'kid is at front');# is((hWindowPos $k_hwnd)->{behind}, 3, 'kid is at front');my ($enum_handle, $first_zorder, $first_non_TOPMOST);{ my $force_PM = OS2::localMorphPM->new(0);  ok $force_PM, 'morphed to PM locally again';  $enum_handle = BeginEnumWindows 1;		# HWND_DESKTOP  ok $enum_handle, 'start enumeration';  $first_non_TOPMOST = $first_zorder = GetNextWindow $enum_handle;  ok $first_zorder, 'GetNextWindow works';  my $f = WindowStyle $first_non_TOPMOST;  ok $f, 'WindowStyle works';  $f = WindowStyle($first_non_TOPMOST = GetNextWindow $enum_handle)    while $f & 0x200000;				# WS_TOPMOST  ok($first_non_TOPMOST, 'There is non-TOPMOST window');  ok(!(WindowStyle($first_non_TOPMOST) & 0x200000), 'Indeed non-TOPMOST');  ok EndEnumWindows($enum_handle), 'end enumeration';}is ($first_non_TOPMOST, $k_hwnd, 'kid is the first in z-order enumeration');ok hWindowPos_set({behind => 4}, $k_hwnd),	# HWND_BOTTOM  'put kid to the back';# This does not work, the result is the handle of "Window List"# is((hWindowPos $k_hwnd)->{behind}, 4, 'kis is at back');my (@list, $next, @list1);{ my $force_PM = OS2::localMorphPM->new(0);  ok $force_PM, 'morphed to PM locally again';  $enum_handle = BeginEnumWindows 1;		# HWND_DESKTOP  ok $enum_handle, 'start enumeration';  push @list, $next while $next = GetNextWindow $enum_handle;  @list1 = ChildWindows;  ok 1, 'embedded ChildWindows()';  ok EndEnumWindows($enum_handle), 'end enumeration';  is_deeply \@list, \@list1, 'Manual list same as by ChildWindows()';  # Apparently, the 'Desktop' window is still behind us;  # Note that this window is *not* what is returned by DesktopWindow  pop @list if WindowText($list[-1]) eq 'Desktop';}is ($list[-1], $k_hwnd, 'kid is the last in z-order enumeration');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -