GeneralWin32.java revision 2362
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This code is free software; you can redistribute it and/or modify it
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * under the terms of the GNU General Public License version 2 only, as
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * published by the Free Software Foundation.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *
30eec077db2bdcb6f2a0dc388a3cdde2ede75ec1Mark Andrews * This code is distributed in the hope that it will be useful, but WITHOUT
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * version 2 for more details (a copy is included in the LICENSE file that
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt * accompanied this code).
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * You should have received a copy of the GNU General Public License version
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * 2 along with this work; if not, write to the Free Software Foundation,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * or visit www.oracle.com if you need additional information or have any
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * questions.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein/* @test
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein @bug 4032066 4039597 4046914 4054511 4065189 4109131 4875229
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein @summary General exhaustive test of win32 pathname handling
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein @author Mark Reinhold
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein @build General GeneralWin32
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein @run main/timeout=600 GeneralWin32
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Huntimport java.io.*;
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Huntimport java.util.*;
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrewspublic class GeneralWin32 extends General {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Hardwired UNC pathnames used for testing
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein *
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * This test attempts to use the host and share names defined in this class
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * to test UNC pathnames. The test will not fail if the host or share
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * don't exist, but it will print a warning saying that it was unable to
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * test UNC pathnames completely.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews private static final String EXISTENT_UNC_HOST = "pc-cup01";
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews private static final String EXISTENT_UNC_SHARE = "pcdist";
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews private static final String NONEXISTENT_UNC_HOST = "non-existent-unc-host";
d6fa26d0adaec6c910115be34fe7a5a5f402c14fMark Andrews private static final String NONEXISTENT_UNC_SHARE = "bogus-share";
7ae9399897c55d35cb6764277bce4b91d052e0dcEvan Hunt
dd66b77417aff9a7805f52b1e37ac48e647e0102Evan Hunt
7ae9399897c55d35cb6764277bce4b91d052e0dcEvan Hunt /* Pathnames relative to working directory */
7ae9399897c55d35cb6764277bce4b91d052e0dcEvan Hunt
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein private static void checkCaseLookup(String ud) throws IOException {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /* Use long names here to avoid 8.3 format, which Samba servers often
30eec077db2bdcb6f2a0dc388a3cdde2ede75ec1Mark Andrews force to lowercase */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein File d = new File("XyZzY0123", "FOO_bar_BAZ");
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein File f = new File(d, "GLORPified");
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (!f.exists()) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (!d.exists()) {
if (!d.mkdirs()) {
throw new RuntimeException("Can't create directory " + d);
}
}
OutputStream o = new FileOutputStream(f);
o.close();
}
File f2 = new File(d.getParent(), "mumble"); /* For later ud tests */
if (!f2.exists()) {
OutputStream o = new FileOutputStream(f2);
o.close();
}
/* Computing the canonical path of a Win32 file should expose the true
case of filenames, rather than just using the input case */
File y = new File(ud, f.getPath());
String ans = y.getPath();
check(ans, "XyZzY0123\\FOO_bar_BAZ\\GLORPified");
check(ans, "xyzzy0123\\foo_bar_baz\\glorpified");
check(ans, "XYZZY0123\\FOO_BAR_BAZ\\GLORPIFIED");
}
private static void checkWild(File f) throws Exception {
try {
f.getCanonicalPath();
} catch (IOException x) {
return;
}
throw new Exception("Wildcard path not rejected: " + f);
}
private static void checkWildCards(String ud) throws Exception {
File d = new File(ud).getCanonicalFile();
checkWild(new File(d, "*.*"));
checkWild(new File(d, "*.???"));
checkWild(new File(new File(d, "*.*"), "foo"));
}
private static void checkRelativePaths() throws Exception {
String ud = System.getProperty("user.dir").replace('/', '\\');
checkCaseLookup(ud);
checkWildCards(ud);
checkNames(3, true, ud + "\\", "");
}
/* Pathnames with drive specifiers */
private static char findInactiveDrive() {
for (char d = 'Z'; d >= 'E'; d--) {
File df = new File(d + ":\\");
if (!df.exists()) {
return d;
}
}
throw new RuntimeException("Can't find an inactive drive");
}
private static char findActiveDrive() {
for (char d = 'C'; d <= 'Z'; d--) {
File df = new File(d + ":\\");
if (df.exists()) return d;
}
throw new RuntimeException("Can't find an active drive");
}
private static void checkDrive(int depth, char drive, boolean exists)
throws Exception
{
String d = drive + ":";
File df = new File(d);
String ans = exists ? df.getAbsolutePath() : d;
if (!ans.endsWith("\\"))
ans = ans + "\\";
checkNames(depth, false, ans, d);
}
private static void checkDrivePaths() throws Exception {
checkDrive(2, findActiveDrive(), true);
checkDrive(2, findInactiveDrive(), false);
}
/* UNC pathnames */
private static void checkUncPaths() throws Exception {
String s = ("\\\\" + NONEXISTENT_UNC_HOST
+ "\\" + NONEXISTENT_UNC_SHARE);
ensureNon(s);
checkSlashes(2, false, s, s);
s = "\\\\" + EXISTENT_UNC_HOST + "\\" + EXISTENT_UNC_SHARE;
if (!(new File(s)).exists()) {
System.err.println("WARNING: " + s +
" does not exist, unable to test UNC pathnames");
return;
}
checkSlashes(2, false, s, s);
}
public static void main(String[] args) throws Exception {
if (File.separatorChar != '\\') {
/* This test is only valid on win32 systems */
return;
}
if (args.length > 0) debug = true;
checkRelativePaths();
checkDrivePaths();
checkUncPaths();
}
}