From 2d720adf0aaa6ec0a9fc5c1945cc6abf11805039 Mon Sep 17 00:00:00 2001 From: pombredanne Date: Sun, 4 Nov 2007 02:19:20 +0000 Subject: [PATCH] Added some more tests,a nd reformtted the code a little. --- .../launching/PHPSourceLookupParticipantTest.java | 72 +++++++++++++++++--- .../AbstractSourceLookupParticipantTest.java | 22 ++++++ 2 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 net.sourceforge.phpeclipse.xdebug.test/src/org/eclipse/debug/core/sourcelookup/AbstractSourceLookupParticipantTest.java diff --git a/net.sourceforge.phpeclipse.xdebug.test/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipantTest.java b/net.sourceforge.phpeclipse.xdebug.test/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipantTest.java index ad46b6f..e0bf427 100644 --- a/net.sourceforge.phpeclipse.xdebug.test/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipantTest.java +++ b/net.sourceforge.phpeclipse.xdebug.test/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipantTest.java @@ -1,41 +1,91 @@ package net.sourceforge.phpeclipse.xdebug.php.launching; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; import net.sourceforge.phpeclipse.xdebug.php.model.XDebugStackFrame; -import net.sourceforge.phpeclipse.xdebug.php.model.XDebugThread; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; - -import junit.framework.TestCase; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.ui.PlatformUI; public class PHPSourceLookupParticipantTest extends TestCase { public void testFindSourceElementsObject() throws CoreException { PHPSourceLookupParticipant psp = new PHPSourceLookupParticipant(); Object[] findSourceElements = psp.findSourceElements(new Object()); - assertTrue("array should be empty",findSourceElements.length == 0); + assertTrue("array should be empty", findSourceElements.length == 0); } - + public void testFindSourceElementsObject_WithNull() throws CoreException { PHPSourceLookupParticipant psp = new PHPSourceLookupParticipant(); Object[] findSourceElements = psp.findSourceElements(null); - assertTrue("array should be empty",findSourceElements.length == 0); + assertTrue("array should be empty", findSourceElements.length == 0); } - public void testFindSourceElementsObject_WithXdebugStackFrame() throws CoreException { + + public void testFindSourceElementsObject_WithXdebugStackFrame() + throws CoreException { PHPSourceLookupParticipant psp = new PHPSourceLookupParticipant(); XDebugStackFrame frame = new MockXDebugStackFrame(); Object[] findSourceElements = psp.findSourceElements(frame); - assertTrue("array should be empty",findSourceElements.length == 0); + assertTrue("array should be empty", findSourceElements.length == 0); } - + class MockXDebugStackFrame extends XDebugStackFrame { public MockXDebugStackFrame() { super(null, 0); } } - + + public void testFindSourceElementsObject_TestPippo() throws CoreException { + PHPSourceLookupParticipant psp = new PHPSourceLookupParticipant(); + XDebugStackFrame frame = new PippoXDebugStackFrame(); + Object[] findSourceElements = psp.findSourceElements(frame); + assertEquals(1, findSourceElements.length); + assertEquals("pippo", findSourceElements[0]); + } + + class PippoXDebugStackFrame extends XDebugStackFrame { + public PippoXDebugStackFrame() { + super(null, 0); + } + + public String getType() { + return "eval"; + } + + public String getSourceName() { + return ""; + } + } + public void testGetSourceName() throws CoreException { PHPSourceLookupParticipant psp = new PHPSourceLookupParticipant(); psp.getSourceName(null); } -} + public void testAddMatching_withNull() { + PHPSourceLookupParticipant.addMatching(null, null, null); + } + + public void testAddMatching_updatesList() { + // setup + List l = new ArrayList(); + + Object o1 = new Object(); + Object o2 = new Object(); + Object[] os = new Object[] { o1, o2 }; + + IPath p = new Path("/some/path"); + + // test + PHPSourceLookupParticipant.addMatching(l, p, os); + assertTrue(l.isEmpty()); + } + + +} diff --git a/net.sourceforge.phpeclipse.xdebug.test/src/org/eclipse/debug/core/sourcelookup/AbstractSourceLookupParticipantTest.java b/net.sourceforge.phpeclipse.xdebug.test/src/org/eclipse/debug/core/sourcelookup/AbstractSourceLookupParticipantTest.java new file mode 100644 index 0000000..523f095 --- /dev/null +++ b/net.sourceforge.phpeclipse.xdebug.test/src/org/eclipse/debug/core/sourcelookup/AbstractSourceLookupParticipantTest.java @@ -0,0 +1,22 @@ +package org.eclipse.debug.core.sourcelookup; + +import org.eclipse.core.runtime.CoreException; + +import junit.framework.TestCase; + +public class AbstractSourceLookupParticipantTest extends TestCase { + + public void testIsFindDuplicates() { + fail("Not yet implemented"); + } + + class MockAbstractSourceLookupParticipant extends AbstractSourceLookupParticipant { + public String getSourceName(Object object) throws CoreException { + return null; + } + + protected boolean isFindDuplicates() { + return false; + } + } +} -- 1.7.1