1*b39c5158Smillert#! /usr/bin/perl -w 2*b39c5158Smillert 3*b39c5158Smillertuse strict; 4*b39c5158Smillertuse Test::More tests => 87; 5*b39c5158SmillertBEGIN {use_ok 'OS2::Process', qw(:DEFAULT CFI_POINTER CF_TEXT)} 6*b39c5158Smillert 7*b39c5158Smillert# Initialize 8*b39c5158Smillertmy $raw = "Just a random\nselection"; 9*b39c5158Smillert(my $cr = $raw) =~ s/\n/\r\n/g; 10*b39c5158Smillertok(ClipbrdText_set($raw), 'ClipbrdText_set'); 11*b39c5158Smillert 12*b39c5158Smillertmy ($v, $p, @f); 13*b39c5158Smillertis(ClipbrdText, $cr, "ClipbrdText it back"); 14*b39c5158Smillertis(ClipbrdOwner, 0, "ClipbrdOwner is not defined"); 15*b39c5158Smillert$v = ClipbrdViewer; 16*b39c5158Smillertok((!$v || IsWindow $v), "ClipbrdViewer is not defined or a valid window"); 17*b39c5158Smillert 18*b39c5158Smillert{ 19*b39c5158Smillert my $h = OS2::localClipbrd->new; 20*b39c5158Smillert $p = ClipbrdData; 21*b39c5158Smillert 22*b39c5158Smillert @f = MemoryRegionSize($p, 0x4000); # 4 pages, 16K, limit 23*b39c5158Smillert is(scalar @f, 2, 'MemoryRegionSize(16K) returns 2 values'); 24*b39c5158Smillert # diag(sprintf '%#x, %#x, %#x, %#x', @f, $f[0]+$p, $p); 25*b39c5158Smillert is($f[0], 4096, 'MemoryRegionSize claims 1 page is available'); 26*b39c5158Smillert ok($f[1] & 0x1, 'MemoryRegionSize claims page readable');# PAG_READ=1 0x12013 27*b39c5158Smillert 28*b39c5158Smillert my @f1 = MemoryRegionSize($p, 0x100000); # 16 blocks, 1M, limit 29*b39c5158Smillert is(scalar @f1, 2, 'MemoryRegionSize(1M) returns 2 values'); 30*b39c5158Smillert is($f1[0], $f[0], 'MemoryRegionSize returns same length'); 31*b39c5158Smillert is($f1[1], $f[1], 'MemoryRegionSize returns same flags'); 32*b39c5158Smillert 33*b39c5158Smillert @f1 = MemoryRegionSize($p); 34*b39c5158Smillert is(scalar @f1, 2, 'MemoryRegionSize(no-limit) returns 2 values'); 35*b39c5158Smillert is($f1[0], $f[0], 'MemoryRegionSize returns same length'); 36*b39c5158Smillert is($f1[1], $f[1], 'MemoryRegionSize returns same flags'); 37*b39c5158Smillert} 38*b39c5158Smillert 39*b39c5158Smillertok($p, 'ClipbrdData'); 40*b39c5158Smillert 41*b39c5158Smillertis(ClipbrdFmtInfo, CFI_POINTER, 'ClipbrdFmtInfo is CFI_POINTER'); 42*b39c5158Smillert 43*b39c5158Smillert# CF_TEXT is 1 44*b39c5158Smillertok(!defined eval {ClipbrdText(1+CF_TEXT); 1}, "ClipbrdText(not CF_TEXT) croaks"); 45*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 46*b39c5158Smillert 47*b39c5158Smillert@f = ClipbrdFmtAtoms; 48*b39c5158Smillertis(scalar @f, 1, "Only one format available"); 49*b39c5158Smillertis($f[0], CF_TEXT, "format is CF_TEXT"); 50*b39c5158Smillert 51*b39c5158Smillert@f = ClipbrdFmtNames; 52*b39c5158Smillertis(scalar @f, 1, "Only one format available"); 53*b39c5158Smillertis($f[0], '#1', "format is CF_TEXT='#1'"); 54*b39c5158Smillert 55*b39c5158Smillert{ 56*b39c5158Smillert my $h = OS2::localClipbrd->new; 57*b39c5158Smillert ok(EmptyClipbrd, 'EmptyClipbrd'); 58*b39c5158Smillert} 59*b39c5158Smillert 60*b39c5158Smillert@f = ClipbrdFmtNames; 61*b39c5158Smillertis(scalar @f, 0, "No format available"); 62*b39c5158Smillert 63*b39c5158Smillertundef $p; undef $v; 64*b39c5158Smillerteval { 65*b39c5158Smillert my $h = OS2::localClipbrd->new; 66*b39c5158Smillert $p = ClipbrdData; 67*b39c5158Smillert $v = 1; 68*b39c5158Smillert}; 69*b39c5158Smillert 70*b39c5158Smillertok(! defined $p, 'ClipbrdData croaked'); 71*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 72*b39c5158Smillert 73*b39c5158Smillertok(! defined eval {ClipbrdText}, "ClipbrdText croaks"); 74*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 75*b39c5158Smillert 76*b39c5158Smillert# CF_TEXT is 1 77*b39c5158Smillertok(!defined eval {ClipbrdText(1+CF_TEXT); 1}, "ClipbrdText(not CF_TEXT) croaks"); 78*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 79*b39c5158Smillert 80*b39c5158Smillertis(ClipbrdOwner, 0, "ClipbrdOwner is not defined"); 81*b39c5158Smillert 82*b39c5158Smillert$v = ClipbrdViewer; 83*b39c5158Smillertok((!$v || IsWindow $v), "ClipbrdViewer is not defined or a valid window"); 84*b39c5158Smillert 85*b39c5158Smillertis(ClipbrdFmtInfo, 0, 'ClipbrdFmtInfo is 0'); 86*b39c5158Smillert 87*b39c5158Smillert@f = ClipbrdFmtAtoms; 88*b39c5158Smillertis(scalar @f, 0, "No formats available"); 89*b39c5158Smillert 90*b39c5158Smillert{ 91*b39c5158Smillert my $h = OS2::localClipbrd->new; 92*b39c5158Smillert ok(EmptyClipbrd, 'EmptyClipbrd when clipboard is empty succeeds'); 93*b39c5158Smillert} 94*b39c5158Smillert 95*b39c5158Smillertok(ClipbrdText_set($raw, 1), 'ClipbrdText_set() raw'); 96*b39c5158Smillertis(ClipbrdText, $raw, "ClipbrdText it back"); 97*b39c5158Smillert 98*b39c5158Smillert{ 99*b39c5158Smillert my $h = OS2::localClipbrd->new; 100*b39c5158Smillert ok(EmptyClipbrd, 'EmptyClipbrd again'); 101*b39c5158Smillert} 102*b39c5158Smillert 103*b39c5158Smillertmy $ar = AddAtom 'perltest/unknown_raw'; 104*b39c5158Smillertok($ar, 'Atom added'); 105*b39c5158Smillertmy $ar1 = AddAtom 'perltest/unknown_raw1'; 106*b39c5158Smillertok($ar1, 'Atom added'); 107*b39c5158Smillertmy $a = AddAtom 'perltest/unknown'; 108*b39c5158Smillertok($a, 'Atom added'); 109*b39c5158Smillertmy $a1 = AddAtom 'perltest/unknown1'; 110*b39c5158Smillertok($a1, 'Atom added'); 111*b39c5158Smillert 112*b39c5158Smillert{ 113*b39c5158Smillert my $h = OS2::localClipbrd->new; 114*b39c5158Smillert ok(ClipbrdData_set($raw), 'ClipbrdData_set()'); 115*b39c5158Smillert ok(ClipbrdData_set($raw, 0, $ar1), 'ClipbrdData_set(perltest/unknown_raw1)'); 116*b39c5158Smillert ok(ClipbrdData_set($cr, 0, $ar), 'ClipbrdData_set(perltest/unknown_raw)'); 117*b39c5158Smillert ok(ClipbrdData_set($raw, 1, $a1), 'ClipbrdData_set(perltest/unknown1)'); 118*b39c5158Smillert ok(ClipbrdData_set($cr, 1, $a), 'ClipbrdData_set(perltest/unknown)'); 119*b39c5158Smillert # Results should be the same, except ($raw, 0) one... 120*b39c5158Smillert} 121*b39c5158Smillert 122*b39c5158Smillertis(ClipbrdText, $cr, "ClipbrdText CF_TEXT back"); 123*b39c5158Smillertis(ClipbrdText($ar1), $raw, "ClipbrdText perltest/unknown_raw1 back"); 124*b39c5158Smillertis(ClipbrdText($ar), $cr, "ClipbrdText perltest/unknown_raw back"); 125*b39c5158Smillertis(ClipbrdText($a1), $cr, "ClipbrdText perltest/unknown1 back"); 126*b39c5158Smillertis(ClipbrdText($a), $cr, "ClipbrdText perltest/unknown back"); 127*b39c5158Smillert 128*b39c5158Smillertis(ClipbrdFmtInfo, CFI_POINTER, 'ClipbrdFmtInfo is CFI_POINTER'); 129*b39c5158Smillertis(ClipbrdFmtInfo($ar1), CFI_POINTER, 'ClipbrdFmtInfo is CFI_POINTER'); 130*b39c5158Smillertis(ClipbrdFmtInfo($ar), CFI_POINTER, 'ClipbrdFmtInfo is CFI_POINTER'); 131*b39c5158Smillertis(ClipbrdFmtInfo($a1), CFI_POINTER, 'ClipbrdFmtInfo is CFI_POINTER'); 132*b39c5158Smillertis(ClipbrdFmtInfo($a), CFI_POINTER, 'ClipbrdFmtInfo is CFI_POINTER'); 133*b39c5158Smillert 134*b39c5158Smillert# CF_TEXT is 1 135*b39c5158Smillertok(!defined eval {ClipbrdText(1+CF_TEXT); 1}, "ClipbrdText(1+CF_TEXT) croaks"); 136*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 137*b39c5158Smillert 138*b39c5158Smillertmy $names = join ',', sort '#1', qw(perltest/unknown perltest/unknown1 139*b39c5158Smillert perltest/unknown_raw perltest/unknown_raw1); 140*b39c5158Smillert@f = ClipbrdFmtAtoms; 141*b39c5158Smillertis(scalar @f, 5, "5 formats available"); 142*b39c5158Smillertis((join ',', sort map AtomName($_), @f), $names, "formats are $names"); 143*b39c5158Smillert 144*b39c5158Smillert@f = ClipbrdFmtNames; 145*b39c5158Smillertis(scalar @f, 5, "Only one format available"); 146*b39c5158Smillertis((join ',', sort @f), $names, "formats are $names"); 147*b39c5158Smillert 148*b39c5158Smillert{ 149*b39c5158Smillert my $h = OS2::localClipbrd->new; 150*b39c5158Smillert ok(EmptyClipbrd, 'EmptyClipbrd'); 151*b39c5158Smillert} 152*b39c5158Smillert 153*b39c5158Smillert@f = ClipbrdFmtNames; 154*b39c5158Smillertis(scalar @f, 0, "No formats available"); 155*b39c5158Smillert 156*b39c5158Smillert{ 157*b39c5158Smillert my $h = OS2::localClipbrd->new; 158*b39c5158Smillert ok(ClipbrdText_set($cr, 1, $ar), 'ClipbrdText_set(perltest/unknown_raw)'); 159*b39c5158Smillert}; 160*b39c5158Smillert 161*b39c5158Smillert#diag(join ' ', ClipbrdFmtNames); 162*b39c5158Smillert 163*b39c5158Smillertis(ClipbrdText($ar), $cr, "ClipbrdText perltest/unknown_raw back"); 164*b39c5158Smillertis(ClipbrdFmtInfo($ar), CFI_POINTER, 'ClipbrdFmtInfo is CFI_POINTER'); 165*b39c5158Smillert 166*b39c5158Smillertok(!defined eval {ClipbrdText(CF_TEXT); 1}, "ClipbrdText(CF_TEXT) croaks"); 167*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 168*b39c5158Smillert# CF_TEXT is 1 169*b39c5158Smillertok(!defined eval {ClipbrdText(1+CF_TEXT); 1}, "ClipbrdText(1+CF_TEXT) croaks"); 170*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 171*b39c5158Smillert 172*b39c5158Smillert@f = ClipbrdFmtNames; 173*b39c5158Smillertis(scalar @f, 1, "1 format available"); 174*b39c5158Smillertis($f[0], 'perltest/unknown_raw', "format is perltest/unknown_raw"); 175*b39c5158Smillert 176*b39c5158Smillert@f = ClipbrdFmtAtoms; 177*b39c5158Smillertis(scalar @f, 1, "1 format available"); 178*b39c5158Smillertis($f[0], $ar, "format is perltest/unknown_raw"); 179*b39c5158Smillert 180*b39c5158Smillert{ 181*b39c5158Smillert my $h = OS2::localClipbrd->new; 182*b39c5158Smillert ok(EmptyClipbrd, 'EmptyClipbrd'); 183*b39c5158Smillert} 184*b39c5158Smillert 185*b39c5158Smillertundef $p; undef $v; 186*b39c5158Smillerteval { 187*b39c5158Smillert my $h = OS2::localClipbrd->new; 188*b39c5158Smillert $p = ClipbrdData; 189*b39c5158Smillert $v = 1; 190*b39c5158Smillert}; 191*b39c5158Smillert 192*b39c5158Smillertok(! defined $p, 'ClipbrdData croaked'); 193*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 194*b39c5158Smillert 195*b39c5158Smillertok(! defined eval {ClipbrdText}, "ClipbrdText croaks"); 196*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 197*b39c5158Smillert 198*b39c5158Smillert# CF_TEXT is 1 199*b39c5158Smillertok(!defined eval {ClipbrdText(1+CF_TEXT); 1}, "ClipbrdText(not CF_TEXT) croaks"); 200*b39c5158Smillertlike($@, qr/\bPMERR_INVALID_HWND\b/, 'with expected (lousy) error message'); 201*b39c5158Smillert 202*b39c5158Smillertis(ClipbrdOwner, 0, "ClipbrdOwner is not defined"); 203*b39c5158Smillert 204*b39c5158Smillert$v = ClipbrdViewer; 205*b39c5158Smillertok((!$v || IsWindow $v), "ClipbrdViewer is not defined or a valid window"); 206*b39c5158Smillert 207*b39c5158Smillertis(ClipbrdFmtInfo, 0, 'ClipbrdFmtInfo is 0'); 208*b39c5158Smillert 209*b39c5158Smillert@f = ClipbrdFmtAtoms; 210*b39c5158Smillertis(scalar @f, 0, "No formats available"); 211*b39c5158Smillert 212