diff options
Diffstat (limited to 'org.eclipse.debug.tests')
-rw-r--r-- | org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java | 96 |
1 files changed, 90 insertions, 6 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java index 7f6f828fe..b046728c6 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/launching/LaunchGroupTests.java @@ -4,12 +4,14 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.core.ILaunchListener; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.IDisconnect; import org.eclipse.debug.core.model.IProcess; @@ -22,18 +24,54 @@ import org.eclipse.debug.ui.IDebugUIConstants; public class LaunchGroupTests extends AbstractLaunchTest { private static final String GROUP_TYPE = "org.eclipse.debug.core.groups.GroupLaunchConfigurationType"; //$NON-NLS-1$ + private static final String DEF_GRP_NAME = "Test Group"; //$NON-NLS-1$ + + private final AtomicInteger launchCount = new AtomicInteger(0); + private ILaunchConfiguration lcToCount = null; + private ILaunchListener lcListener = new ILaunchListener() { + @Override + public void launchRemoved(ILaunch launch) { + } + + @Override + public void launchChanged(ILaunch launch) { + } + + @Override + public void launchAdded(ILaunch launch) { + if (launch.getLaunchConfiguration().contentsEqual(lcToCount)) { + launchCount.incrementAndGet(); + } + } + }; public LaunchGroupTests() { super("Launch Groups Test"); //$NON-NLS-1$ } - private ILaunchConfiguration createLaunchGroup(GroupLaunchElement... children) throws CoreException { - ILaunchConfigurationWorkingCopy grp = getLaunchManager().getLaunchConfigurationType(GROUP_TYPE).newInstance(null, "Test Group"); //$NON-NLS-1$ + @Override + protected void setUp() throws Exception { + super.setUp(); + + // reset count + launchCount.set(0); + } + + @Override + protected void tearDown() throws Exception { + // make sure listener is removed + getLaunchManager().removeLaunchListener(lcListener); + + super.tearDown(); + } + + private ILaunchConfiguration createLaunchGroup(String name, GroupLaunchElement... children) throws CoreException { + ILaunchConfigurationWorkingCopy grp = getLaunchManager().getLaunchConfigurationType(GROUP_TYPE).newInstance(null, name); GroupLaunchConfigurationDelegate.storeLaunchElements(grp, Arrays.asList(children)); return grp.doSave(); } - private GroupLaunchElement createLaunchGroupElement(ILaunchConfiguration source, GroupElementPostLaunchAction action, Object param) { + private GroupLaunchElement createLaunchGroupElement(ILaunchConfiguration source, GroupElementPostLaunchAction action, Object param, boolean adopt) { GroupLaunchElement e = new GroupLaunchElement(); e.name = source.getName(); @@ -42,6 +80,7 @@ public class LaunchGroupTests extends AbstractLaunchTest { e.actionParam = param; e.mode = GroupLaunchElement.MODE_INHERIT; e.enabled = true; + e.adoptIfRunning = adopt; return e; } @@ -60,7 +99,7 @@ public class LaunchGroupTests extends AbstractLaunchTest { public void testNone() throws Exception { ILaunchConfiguration t1 = getLaunchConfiguration("Test1"); //$NON-NLS-1$ ILaunchConfiguration t2 = getLaunchConfiguration("Test2"); //$NON-NLS-1$ - ILaunchConfiguration grp = createLaunchGroup(createLaunchGroupElement(t1, GroupElementPostLaunchAction.NONE, null), createLaunchGroupElement(t2, GroupElementPostLaunchAction.NONE, null)); + ILaunchConfiguration grp = createLaunchGroup(DEF_GRP_NAME, createLaunchGroupElement(t1, GroupElementPostLaunchAction.NONE, null, false), createLaunchGroupElement(t2, GroupElementPostLaunchAction.NONE, null, false)); // attention: need to do this before launching! LaunchHistory runHistory = getRunLaunchHistory(); @@ -76,7 +115,7 @@ public class LaunchGroupTests extends AbstractLaunchTest { public void testDelay() throws Exception { ILaunchConfiguration t1 = getLaunchConfiguration("Test1"); //$NON-NLS-1$ ILaunchConfiguration t2 = getLaunchConfiguration("Test2"); //$NON-NLS-1$ - ILaunchConfiguration grp = createLaunchGroup(createLaunchGroupElement(t1, GroupElementPostLaunchAction.DELAY, 2), createLaunchGroupElement(t2, GroupElementPostLaunchAction.NONE, null)); + ILaunchConfiguration grp = createLaunchGroup(DEF_GRP_NAME, createLaunchGroupElement(t1, GroupElementPostLaunchAction.DELAY, 2, false), createLaunchGroupElement(t2, GroupElementPostLaunchAction.NONE, null, false)); long start = System.currentTimeMillis(); // attention: need to do this before launching! @@ -95,7 +134,7 @@ public class LaunchGroupTests extends AbstractLaunchTest { public void testTerminated() throws Exception { final ILaunchConfiguration t1 = getLaunchConfiguration("Test1"); //$NON-NLS-1$ final ILaunchConfiguration t2 = getLaunchConfiguration("Test2"); //$NON-NLS-1$ - ILaunchConfiguration grp = createLaunchGroup(createLaunchGroupElement(t1, GroupElementPostLaunchAction.WAIT_FOR_TERMINATION, null), createLaunchGroupElement(t2, GroupElementPostLaunchAction.NONE, null)); + ILaunchConfiguration grp = createLaunchGroup(DEF_GRP_NAME, createLaunchGroupElement(t1, GroupElementPostLaunchAction.WAIT_FOR_TERMINATION, null, false), createLaunchGroupElement(t2, GroupElementPostLaunchAction.NONE, null, false)); long start = System.currentTimeMillis(); new Thread("Terminate Test1") { //$NON-NLS-1$ @@ -153,4 +192,49 @@ public class LaunchGroupTests extends AbstractLaunchTest { assertTrue("history[2] should be Test1", history[2].contentsEqual(t1)); //$NON-NLS-1$ } + public void testAdopt() throws Exception { + final ILaunchConfiguration t1 = getLaunchConfiguration("Test1"); //$NON-NLS-1$ + final ILaunchConfiguration grp = createLaunchGroup(DEF_GRP_NAME, createLaunchGroupElement(t1, GroupElementPostLaunchAction.NONE, null, false), createLaunchGroupElement(t1, GroupElementPostLaunchAction.NONE, null, true)); + + // attention: need to do this before launching! + LaunchHistory runHistory = getRunLaunchHistory(); + + lcToCount = t1; + getLaunchManager().addLaunchListener(lcListener); + grp.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); + + ILaunchConfiguration[] history = runHistory.getHistory(); + assertTrue("history should be size 2", history.length == 2); //$NON-NLS-1$ + assertTrue("history[0] should be Test Group", history[0].contentsEqual(grp)); //$NON-NLS-1$ + assertTrue("history[1] should be Test1", history[1].contentsEqual(t1)); //$NON-NLS-1$ + assertTrue("Test1 should be launched only once", launchCount.get() == 1); //$NON-NLS-1$ + } + + public void testAdoptComplex() throws Exception { + final ILaunchConfiguration t1 = getLaunchConfiguration("Test1"); //$NON-NLS-1$ + + // Group 1 has Test1 (adopt = false) + // Group 2 has Group 1 + // Group 3 has Group 2 and Test1 (adopt = true) + + final ILaunchConfiguration grp = createLaunchGroup(DEF_GRP_NAME, createLaunchGroupElement(t1, GroupElementPostLaunchAction.NONE, null, false)); + final ILaunchConfiguration grp2 = createLaunchGroup("Group 2", createLaunchGroupElement(grp, GroupElementPostLaunchAction.NONE, null, false)); //$NON-NLS-1$ + final ILaunchConfiguration grp3 = createLaunchGroup("Group 3", createLaunchGroupElement(grp2, GroupElementPostLaunchAction.NONE, null, false), createLaunchGroupElement(t1, GroupElementPostLaunchAction.NONE, null, true)); //$NON-NLS-1$ + + // attention: need to do this before launching! + LaunchHistory runHistory = getRunLaunchHistory(); + + lcToCount = t1; + getLaunchManager().addLaunchListener(lcListener); + grp3.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor()); + + ILaunchConfiguration[] history = runHistory.getHistory(); + assertTrue("history should be size 4", history.length == 4); //$NON-NLS-1$ + assertTrue("history[0] should be Group 3", history[0].contentsEqual(grp3)); //$NON-NLS-1$ + assertTrue("history[1] should be Group 2", history[1].contentsEqual(grp2)); //$NON-NLS-1$ + assertTrue("history[2] should be Group 1", history[2].contentsEqual(grp)); //$NON-NLS-1$ + assertTrue("history[3] should be Test1", history[3].contentsEqual(t1)); //$NON-NLS-1$ + assertTrue("Test1 should be launched only once", launchCount.get() == 1); //$NON-NLS-1$ + } + } |