You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2008/09/23 13:14:54 UTC

svn commit: r698140 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/File.java test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java

Author: hindessm
Date: Tue Sep 23 04:14:54 2008
New Revision: 698140

URL: http://svn.apache.org/viewvc?rev=698140&view=rev
Log:
(new File("\\test")).isAbsolute() should return false on unix.
Adding regression test and fixing invalid tests after fixing the bug.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java?rev=698140&r1=698139&r2=698140&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java Tue Sep 23 04:14:54 2008
@@ -270,7 +270,8 @@
         char newPath[] = origPath.toCharArray();
         for (int i = 0; i < length; i++) {
             char pathChar = newPath[i];
-            if (pathChar == '\\' || pathChar == '/') {
+            if ((separatorChar == '\\' && pathChar == '\\')
+                || pathChar == '/') {
                 /* UNC Name requires 2 leading slashes */
                 if ((foundSlash && i == uncIndex) || !foundSlash) {
                     newPath[newLength++] = separatorChar;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java?rev=698140&r1=698139&r2=698140&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java Tue Sep 23 04:14:54 2008
@@ -122,8 +122,13 @@
         File file = new File(root, "/dir/file");
         assertEquals("Assert 1: wrong path result ", path.getPath(), file
                 .getPath());
-        assertTrue("Assert 1.1: path not absolute ", new File("\\\\\\a\b")
-                .isAbsolute());
+        if (File.separatorChar == '\\') {
+            assertTrue("Assert 1.1: path not absolute ", new File("\\\\\\a\b")
+                       .isAbsolute());
+        } else {
+            assertFalse("Assert 1.1: path absolute ", new File("\\\\\\a\b")
+                       .isAbsolute());
+        }
 
         // Test data used in a few places below
         dirName = System.getProperty("user.dir");
@@ -226,10 +231,13 @@
         assertEquals("wrong result 1", ref1.getPath(), file1.getPath());
         File file2 = new File("/", "//dir1/file1");
         assertEquals("wrong result 2", ref1.getPath(), file2.getPath());
-        File file3 = new File("\\", "\\dir1\\file1");
-        assertEquals("wrong result 3", ref1.getPath(), file3.getPath());
-        File file4 = new File("\\", "\\\\dir1\\file1");
-        assertEquals("wrong result 4", ref1.getPath(), file4.getPath());
+
+        if (File.separatorChar == '\\') {
+            File file3 = new File("\\", "\\dir1\\file1");
+            assertEquals("wrong result 3", ref1.getPath(), file3.getPath());
+            File file4 = new File("\\", "\\\\dir1\\file1");
+            assertEquals("wrong result 4", ref1.getPath(), file4.getPath());
+        }
 
         File ref2 = new File("/lib/content-types.properties");
         File file5 = new File("/", "lib/content-types.properties");
@@ -247,10 +255,13 @@
         assertEquals("wrong result 1", ref1.getPath(), file1.getPath());
         File file2 = new File(root, "//dir1/file1");
         assertEquals("wrong result 2", ref1.getPath(), file2.getPath());
-        File file3 = new File(root, "\\dir1\\file1");
-        assertEquals("wrong result 3", ref1.getPath(), file3.getPath());
-        File file4 = new File(root, "\\\\dir1\\file1");
-        assertEquals("wrong result 4", ref1.getPath(), file4.getPath());
+
+        if (File.separatorChar == '\\') {
+            File file3 = new File(root, "\\dir1\\file1");
+            assertEquals("wrong result 3", ref1.getPath(), file3.getPath());
+            File file4 = new File(root, "\\\\dir1\\file1");
+            assertEquals("wrong result 4", ref1.getPath(), file4.getPath());
+        }
 
         File ref2 = new File("/lib/content-types.properties");
         File file5 = new File(root, "lib/content-types.properties");
@@ -1096,7 +1107,9 @@
                     || (!f.isAbsolute() && f1.isAbsolute()));
         } else {
             File f = new File("/test");
+            File f1 = new File("\\test");
             assertTrue("Absolute returned false", f.isAbsolute());
+            assertFalse("Absolute returned true", f1.isAbsolute());
         }
         assertTrue("Non-Absolute returned true", !new File("../test")
                 .isAbsolute());