|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.equinox.p2.tests.touchpoint.eclipse; |
| 12 |
|
| 13 |
import java.net.MalformedURLException; |
| 14 |
import java.net.URL; |
| 15 |
import org.eclipse.equinox.internal.p2.update.PathUtil; |
| 16 |
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; |
| 17 |
|
| 18 |
/** |
| 19 |
* Tests for {@link org.eclipse.equinox.internal.p2.update.PathUtil}. |
| 20 |
*/ |
| 21 |
public class PathUtilTest extends AbstractProvisioningTest { |
| 22 |
/** Constant value indicating if the current platform is Windows */ |
| 23 |
private static final boolean WINDOWS = java.io.File.separatorChar == '\\'; |
| 24 |
|
| 25 |
public void testMakeRelative() throws MalformedURLException { |
| 26 |
if (!WINDOWS) |
| 27 |
return; |
| 28 |
Object[][] data = new Object[][] { |
| 29 |
// simple path |
| 30 |
new Object[] {"file:/c:/a/b", new URL("file:/c:/a/x"), "file:../b"}, |
| 31 |
// common root |
| 32 |
new Object[] {"file:/c:/eclipse/plugins/foo.jar", new URL("file:/c:/eclipse/"), "file:plugins\\foo.jar"}, |
| 33 |
// different drives |
| 34 |
new Object[] {"file:/c:/a/b", new URL("file:/d:/a/x"), "file:/c:/a/b"}, // |
| 35 |
new Object[] {"file:/c:/eclipse/plugins/foo.jar", new URL("file:/d:/eclipse/"), "file:/c:/eclipse/plugins/foo.jar"}, |
| 36 |
// non-local |
| 37 |
new Object[] {"http:/c:/a/b", new URL("file:/c:/a/x"), "http:/c:/a/b"}, // |
| 38 |
new Object[] {"file:/c:/a/b", new URL("http:/c:/a/x"), "file:/c:/a/b"}, // |
| 39 |
// |
| 40 |
new Object[] {"file:/c:/a/b", new URL("file:/C:/a/x"), "file:../b"}, // |
| 41 |
new Object[] {"file:/c:/", new URL("file:/d:/"), "file:/c:/"}, // |
| 42 |
new Object[] {"file:/c:/", new URL("file:/c:/"), "file:/c:/"}, // |
| 43 |
}; |
| 44 |
for (int i = 0; i < data.length; i++) { |
| 45 |
String location = data[i][0].toString(); |
| 46 |
URL root = (URL) data[i][1]; |
| 47 |
String expected = data[i][2].toString(); |
| 48 |
String actual = PathUtil.makeRelative(location, root); |
| 49 |
assertEquals("2." + Integer.toString(i), expected, actual); |
| 50 |
} |
| 51 |
} |
| 52 |
} |