test/java/io/pathNames/General.java

Print this page

        

*** 37,52 **** private static boolean win32 = (File.separatorChar == '\\'); private static int gensymCounter = 0; /* Generate a filename unique to this run */ ! protected static String gensym() { 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. --- 37,80 ---- private static boolean win32 = (File.separatorChar == '\\'); private static int gensymCounter = 0; + protected static final String userDir = System.getProperty("user.dir"); + + protected static String baseDir = null; + protected static String relative = null; /* Generate a filename unique to this run */ ! private static String gensym() { return "x." + ++gensymCounter; } + /** + * Create files and folders in the test working directory. + * The purpose is to make sure the test will not go out of + * its user dir when walking the file tree. + * + * @param depth The number of directory levels to be created under + * the user directory. It should be the maximum value + * of the depths passed to checkNames method (including + * direct or indirect calling) in a whole test. + */ + protected static void initTestData(int depth) throws IOException { + File parent = new File(userDir); + for (int i = 0; i < depth; i++) { + File tmp = new File(parent, gensym()); + tmp.createNewFile(); + tmp = new File(parent, gensym()); + if (tmp.mkdir()) + parent = tmp; + else + throw new IOException("Fail to create directory, " + tmp); + } + baseDir = parent.getAbsolutePath(); + relative = baseDir.substring(userDir.length() + 1); + } /** * 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.
*** 212,222 **** } /** Hash table of input pathnames, used to detect duplicates */ ! private static Hashtable checked = new Hashtable(); /** * 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. --- 240,250 ---- } /** Hash table of input pathnames, used to detect duplicates */ ! private static Hashtable<String, String> checked = new Hashtable<>(); /** * 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.
*** 270,280 **** * String ask Input pathname to be passed to the check method */ /** Check a single slash case, plus its children */ ! public static void checkSlash(int depth, boolean create, String ans, String ask, String slash) throws Exception { check(ans, ask + slash); checkNames(depth, create, --- 298,308 ---- * String ask Input pathname to be passed to the check method */ /** Check a single slash case, plus its children */ ! private static void checkSlash(int depth, boolean create, String ans, String ask, String slash) throws Exception { check(ans, ask + slash); checkNames(depth, create,