Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 54727 invoked from network); 1 Nov 2007 15:16:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 1 Nov 2007 15:16:02 -0000 Received: (qmail 47453 invoked by uid 500); 1 Nov 2007 14:59:03 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 47418 invoked by uid 500); 1 Nov 2007 14:59:03 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 47406 invoked by uid 500); 1 Nov 2007 14:59:02 -0000 Received: (qmail 47403 invoked by uid 99); 1 Nov 2007 14:59:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Nov 2007 07:59:02 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Nov 2007 14:59:30 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 48DC51A9832; Thu, 1 Nov 2007 07:58:51 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r591037 - /ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java Date: Thu, 01 Nov 2007 14:58:50 -0000 To: ant-cvs@apache.org From: stevel@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071101145851.48DC51A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: stevel Date: Thu Nov 1 07:58:49 2007 New Revision: 591037 URL: http://svn.apache.org/viewvc?rev=591037&view=rev Log: test changes to handle windows systems better Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java?rev=591037&r1=591036&r2=591037&view=diff ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java (original) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java Thu Nov 1 07:58:49 2007 @@ -23,9 +23,14 @@ import java.net.URISyntaxException; import java.io.File; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.apache.tools.ant.taskdefs.condition.Os; + /** Test the locator in the ant-launch JAR */ public class LocatorTest extends TestCase { + private boolean windows; + private boolean unix; /** @@ -40,6 +45,17 @@ super(name); } + + /** + * Sets up the fixture, for example, open a network connection. + * This method is called before a test is executed. + */ + protected void setUp() throws Exception { + super.setUp(); + windows = Os.isFamily(Os.FAMILY_DOS); + unix = Os.isFamily(Os.FAMILY_UNIX); + } + private String resolve(String uri) { String j14= Locator.fromURI(uri); String j13 = Locator.fromURIJava13(uri); @@ -48,44 +64,47 @@ return j14; } - private void resolveTo(String uri,String expectedResult) { + /** + * expect a uri to resolve to strings on different platforms + * @param uri uri to parse + * @param expectedUnix unix string (or null to skip that test) + * @param expectedDos DOS string (or null to skip that test) + */ + private String resolveTo(String uri, String expectedUnix, String expectedDos) { String result = resolve(uri); - assertResolved(uri, expectedResult, result); + assertResolved(uri, expectedUnix, result, unix); + assertResolved(uri, expectedDos, result, windows); + return result; } - private void assertResolved(String uri, String expectedResult, String result) { - assertEquals("Expected "+uri+" to resolve to \n"+expectedResult+"\n but got\n"+result+"\n", + private void assertResolved(String uri, String expectedResult, String result, boolean condition) { + if(condition && expectedResult!=null && expectedResult.length()>0) { + assertEquals("Expected "+uri+" to resolve to \n"+expectedResult+"\n but got\n"+result+"\n", expectedResult,result); + } } /** * This asserts that we can round trip the path to a URI and back again - * @param path + * @param path filename with no directory separators + * @return the trailing filename */ - private void assertResolves(String path) throws Exception { + private String assertResolves(String path) throws Exception { String asuri = new File(path).toURI().toASCIIString(); - logURI(path +" => "+asuri); - resolveTo(asuri,path); - } - - private void resolveTo13(String uri, String expectedResult) { - String result = Locator.fromURIJava13(uri); - assertResolved(uri, expectedResult, result); + String fullpath = System.getProperty("user.dir") + File.separator + path; + String result=resolveTo(asuri, fullpath, fullpath); + return result.substring(result.lastIndexOf(File.separatorChar)+1); } - private void logURI(String path) throws URISyntaxException{ - - String s = new File(path).toURI().toASCIIString(); - System.out.println(path+" => "+s); - - } /** * this isnt really a valid URI, except maybe in IE * @throws Exception */ public void testNetworkURI() throws Exception { - resolveTo("file:\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar","\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); + resolveTo("file:\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar","" + + "\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar", + "\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); } /** @@ -93,23 +112,25 @@ * @throws Exception */ public void NotestTripleForwardSlashNetworkURI() throws Exception { - resolveTo("file:///PC03/jclasses/lib/ant-1.7.0.jar", "///PC03/jclasses/lib/ant-1.7.0.jar"); + resolveTo("file:///PC03/jclasses/lib/ant-1.7.0.jar", + "///PC03/jclasses/lib/ant-1.7.0.jar", + "\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); } public void testUnixNetworkPath() throws Exception { - resolveTo("file://cluster/home/ant/lib", "//cluster/home/ant/lib"); - } - - public void testUnixNetworkPath13() throws Exception { - resolveTo13("file://cluster/home/ant/lib", "//cluster/home/ant/lib"); + resolveTo("file://cluster/home/ant/lib", + "//cluster/home/ant/lib", + "\\\\cluster\\home\\ant\\lib"); } public void testUnixPath() throws Exception { - resolveTo("file:/home/ant/lib", "/home/ant/lib"); + resolveTo("file:/home/ant/lib", "/home/ant/lib", null); } public void testSpacedURI() throws Exception { - resolveTo("file:C:\\Program Files\\Ant\\lib","C:\\Program Files\\Ant\\lib"); + resolveTo("file:C:\\Program Files\\Ant\\lib", + "C:\\Program Files\\Ant\\lib", + "C:\\Program Files\\Ant\\lib"); } public void testHttpURI() throws Exception { @@ -125,11 +146,14 @@ public void testInternationalURI() throws Exception { - assertResolves("/L\\u00f6wenbrau/aus/M\\u00fcnchen"); + String result=assertResolves("L\\u00f6wenbrau.aus.M\\u00fcnchen"); + char umlauted = result.charAt(1); + assertEquals("expected 0xf6 (\\u00f6), but got "+Integer.toHexString(umlauted)+" '"+umlauted+"'", + 0xf6, umlauted); } public void testOddLowAsciiURI() throws Exception { - assertResolves("/hash#/ and /percent%"); + assertResolves("hash# and percent%"); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org