|
From: David C. <dc...@us...> - 2005-10-16 23:53:11
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.debug.ui.tests/src/org/rubypeople/rdt/internal/debug/ui/launcher In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24567/src/org/rubypeople/rdt/internal/debug/ui/launcher Added Files: TC_RubyEnvironmentTab.java TC_RubyApplicationShortcut.java ShamApplicationLaunchConfigurationDelegate.java TS_InternalDebugUiLauncher.java TC_RubyArgumentsTab.java TC_RubyEntryPointTab.java Log Message: Organize tests for consistency. Found a few TCs that weren't being called for the main suite. --- NEW FILE: TC_RubyEnvironmentTab.java --- package org.rubypeople.rdt.internal.debug.ui.launcher; import junit.framework.TestCase; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.rubypeople.eclipse.shams.debug.core.ShamLaunchConfigurationWorkingCopy; import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiMessages; import org.rubypeople.rdt.internal.debug.ui.launcher.RubyEnvironmentTab; import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute; public class TC_RubyEnvironmentTab extends TestCase { public TC_RubyEnvironmentTab(String name) { super(name); } public void testIsValid() { RubyEnvironmentTab tab = new RubyEnvironmentTab(); ILaunchConfigurationWorkingCopy configuration = new ShamLaunchConfigurationWorkingCopy(); String errorMessage = tab.getErrorMessage(); assertNull("There should be no error message.", errorMessage); assertTrue("The tab is not valid when the configuration is completely empty.", !tab.isValid(configuration)); errorMessage = RdtDebugUiMessages.getString("LaunchConfigurationTab.RubyEnvironment.interpreter_not_selected_error_message"); assertEquals("The tab should set the error message for no interpreter selected.", errorMessage, tab.getErrorMessage()); configuration.setAttribute(RubyLaunchConfigurationAttribute.SELECTED_INTERPRETER, "anInterpreter"); assertTrue("The tab is valid when the configuration has a selected interpreter.", tab.isValid(configuration)); assertNull("The tab should set the error message to null when there is a selected interpreter.", tab.getErrorMessage()); } } --- NEW FILE: TC_RubyArgumentsTab.java --- package org.rubypeople.rdt.internal.debug.ui.launcher; import junit.framework.TestCase; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.rubypeople.eclipse.shams.debug.core.ShamLaunchConfigurationWorkingCopy; import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiMessages; import org.rubypeople.rdt.internal.debug.ui.launcher.RubyArgumentsTab; import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute; public class TC_RubyArgumentsTab extends TestCase { public TC_RubyArgumentsTab(String name) { super(name); } public void testIsValid() { RubyArgumentsTab tab = new RubyArgumentsTab(); ILaunchConfigurationWorkingCopy configuration = new ShamLaunchConfigurationWorkingCopy(); String errorMessage = tab.getErrorMessage(); assertNull("There should be no error message.", errorMessage); assertTrue("The tab is not valid when the configuration is completely empty.", !tab.isValid(configuration)); errorMessage = RdtDebugUiMessages.getString("LaunchConfigurationTab.RubyArguments.working_dir_error_message"); assertEquals("The tab should set the error message for invalid working directory.", errorMessage, tab.getErrorMessage()); configuration.setAttribute(RubyLaunchConfigurationAttribute.WORKING_DIRECTORY, "aValidDirectory"); assertTrue("The tab is valid when the configuration has a working directory.", tab.isValid(configuration)); assertNull("The tab should set the error message to null when there is a working directory.", tab.getErrorMessage()); } } --- NEW FILE: TC_RubyApplicationShortcut.java --- package org.rubypeople.rdt.internal.debug.ui.launcher; import java.io.ByteArrayInputStream; import java.io.File; import java.util.Arrays; import junit.framework.Assert; import junit.framework.TestCase; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.core.ILaunchManager; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.FileEditorInput; import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiPlugin; import org.rubypeople.rdt.internal.debug.ui.RubySourceLocator; import org.rubypeople.rdt.internal.debug.ui.launcher.RubyApplicationShortcut; import org.rubypeople.rdt.internal.launching.RubyInterpreter; import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute; import org.rubypeople.rdt.internal.launching.RubyRuntime; import org.rubypeople.rdt.ui.IRubyConstants; public class TC_RubyApplicationShortcut extends TestCase { protected ShamRubyApplicationShortcut shortcut; protected IFile rubyFile, nonRubyFile; private static String SHAM_LAUNCH_CONFIG_TYPE = "org.rubypeople.rdt.debug.ui.tests.launching.LaunchConfigurationTypeSham"; public TC_RubyApplicationShortcut(String name) { super(name); } protected IProject getOrCreateProject(String pName) throws CoreException { IProject p = RdtDebugUiPlugin.getWorkspace().getRoot().getProject(pName); if (!p.exists()) { p.create(null); p.open(null); } return p; } protected IFile getOrCreateFile(String pName) throws CoreException { IFile f = RdtDebugUiPlugin.getWorkspace().getRoot().getFile(new Path(pName)); if (!f.exists()) { f.create(new ByteArrayInputStream(new byte[0]), true, null); } return f; } protected IFolder getOrCreateDir(String pName) throws CoreException { IFolder f = RdtDebugUiPlugin.getWorkspace().getRoot().getFolder(new Path(pName)); if (!f.exists()) { f.create(true, true, null); } return f; } protected void createLaunchConfiguration(String pName, IFile pFile) throws Exception { ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(SHAM_LAUNCH_CONFIG_TYPE); ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, pName); wc.setAttribute(RubyLaunchConfigurationAttribute.PROJECT_NAME, pFile.getProject().getName()); wc.setAttribute(RubyLaunchConfigurationAttribute.FILE_NAME, pFile.getProjectRelativePath().toString()); wc.setAttribute(RubyLaunchConfigurationAttribute.WORKING_DIRECTORY, ""); wc.setAttribute(RubyLaunchConfigurationAttribute.SELECTED_INTERPRETER, RubyRuntime.getDefault().getSelectedInterpreter().getName()); wc.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, "org.rubypeople.rdt.debug.ui.rubySourceLocator"); wc.doSave(); } protected ILaunchConfiguration[] getLaunchConfigurations() throws CoreException { ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); return launchManager.getLaunchConfigurations(launchManager.getLaunchConfigurationType(SHAM_LAUNCH_CONFIG_TYPE)); } protected void setUp() throws CoreException { shortcut = new ShamRubyApplicationShortcut(); this.getOrCreateProject("/project1"); this.getOrCreateDir("/project1/folderOne"); nonRubyFile = this.getOrCreateFile("/project1/folderOne/myFile.java"); rubyFile = this.getOrCreateFile("/project1/folderOne/myFile.rb"); ILaunchConfiguration[] configs = this.getLaunchConfigurations(); for (int i = 0; i < configs.length; i++) { configs[i].delete(); } Assert.assertEquals("All configurations deleted.", 0, this.getLaunchConfigurations().length); ShamApplicationLaunchConfigurationDelegate.resetLaunches(); RubyInterpreter interpreterOne = new RubyInterpreter("InterpreterOne", new Path("C:/RubyInstallRootOne")); RubyRuntime.getDefault().setInstalledInterpreters(Arrays.asList(new Object[] { interpreterOne})); } public void testNoInterpreterInstalled() throws Exception { RubyRuntime.getDefault().setInstalledInterpreters(Arrays.asList(new Object[] { })); ISelection selection = new StructuredSelection(rubyFile); shortcut.launch(selection, ILaunchManager.RUN_MODE); assertTrue("A dialog has been shown.", shortcut.didShowDialog); } public void testLaunchWithSelectedRubyFile() throws Exception { ISelection selection = new StructuredSelection(rubyFile); shortcut.launch(selection, ILaunchManager.RUN_MODE); assertEquals("A configuration has been created", 1, this.getLaunchConfigurations().length); assertEquals("A launch took place.", 1, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should not log a message when asked to launch the correct file type.", !shortcut.didLog()); } public void testLaunchWithSelectedNonRubyFile() throws Exception { ISelection selection = new StructuredSelection(nonRubyFile); shortcut.launch(selection, ILaunchManager.RUN_MODE); assertEquals("There is no configuration.", 0, this.getLaunchConfigurations().length); assertEquals("There was no launch.", 0, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should log a message when asked to launch the wrong file type.", shortcut.didLog()); } public void testLaunchWithSelectionMultipleConfigurationsExist() throws Exception { shortcut.expectException(); this.createLaunchConfiguration("id1", rubyFile); this.createLaunchConfiguration("id2", rubyFile); ISelection selection = new StructuredSelection(rubyFile); shortcut.launch(selection, ILaunchManager.RUN_MODE); assertEquals("A new configuration for myFile.rb should not be created when one ore more configurations already exist.", 2, this.getLaunchConfigurations().length); assertEquals("The configuration for myFile.rb should not be launched when multiple configurations exist.", 0, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should log a message when asked to launch a file that has multiple configurations.", shortcut.didLog()); } public void testLaunchWithSelectionMultipleSelections() throws Exception { ISelection selection = new StructuredSelection(new Object[] { rubyFile, this.getOrCreateFile("project1/folderOne/yourFile.rb")}); shortcut.launch(selection, ILaunchManager.RUN_MODE); ILaunchConfiguration[] configurations = this.getLaunchConfigurations(); assertEquals("A configuration has been created", 1, configurations.length); assertEquals("A launch took place.", 1, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should not log a message when asked to launch the correct file type.", !shortcut.didLog()); String launchedFileName = configurations[0].getAttribute(RubyLaunchConfigurationAttribute.FILE_NAME, ""); assertEquals("folderOne/myFile.rb", launchedFileName); } public void testLaunchWithSelectionTwice() throws Exception { ISelection selection = new StructuredSelection(rubyFile); shortcut.launch(selection, ILaunchManager.RUN_MODE); shortcut.launch(selection, ILaunchManager.RUN_MODE); assertEquals("Only one configuration has been created", 1, this.getLaunchConfigurations().length); assertEquals("Two launches took place.", 2, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should not log a message when asked to launch the correct file type.", !shortcut.didLog()); } public void testLaunchWithSelectionWhenFileNamesSameInDifferentDirectory() throws Exception { IFile anotherRubyFileWithSameNameInDifferentFolder = this.getOrCreateFile("project1/myFile.rb"); ISelection selection = new StructuredSelection(rubyFile); shortcut.launch(selection, ILaunchManager.RUN_MODE); ILaunchConfiguration[] configurations = this.getLaunchConfigurations(); assertEquals("A configuration has been created", 1, configurations.length); assertEquals("A launch took place.", 1, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should not log a message when asked to launch the correct file type.", !shortcut.didLog()); String launchedFileName = configurations[0].getAttribute(RubyLaunchConfigurationAttribute.FILE_NAME, ""); assertEquals("folderOne/myFile.rb", launchedFileName); } public void testLaunchFromEditorWithRubyFile() throws Exception { IFile file = this.getOrCreateFile("/project1/test.rb"); RubySourceLocator sourceLocator = new RubySourceLocator(); String fullPath = RdtDebugUiPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator + file.getFullPath().toOSString(); Object sourceElement = sourceLocator.getSourceElement(fullPath); IEditorInput input = sourceLocator.getEditorInput(sourceElement); IEditorPart rubyEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, IRubyConstants.EDITOR_ID); shortcut.launch(rubyEditor, ILaunchManager.RUN_MODE); assertEquals("A configuration has been created", 1, this.getLaunchConfigurations().length); assertEquals("A launch took place.", 1, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should not log a message when asked to launch the correct file type.", !shortcut.didLog()); } public void testLaunchFromEditorWithTxtFile() throws Exception { IFile file = this.getOrCreateFile("/project1/test.txt"); IEditorInput input = new FileEditorInput(file); IEditorPart txtEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, "org.eclipse.ui.DefaultTextEditor"); shortcut.launch(txtEditor, ILaunchManager.RUN_MODE); assertEquals("No configuration has been created", 0, this.getLaunchConfigurations().length); assertEquals("No launch took place.", 0, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should must have logged a message.", shortcut.didLog()); } public void testLaunchFromExternalRubyFileEditor() throws Exception { File tmpFile = File.createTempFile("rubyfile.rb", null); //$NON-NLS-1$ RubySourceLocator sourceLocator = new RubySourceLocator(); Object sourceElement = sourceLocator.getSourceElement(tmpFile.getAbsolutePath()); IEditorInput input = sourceLocator.getEditorInput(sourceElement); IEditorPart rubyExternalEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, IRubyConstants.EXTERNAL_FILES_EDITOR_ID); shortcut.launch(rubyExternalEditor, ILaunchManager.RUN_MODE); assertEquals("No configuration has been created", 0, this.getLaunchConfigurations().length); assertEquals("No launch took place.", 0, ShamApplicationLaunchConfigurationDelegate.getLaunches()); assertTrue("The shortcut should must have logged a message.", shortcut.didLog()); } protected class ShamRubyApplicationShortcut extends RubyApplicationShortcut { protected boolean didLog; protected boolean didShowDialog=false; private boolean expectingException; protected void log(String message) { didLog = true; } public void expectException() { expectingException = true; } protected void log(Throwable t) { if (!expectingException) throw new RuntimeException("Unexpected throwable", t); didLog = true; } protected boolean didLog() { return didLog; } protected ILaunchConfigurationType getRubyLaunchConfigType() { return DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(SHAM_LAUNCH_CONFIG_TYPE); } protected void showNoInterpreterDialog() { didShowDialog = true ; } } } --- NEW FILE: TC_RubyEntryPointTab.java --- package org.rubypeople.rdt.internal.debug.ui.launcher; import junit.framework.TestCase; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.rubypeople.eclipse.shams.debug.core.ShamLaunchConfigurationWorkingCopy; import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiMessages; import org.rubypeople.rdt.internal.debug.ui.launcher.RubyEntryPointTab; import org.rubypeople.rdt.internal.launching.RubyLaunchConfigurationAttribute; public class TC_RubyEntryPointTab extends TestCase { public TC_RubyEntryPointTab(String name) { super(name); } public void testIsValid() { RubyEntryPointTab tab = new RubyEntryPointTab(); ILaunchConfigurationWorkingCopy configuration = new ShamLaunchConfigurationWorkingCopy(); String errorMessage = tab.getErrorMessage(); assertNull("There should be no error message.", errorMessage); assertTrue("The tab is not valid when the configuration is completely empty.", !tab.isValid(configuration)); errorMessage = RdtDebugUiMessages.getString("LaunchConfigurationTab.RubyEntryPoint.invalidProjectSelectionMessage"); assertEquals("The tab should set the error message for no project.", errorMessage, tab.getErrorMessage()); configuration.setAttribute(RubyLaunchConfigurationAttribute.PROJECT_NAME, "myProjectName"); assertTrue("The tab is not valid when the configuration has only a projectname.", !tab.isValid(configuration)); errorMessage = RdtDebugUiMessages.getString("LaunchConfigurationTab.RubyEntryPoint.invalidFileSelectionMessage"); assertEquals("The tab should set the error message for no file.", errorMessage, tab.getErrorMessage()); configuration.setAttribute(RubyLaunchConfigurationAttribute.FILE_NAME, "myFileName"); assertTrue("The tab is valid when the configuration has a filename and projectName.", tab.isValid(configuration)); assertNull("The tab should set the error message to null when there is a filename and projectname.", tab.getErrorMessage()); } } --- NEW FILE: TS_InternalDebugUiLauncher.java --- package org.rubypeople.rdt.internal.debug.ui.launcher; import junit.framework.Test; import junit.framework.TestSuite; public class TS_InternalDebugUiLauncher { public static Test suite() { TestSuite suite = new TestSuite("Test for org.rubypeople.rdt.internal.debug.ui.launcher"); suite.addTestSuite(TC_RubyArgumentsTab.class); suite.addTestSuite(TC_RubyApplicationShortcut.class); suite.addTestSuite(TC_RubyEntryPointTab.class); suite.addTestSuite(TC_RubyEnvironmentTab.class); return suite; } } --- NEW FILE: ShamApplicationLaunchConfigurationDelegate.java --- package org.rubypeople.rdt.internal.debug.ui.launcher; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; public class ShamApplicationLaunchConfigurationDelegate implements ILaunchConfigurationDelegate { private static int launches ; /** * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor) */ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { launches += 1 ; } public static int getLaunches() { return launches; } public static void resetLaunches() { launches = 0 ; } } |