Commit | Line | Data |
8883bb5a |
1 | use strict;\r |
2 | use Test;\r |
3 | use Cwd qw(cwd);\r |
4 | use Win32;\r |
5 | \r |
6 | BEGIN {\r |
7 | unless (defined &Win32::BuildNumber && Win32::BuildNumber() >= 820 or $] >= 5.008009) {\r |
8 | print "1..0 # Skip: Needs ActivePerl 820 or Perl 5.8.9 or later\n";\r |
9 | exit 0;\r |
10 | }\r |
11 | if ((((Win32::FsType())[1] & 4) == 0) || (Win32::FsType() =~ /^FAT/)) {\r |
12 | print "1..0 # Skip: Filesystem doesn't support Unicode\n";\r |
13 | exit 0;\r |
14 | }\r |
15 | unless ((Win32::GetOSVersion())[1] > 4) {\r |
16 | print "1..0 # Skip: Unicode support requires Windows 2000 or later\n";\r |
17 | exit 0;\r |
18 | }\r |
19 | }\r |
20 | \r |
21 | my $home = Win32::GetCwd();\r |
22 | my $cwd = cwd(); # may be a Cygwin path\r |
23 | my $dir = "Foo \x{394}\x{419} Bar \x{5E7}\x{645} Baz";\r |
24 | my $file = "$dir\\xyzzy \x{394}\x{419} plugh \x{5E7}\x{645}";\r |
25 | \r |
26 | sub cleanup {\r |
27 | chdir($home);\r |
28 | my $ansi = Win32::GetANSIPathName($file);\r |
29 | unlink($ansi) if -f $ansi;\r |
30 | $ansi = Win32::GetANSIPathName($dir);\r |
31 | rmdir($ansi) if -d $ansi;\r |
32 | }\r |
33 | \r |
34 | cleanup();\r |
35 | END { cleanup() }\r |
36 | \r |
37 | plan test => 12;\r |
38 | \r |
39 | # Create Unicode directory\r |
40 | Win32::CreateDirectory($dir);\r |
41 | ok(-d Win32::GetANSIPathName($dir));\r |
42 | \r |
43 | # Create Unicode file\r |
44 | Win32::CreateFile($file);\r |
45 | ok(-f Win32::GetANSIPathName($file));\r |
46 | \r |
47 | # readdir() returns ANSI form of Unicode filename\r |
48 | ok(opendir(my $dh, Win32::GetANSIPathName($dir)));\r |
49 | while ($_ = readdir($dh)) {\r |
50 | next if /^\./;\r |
51 | ok($file, Win32::GetLongPathName("$dir\\$_"));\r |
52 | }\r |
53 | closedir($dh);\r |
54 | \r |
55 | # Win32::GetLongPathName() of the absolute path restores the Unicode dir name\r |
56 | my $full = Win32::GetFullPathName($dir);\r |
57 | my $long = Win32::GetLongPathName($full);\r |
58 | \r |
59 | ok($long, Win32::GetLongPathName($home)."\\$dir");\r |
60 | \r |
61 | # We can Win32::SetCwd() into the Unicode directory\r |
62 | ok(Win32::SetCwd($dir));\r |
63 | \r |
64 | my $w32dir = Win32::GetCwd();\r |
65 | # cwd() also returns a usable ANSI directory name\r |
66 | my $subdir = cwd();\r |
67 | \r |
68 | # change back to home directory to make sure relative paths\r |
69 | # in @INC continue to work\r |
70 | ok(chdir($home));\r |
71 | ok(Win32::GetCwd(), $home);\r |
72 | \r |
73 | ok(Win32::GetLongPathName($w32dir), $long);\r |
74 | \r |
75 | # cwd() on Cygwin returns a mapped path that we need to translate\r |
76 | # back to a Windows path. Invoking `cygpath` on $subdir doesn't work.\r |
77 | if ($^O eq "cygwin") {\r |
78 | $subdir = Cygwin::posix_to_win_path($subdir, 1);\r |
79 | }\r |
80 | $subdir =~ s,/,\\,g;\r |
81 | ok(Win32::GetLongPathName($subdir), $long);\r |
82 | \r |
83 | # We can chdir() into the Unicode directory if we use the ANSI name\r |
84 | ok(chdir(Win32::GetANSIPathName($dir)));\r |
85 | ok(Win32::GetLongPathName(Win32::GetCwd()), $long);\r |