1b39c5158Smillert#!/usr/bin/perl -w 2b39c5158Smillert# Before `make install' is performed this script should be runnable with 3b39c5158Smillert# `make test'. After `make install' it should work as `perl test.pl' 4b39c5158Smillert 5b39c5158Smillert######################### We start with some black magic to print on failure. 6b39c5158Smillert 7b39c5158SmillertBEGIN { 8b39c5158Smillert $|= 1; 9b39c5158Smillert 10b39c5158Smillert # when building perl, skip this test if Win32API::File isn't being built 11b39c5158Smillert if ( $ENV{PERL_CORE} ) { 12b39c5158Smillert require Config; 13b39c5158Smillert if ( $Config::Config{extensions} !~ m:(?<!\S)Win32API/File(?!\S): ) { 14b39c5158Smillert print "1..0 # Skip Win32API::File extension not built\n"; 15b39c5158Smillert exit(); 16b39c5158Smillert } 17b39c5158Smillert } 18b39c5158Smillert 19*91f110e0Safresh1 print "1..270\n"; 20b39c5158Smillert} 21b39c5158SmillertEND {print "not ok 1\n" unless $loaded;} 22b39c5158Smillert 23b39c5158Smillert# Win32API::File does an implicit "require Win32", but 24b39c5158Smillert# the ../lib directory in @INC will no longer work once 25b39c5158Smillert# we chdir() into the TEMP directory. 26b39c5158Smillert 27*91f110e0Safresh1use Win32; 28b39c5158Smillertuse File::Spec; 29b39c5158Smillertuse Carp; 30b39c5158Smillertuse Carp::Heavy; 31b39c5158Smillert 32b39c5158Smillertuse Win32API::File qw(:ALL); 33b39c5158Smillert$loaded = 1; 34b39c5158Smillertprint "ok 1\n"; 35b39c5158Smillert 36b39c5158Smillert######################### End of black magic. 37b39c5158Smillert 38b39c5158Smillert$test= 1; 39b39c5158Smillert 40b39c5158Smillertuse strict qw(subs); 41b39c5158Smillert 42b39c5158Smillert$temp= File::Spec->tmpdir(); 43b39c5158Smillert$dir= "W32ApiF.tmp"; 44b39c5158Smillert 45b39c5158Smillert$ENV{WINDIR} = $ENV{SYSTEMROOT} if not exists $ENV{WINDIR}; 46b39c5158Smillert 47b39c5158Smillertchdir( $temp ) 48b39c5158Smillert or die "# Can't cd to temp directory, $temp: $!\n"; 49b39c5158Smillert$tempdir = File::Spec->catdir($temp,$dir); 50b39c5158Smillertif( -d $dir ) { 51b39c5158Smillert print "# deleting ",File::Spec->catdir($temp,$dir,'*'),"\n" if glob "$dir/*"; 52b39c5158Smillert 53b39c5158Smillert for (glob "$dir/*") { 54b39c5158Smillert chmod 0777, $_; 55b39c5158Smillert unlink $_; 56b39c5158Smillert } 57b39c5158Smillert rmdir $dir or die "Could not rmdir $dir: $!"; 58b39c5158Smillert} 59b39c5158Smillertmkdir( $dir, 0777 ) 60b39c5158Smillert or die "# Can't create temp dir, $tempdir: $!\n"; 61b39c5158Smillertprint "# chdir $tempdir\n"; 62b39c5158Smillertchdir( $dir ) 63b39c5158Smillert or die "# Can't cd to my dir, $tempdir: $!\n"; 64b39c5158Smillert$h1= createFile( "ReadOnly.txt", "r", { Attributes=>"r" } ); 65b39c5158Smillert$ok= ! $h1 && Win32API::File::_fileLastError() == 2; # could not find the file 66b39c5158Smillert$ok or print "# ","".fileLastError(),"\n"; 67b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 2 68b39c5158Smillertif( ! $ok ) { CloseHandle($h1); unlink("ReadOnly.txt"); } 69b39c5158Smillert 70b39c5158Smillert$ok= $h1= createFile( "ReadOnly.txt", "wcn", { Attributes=>"r" } ); 71b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 72b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 3 73b39c5158Smillert 74b39c5158Smillert$ok= WriteFile( $h1, "Original text\n", 0, [], [] ); 75b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 76b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 4 77b39c5158Smillert 78b39c5158Smillert$h2= createFile( "ReadOnly.txt", "rcn" ); 79b39c5158Smillert$ok= ! $h2 && Win32API::File::_fileLastError() == 80; # file exists 80b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 81b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 5 82b39c5158Smillertif( ! $ok ) { CloseHandle($h2); } 83b39c5158Smillert 84b39c5158Smillert$h2= createFile( "ReadOnly.txt", "rwke" ); 85b39c5158Smillert$ok= ! $h2 && Win32API::File::_fileLastError() == 5; # access is denied 86b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 87b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 6 88b39c5158Smillertif( ! $ok ) { CloseHandle($h2); } 89b39c5158Smillert 90b39c5158Smillert$ok= $h2= createFile( "ReadOnly.txt", "r" ); 91b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 92b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 7 93b39c5158Smillert 94b39c5158Smillert$ok= SetFilePointer( $h1, length("Original"), [], FILE_BEGIN ); 95b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 96b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 8 97b39c5158Smillert 98b39c5158Smillert$ok= WriteFile( $h1, "ly was other text\n", 0, $len, [] ) 99b39c5158Smillert && $len == length("ly was other text\n"); 100b39c5158Smillert$ok or print "# <$len> should be <", 101b39c5158Smillert length("ly was other text\n"),">: ",fileLastError(),"\n"; 102b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 9 103b39c5158Smillert 104b39c5158Smillert$ok= ReadFile( $h2, $text, 80, $len, [] ) 105b39c5158Smillert && $len == length($text); 106b39c5158Smillert$ok or print "# <$len> should be <",length($text), 107b39c5158Smillert ">: ",fileLastError(),"\n"; 108b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 10 109b39c5158Smillert 110b39c5158Smillert$ok= $text eq "Originally was other text\n"; 111b39c5158Smillertif( !$ok ) { 112b39c5158Smillert $text =~ s/\r/\\r/g; $text =~ s/\n/\\n/g; 113b39c5158Smillert print "# <$text> should be <Originally was other text\\n>.\n"; 114b39c5158Smillert} 115b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 11 116b39c5158Smillert 117b39c5158Smillert$ok= CloseHandle($h2); 118b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 119b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 12 120b39c5158Smillert 121b39c5158Smillert$ok= ! ReadFile( $h2, $text, 80, $len, [] ) 122b39c5158Smillert && Win32API::File::_fileLastError() == 6; # handle is invalid 123b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 124b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 13 125b39c5158Smillert 126b39c5158SmillertCloseHandle($h1); 127b39c5158Smillert 128b39c5158Smillert$ok= $h1= createFile( "CanWrite.txt", "rw", FILE_SHARE_WRITE, 129b39c5158Smillert { Create=>CREATE_ALWAYS } ); 130b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 131b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 14 132b39c5158Smillert 133b39c5158Smillert$ok= WriteFile( $h1, "Just this and not this", 10, [], [] ); 134b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 135b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 15 136b39c5158Smillert 137b39c5158Smillert$ok= $h2= createFile( "CanWrite.txt", "wk", { Share=>"rw" } ); 138b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 139b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 16 140b39c5158Smillert 141b39c5158Smillert$ok= OsFHandleOpen( "APP", $h2, "wat" ); 142b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 143b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 17 144b39c5158Smillert 145b39c5158Smillert$ok= $h2 == GetOsFHandle( "APP" ); 146b39c5158Smillert$ok or print "# $h2 != ",GetOsFHandle("APP"),"\n"; 147b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 18 148b39c5158Smillert 149b39c5158Smillert{ my $save= select(APP); $|= 1; select($save); } 150b39c5158Smillert$ok= print APP "is enough\n"; 151b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 152b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 19 153b39c5158Smillert 154b39c5158SmillertSetFilePointer($h1, 0, [], FILE_BEGIN) if $^O eq 'cygwin'; 155b39c5158Smillert 156b39c5158Smillert$ok= ReadFile( $h1, $text, 0, [], [] ); 157b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 158b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 20 159b39c5158Smillert 160b39c5158Smillert$ok= $text eq "is enough\r\n"; 161b39c5158Smillertif( !$ok ) { 162b39c5158Smillert $text =~ s/\r/\\r/g; 163b39c5158Smillert $text =~ s/\n/\\n/g; 164b39c5158Smillert print "# <$text> should be <is enough\\r\\n>\n"; 165b39c5158Smillert} 166b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 21 167b39c5158Smillert 168b39c5158Smillert$skip = ""; 169b39c5158Smillertif ($^O eq 'cygwin') { 170b39c5158Smillert $ok = 1; 171b39c5158Smillert $skip = " # skip cygwin can delete open files"; 172b39c5158Smillert} 173b39c5158Smillertelse { 174b39c5158Smillert unlink("CanWrite.txt"); 175b39c5158Smillert $ok = -e "CanWrite.txt" && $! =~ /permission denied/i; 176b39c5158Smillert $ok or print "# $!\n"; 177b39c5158Smillert} 178b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "$skip\n"; # ok 22 179b39c5158Smillert 180b39c5158Smillertclose(APP); # Also does C<CloseHandle($h2)> 181b39c5158Smillert## CloseHandle( $h2 ); 182b39c5158SmillertCloseHandle( $h1 ); 183b39c5158Smillert 184b39c5158Smillert$ok= ! DeleteFile( "ReadOnly.txt" ) 185b39c5158Smillert && Win32API::File::_fileLastError() == 5; # access is denied 186b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 187b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 23 188b39c5158Smillert 189b39c5158Smillert$ok= ! CopyFile( "ReadOnly.txt", "CanWrite.txt", 1 ) 190b39c5158Smillert && Win32API::File::_fileLastError() == 80; # file exists 191b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 192b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 24 193b39c5158Smillert 194b39c5158Smillert$ok= ! CopyFile( "CanWrite.txt", "ReadOnly.txt", 0 ) 195b39c5158Smillert && Win32API::File::_fileLastError() == 5; # access is denied 196b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 197b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 25 198b39c5158Smillert 199b39c5158Smillert$ok= ! MoveFile( "NoSuchFile", "NoSuchDest" ) 200b39c5158Smillert && Win32API::File::_fileLastError() == 2; # not find the file 201b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 202b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 26 203b39c5158Smillert 204b39c5158Smillert$ok= ! MoveFileEx( "NoSuchFile", "NoSuchDest", 0 ) 205b39c5158Smillert && Win32API::File::_fileLastError() == 2; # not find the file 206b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 207b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 27 208b39c5158Smillert 209b39c5158Smillert$ok= ! MoveFile( "ReadOnly.txt", "CanWrite.txt" ) 210b39c5158Smillert && Win32API::File::_fileLastError() == 183; # file already exists 211b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 212b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 28 213b39c5158Smillert 214b39c5158Smillert$ok= ! MoveFileEx( "ReadOnly.txt", "CanWrite.txt", 0 ) 215b39c5158Smillert && Win32API::File::_fileLastError() == 183; # file already exists 216b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 217b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 29 218b39c5158Smillert 219b39c5158Smillert$ok= CopyFile( "ReadOnly.txt", "ReadOnly.cp", 1 ) 220b39c5158Smillert && CopyFile( "CanWrite.txt", "CanWrite.cp", 1 ); 221b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 222b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 30 223b39c5158Smillert 224b39c5158Smillert$ok= ! MoveFileEx( "CanWrite.txt", "ReadOnly.cp", MOVEFILE_REPLACE_EXISTING ) 225b39c5158Smillert && (Win32API::File::_fileLastError() == 5 # access is denied 226b39c5158Smillert || Win32API::File::_fileLastError() == 183); # already exists 227b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 228b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 31 229b39c5158Smillert 230b39c5158Smillert$ok= MoveFileEx( "ReadOnly.cp", "CanWrite.cp", MOVEFILE_REPLACE_EXISTING ); 231b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 232b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 32 233b39c5158Smillert 234b39c5158Smillert$ok= MoveFile( "CanWrite.cp", "Moved.cp" ); 235b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 236b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 33 237b39c5158Smillert 238b39c5158Smillert$ok= ! unlink( "ReadOnly.cp" ) 239b39c5158Smillert && $! =~ /no such file/i 240b39c5158Smillert && ! unlink( "CanWrite.cp" ) 241b39c5158Smillert && $! =~ /no such file/i; 242b39c5158Smillert$ok or print "# $!\n"; 243b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 34 244b39c5158Smillert 245b39c5158Smillert$ok= ! DeleteFile( "Moved.cp" ) 246b39c5158Smillert && Win32API::File::_fileLastError() == 5; # access is denied 247b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 248b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 35 249b39c5158Smillert 250b39c5158Smillertif ($^O eq 'cygwin') { 251b39c5158Smillert chmod( 0200 | 07777 & (stat("Moved.cp"))[2], "Moved.cp" ); 252b39c5158Smillert} 253b39c5158Smillertelse { 254b39c5158Smillert system( "attrib -r Moved.cp" ); 255b39c5158Smillert} 256b39c5158Smillert 257b39c5158Smillert$ok= DeleteFile( "Moved.cp" ); 258b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 259b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 36 260b39c5158Smillert 261b39c5158Smillert$new= SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX; 262b39c5158Smillert$old= SetErrorMode( $new ); 263b39c5158Smillert$renew= SetErrorMode( $old ); 264b39c5158Smillert$reold= SetErrorMode( $old ); 265b39c5158Smillert 266b39c5158Smillert$ok= $old == $reold; 267b39c5158Smillert$ok or print "# $old != $reold: ",fileLastError(),"\n"; 268b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 37 269b39c5158Smillert 270b39c5158Smillert$ok= ($renew&$new) == $new; 271b39c5158Smillert$ok or print "# $new != $renew: ",fileLastError(),"\n"; 272b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 38 273b39c5158Smillert 274b39c5158Smillert$ok= @drives= getLogicalDrives(); 275b39c5158Smillert$ok && print "# @drives\n"; 276b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 277b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 39 278b39c5158Smillert 279b39c5158Smillert$ok= $drives[0] !~ /^[ab]/ || DRIVE_REMOVABLE == GetDriveType($drives[0]); 280b39c5158Smillert$ok or print "# ",DRIVE_REMOVABLE," != ",GetDriveType($drives[0]), 281b39c5158Smillert ": ",fileLastError(),"\n"; 282b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 40 283b39c5158Smillert 284b39c5158Smillert$drive= substr( $ENV{WINDIR}, 0, 3 ); 285b39c5158Smillert 286b39c5158Smillert$ok= 1 == grep /^\Q$drive\E/i, @drives; 287b39c5158Smillert$ok or print "# No $drive found in list of drives.\n"; 288b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 41 289b39c5158Smillert 290b39c5158Smillert$ok= DRIVE_FIXED == GetDriveType( $drive ); 291b39c5158Smillert$ok or print 292b39c5158Smillert "# ",DRIVE_FIXED," != ",GetDriveType($drive),": ",fileLastError(),"\n"; 293b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 42 294b39c5158Smillert 295b39c5158Smillert$ok= GetVolumeInformation( $drive, $vol, 64, $ser, $max, $flag, $fs, 16 ); 296b39c5158Smillert$ok or print "# ",fileLastError(),"\n"; 297b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 43 298b39c5158Smillert$vol= $ser= $max= $flag= $fs= ""; # Prevent warnings. 299b39c5158Smillert 300b39c5158Smillertchop($drive); 301b39c5158Smillert$ok= QueryDosDevice( $drive, $dev, 80 ); 302b39c5158Smillert$ok or print "# $drive: ",fileLastError(),"\n"; 303b39c5158Smillertif( $ok ) { 304b39c5158Smillert ( $text= $dev ) =~ s/\0/\\0/g; 305b39c5158Smillert print "# $drive => $text\n"; 306b39c5158Smillert} 307b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 44 308b39c5158Smillert 309b39c5158Smillert$bits= GetLogicalDrives(); 310b39c5158Smillert$let= 25; 311b39c5158Smillert$bit= 1<<$let; 312b39c5158Smillertwhile( $bit & $bits ) { 313b39c5158Smillert $let--; 314b39c5158Smillert $bit >>= 1; 315b39c5158Smillert} 316b39c5158Smillert$let= pack( "C", $let + unpack("C","A") ) . ":"; 317b39c5158Smillertprint "# Querying undefined $let.\n"; 318b39c5158Smillert 319b39c5158Smillert$ok= DefineDosDevice( 0, $let, $ENV{WINDIR} ); 320b39c5158Smillert$ok or print "# $let,$ENV{WINDIR}: ",fileLastError(),"\n"; 321b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 45 322b39c5158Smillert 323b39c5158Smillert$ok= -s $let."/Win.ini" == -s $ENV{WINDIR}."/Win.ini"; 324b39c5158Smillert$ok or print "# ", -s $let."/Win.ini", " vs. ", 325b39c5158Smillert -s $ENV{WINDIR}."/Win.ini", ": ",fileLastError(),"\n"; 326b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 46 327b39c5158Smillert 328b39c5158Smillert$ok= DefineDosDevice( DDD_REMOVE_DEFINITION|DDD_EXACT_MATCH_ON_REMOVE, 329b39c5158Smillert $let, $ENV{WINDIR} ); 330b39c5158Smillert$ok or print "# $let,$ENV{WINDIR}: ",fileLastError(),"\n"; 331b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 47 332b39c5158Smillert 333b39c5158Smillert$ok= ! -f $let."/Win.ini" 334b39c5158Smillert && $! =~ /no such file/i; 335b39c5158Smillert$ok or print "# $!\n"; 336b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 48 337b39c5158Smillert 338b39c5158Smillert$ok= DefineDosDevice( DDD_RAW_TARGET_PATH, $let, $dev ); 339b39c5158Smillertif( !$ok ) { 340b39c5158Smillert ( $text= $dev ) =~ s/\0/\\0/g; 341b39c5158Smillert print "# $let,$text: ",fileLastError(),"\n"; 342b39c5158Smillert} 343b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 49 344b39c5158Smillert 345*91f110e0Safresh1my $path = $ENV{WINDIR}; 346*91f110e0Safresh1$ok= -f $let.substr($path,$^O eq 'cygwin'?2:3)."/win.ini"; 347*91f110e0Safresh1$ok or print "# ",$let.substr($path,3)."/win.ini ",fileLastError(),"\n"; 348b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 50 349b39c5158Smillert 350b39c5158Smillert$ok= DefineDosDevice( DDD_REMOVE_DEFINITION|DDD_EXACT_MATCH_ON_REMOVE 351b39c5158Smillert |DDD_RAW_TARGET_PATH, $let, $dev ); 352b39c5158Smillert$ok or print "# $let,$dev: ",fileLastError(),"\n"; 353b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 51 354b39c5158Smillert 355b39c5158Smillertmy $attrs = GetFileAttributes( $path ); 356b39c5158Smillert$ok= $attrs != INVALID_FILE_ATTRIBUTES; 357b39c5158Smillert$ok or print "# $path gave invalid attribute value, attrs=$attrs: ",fileLastError(),"\n"; 358b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 52 359b39c5158Smillert 360b39c5158Smillert$ok= ($attrs & FILE_ATTRIBUTE_DIRECTORY); 361b39c5158Smillert$ok or print "# $path not a directory, attrs=$attrs: ",fileLastError(),"\n"; 362b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 53 363b39c5158Smillert 364b39c5158Smillert$path .= "/win.ini"; 365b39c5158Smillert$attrs = GetFileAttributes( $path ); 366b39c5158Smillert$ok= $attrs != INVALID_FILE_ATTRIBUTES; 367b39c5158Smillert$ok or print "# $path gave invalid attribute value, attrs=$attrs: ",fileLastError(),"\n"; 368b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 54 369b39c5158Smillert 370b39c5158Smillert$ok= !($attrs & FILE_ATTRIBUTE_DIRECTORY); 371b39c5158Smillert$ok or print "# $path is a directory, attrs=$attrs: ",fileLastError(),"\n"; 372b39c5158Smillertprint $ok ? "" : "not ", "ok ", ++$test, "\n"; # ok 55 373b39c5158Smillert 374b39c5158Smillert# DefineDosDevice 375b39c5158Smillert# GetFileType 376b39c5158Smillert# GetVolumeInformation 377b39c5158Smillert# QueryDosDevice 378b39c5158Smillert#Add a drive letter that points to our temp directory 379b39c5158Smillert#Add a drive letter that points to the drive our directory is in 380b39c5158Smillert 381b39c5158Smillert#winnt.t: 382b39c5158Smillert# get first drive letters and use to test disk and storage IOCTLs 383b39c5158Smillert# "//./PhysicalDrive0" 384b39c5158Smillert# DeviceIoControl 385b39c5158Smillert 386b39c5158Smillertmy %consts; 387b39c5158Smillertmy @consts= @Win32API::File::EXPORT_OK; 388b39c5158Smillert@consts{@consts}= @consts; 389b39c5158Smillert 390b39c5158Smillertmy( @noargs, %noargs )= qw( 391b39c5158Smillert attrLetsToBits fileLastError getLogicalDrives GetLogicalDrives ); 392b39c5158Smillert@noargs{@noargs}= @noargs; 393b39c5158Smillert 394b39c5158Smillertforeach $func ( @{$Win32API::File::EXPORT_TAGS{Func}} ) { 395b39c5158Smillert delete $consts{$func}; 396b39c5158Smillert if( defined( $noargs{$func} ) ) { 397b39c5158Smillert $ok= ! eval("$func(0,0)") && $@ =~ /(::|\s)_?${func}A?[(:\s]/; 398b39c5158Smillert } else { 399b39c5158Smillert $ok= ! eval("$func()") && $@ =~ /(::|\s)_?${func}A?[(:\s]/; 400b39c5158Smillert } 401b39c5158Smillert $ok or print "# $func: $@\n"; 402b39c5158Smillert print $ok ? "" : "not ", "ok ", ++$test, "\n"; 403b39c5158Smillert} 404b39c5158Smillert 405b39c5158Smillertforeach $func ( @{$Win32API::File::EXPORT_TAGS{FuncA}}, 406b39c5158Smillert @{$Win32API::File::EXPORT_TAGS{FuncW}} ) { 407b39c5158Smillert $ok= ! eval("$func()") && $@ =~ /::_?${func}\(/; 408b39c5158Smillert delete $consts{$func}; 409b39c5158Smillert $ok or print "# $func: $@\n"; 410b39c5158Smillert print $ok ? "" : "not ", "ok ", ++$test, "\n"; 411b39c5158Smillert} 412b39c5158Smillert 413b39c5158Smillertforeach $const ( keys(%consts) ) { 414b39c5158Smillert $ok= eval("my \$x= $const(); 1"); 415b39c5158Smillert $ok or print "# Constant $const: $@\n"; 416b39c5158Smillert print $ok ? "" : "not ", "ok ", ++$test, "\n"; 417b39c5158Smillert} 418b39c5158Smillert 419b39c5158Smillertchdir( $temp ); 420b39c5158Smillertif (-e "$dir/ReadOnly.txt") { 421b39c5158Smillert chmod 0777, "$dir/ReadOnly.txt"; 422b39c5158Smillert unlink "$dir/ReadOnly.txt"; 423b39c5158Smillert} 424b39c5158Smillertunlink "$dir/CanWrite.txt" if -e "$dir/CanWrite.txt"; 425b39c5158Smillertrmdir $dir; 426b39c5158Smillert 427b39c5158Smillert__END__ 428