|
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 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24567/src/org/rubypeople/rdt/internal/debug/ui Added Files: TC_RubySourceLocator.java TS_InternalDebugUi.java TC_RubyConsoleTracker.java Log Message: Organize tests for consistency. Found a few TCs that weren't being called for the main suite. --- NEW FILE: TC_RubySourceLocator.java --- package org.rubypeople.rdt.internal.debug.ui; import java.io.ByteArrayInputStream; import java.io.File; import java.util.List; import java.util.Map; import junit.framework.TestCase; import org.eclipse.core.internal.resources.Project; import org.eclipse.core.internal.resources.Workspace; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.PlatformUI; import org.rubypeople.rdt.internal.debug.core.model.RubyStackFrame; import org.rubypeople.rdt.internal.debug.ui.RdtDebugUiPlugin; import org.rubypeople.rdt.internal.debug.ui.RubySourceLocator; public class TC_RubySourceLocator extends TestCase { public TC_RubySourceLocator(String name) { super(name); } protected void setUp() { } public void testWorkspaceInternalFile() throws Exception { Workspace workspace = (Workspace) RdtDebugUiPlugin.getWorkspace() ; // Create a project called 'SourceLocatorTest' Project p = new TestProject("/SourceLocatorTest", workspace) ; //$NON-NLS-1$ p.create(null) ; p.open(null) ; IPath filePath = new Path("/SourceLocatorTest/test.rb") ; //$NON-NLS-1$ IFile file =RdtDebugUiPlugin.getWorkspace().getRoot().getFile(filePath) ; file.create(new ByteArrayInputStream(new byte[0]) ,true, null) ; // using slashes for the workspace internal path is platform independent String fullPath = workspace.getRoot().getLocation().toOSString() + File.separator + "SourceLocatorTest/test.rb" ; //$NON-NLS-1$ RubySourceLocator sourceLocator = new RubySourceLocator() ; RubyStackFrame rubyStackFrame = new RubyStackFrame(null,fullPath, 5, 1) ; Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ; IEditorInput input = sourceLocator.getEditorInput(sourceElement) ; assertNotNull(input) ; assertTrue(input.exists()) ; PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ; } public void testWorkspaceExternalFile() throws Exception { // external File File tmpFile = File.createTempFile("rubyfile", null) ; //$NON-NLS-1$ RubyStackFrame rubyStackFrame = new RubyStackFrame(null,tmpFile.getAbsolutePath(), 5, 1) ; RubySourceLocator sourceLocator = new RubySourceLocator() ; Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ; IEditorInput input = sourceLocator.getEditorInput(sourceElement) ; assertNotNull(input) ; assertTrue(input.exists()) ; PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ; // set Working Directory to a project location Workspace workspace = (Workspace) RdtDebugUiPlugin.getWorkspace() ; Project p = new TestProject("/WorkingDirIsProject", workspace) ; //$NON-NLS-1$ p.create(null) ; p.open(null) ; sourceLocator.initializeDefaults(new LaunchConfiguration(workspace.getRoot().getLocation().toOSString() + File.separator + "WorkingDirIsProject")) ; sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ; input = sourceLocator.getEditorInput(sourceElement) ; assertNotNull(input) ; assertTrue(input.exists()) ; PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ; // An External file which is relative to the working directory // If an external file is found within an include path, ruby seems always to deliver an // absolte file path. But if the file found relative to the working directory, ruby // shows a relative path String workspacePath = workspace.getRoot().getLocation().toOSString() ; File externalFile = new File(workspacePath + File.separator + "externalRelativeRubyFile.rb") ; assertTrue(externalFile.createNewFile()) ; // current directory = working dir = workspacePath/WorkingDirIsProject rubyStackFrame = new RubyStackFrame(null,"../externalRelativeRubyFile.rb", 5, 1) ; sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ; input = sourceLocator.getEditorInput(sourceElement) ; assertNotNull(input) ; assertTrue(input.exists()) ; PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, sourceLocator.getEditorId(input, sourceElement)) ; } public void testNotExistingFile() throws Exception { RubyStackFrame rubyStackFrame = new RubyStackFrame(null,"/tmp/nonexistingtestfile", 5, 1) ; //$NON-NLS-1$ RubySourceLocator sourceLocator = new RubySourceLocator() ; Object sourceElement = sourceLocator.getSourceElement(rubyStackFrame) ; IEditorInput input = sourceLocator.getEditorInput(sourceElement) ; assertNull(input) ; } public class TestProject extends Project { public TestProject(String aName, Workspace aWorkspace) { super(new Path(aName), aWorkspace) ; } } public class LaunchConfiguration implements ILaunchConfiguration { String workingDir ; public LaunchConfiguration(String pDir) { workingDir = pDir ; } public boolean contentsEqual(ILaunchConfiguration configuration) { return false; } public ILaunchConfigurationWorkingCopy copy(String name) throws CoreException { return null; } public void delete() throws CoreException { } public boolean exists() { return false; } public boolean getAttribute(String attributeName, boolean defaultValue) throws CoreException { return false; } public int getAttribute(String attributeName, int defaultValue) throws CoreException { return 0; } public List getAttribute(String attributeName, List defaultValue) throws CoreException { return null; } public Map getAttribute(String attributeName, Map defaultValue) throws CoreException { return null; } public String getAttribute(String attributeName, String defaultValue) throws CoreException { return workingDir ; } public Map getAttributes() throws CoreException { return null; } public String getCategory() throws CoreException { return null; } public IFile getFile() { return null; } public IPath getLocation() { return null; } public String getMemento() throws CoreException { return null; } public String getName() { return null; } public ILaunchConfigurationType getType() throws CoreException { return null; } public ILaunchConfigurationWorkingCopy getWorkingCopy() throws CoreException { return null; } public boolean isLocal() { return false; } public boolean isWorkingCopy() { return false; } public ILaunch launch(String mode, IProgressMonitor monitor) throws CoreException { return null; } public boolean supportsMode(String mode) throws CoreException { return false; } public Object getAdapter(Class adapter) { return null; } public ILaunch launch(String mode, IProgressMonitor monitor, boolean build) throws CoreException { return null; } public ILaunch launch(String mode, IProgressMonitor monitor, boolean build, boolean register) throws CoreException { // TODO Auto-generated method stub return null; } } } --- NEW FILE: TS_InternalDebugUi.java --- package org.rubypeople.rdt.internal.debug.ui; import junit.framework.Test; import junit.framework.TestSuite; public class TS_InternalDebugUi { public static Test suite() { TestSuite suite = new TestSuite("Test for org.rubypeople.rdt.internal.debug.ui"); suite.addTestSuite(TC_RubyConsoleTracker.class); suite.addTestSuite(TC_RubySourceLocator.class); return suite; } } --- NEW FILE: TC_RubyConsoleTracker.java --- package org.rubypeople.rdt.internal.debug.ui; import java.util.ArrayList; import java.util.List; import junit.framework.TestCase; import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.core.model.IStreamMonitor; import org.eclipse.debug.core.model.IStreamsProxy; import org.eclipse.debug.ui.console.IConsole; import org.eclipse.debug.ui.console.IConsoleHyperlink; import org.eclipse.jface.text.AbstractDocument; import org.eclipse.jface.text.DefaultLineTracker; import org.eclipse.jface.text.GapTextStore; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.ui.console.IOConsoleOutputStream; import org.eclipse.ui.console.IPatternMatchListener; import org.rubypeople.rdt.internal.debug.ui.console.RubyConsoleTracker; import org.rubypeople.rdt.internal.debug.ui.console.RubyStackTraceHyperlink; import org.rubypeople.rdt.internal.debug.ui.console.RubyConsoleTracker.FileExistanceChecker; public class TC_RubyConsoleTracker extends TestCase { private static final String SYNTAX_IN_REQUIRE = " /RdtTest/FooTest.rb:2:in `require': /RdtTestLib/anotherFile.rb:9: parse error (SyntaxError)"; private TestConsole console; private MockFileExistanceChecker fileChecker; public void setUp() throws Exception { fileChecker = new MockFileExistanceChecker(); console = new TestConsole(fileChecker); } public void testCorrect() throws Exception { //data/test/configFile.rb:1:in `require': No such file to load -- inifile (LoadError) // * from /data/test/configFile.rb:1 // * from /data/test/fetchmail.rb:2:in `require' fileChecker.addKnownFile("/d/t.rb"); fileChecker.addKnownFile("c:/d/abc.rb"); console.lineAppend("/d/t.rb:1:in `require': No such file to load -- inifile (LoadError)") ; console.lineAppend("\tfrom c:/d/abc.rb:99") ; console.lineAppend(" /name with from in the middle/rb.rb:123") ; console.assertLink(0, 9, "/d/t.rb", 1, 0); console.assertLink(6, 14, "c:/d/abc.rb", 99, 1); console.assertLinkCount(2); } public void testSyntaxErrorInRequire() throws Exception { fileChecker.addKnownFile("/RdtTest/FooTest.rb"); fileChecker.addKnownFile("/RdtTestLib/anotherFile.rb"); console.lineAppend(SYNTAX_IN_REQUIRE) ; console.assertLinkCount(2); console.assertLink( 1, 21, "/RdtTest/FooTest.rb", 2, 0); console.assertLink(37, 28, "/RdtTestLib/anotherFile.rb", 9, 1); } public void testSecondWithoutFirst() throws Exception { fileChecker.addKnownFile("c:/d/abc.rb"); console.lineAppend("\tfrom c:/d/abc.rb:99") ; console.assertLink(6, 14, "c:/d/abc.rb", 99, 0); } public void testInCorrect() throws Exception { fileChecker.addKnownFile("/d/t.rb"); console.lineAppend("/d/t.rb:a:in `require': No such file to load -- inifile (LoadError)") ; console.lineAppend("/d/t.rb:123 "); console.assertLinkCount(0); } private final class MockFileExistanceChecker implements RubyConsoleTracker.FileExistanceChecker { private List knownFiles = new ArrayList(); public void addKnownFile(String filename) { knownFiles.add(filename); } public boolean fileExists(String filename) { return knownFiles.contains(filename); } } public class TestConsole implements IConsole { private class MetaLink { public RubyStackTraceHyperlink link; public int offset; public int length; } private List metaLinks = new ArrayList(); SimpleDocument doc = new SimpleDocument() ; RubyConsoleTracker tracker ; public TestConsole(FileExistanceChecker fileChecker) throws Exception { tracker = new RubyConsoleTracker(fileChecker); tracker.init(this) ; } public void assertLinkCount(int expectedLinkCount) { assertEquals(expectedLinkCount, metaLinks.size()); } public void assertLink(int expectedOffset, int expectedLength, String expectedFilename, int expectedLineNumber, int linkIndex) { MetaLink metaLink = (MetaLink) metaLinks.get(linkIndex); assertNotNull(metaLink); assertEquals("Offset of link["+linkIndex+"]", expectedOffset, metaLink.offset); assertEquals(expectedLength, metaLink.length); assertEquals(expectedFilename, metaLink.link.getFilename()); assertEquals(expectedLineNumber, metaLink.link.getLineNumber()); } public void addLink(IConsoleHyperlink pLink, int pOffset, int pLength) { } public void addLink(org.eclipse.ui.console.IHyperlink pLink, int pOffset, int pLength) { MetaLink metaLink = new MetaLink(); metaLink.link = (RubyStackTraceHyperlink) pLink ; metaLink.offset = pOffset ; metaLink.length = pLength ; metaLinks.add(metaLink); } public void connect(IStreamMonitor streamMonitor, String streamIdentifer) { throw new RuntimeException("Not Implemented Exception"); } public void connect(IStreamsProxy streamsProxy) { throw new RuntimeException("Not Implemented Exception"); } public IDocument getDocument() { return doc; } public IProcess getProcess() { throw new RuntimeException("Not Implemented Exception"); } public IRegion getRegion(IConsole link) { throw new RuntimeException("Not Implemented Exception"); } public void lineAppend(String pLine) throws Exception { doc.set(pLine) ; tracker.lineAppended(doc.getLineInformationOfOffset(1)) ; } public IRegion getRegion(IConsoleHyperlink link) { // TODO Auto-generated method stub return null; } public IRegion getRegion(org.eclipse.ui.console.IHyperlink link) { // TODO Auto-generated method stub return null; } public void addPatternMatchListener(IPatternMatchListener matchListener) { // TODO Auto-generated method stub } public void removePatternMatchListener(IPatternMatchListener matchListener) { // TODO Auto-generated method stub } public IOConsoleOutputStream getStream(String streamIdentifier) { // TODO Auto-generated method stub return null; } } public class SimpleDocument extends AbstractDocument { public SimpleDocument() { // The text store is not really necessary, but there is a not null assert in AbstractDocument this.setTextStore(new GapTextStore(1,2)) ; setLineTracker(new DefaultLineTracker()); completeInitialization(); } } } |