From 184730559ba91c4554d4e9a5479662066f727893 Mon Sep 17 00:00:00 2001 From: "Wainer S. Moschetta" Date: Wed, 1 Apr 2015 09:26:16 -0300 Subject: [PATCH] Bug 45149 - Add tests to UNCPathConverter class Change-Id: I7638627370dd07a28a8682a6a8704f28dd6332a9 Signed-off-by: Wainer S. Moschetta --- .../cdt/utils/UNCPathConverterTest.java | 63 +++++++++++++++++++ .../core/suite/AutomatedIntegrationSuite.java | 2 + 2 files changed, 65 insertions(+) create mode 100644 core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/UNCPathConverterTest.java diff --git a/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/UNCPathConverterTest.java b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/UNCPathConverterTest.java new file mode 100644 index 00000000000..98bbd09b992 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/misc/org/eclipse/cdt/utils/UNCPathConverterTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2015 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wainer S. Moschetta (IBM Corporation) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.utils; + +import static org.junit.Assert.assertEquals; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Collection; + +import junit.framework.JUnit4TestAdapter; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.junit.runner.RunWith; +import org.junit.Test; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +@RunWith(Parameterized.class) +public class UNCPathConverterTest { + private URI testURI; + private IPath expectedPath; + + public UNCPathConverterTest(URI uri, IPath expectedPath) { + this.testURI = uri; + this.expectedPath = expectedPath; + } + + public static junit.framework.Test suite() { + return new JUnit4TestAdapter(UNCPathConverterTest.class); + } + + @Parameters(name = "{index}: {0}") + public static Collection testToPathCases() throws URISyntaxException { + return Arrays.asList(new Object [][] { + // Without scheme + {new URI("/foo/bar"), Path.fromOSString("/foo/bar")}, + // With Scheme, no authority + {new URI("file", "/foo/bar", null), Path.fromOSString("/foo/bar")}, + // With scheme and host + {new URI("http", "example.com", "/foo/bar", null), Path.fromOSString("//example.com/foo/bar")}, + // With server-based authority + {new URI("ssh", "user:password", "example.com", 8080, "/foo/bar", null, null), Path.fromOSString("//example.com/foo/bar")}, + // With Registry-based authority + {new URI("remotetools", "My Connection", "/foo/bar", null, null), Path.fromOSString("//My Connection/foo/bar")}} + ); + } + + @Test + public void testToPath() { + assertEquals("Failed to convert an URI to Path", expectedPath, UNCPathConverter.toPath(testURI)); + } +} diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java index f13d89a24f2..4c048d4669c 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -38,6 +38,7 @@ import org.eclipse.cdt.utils.CdtVariableResolverTest; import org.eclipse.cdt.utils.CommandLineUtilTest; import org.eclipse.cdt.utils.FindProgramLocationTest; import org.eclipse.cdt.utils.StorableCdtVariablesTest; +import org.eclipse.cdt.utils.UNCPathConverterTest; import org.eclipse.cdt.utils.WeakHashSetTest; /** @@ -86,6 +87,7 @@ public class AutomatedIntegrationSuite extends TestSuite { suite.addTest(FindProgramLocationTest.suite()); suite.addTest(EFSExtensionTests.suite()); suite.addTest(ByteUtilsTest.suite()); + suite.addTest(UNCPathConverterTest.suite()); // Add in PDOM tests suite.addTest(PDOMTests.suite());