/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@summary Common definitions for general exhaustive pathname tests
@author Mark Reinhold
*/
public class General {
public static boolean debug = false;
/* Generate a filename unique to this run */
return "x." + ++gensymCounter;
}
/**
* Find a file in the given subdirectory, or descend into further
* subdirectories, if any, if no file is found here. Return null if no
* file can be found anywhere beneath the given subdirectory.
* @param dir Directory at which we started
* @param subdir Subdirectory that we're exploring
* @param dl Listing of subdirectory
*/
return f.getPath();
}
}
}
}
}
return null;
}
/**
* Construct a string that names a file in the given directory. If create
* is true, then create a file if none is found, and throw an exception if
* that is not possible; otherwise, return null if no file can be found.
*/
}
if (f.isFile()) {
return dl[i];
}
}
if (f != null) {
return f;
}
if (create) {
try {
} catch (IOException x) {
}
}
return null;
}
/**
* Construct a string that names a subdirectory of the given directory.
* If create is true, then create a subdirectory if none is found, and
* throw an exception if that is not possible; otherwise, return null if
* no subdirectory can be found.
*/
}
if (f.isDirectory() && f.canRead()) {
/* Heuristic to avoid scanning huge directories */
continue;
}
return dl[i];
}
}
if (create) {
}
return null;
}
/** Construct a string that does not name a file in the given directory */
for (int i = 0; i < x.length; i++) {
if (!f.exists()) {
return x[i];
}
}
for (int i = 0; i < 1024; i++) {
if (!f.exists()) {
return n;
}
}
}
/** Ensure that the named file does not exist */
}
}
/** Tell whether the given character is a "slash" on this platform */
private static boolean isSlash(char x) {
if (x == File.separatorChar) return true;
if (win32 && (x == '/')) return true;
return false;
}
/**
* Trim trailing slashes from the given string, but leave singleton slashes
* alone (they denote root directories)
*/
int n = s.length();
if (n == 0) return s;
n--;
n--;
}
}
/** Concatenate two paths, trimming slashes as needed */
if (a.length() == 0) return b;
if (b.length() == 0) return a;
return a + b;
} else {
return a + File.separatorChar + b;
}
}
/** Hash table of input pathnames, used to detect duplicates */
/**
* Check the given pathname. Its canonical pathname should be the given
* answer. If the path names a file that exists and is readable, then
* FileInputStream and RandomAccessFile should both be able to open it.
*/
return;
}
try {
cpath = f.getCanonicalPath();
}
} catch (IOException x) {
if (debug) return;
else throw x;
}
} else {
if (!debug) {
", should be " + ans);
}
}
}
/*
* The following three mutually-recursive methods generate and check a tree
* of filenames of arbitrary depth. Each method has (at least) these
* arguments:
*
* int depth Remaining tree depth
* boolean create Controls whether test files and directories
* will be created as needed
* String ans Expected answer for the check method (above)
* String ask Input pathname to be passed to the check method
*/
/** Check a single slash case, plus its children */
throws Exception
{
}
/** Check slash cases for the given ask string */
throws Exception
{
if (depth == 0) return;
if (win32) {
}
}
/** Check name cases for the given ask string */
throws Exception
{
int d = depth - 1;
String n;
/* Normal name */
if (f.exists()) {
if (f.isDirectory() && f.canRead()) {
}
} else {
n = "foo" + depth;
}
/* "." */
/* ".." */
if (win32
/* Win32 resolves \\foo\bar\.. to \\foo\bar */
} else {
}
}
else {
if (win32)
else {
// Fix for 4237875. We must ensure that we are sufficiently
// deep in the path hierarchy to test parents this high up
}
}
}
}