Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2010-09-27 21:41:44 +0000
committerPawel Piech2010-09-27 21:41:44 +0000
commit069c1724663ee8083dc73571b2efcffe2bf83512 (patch)
treebb8f4ba8042d4a72c280f6b20c35f87eae9b7d2a /org.eclipse.debug.tests
parent158a4a8309e4e0cd8ea18700aca5141ddfccfc6c (diff)
downloadeclipse.platform.debug-069c1724663ee8083dc73571b2efcffe2bf83512.tar.gz
eclipse.platform.debug-069c1724663ee8083dc73571b2efcffe2bf83512.tar.xz
eclipse.platform.debug-069c1724663ee8083dc73571b2efcffe2bf83512.zip
Bug 324100 - Top index not maintained properly in variables / registers view
Diffstat (limited to 'org.eclipse.debug.tests')
-rw-r--r--org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java317
-rw-r--r--org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java1
-rw-r--r--org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreeModelViewerAutopopulateAgent.java5
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java2
4 files changed, 325 insertions, 0 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java
new file mode 100644
index 000000000..f3a764ed7
--- /dev/null
+++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/JFaceViewerTopIndexTests.java
@@ -0,0 +1,317 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Wind River Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipe.debug.tests.viewer.model;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.eclipe.debug.tests.viewer.model.TestModel.TestElement;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.debug.internal.ui.viewers.model.ITreeModelContentProviderTarget;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @since 3.6
+ */
+public class JFaceViewerTopIndexTests extends TestCase implements ITestModelUpdatesListenerConstants {
+
+ Display fDisplay;
+ Shell fShell;
+ TreeModelViewer fViewer;
+ TestModelUpdatesListener fListener;
+
+ public JFaceViewerTopIndexTests(String name) {
+ super(name);
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void setUp() throws Exception {
+ fDisplay = PlatformUI.getWorkbench().getDisplay();
+ fShell = new Shell(fDisplay/*, SWT.ON_TOP | SWT.SHELL_TRIM*/);
+ fShell.setSize(300, 100);
+ fShell.setLayout(new FillLayout());
+
+ fViewer = createViewer(fDisplay, fShell);
+
+ fListener = new TestModelUpdatesListener(fViewer, false, false);
+
+ fShell.open ();
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void tearDown() throws Exception {
+ fListener.dispose();
+ fViewer.getPresentationContext().dispose();
+
+ // Close the shell and exit.
+ fShell.close();
+ while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+ }
+
+ protected void runTest() throws Throwable {
+ try {
+ super.runTest();
+ } catch (Throwable t) {
+ throw new ExecutionException("Test failed: " + t.getMessage() + "\n fListener = " + fListener.toString(), t);
+ }
+ }
+
+ protected ITreeModelContentProviderTarget getCTargetViewer() {
+ return (ITreeModelContentProviderTarget)fViewer;
+ }
+
+ protected TreeModelViewer createViewer(Display display, Shell shell) {
+ return new TreeModelViewer(fShell, SWT.VIRTUAL | SWT.MULTI, new PresentationContext("TestViewer"));
+ }
+
+ /**
+ * Restore REVEAL on simple model with elements without children.
+ *
+ */
+ public void testRestoreTopIndex() {
+ TreeModelViewerAutopopulateAgent autopopulateAgent = new TreeModelViewerAutopopulateAgent(fViewer);
+
+ TestModel model = new TestModel();
+
+ TestElement[] elements = new TestElement[8];
+ for (int i = 0; i < elements.length; i++) {
+ String text = Integer.toString(i + 1);
+ // elements don't have children
+ elements[i] =
+ new TestElement(model, text, new TestElement[0] );
+
+ }
+ model.setRoot(new TestElement(model, "root", elements));
+
+ // Create the listener, only check the first level
+ fListener.reset(TreePath.EMPTY, model.getRootElement(), 1, false, false);
+
+ // Set the input into the view and update the view.
+ fViewer.setInput(model.getRootElement());
+
+ while (!fListener.isFinished()) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+ model.validateData(fViewer, TreePath.EMPTY, true);
+
+ // Stop forcing view updates.
+ autopopulateAgent.dispose();
+
+ // scroll to the 5th element
+ int indexRevealElem = 4;
+ getCTargetViewer().reveal(TreePath.EMPTY, indexRevealElem);
+ while(fDisplay.readAndDispatch()) {}
+ final TreePath originalTopPath = getCTargetViewer().getTopElementPath();
+ Assert.assertNotNull("Top item should not be null!", originalTopPath);
+ Assert.assertEquals(elements[indexRevealElem], originalTopPath.getLastSegment());
+
+ // Set the viewer input to null. This will trigger the view to save the viewer state.
+ fListener.reset(true, false);
+ fListener.addStateUpdates(getCTargetViewer(), TreePath.EMPTY, model.getRootElement());
+
+ fViewer.setInput(null);
+ while (!fListener.isFinished(STATE_SAVE_COMPLETE)) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ // Set the viewer input back to the model to trigger RESTORE operation.
+ fListener.reset(false, false);
+ fViewer.setInput(model.getRootElement());
+ while (!fListener.isFinished(ALL_UPDATES_COMPLETE | STATE_RESTORE_COMPLETE)) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ while (fDisplay.readAndDispatch ()) {}
+ // check if REVEAL was restored OK
+ final TreePath topPath = getCTargetViewer().getTopElementPath();
+ Assert.assertNotNull("Top item should not be null!", topPath);
+ Assert.assertEquals(elements[indexRevealElem], topPath.getLastSegment());
+ Assert.assertEquals(originalTopPath, topPath);
+
+ }
+
+ /**
+ * Restore REVEAL when having also to restore an expanded element
+ * that is just above the REVEAL element.
+ *
+ * See bug 324100
+ */
+ public void testRestoreTopAndExpand() {
+ TreeModelViewerAutopopulateAgent autopopulateAgent = new TreeModelViewerAutopopulateAgent(fViewer);
+
+ TestModel model = new TestModel();
+
+ TestElement[] elements = new TestElement[10];
+ for (int i = 0; i < elements.length; i++) {
+ String text = Integer.toString(i + 1);
+ // first element has 2 children
+ if (i == 0) {
+ elements[i] =
+ new TestElement(model, text, new TestElement[] {
+ new TestElement(model, text + ".1", new TestElement[0] ),
+ new TestElement(model, text + ".2", new TestElement[0] )
+ });
+ } else {
+ // rest of elements don't have children
+ elements[i] =
+ new TestElement(model, text, new TestElement[0] );
+ }
+
+ }
+ model.setRoot(new TestElement(model, "root", elements));
+
+ // Create the listener, only check the first level
+ fListener.reset(TreePath.EMPTY, model.getRootElement(), 1, false, false);
+
+ // Set the input into the view and update the view.
+ fViewer.setInput(model.getRootElement());
+
+ while (!fListener.isFinished()) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+ model.validateData(fViewer, TreePath.EMPTY, true);
+
+ // Expand first element
+ fListener.reset();
+ fListener.setFailOnRedundantUpdates(false);
+ int indexFirstElem = 0;
+ TestElement firstElem = elements[indexFirstElem];
+ ModelDelta rootDelta = new ModelDelta(model.getRootElement(), IModelDelta.NO_CHANGE);
+ ModelDelta delta = model.getBaseDelta(rootDelta);
+ TreePath firstElemPath = model.findElement(firstElem.getLabel());
+ fListener.addUpdates(
+ firstElemPath, firstElem, 1,
+ CHILD_COUNT_UPDATES | CHILDREN_UPDATES );
+ delta.addNode(firstElem, indexFirstElem, IModelDelta.EXPAND, firstElem.getChildren().length);
+
+ model.postDelta(rootDelta);
+
+ while (!fListener.isFinished(CONTENT_UPDATES_COMPLETE | MODEL_CHANGED_COMPLETE))
+ if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ // Validate that the first node is expanded
+ Assert.assertTrue(getCTargetViewer().getExpandedState(firstElemPath) == true);
+
+ // Stop forcing view updates.
+ autopopulateAgent.dispose();
+
+ // scroll to the 2nd element
+ getCTargetViewer().reveal(TreePath.EMPTY, 1);
+ while(fDisplay.readAndDispatch()) {}
+ final TreePath originalTopPath = getCTargetViewer().getTopElementPath();
+ Assert.assertNotNull("Top item should not be null!", originalTopPath);
+ Assert.assertEquals(elements[1], originalTopPath.getLastSegment());
+
+ // Set the viewer input to null. This will trigger the view to save the viewer state.
+ fListener.reset(true, false);
+ fListener.addStateUpdates(getCTargetViewer(), TreePath.EMPTY, model.getRootElement());
+ fViewer.setInput(null);
+ while (!fListener.isFinished(STATE_SAVE_COMPLETE)) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ // Set the viewer input back to the model
+ fListener.reset(false, false);
+ fViewer.setInput(model.getRootElement());
+ while (!fListener.isFinished(ALL_UPDATES_COMPLETE | STATE_RESTORE_COMPLETE)) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ while (fDisplay.readAndDispatch ()) {}
+ // check if REVEAL was restored OK
+ final TreePath topPath = getCTargetViewer().getTopElementPath();
+ Assert.assertNotNull("Top item should not be null!", topPath);
+ Assert.assertEquals(elements[1], topPath.getLastSegment());
+ Assert.assertEquals(originalTopPath, topPath);
+
+ }
+
+ /**
+ * Restore REVEAL when this operation triggers restoring of an expanded
+ * element.
+ *
+ * See bug 324100
+ */
+ public void testRestoreTopTriggersExpand() {
+ TreeModelViewerAutopopulateAgent autopopulateAgent = new TreeModelViewerAutopopulateAgent(fViewer);
+
+ TestModel model = new TestModel();
+
+ TestElement[] elements = new TestElement[10];
+ for (int i = 0; i < elements.length; i++) {
+ String text = Integer.toString(i + 1);
+ // last element has 2 children
+ if (i == elements.length - 1) {
+ elements[i] =
+ new TestElement(model, text, new TestElement[] {
+ new TestElement(model, text + ".1", new TestElement[0] ),
+ new TestElement(model, text + ".2", new TestElement[0] )
+ });
+ } else {
+ // rest of elements don't have children
+ elements[i] =
+ new TestElement(model, text, new TestElement[0] );
+ }
+
+ }
+
+ fViewer.setAutoExpandLevel(-1);
+ model.setRoot(new TestElement(model, "root", elements));
+
+ // Create the listener, only check the first level
+ fListener.reset(TreePath.EMPTY, model.getRootElement(), -1, false, false);
+
+ // Set the input into the view and update the view.
+ fViewer.setInput(model.getRootElement());
+
+ while (!fListener.isFinished()) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+ model.validateData(fViewer, TreePath.EMPTY, true);
+
+ int indexLastElem = elements.length-1;
+ TestElement lastElem = elements[indexLastElem];
+ TreePath lastElemePath = model.findElement(lastElem.getLabel());
+
+ // Validate that the last node is expanded
+ Assert.assertTrue(getCTargetViewer().getExpandedState(lastElemePath) == true);
+
+ // Stop forcing view updates.
+ fViewer.setAutoExpandLevel(0);
+ autopopulateAgent.dispose();
+
+ // scroll to the element before last element
+ getCTargetViewer().reveal(TreePath.EMPTY, indexLastElem-1);
+ while(fDisplay.readAndDispatch()) {}
+ final TreePath originalTopPath = getCTargetViewer().getTopElementPath();
+ Assert.assertNotNull("Top item should not be null!", originalTopPath);
+ Assert.assertEquals(elements[indexLastElem-1], originalTopPath.getLastSegment());
+
+ // Set the viewer input to null. This will trigger the view to save the viewer state.
+ fListener.reset(true, false);
+ fListener.addStateUpdates(getCTargetViewer(), TreePath.EMPTY, model.getRootElement());
+
+ fViewer.setInput(null);
+ while (!fListener.isFinished(STATE_SAVE_COMPLETE)) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ // Set the viewer input back to the model.
+ fListener.reset(false, false);
+ fViewer.setInput(model.getRootElement());
+ while (!fListener.isFinished(ALL_UPDATES_COMPLETE | STATE_RESTORE_COMPLETE)) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ while (fDisplay.readAndDispatch ()) {}
+ // check if REVEAL was restored OK
+ final TreePath topPath = getCTargetViewer().getTopElementPath();
+ Assert.assertNotNull("Top item should not be null!", topPath);
+ Assert.assertEquals(elements[indexLastElem-1], topPath.getLastSegment());
+ Assert.assertEquals(originalTopPath, topPath);
+
+ }
+}
diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java
index 468e7d1c3..d0b831bdf 100644
--- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java
+++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TestModelUpdatesListener.java
@@ -470,6 +470,7 @@ public class TestModelUpdatesListener
}
public void stateRestoreUpdatesComplete(Object input) {
+ Assert.assertFalse("RESTORE STATE already complete!", fStateRestoreComplete);
fStateRestoreComplete = true;
}
diff --git a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreeModelViewerAutopopulateAgent.java b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreeModelViewerAutopopulateAgent.java
index 2600fbebb..38f9eb052 100644
--- a/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreeModelViewerAutopopulateAgent.java
+++ b/org.eclipse.debug.tests/src/org/eclipe/debug/tests/viewer/model/TreeModelViewerAutopopulateAgent.java
@@ -36,6 +36,11 @@ public class TreeModelViewerAutopopulateAgent implements IViewerUpdateListener {
fViewer.addViewerUpdateListener(this);
}
+ public void dispose() {
+ fViewer.removeViewerUpdateListener(this);
+ fViewer = null;
+ }
+
public void updateComplete(IViewerUpdate update) {
if (update instanceof IChildrenCountUpdate) {
TreePath path = update.getElementPath();
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java
index 4d9b0b45b..2e33dc384 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java
@@ -27,6 +27,7 @@ import org.eclipe.debug.tests.viewer.model.JFaceViewerContentTests;
import org.eclipe.debug.tests.viewer.model.JFaceViewerDeltaTests;
import org.eclipe.debug.tests.viewer.model.JFaceViewerSelectionTests;
import org.eclipe.debug.tests.viewer.model.JFaceViewerStateTests;
+import org.eclipe.debug.tests.viewer.model.JFaceViewerTopIndexTests;
import org.eclipe.debug.tests.viewer.model.JFaceViewerUpdateTests;
import org.eclipe.debug.tests.viewer.model.PresentationContextTests;
import org.eclipe.debug.tests.viewer.model.VirtualViewerContentTests;
@@ -64,6 +65,7 @@ public class AutomatedSuite extends TestSuite {
addTest(new TestSuite(JFaceViewerSelectionTests.class));
addTest(new TestSuite(JFaceViewerStateTests.class));
addTest(new TestSuite(JFaceViewerUpdateTests.class));
+ addTest(new TestSuite(JFaceViewerTopIndexTests.class));
// Virtual viewer tests
addTest(new TestSuite(VirtualViewerDeltaTests.class));

Back to the top