Added some more tests,a nd reformtted the code a little.
authorpombredanne <pombredanne>
Sun, 4 Nov 2007 02:19:20 +0000 (02:19 +0000)
committerpombredanne <pombredanne>
Sun, 4 Nov 2007 02:19:20 +0000 (02:19 +0000)
net.sourceforge.phpeclipse.xdebug.test/src/net/sourceforge/phpeclipse/xdebug/php/launching/PHPSourceLookupParticipantTest.java
net.sourceforge.phpeclipse.xdebug.test/src/org/eclipse/debug/core/sourcelookup/AbstractSourceLookupParticipantTest.java [new file with mode: 0644]

index ad46b6f..e0bf427 100644 (file)
@@ -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 (file)
index 0000000..523f095
--- /dev/null
@@ -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;
+               }
+       }
+}