Fix failing FileTest#test_canonicalCachesAreOff() FileTest#test_canonicalCachesAreOff() were passing only in vogar, in cts they were failing to create a symlink named "test_sl". Fixed the test by making the symlink name a valid one (that can be created without an error). Test: FileTest in vogar and cts Bug: 62301183 Bug: 64598164 Change-Id: I6162d1f8e8d3dc83c5dd6a5c5f4ac68ca0204685 (cherry picked from commit 07e6e4e2af1ec4c8ef4e1d70fe55664270c4f4c9)
diff --git a/luni/src/test/java/libcore/java/io/FileTest.java b/luni/src/test/java/libcore/java/io/FileTest.java index be28f60..04de751 100644 --- a/luni/src/test/java/libcore/java/io/FileTest.java +++ b/luni/src/test/java/libcore/java/io/FileTest.java
@@ -371,19 +371,22 @@ // http://b/62301183 public void test_canonicalCachesAreOff() throws Exception { - File f1 = File.createTempFile("testCannonCachesOff1", "tmp"); - File f2 = File.createTempFile("testCannonCachesOff2", "tmp"); - File symlinkFile = new File("test_sl"); + File tempDir = createTemporaryDirectory(); + File f1 = new File(tempDir, "testCannonCachesOff1"); + f1.createNewFile(); + File f2 = new File(tempDir, "testCannonCachesOff2"); + f2.createNewFile(); + File symlinkFile = new File(tempDir, "symlink"); // Create a symlink from symlink to f1 and populate canonical path cache assertEquals(0, Runtime.getRuntime().exec("ln -s " + f1.getAbsolutePath() + " " + symlinkFile.getAbsolutePath()).waitFor()); - assertEquals(symlinkFile.getCanonicalPath(), f1.toString()); + assertEquals(symlinkFile.getCanonicalPath(), f1.getCanonicalPath()); // Remove it and replace it with a symlink to f2 (using java File/Files would flush caches). assertEquals(0, Runtime.getRuntime().exec("rm " + symlinkFile.getAbsolutePath()).waitFor()); assertEquals(0, Runtime.getRuntime().exec("ln -s " + f2.getAbsolutePath() + " " + symlinkFile.getAbsolutePath()).waitFor()); // Did we cache canonical path results? hope not! - assertEquals(symlinkFile.getCanonicalPath(), f2.toString()); + assertEquals(symlinkFile.getCanonicalPath(), f2.getCanonicalPath()); } }