author | dxu |
Tue, 19 Nov 2013 13:22:50 -0800 | |
changeset 21824 | 123a828f30dc |
parent 17924 | c4e51dc609b1 |
child 43108 | 9849ccac1f10 |
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"; |
|
50 |
||
51 |
/* Pathnames relative to working directory */ |
|
52 |
||
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
53 |
private static void checkCaseLookup() throws IOException { |
2 | 54 |
/* Use long names here to avoid 8.3 format, which Samba servers often |
55 |
force to lowercase */ |
|
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
56 |
File d = new File("XyZzY0123", "FOO_bar_BAZ"); |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
57 |
File f = new File(d, "GLORPified"); |
2 | 58 |
if (!f.exists()) { |
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
59 |
if (!d.exists()) { |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
60 |
if (!d.mkdirs()) { |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
61 |
throw new RuntimeException("Can't create directory " + d); |
2 | 62 |
} |
63 |
} |
|
64 |
OutputStream o = new FileOutputStream(f); |
|
65 |
o.close(); |
|
66 |
} |
|
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
67 |
File f2 = new File(d.getParent(), "mumble"); /* For later ud tests */ |
2 | 68 |
if (!f2.exists()) { |
69 |
OutputStream o = new FileOutputStream(f2); |
|
70 |
o.close(); |
|
71 |
} |
|
72 |
||
73 |
/* Computing the canonical path of a Win32 file should expose the true |
|
74 |
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
|
75 |
File y = new File(userDir, f.getPath()); |
2 | 76 |
String ans = y.getPath(); |
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
77 |
check(ans, "XyZzY0123\\FOO_bar_BAZ\\GLORPified"); |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
78 |
check(ans, "xyzzy0123\\foo_bar_baz\\glorpified"); |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
79 |
check(ans, "XYZZY0123\\FOO_BAR_BAZ\\GLORPIFIED"); |
2 | 80 |
} |
81 |
||
82 |
private static void checkWild(File f) throws Exception { |
|
83 |
try { |
|
84 |
f.getCanonicalPath(); |
|
85 |
} catch (IOException x) { |
|
86 |
return; |
|
87 |
} |
|
88 |
throw new Exception("Wildcard path not rejected: " + f); |
|
89 |
} |
|
90 |
||
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
91 |
private static void checkWildCards() throws Exception { |
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
92 |
File d = new File(userDir).getCanonicalFile(); |
2 | 93 |
checkWild(new File(d, "*.*")); |
94 |
checkWild(new File(d, "*.???")); |
|
95 |
checkWild(new File(new File(d, "*.*"), "foo")); |
|
96 |
} |
|
97 |
||
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
98 |
private static void checkRelativePaths(int depth) throws Exception { |
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
99 |
checkCaseLookup(); |
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
100 |
checkWildCards(); |
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
101 |
// Make sure that an empty relative path is tested |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
102 |
checkNames(1, true, userDir + File.separator, ""); |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
103 |
checkNames(depth, true, baseDir + File.separator, |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
104 |
relative + File.separator); |
2 | 105 |
} |
106 |
||
107 |
||
108 |
/* Pathnames with drive specifiers */ |
|
109 |
||
110 |
private static char findInactiveDrive() { |
|
111 |
for (char d = 'Z'; d >= 'E'; d--) { |
|
112 |
File df = new File(d + ":\\"); |
|
113 |
if (!df.exists()) { |
|
114 |
return d; |
|
115 |
} |
|
116 |
} |
|
117 |
throw new RuntimeException("Can't find an inactive drive"); |
|
118 |
} |
|
119 |
||
120 |
private static char findActiveDrive() { |
|
121 |
for (char d = 'C'; d <= 'Z'; d--) { |
|
122 |
File df = new File(d + ":\\"); |
|
123 |
if (df.exists()) return d; |
|
124 |
} |
|
125 |
throw new RuntimeException("Can't find an active drive"); |
|
126 |
} |
|
127 |
||
128 |
private static void checkDrive(int depth, char drive, boolean exists) |
|
129 |
throws Exception |
|
130 |
{ |
|
131 |
String d = drive + ":"; |
|
132 |
File df = new File(d); |
|
133 |
String ans = exists ? df.getAbsolutePath() : d; |
|
134 |
if (!ans.endsWith("\\")) |
|
135 |
ans = ans + "\\"; |
|
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
136 |
checkNames(depth, false, ans, d); |
2 | 137 |
} |
138 |
||
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
139 |
private static void checkDrivePaths(int depth) throws Exception { |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
140 |
checkDrive(depth, findActiveDrive(), true); |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
141 |
checkDrive(depth, findInactiveDrive(), false); |
2 | 142 |
} |
143 |
||
144 |
||
145 |
/* UNC pathnames */ |
|
146 |
||
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
147 |
private static void checkUncPaths(int depth) throws Exception { |
2 | 148 |
String s = ("\\\\" + NONEXISTENT_UNC_HOST |
149 |
+ "\\" + NONEXISTENT_UNC_SHARE); |
|
150 |
ensureNon(s); |
|
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
151 |
checkSlashes(depth, false, s, s); |
2 | 152 |
|
153 |
s = "\\\\" + EXISTENT_UNC_HOST + "\\" + EXISTENT_UNC_SHARE; |
|
154 |
if (!(new File(s)).exists()) { |
|
155 |
System.err.println("WARNING: " + s + |
|
156 |
" does not exist, unable to test UNC pathnames"); |
|
157 |
return; |
|
158 |
} |
|
159 |
||
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
160 |
checkSlashes(depth, false, s, s); |
2 | 161 |
} |
162 |
||
163 |
||
164 |
public static void main(String[] args) throws Exception { |
|
165 |
if (File.separatorChar != '\\') { |
|
166 |
/* This test is only valid on win32 systems */ |
|
167 |
return; |
|
168 |
} |
|
169 |
if (args.length > 0) debug = true; |
|
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
170 |
|
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
171 |
initTestData(3); |
2 | 172 |
|
21824
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
173 |
checkRelativePaths(3); |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
174 |
checkDrivePaths(2); |
123a828f30dc
8028631: Improve the test coverage to the pathname handling on unix-like platforms
dxu
parents:
17924
diff
changeset
|
175 |
checkUncPaths(2); |
17726
4aff99bf471b
8009258: TEST_BUG:java/io/pathNames/GeneralWin32.java fails intermittently
ewang
parents:
7668
diff
changeset
|
176 |
} |
2 | 177 |
} |