author | dxu |
Fri, 31 May 2013 13:34:27 -0700 | |
changeset 17924 | c4e51dc609b1 |
parent 17726 | 4aff99bf471b |
child 21824 | 123a828f30dc |
permissions | -rw-r--r-- |
2 | 1 |
/* |
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
2 |
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
25 |
@bug 4032066 4039597 4046914 4054511 4065189 4109131 4875229 6983520 8009258 |
2 | 26 |
@summary General exhaustive test of win32 pathname handling |
27 |
@author Mark Reinhold |
|
28 |
||
29 |
@build General GeneralWin32 |
|
30 |
@run main/timeout=600 GeneralWin32 |
|
31 |
*/ |
|
32 |
||
33 |
import java.io.*; |
|
34 |
||
35 |
public class GeneralWin32 extends General { |
|
36 |
||
37 |
||
38 |
/** |
|
39 |
* Hardwired UNC pathnames used for testing |
|
40 |
* |
|
41 |
* This test attempts to use the host and share names defined in this class |
|
42 |
* to test UNC pathnames. The test will not fail if the host or share |
|
43 |
* don't exist, but it will print a warning saying that it was unable to |
|
44 |
* test UNC pathnames completely. |
|
45 |
*/ |
|
46 |
private static final String EXISTENT_UNC_HOST = "pc-cup01"; |
|
47 |
private static final String EXISTENT_UNC_SHARE = "pcdist"; |
|
48 |
private static final String NONEXISTENT_UNC_HOST = "non-existent-unc-host"; |
|
49 |
private static final String NONEXISTENT_UNC_SHARE = "bogus-share"; |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
50 |
private static final int DEPTH = 2; |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
51 |
private static String baseDir = null; |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
52 |
private static String userDir = null; |
17924
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
53 |
private static String relative = null; |
2 | 54 |
|
55 |
/* Pathnames relative to working directory */ |
|
56 |
||
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
57 |
private static void checkCaseLookup() throws IOException { |
2 | 58 |
/* Use long names here to avoid 8.3 format, which Samba servers often |
59 |
force to lowercase */ |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
60 |
File d1 = new File(relative, "XyZzY0123"); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
61 |
File d2 = new File(d1, "FOO_bar_BAZ"); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
62 |
File f = new File(d2, "GLORPified"); |
2 | 63 |
if (!f.exists()) { |
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
64 |
if (!d2.exists()) { |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
65 |
if (!d2.mkdirs()) { |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
66 |
throw new RuntimeException("Can't create directory " + d2); |
2 | 67 |
} |
68 |
} |
|
69 |
OutputStream o = new FileOutputStream(f); |
|
70 |
o.close(); |
|
71 |
} |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
72 |
File f2 = new File(d2.getParent(), "mumble"); /* For later ud tests */ |
2 | 73 |
if (!f2.exists()) { |
74 |
OutputStream o = new FileOutputStream(f2); |
|
75 |
o.close(); |
|
76 |
} |
|
77 |
||
78 |
/* Computing the canonical path of a Win32 file should expose the true |
|
79 |
case of filenames, rather than just using the input case */ |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
80 |
File y = new File(userDir, f.getPath()); |
2 | 81 |
String ans = y.getPath(); |
17924
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
82 |
check(ans, relative + "XyZzY0123\\FOO_bar_BAZ\\GLORPified"); |
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
83 |
check(ans, relative + "xyzzy0123\\foo_bar_baz\\glorpified"); |
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
84 |
check(ans, relative + "XYZZY0123\\FOO_BAR_BAZ\\GLORPIFIED"); |
2 | 85 |
} |
86 |
||
87 |
private static void checkWild(File f) throws Exception { |
|
88 |
try { |
|
89 |
f.getCanonicalPath(); |
|
90 |
} catch (IOException x) { |
|
91 |
return; |
|
92 |
} |
|
93 |
throw new Exception("Wildcard path not rejected: " + f); |
|
94 |
} |
|
95 |
||
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
96 |
private static void checkWildCards() throws Exception { |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
97 |
File d = new File(baseDir).getCanonicalFile(); |
2 | 98 |
checkWild(new File(d, "*.*")); |
99 |
checkWild(new File(d, "*.???")); |
|
100 |
checkWild(new File(new File(d, "*.*"), "foo")); |
|
101 |
} |
|
102 |
||
103 |
private static void checkRelativePaths() throws Exception { |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
104 |
checkCaseLookup(); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
105 |
checkWildCards(); |
17924
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
106 |
checkNames(3, true, baseDir, relative); |
2 | 107 |
} |
108 |
||
109 |
||
110 |
/* Pathnames with drive specifiers */ |
|
111 |
||
112 |
private static char findInactiveDrive() { |
|
113 |
for (char d = 'Z'; d >= 'E'; d--) { |
|
114 |
File df = new File(d + ":\\"); |
|
115 |
if (!df.exists()) { |
|
116 |
return d; |
|
117 |
} |
|
118 |
} |
|
119 |
throw new RuntimeException("Can't find an inactive drive"); |
|
120 |
} |
|
121 |
||
122 |
private static char findActiveDrive() { |
|
123 |
for (char d = 'C'; d <= 'Z'; d--) { |
|
124 |
File df = new File(d + ":\\"); |
|
125 |
if (df.exists()) return d; |
|
126 |
} |
|
127 |
throw new RuntimeException("Can't find an active drive"); |
|
128 |
} |
|
129 |
||
130 |
private static void checkDrive(int depth, char drive, boolean exists) |
|
131 |
throws Exception |
|
132 |
{ |
|
133 |
String d = drive + ":"; |
|
134 |
File df = new File(d); |
|
135 |
String ans = exists ? df.getAbsolutePath() : d; |
|
136 |
if (!ans.endsWith("\\")) |
|
137 |
ans = ans + "\\"; |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
138 |
checkNames(depth, false, ans + relative, d + relative); |
2 | 139 |
} |
140 |
||
141 |
private static void checkDrivePaths() throws Exception { |
|
142 |
checkDrive(2, findActiveDrive(), true); |
|
143 |
checkDrive(2, findInactiveDrive(), false); |
|
144 |
} |
|
145 |
||
146 |
||
147 |
/* UNC pathnames */ |
|
148 |
||
149 |
private static void checkUncPaths() throws Exception { |
|
150 |
String s = ("\\\\" + NONEXISTENT_UNC_HOST |
|
151 |
+ "\\" + NONEXISTENT_UNC_SHARE); |
|
152 |
ensureNon(s); |
|
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
153 |
checkSlashes(DEPTH, false, s, s); |
2 | 154 |
|
155 |
s = "\\\\" + EXISTENT_UNC_HOST + "\\" + EXISTENT_UNC_SHARE; |
|
156 |
if (!(new File(s)).exists()) { |
|
157 |
System.err.println("WARNING: " + s + |
|
158 |
" does not exist, unable to test UNC pathnames"); |
|
159 |
return; |
|
160 |
} |
|
161 |
||
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
162 |
checkSlashes(DEPTH, false, s, s); |
2 | 163 |
} |
164 |
||
165 |
||
166 |
public static void main(String[] args) throws Exception { |
|
167 |
if (File.separatorChar != '\\') { |
|
168 |
/* This test is only valid on win32 systems */ |
|
169 |
return; |
|
170 |
} |
|
171 |
if (args.length > 0) debug = true; |
|
17924
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
172 |
userDir = System.getProperty("user.dir") + '\\'; |
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
173 |
baseDir = initTestData(6) + '\\'; |
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
174 |
relative = baseDir.substring(userDir.length()); |
2 | 175 |
checkRelativePaths(); |
176 |
checkDrivePaths(); |
|
177 |
checkUncPaths(); |
|
178 |
} |
|
179 |
||
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
180 |
private static String initTestData(int maxDepth) throws IOException { |
17924
c4e51dc609b1
8015628: Test Failure in closed/java/io/pathNames/GeneralSolaris.java
dxu
parents:
17726
diff
changeset
|
181 |
File parent = new File(userDir); |
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
182 |
String baseDir = null; |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
183 |
maxDepth = maxDepth < DEPTH + 2 ? DEPTH + 2 : maxDepth; |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
184 |
for (int i = 0; i < maxDepth; i ++) { |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
185 |
File dir1 = new File(parent, gensym()); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
186 |
dir1.mkdir(); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
187 |
if (i != 0) { |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
188 |
File dir2 = new File(parent, gensym()); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
189 |
dir2.mkdir(); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
190 |
File f1 = new File(parent, gensym()); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
191 |
f1.createNewFile(); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
192 |
File f2 = new File(parent, gensym()); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
193 |
f2.createNewFile(); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
194 |
} |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
195 |
if (i == DEPTH + 1) { |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
196 |
baseDir = dir1.getAbsolutePath(); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
197 |
} |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
198 |
parent = dir1; |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
199 |
} |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
200 |
return baseDir; |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
201 |
} |
2 | 202 |
} |