From 8e8d51c354df7a741acbc48987b05e3d79ed8f9d Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 8 Aug 2001 09:01:11 +0000 Subject: [PATCH] Testcase for Project.resolveFile git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269515 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/ProjectTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/testcases/org/apache/tools/ant/ProjectTest.java b/src/testcases/org/apache/tools/ant/ProjectTest.java index 019e04edf..ac2fced02 100644 --- a/src/testcases/org/apache/tools/ant/ProjectTest.java +++ b/src/testcases/org/apache/tools/ant/ProjectTest.java @@ -56,6 +56,8 @@ package org.apache.tools.ant; import org.apache.tools.ant.types.*; +import java.io.File; + import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -88,4 +90,63 @@ public class ProjectTest extends TestCase { p.createDataType("patternset") instanceof PatternSet); assert("Path", p.createDataType("path") instanceof Path); } + + public void testResolveFile() { + /* + * Start with simple absolute file names. + */ + assertEquals(File.separator, + p.resolveFile("/", null).getPath()); + assertEquals(File.separator, + p.resolveFile("\\", null).getPath()); + + /* + * throw in drive letters + */ + String driveSpec = "C:"; + assertEquals(driveSpec + "\\", + p.resolveFile(driveSpec + "/", null).getPath()); + assertEquals(driveSpec + "\\", + p.resolveFile(driveSpec + "\\", null).getPath()); + String driveSpecLower = "c:"; + assertEquals(driveSpec + "\\", + p.resolveFile(driveSpecLower + "/", null).getPath()); + assertEquals(driveSpec + "\\", + p.resolveFile(driveSpecLower + "\\", null).getPath()); + /* + * promised to eliminate consecutive slashes after drive letter. + */ + assertEquals(driveSpec + "\\", + p.resolveFile(driveSpec + "/////", null).getPath()); + assertEquals(driveSpec + "\\", + p.resolveFile(driveSpec + "\\\\\\\\\\\\", null).getPath()); + + /* + * Now test some relative file name magic. + */ + assertEquals(localize("/1/2/3/4"), + p.resolveFile("4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("./4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile(".\\4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("./.\\4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("../3/4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("..\\3\\4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("../../5/.././2/./3/6/../4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("..\\../5/..\\./2/./3/6\\../4", new File(localize("/1/2/3"))).getPath()); + + } + + /** + * adapt file separators to local conventions + */ + private String localize(String path) { + return path.replace('\\', File.separatorChar).replace('/', File.separatorChar); + } }