Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2010-09-24 18:58:49 +0000
committerPawel Piech2010-09-24 18:58:49 +0000
commit4d3edd80a2216db9e44594bc2b001410392147f4 (patch)
treeaead2d9e55ec05d9edd459f5aaddd2f104d210ed /dsf/org.eclipse.cdt.tests.dsf
parentde6322ba9cc997cda01596d337f44c00cf636183 (diff)
downloadorg.eclipse.cdt-4d3edd80a2216db9e44594bc2b001410392147f4.tar.gz
org.eclipse.cdt-4d3edd80a2216db9e44594bc2b001410392147f4.tar.xz
org.eclipse.cdt-4d3edd80a2216db9e44594bc2b001410392147f4.zip
Bug 321932 - [update policy] When in manual mode, switching number format should still show value in other formats if value is cached.
Diffstat (limited to 'dsf/org.eclipse.cdt.tests.dsf')
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/IViewerUpdatesListenerConstants.java51
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java25
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ViewerUpdatesListener.java644
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTest1.java141
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTestBase.java128
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/DummyFormattedValueService.java58
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java372
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValuesListener.java200
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/IFormattedValuesListener.java22
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/ITestModelUpdatesListenerConstants.java40
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/JFaceViewerFormattedValueTests.java38
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/PerformanceTests.java32
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestElementVMContext.java17
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModel.java293
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelCachingVMProvider.java113
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelDMVMNode.java252
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelUpdatesListener.java451
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMAdapter.java2
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMNode.java22
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMProvider.java3
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/VirtualViewerPerformanceTests.java2
21 files changed, 2263 insertions, 643 deletions
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/IViewerUpdatesListenerConstants.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/IViewerUpdatesListenerConstants.java
new file mode 100644
index 00000000000..eca8593d9b4
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/IViewerUpdatesListenerConstants.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.eclipse.cdt.tests.dsf;
+
+/**
+ * Convenience interface with constants used by the test model update listener.
+ * @since 2.2
+ */
+public interface IViewerUpdatesListenerConstants {
+
+ public static final int LABEL_SEQUENCE_COMPLETE = 0X00000001;
+ public static final int CONTENT_SEQUENCE_COMPLETE = 0X00000002;
+ public static final int CONTENT_SEQUENCE_STARTED = 0X00020000;
+ public static final int LABEL_UPDATES = 0X00000004;
+ public static final int LABEL_SEQUENCE_STARTED = 0X00040000;
+ public static final int HAS_CHILDREN_UPDATES = 0X00000008;
+ public static final int HAS_CHILDREN_UPDATES_STARTED = 0X00080000;
+ public static final int CHILD_COUNT_UPDATES = 0X00000010;
+ public static final int CHILD_COUNT_UPDATES_STARTED = 0X00100000;
+ public static final int CHILDREN_UPDATES = 0X00000020;
+ public static final int CHILDREN_UPDATES_STARTED = 0X00200000;
+ public static final int MODEL_CHANGED_COMPLETE = 0X00000040;
+ public static final int MODEL_PROXIES_INSTALLED = 0X00000080;
+ public static final int STATE_SAVE_COMPLETE = 0X00000100;
+ public static final int STATE_SAVE_STARTED = 0X01000000;
+ public static final int STATE_RESTORE_COMPLETE = 0X00000200;
+ public static final int STATE_RESTORE_STARTED = 0X02000000;
+ public static final int STATE_UPDATES = 0X00000400;
+ public static final int STATE_UPDATES_STARTED = 0X04000000;
+ public static final int PROPERTY_UPDATES = 0X00000800;
+ public static final int PROPERTY_UPDATES_STARTED = 0X08000000;
+
+ public static final int VIEWER_UPDATES_RUNNING = 0X00001000;
+ public static final int LABEL_UPDATES_RUNNING = 0X00002000;
+
+ public static final int VIEWER_UPDATES_STARTED = HAS_CHILDREN_UPDATES_STARTED | CHILD_COUNT_UPDATES_STARTED | CHILDREN_UPDATES_STARTED;
+
+ public static final int LABEL_COMPLETE = LABEL_SEQUENCE_COMPLETE | LABEL_UPDATES | LABEL_UPDATES_RUNNING;
+ public static final int CONTENT_UPDATES = HAS_CHILDREN_UPDATES | CHILD_COUNT_UPDATES | CHILDREN_UPDATES;
+ public static final int CONTENT_COMPLETE = CONTENT_UPDATES | CONTENT_SEQUENCE_COMPLETE | VIEWER_UPDATES_RUNNING;
+
+ public static final int ALL_UPDATES_COMPLETE = LABEL_COMPLETE | CONTENT_COMPLETE | MODEL_PROXIES_INSTALLED | LABEL_UPDATES_RUNNING | VIEWER_UPDATES_RUNNING;
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java
index 6b28f74b10d..9e25b8924bd 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ServiceEventWaitor.java
@@ -12,6 +12,7 @@ package org.eclipse.cdt.tests.dsf;
import org.eclipse.cdt.dsf.service.DsfServiceEventHandler;
import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.swt.widgets.Display;
/*
* This class provides a way to wait for an asynchronous ServerEvent
@@ -34,14 +35,16 @@ public class ServiceEventWaitor<V> {
/* The type of event to wait for */
private Class<V> fEventTypeClass;
- private DsfSession fSession;
+ private final DsfSession fSession;
private V fEvent;
+ private final Display fDisplay;
/* Empty contructor. registerForEvent() should be called when
* this constructor is used.
*/
public ServiceEventWaitor(DsfSession session) {
+ fDisplay = Display.getDefault();
fSession = session;
}
@@ -62,10 +65,12 @@ public class ServiceEventWaitor<V> {
fSession.addServiceEventListener(this, null);
}
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- if (fEventTypeClass != null) fSession.removeServiceEventListener(this);
+ public DsfSession getSession() {
+ return fSession;
+ }
+
+ public void dispose() {
+ if (fEventTypeClass != null) fSession.removeServiceEventListener(this);
}
/* Block until 'timeout' or the previously specified event has been
@@ -80,7 +85,15 @@ public class ServiceEventWaitor<V> {
// The event might have already been received
if (fEvent != null) return fEvent;
- wait(timeout);
+ long timeoutTime = System.currentTimeMillis() + timeout;
+ while (timeoutTime > System.currentTimeMillis()) {
+ if (fEvent != null) {
+ break;
+ }
+ if (!fDisplay.readAndDispatch()) {
+ Thread.sleep(0);
+ }
+ }
if (fEvent == null) {
throw new Exception("Timed out waiting for ServiceEvent: " + fEventTypeClass.getName());
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ViewerUpdatesListener.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ViewerUpdatesListener.java
new file mode 100644
index 00000000000..33985c1d252
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/ViewerUpdatesListener.java
@@ -0,0 +1,644 @@
+/*******************************************************************************
+ * 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.eclipse.cdt.tests.dsf;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import junit.framework.Assert;
+
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdateListener;
+import org.eclipse.debug.internal.ui.viewers.model.ILabelUpdateListener;
+import org.eclipse.debug.internal.ui.viewers.model.ITreeModelViewer;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IStateUpdateListener;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdateListener;
+import org.eclipse.jface.viewers.TreePath;
+
+/**
+ * @since 2.2
+ */
+public class ViewerUpdatesListener
+ implements IViewerUpdateListener, ILabelUpdateListener, IModelChangedListener, IViewerUpdatesListenerConstants,
+ IStateUpdateListener, IPropertiesUpdateListener
+{
+ private ITreeModelViewer fViewer;
+
+ private boolean fFailOnRedundantUpdates;
+ private Set<IViewerUpdate> fRedundantUpdates = new HashSet<IViewerUpdate>();
+
+ private boolean fFailOnMultipleModelUpdateSequences;
+ private boolean fMultipleModelUpdateSequencesObserved;
+ private boolean fFailOnMultipleLabelUpdateSequences;
+ private boolean fMultipleLabelUpdateSequencesObserved;
+
+ private Set<TreePath> fHasChildrenUpdatesScheduled = makeTreePathSet();
+ private Set<IViewerUpdate> fHasChildrenUpdatesRunning = new HashSet<IViewerUpdate>();
+ private Set<IViewerUpdate> fHasChildrenUpdatesCompleted = new HashSet<IViewerUpdate>();
+ private Map<TreePath, Set<Integer>> fChildrenUpdatesScheduled = makeTreePathMap();
+ private Set<IViewerUpdate> fChildrenUpdatesRunning = new HashSet<IViewerUpdate>();
+ private Set<IViewerUpdate> fChildrenUpdatesCompleted = new HashSet<IViewerUpdate>();
+ private Set<TreePath> fChildCountUpdatesScheduled = makeTreePathSet();
+ private Set<IViewerUpdate> fChildCountUpdatesRunning = new HashSet<IViewerUpdate>();
+ private Set<IViewerUpdate> fChildCountUpdatesCompleted = new HashSet<IViewerUpdate>();
+ private Set<TreePath> fLabelUpdates = makeTreePathSet();
+ private Set<IViewerUpdate> fLabelUpdatesRunning = new HashSet<IViewerUpdate>();
+ private Set<IViewerUpdate> fLabelUpdatesCompleted = new HashSet<IViewerUpdate>();
+ private Set<TreePath> fPropertiesUpdates = makeTreePathSet();
+ private Set<IViewerUpdate> fPropertiesUpdatesRunning = new HashSet<IViewerUpdate>();
+ private Set<IViewerUpdate> fPropertiesUpdatesCompleted = new HashSet<IViewerUpdate>();
+// private Set<TreePath> fProxyModels = new HashSet<TreePath>();
+ private Set<TreePath> fStateUpdates = makeTreePathSet();
+ private boolean fContentSequenceStarted;
+ private boolean fContentSequenceComplete;
+ private boolean fLabelUpdatesStarted;
+ private boolean fLabelSequenceComplete;
+ private boolean fModelChangedComplete;
+ private boolean fStateSaveStarted;
+ private boolean fStateSaveComplete;
+ private boolean fStateRestoreStarted;
+ private boolean fStateRestoreComplete;
+ private int fContentUpdatesCounter;
+ private int fLabelUpdatesCounter;
+ private int fPropertiesUpdatesCounter;
+ private int fTimeoutInterval = 60000;
+ private long fTimeoutTime;
+
+ protected Set<TreePath> makeTreePathSet() {
+ return new HashSet<TreePath>();
+ }
+
+ protected <V> Map<TreePath, V> makeTreePathMap() {
+ return new HashMap<TreePath, V>();
+ }
+
+
+ public ViewerUpdatesListener(ITreeModelViewer viewer, boolean failOnRedundantUpdates, boolean failOnMultipleModelUpdateSequences) {
+ this(viewer);
+ setFailOnRedundantUpdates(failOnRedundantUpdates);
+ setFailOnMultipleModelUpdateSequences(failOnMultipleModelUpdateSequences);
+ }
+
+ public ViewerUpdatesListener() {
+ // No viewer to register with. Client will have to register the listener manually.
+ }
+
+ public ViewerUpdatesListener(ITreeModelViewer viewer) {
+ fViewer = viewer;
+ fViewer.addLabelUpdateListener(this);
+ fViewer.addModelChangedListener(this);
+ fViewer.addStateUpdateListener(this);
+ fViewer.addViewerUpdateListener(this);
+ }
+
+ public void dispose() {
+ if (fViewer != null) {
+ fViewer.removeLabelUpdateListener(this);
+ fViewer.removeModelChangedListener(this);
+ fViewer.removeStateUpdateListener(this);
+ fViewer.removeViewerUpdateListener(this);
+ fViewer = null;
+ }
+ }
+
+
+ public void setFailOnRedundantUpdates(boolean failOnRedundantUpdates) {
+ fFailOnRedundantUpdates = failOnRedundantUpdates;
+ }
+
+ public void setFailOnMultipleModelUpdateSequences(boolean failOnMultipleLabelUpdateSequences) {
+ fFailOnMultipleModelUpdateSequences = failOnMultipleLabelUpdateSequences;
+ }
+
+ public void setFailOnMultipleLabelUpdateSequences(boolean failOnMultipleLabelUpdateSequences) {
+ fFailOnMultipleLabelUpdateSequences = failOnMultipleLabelUpdateSequences;
+ }
+
+ /**
+ * Sets the the maximum amount of time (in milliseconds) that the update listener
+ * is going to wait. If set to -1, the listener will wait indefinitely.
+ */
+ public void setTimeoutInterval(int milis) {
+ fTimeoutInterval = milis;
+ }
+
+ public void reset() {
+ fRedundantUpdates.clear();
+ fMultipleLabelUpdateSequencesObserved = false;
+ fMultipleModelUpdateSequencesObserved = false;
+ fHasChildrenUpdatesScheduled.clear();
+ fHasChildrenUpdatesRunning.clear();
+ fHasChildrenUpdatesCompleted.clear();
+ fChildrenUpdatesScheduled.clear();
+ fChildrenUpdatesRunning.clear();
+ fChildrenUpdatesCompleted.clear();
+ fChildCountUpdatesScheduled.clear();
+ fChildCountUpdatesRunning.clear();
+ fChildCountUpdatesCompleted.clear();
+ fLabelUpdates.clear();
+ fLabelUpdatesRunning.clear();
+ fLabelUpdatesCompleted.clear();
+// fProxyModels.clear();
+ fContentSequenceStarted = false;
+ fContentSequenceComplete = false;
+ fLabelUpdatesStarted = false;
+ fLabelSequenceComplete = false;
+ fStateSaveStarted = false;
+ fStateSaveComplete = false;
+ fStateRestoreStarted = false;
+ fStateRestoreComplete = false;
+ fTimeoutTime = System.currentTimeMillis() + fTimeoutInterval;
+ resetModelChanged();
+ }
+
+ public void resetModelChanged() {
+ fModelChangedComplete = false;
+ }
+
+ public void addHasChildrenUpdate(TreePath path) {
+ fHasChildrenUpdatesScheduled.add(path);
+ }
+
+ public void removeHasChildrenUpdate(TreePath path) {
+ fHasChildrenUpdatesScheduled.remove(path);
+ }
+
+ public void addChildCountUpdate(TreePath path) {
+ fChildCountUpdatesScheduled.add(path);
+ }
+
+ public void removeChildreCountUpdate(TreePath path) {
+ fChildCountUpdatesScheduled.remove(path);
+ }
+
+ public void addChildreUpdate(TreePath path, int index) {
+ Set<Integer> childrenIndexes = fChildrenUpdatesScheduled.get(path);
+ if (childrenIndexes == null) {
+ childrenIndexes = new TreeSet<Integer>();
+ fChildrenUpdatesScheduled.put(path, childrenIndexes);
+ }
+ childrenIndexes.add(new Integer(index));
+ }
+
+ public void removeChildrenUpdate(TreePath path, int index) {
+ Set<Integer> childrenIndexes = fChildrenUpdatesScheduled.get(path);
+ if (childrenIndexes != null) {
+ childrenIndexes.remove(new Integer(index));
+ if (childrenIndexes.isEmpty()) {
+ fChildrenUpdatesScheduled.remove(path);
+ }
+ }
+ }
+
+ public void addLabelUpdate(TreePath path) {
+ fLabelUpdates.add(path);
+ }
+
+ public void addPropertiesUpdate(TreePath path) {
+ fPropertiesUpdates.add(path);
+ }
+
+ public void removeLabelUpdate(TreePath path) {
+ fLabelUpdates.remove(path);
+ }
+
+ public void addStateUpdate(TreePath path) {
+ fStateUpdates.add(path);
+ }
+
+ public void removeStateUpdate(TreePath path) {
+ fStateUpdates.remove(path);
+ }
+
+
+ public boolean isFinished() {
+ return isFinished(ALL_UPDATES_COMPLETE);
+ }
+
+ public boolean isTimedOut() {
+ return fTimeoutInterval > 0 && fTimeoutTime < System.currentTimeMillis();
+ }
+
+ public boolean isFinished(int flags) {
+ if (isTimedOut()) {
+ throw new RuntimeException("Timed Out: " + toString(flags));
+ }
+
+ if (fFailOnRedundantUpdates && !fRedundantUpdates.isEmpty()) {
+ Assert.fail("Redundant Updates: " + fRedundantUpdates.toString());
+ }
+ if (fFailOnMultipleLabelUpdateSequences && !fMultipleLabelUpdateSequencesObserved) {
+ Assert.fail("Multiple label update sequences detected");
+ }
+ if (fFailOnMultipleModelUpdateSequences && fMultipleModelUpdateSequencesObserved) {
+ Assert.fail("Multiple viewer update sequences detected");
+ }
+
+ if ( (flags & LABEL_SEQUENCE_COMPLETE) != 0) {
+ if (!fLabelSequenceComplete) return false;
+ }
+ if ( (flags & LABEL_SEQUENCE_STARTED) != 0) {
+ if (!fLabelUpdatesStarted) return false;
+ }
+ if ( (flags & LABEL_UPDATES) != 0) {
+ if (!fLabelUpdates.isEmpty()) return false;
+ }
+ if ( (flags & CONTENT_SEQUENCE_STARTED) != 0) {
+ if (!fContentSequenceStarted) return false;
+ }
+ if ( (flags & CONTENT_SEQUENCE_COMPLETE) != 0) {
+ if (!fContentSequenceComplete) return false;
+ }
+ if ( (flags & HAS_CHILDREN_UPDATES_STARTED) != 0) {
+ if (fHasChildrenUpdatesRunning.isEmpty() && fHasChildrenUpdatesCompleted.isEmpty()) return false;
+ }
+ if ( (flags & HAS_CHILDREN_UPDATES) != 0) {
+ if (!fHasChildrenUpdatesScheduled.isEmpty()) return false;
+ }
+ if ( (flags & CHILD_COUNT_UPDATES_STARTED) != 0) {
+ if (fChildCountUpdatesRunning.isEmpty() && fChildCountUpdatesCompleted.isEmpty()) return false;
+ }
+ if ( (flags & CHILD_COUNT_UPDATES) != 0) {
+ if (!fChildCountUpdatesScheduled.isEmpty()) return false;
+ }
+ if ( (flags & CHILDREN_UPDATES_STARTED) != 0) {
+ if (fChildrenUpdatesRunning.isEmpty() && fChildrenUpdatesCompleted.isEmpty()) return false;
+ }
+ if ( (flags & CHILDREN_UPDATES) != 0) {
+ if (!fChildrenUpdatesScheduled.isEmpty()) return false;
+ }
+ if ( (flags & MODEL_CHANGED_COMPLETE) != 0) {
+ if (!fModelChangedComplete) return false;
+ }
+ if ( (flags & STATE_SAVE_COMPLETE) != 0) {
+ if (!fStateSaveComplete) return false;
+ }
+ if ( (flags & STATE_SAVE_STARTED) != 0) {
+ if (!fStateSaveStarted) return false;
+ }
+ if ( (flags & STATE_RESTORE_COMPLETE) != 0) {
+ if (!fStateRestoreComplete) return false;
+ }
+ if ( (flags & STATE_RESTORE_STARTED) != 0) {
+ if (!fStateRestoreStarted) return false;
+ }
+// if ( (flags & MODEL_PROXIES_INSTALLED) != 0) {
+// if (fProxyModels.size() != 0) return false;
+// }
+ if ( (flags & VIEWER_UPDATES_RUNNING) != 0) {
+ if (fContentUpdatesCounter != 0) {
+ return false;
+ }
+ }
+ if ( (flags & LABEL_UPDATES_RUNNING) != 0) {
+ if (fLabelUpdatesCounter != 0) {
+ return false;
+ }
+ }
+ if ( (flags & PROPERTY_UPDATES) != 0) {
+ if (!fPropertiesUpdates.isEmpty()) return false;
+ }
+ if ( (flags & PROPERTY_UPDATES_STARTED) != 0) {
+ if (fPropertiesUpdatesRunning.isEmpty() && fPropertiesUpdatesCompleted.isEmpty()) return false;
+ }
+
+ return true;
+ }
+
+ public void updateStarted(IViewerUpdate update) {
+ synchronized (this) {
+ fContentUpdatesCounter++;
+ if (update instanceof IHasChildrenUpdate) {
+ fHasChildrenUpdatesRunning.add(update);
+ } if (update instanceof IChildrenCountUpdate) {
+ fChildCountUpdatesRunning.add(update);
+ } else if (update instanceof IChildrenUpdate) {
+ fChildCountUpdatesRunning.add(update);
+ }
+ }
+ }
+
+ public void updateComplete(IViewerUpdate update) {
+ synchronized (this) {
+ fContentUpdatesCounter--;
+ }
+
+ if (!update.isCanceled()) {
+ if (update instanceof IHasChildrenUpdate) {
+ fHasChildrenUpdatesRunning.remove(update);
+ fHasChildrenUpdatesCompleted.add(update);
+ if (!fHasChildrenUpdatesScheduled.remove(update.getElementPath()) && fFailOnRedundantUpdates) {
+ fRedundantUpdates.add(update);
+ }
+ } if (update instanceof IChildrenCountUpdate) {
+ fChildCountUpdatesRunning.remove(update);
+ fChildCountUpdatesCompleted.add(update);
+ if (!fChildCountUpdatesScheduled.remove(update.getElementPath()) && fFailOnRedundantUpdates) {
+ fRedundantUpdates.add(update);
+ }
+ } else if (update instanceof IChildrenUpdate) {
+ fChildrenUpdatesRunning.remove(update);
+ fChildrenUpdatesCompleted.add(update);
+
+ int start = ((IChildrenUpdate)update).getOffset();
+ int end = start + ((IChildrenUpdate)update).getLength();
+
+ Set<Integer> childrenIndexes = fChildrenUpdatesScheduled.get(update.getElementPath());
+ if (childrenIndexes != null) {
+ for (int i = start; i < end; i++) {
+ childrenIndexes.remove(new Integer(i));
+ }
+ if (childrenIndexes.isEmpty()) {
+ fChildrenUpdatesScheduled.remove(update.getElementPath());
+ }
+ } else if (fFailOnRedundantUpdates) {
+ fRedundantUpdates.add(update);
+ }
+ }
+ }
+ }
+
+ public void viewerUpdatesBegin() {
+ if (fFailOnMultipleModelUpdateSequences && fContentSequenceComplete) {
+ fMultipleModelUpdateSequencesObserved = true;
+ }
+ fContentSequenceStarted = true;
+ }
+
+ public void viewerUpdatesComplete() {
+ fContentSequenceComplete = true;
+ }
+
+ public void labelUpdateComplete(ILabelUpdate update) {
+ synchronized (this) {
+ fLabelUpdatesRunning.remove(update);
+ fLabelUpdatesCompleted.add(update);
+ fLabelUpdatesCounter--;
+ }
+ if (!fLabelUpdates.remove(update.getElementPath()) && fFailOnRedundantUpdates) {
+ fRedundantUpdates.add(update);
+ }
+ }
+
+ public void labelUpdateStarted(ILabelUpdate update) {
+ synchronized (this) {
+ fLabelUpdatesRunning.add(update);
+ fLabelUpdatesCounter++;
+ }
+ }
+
+ public void labelUpdatesBegin() {
+ if (fFailOnMultipleLabelUpdateSequences && fLabelSequenceComplete) {
+ fMultipleLabelUpdateSequencesObserved = true;
+ }
+ fLabelUpdatesStarted = true;
+ }
+
+ public void labelUpdatesComplete() {
+ fLabelSequenceComplete = true;
+ }
+
+ public void propertiesUpdatesStarted(IPropertiesUpdate[] updates) {
+ for (IPropertiesUpdate update : updates) {
+ fPropertiesUpdatesRunning.add(update);
+ fPropertiesUpdatesCounter++;
+ }
+ }
+
+ public void propertiesUpdateCompleted(IPropertiesUpdate update) {
+ synchronized (this) {
+ fPropertiesUpdatesRunning.remove(update);
+ fPropertiesUpdatesCompleted.add(update);
+ fPropertiesUpdatesCounter--;
+ }
+ if (!fPropertiesUpdates.remove(update.getElementPath()) && fFailOnRedundantUpdates) {
+ fRedundantUpdates.add(update);
+ }
+
+ }
+
+ public void modelChanged(IModelDelta delta, IModelProxy proxy) {
+ fModelChangedComplete = true;
+ }
+
+ public void stateRestoreUpdatesBegin(Object input) {
+ fStateRestoreStarted = true;
+ }
+
+ public void stateRestoreUpdatesComplete(Object input) {
+ fStateRestoreComplete = true;
+ }
+
+ public void stateSaveUpdatesBegin(Object input) {
+ fStateSaveStarted = true;
+ }
+
+ public void stateSaveUpdatesComplete(Object input) {
+ fStateSaveComplete = true;
+ }
+
+ public void stateUpdateComplete(Object input, IViewerUpdate update) {
+ }
+
+ public void stateUpdateStarted(Object input, IViewerUpdate update) {
+ }
+
+ private String toString(int flags) {
+ StringBuffer buf = new StringBuffer("Viewer Update Listener");
+
+ if (fFailOnRedundantUpdates) {
+ buf.append("\n\t");
+ buf.append("fRedundantUpdates = ");
+ buf.append( toStringViewerUpdatesSet(fRedundantUpdates) );
+ }
+ if (fFailOnMultipleLabelUpdateSequences) {
+ buf.append("\n\t");
+ buf.append("fMultipleLabelUpdateSequencesObserved = " + fMultipleLabelUpdateSequencesObserved);
+ }
+ if (fFailOnMultipleModelUpdateSequences) {
+ buf.append("\n\t");
+ buf.append("fMultipleModelUpdateSequencesObserved = " + fMultipleModelUpdateSequencesObserved);
+ }
+ if ( (flags & LABEL_SEQUENCE_COMPLETE) != 0) {
+ buf.append("\n\t");
+ buf.append("fLabelSequenceComplete = " + fLabelSequenceComplete);
+ }
+ if ( (flags & LABEL_UPDATES_RUNNING) != 0) {
+ buf.append("\n\t");
+ buf.append("fLabelUpdatesRunning = " + fLabelUpdatesCounter);
+ }
+ if ( (flags & LABEL_SEQUENCE_STARTED) != 0) {
+ buf.append("\n\t");
+ buf.append("fLabelUpdatesRunning = ");
+ buf.append( toStringViewerUpdatesSet(fLabelUpdatesRunning) );
+ buf.append("\n\t");
+ buf.append("fLabelUpdatesCompleted = ");
+ buf.append( toStringViewerUpdatesSet(fLabelUpdatesCompleted) );
+ }
+ if ( (flags & LABEL_UPDATES) != 0) {
+ buf.append("\n\t");
+ buf.append("fLabelUpdates = ");
+ buf.append( toString(fLabelUpdates) );
+ }
+ if ( (flags & CONTENT_SEQUENCE_COMPLETE) != 0) {
+ buf.append("\n\t");
+ buf.append("fContentSequenceComplete = " + fContentSequenceComplete);
+ }
+ if ( (flags & VIEWER_UPDATES_RUNNING) != 0) {
+ buf.append("\n\t");
+ buf.append("fContentUpdatesCounter = " + fContentUpdatesCounter);
+ }
+ if ( (flags & HAS_CHILDREN_UPDATES_STARTED) != 0) {
+ buf.append("\n\t");
+ buf.append("fHasChildrenUpdatesRunning = ");
+ buf.append( toStringViewerUpdatesSet(fHasChildrenUpdatesRunning) );
+ buf.append("\n\t");
+ buf.append("fHasChildrenUpdatesCompleted = ");
+ buf.append( toStringViewerUpdatesSet(fHasChildrenUpdatesCompleted) );
+ }
+ if ( (flags & HAS_CHILDREN_UPDATES) != 0) {
+ buf.append("\n\t");
+ buf.append("fHasChildrenUpdates = ");
+ buf.append( toString(fHasChildrenUpdatesScheduled) );
+ }
+ if ( (flags & CHILD_COUNT_UPDATES_STARTED) != 0) {
+ buf.append("\n\t");
+ buf.append("fChildCountUpdatesRunning = ");
+ buf.append( toStringViewerUpdatesSet(fChildCountUpdatesRunning) );
+ buf.append("\n\t");
+ buf.append("fChildCountUpdatesCompleted = ");
+ buf.append( toStringViewerUpdatesSet(fChildCountUpdatesCompleted) );
+ }
+ if ( (flags & CHILD_COUNT_UPDATES) != 0) {
+ buf.append("\n\t");
+ buf.append("fChildCountUpdates = ");
+ buf.append( toString(fChildCountUpdatesScheduled) );
+ }
+ if ( (flags & CHILDREN_UPDATES_STARTED) != 0) {
+ buf.append("\n\t");
+ buf.append("fChildrenUpdatesRunning = ");
+ buf.append( fChildrenUpdatesRunning );
+ buf.append("\n\t");
+ buf.append("fChildrenUpdatesCompleted = ");
+ buf.append( toStringViewerUpdatesSet(fChildrenUpdatesCompleted) );
+ }
+ if ( (flags & CHILDREN_UPDATES) != 0) {
+ buf.append("\n\t");
+ buf.append("fChildrenUpdates = ");
+ buf.append( toStringTreePathMap(fChildrenUpdatesScheduled) );
+ }
+ if ( (flags & MODEL_CHANGED_COMPLETE) != 0) {
+ buf.append("\n\t");
+ buf.append("fModelChangedComplete = " + fModelChangedComplete);
+ }
+ if ( (flags & STATE_SAVE_COMPLETE) != 0) {
+ buf.append("\n\t");
+ buf.append("fStateSaveComplete = " + fStateSaveComplete);
+ }
+ if ( (flags & STATE_RESTORE_COMPLETE) != 0) {
+ buf.append("\n\t");
+ buf.append("fStateRestoreComplete = " + fStateRestoreComplete);
+ }
+// if ( (flags & MODEL_PROXIES_INSTALLED) != 0) {
+// buf.append("\n\t");
+// buf.append("fProxyModels = " + fProxyModels);
+// }
+ if ( (flags & PROPERTY_UPDATES_STARTED) != 0) {
+ buf.append("\n\t");
+ buf.append("fPropertiesUpdatesRunning = ");
+ buf.append(toStringViewerUpdatesSet(fPropertiesUpdatesRunning));
+ buf.append("\n\t");
+ buf.append("fPropertiesUpdatesCompleted = " + fPropertiesUpdatesCompleted);
+ }
+ if ( (flags & PROPERTY_UPDATES) != 0) {
+ buf.append("\n\t");
+ buf.append("fPropertiesUpdates = ");
+ buf.append( toString(fPropertiesUpdates) );
+ }
+ if (fTimeoutInterval > 0) {
+ buf.append("\n\t");
+ buf.append("fTimeoutInterval = " + fTimeoutInterval);
+ }
+ return buf.toString();
+ }
+
+ private String toString(Set<TreePath> set) {
+ if (set.isEmpty()) {
+ return "(EMPTY)";
+ }
+ StringBuffer buf = new StringBuffer();
+ for (Iterator<TreePath> itr = set.iterator(); itr.hasNext(); ) {
+ buf.append("\n\t\t");
+ buf.append(toStringTreePath(itr.next()));
+ }
+ return buf.toString();
+ }
+
+ private String toStringViewerUpdatesSet(Set<IViewerUpdate> set) {
+ if (set.isEmpty()) {
+ return "(EMPTY)";
+ }
+ StringBuffer buf = new StringBuffer();
+ for (Iterator<IViewerUpdate> itr = set.iterator(); itr.hasNext(); ) {
+ buf.append("\n\t\t");
+ buf.append(toStringTreePath((itr.next()).getElementPath()));
+ }
+ return buf.toString();
+ }
+
+ private String toStringTreePathMap(Map<TreePath, Set<Integer>> map) {
+ if (map.isEmpty()) {
+ return "(EMPTY)";
+ }
+ StringBuffer buf = new StringBuffer();
+ for (Iterator<TreePath> itr = map.keySet().iterator(); itr.hasNext(); ) {
+ buf.append("\n\t\t");
+ TreePath path = itr.next();
+ buf.append(toStringTreePath(path));
+ Set<?> updates = map.get(path);
+ buf.append(" = ");
+ buf.append(updates.toString());
+ }
+ return buf.toString();
+ }
+
+ private String toStringTreePath(TreePath path) {
+ if (path.getSegmentCount() == 0) {
+ return "/";
+ }
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < path.getSegmentCount(); i++) {
+ buf.append("/");
+ buf.append(path.getSegment(i));
+ }
+ return buf.toString();
+ }
+
+ @Override
+ public String toString() {
+ return toString(ALL_UPDATES_COMPLETE | MODEL_CHANGED_COMPLETE | STATE_RESTORE_COMPLETE |
+ VIEWER_UPDATES_STARTED | LABEL_SEQUENCE_STARTED | PROPERTY_UPDATES | PROPERTY_UPDATES_STARTED);
+ }
+}
+
+
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTest1.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTest1.java
new file mode 100644
index 00000000000..fb2aa034d40
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTest1.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.eclipse.cdt.tests.dsf.debug.vm.launch;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.Query;
+import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.launch.ILaunchVMConstants;
+import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IElementPropertiesProvider;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.VMPropertiesUpdate;
+import org.eclipse.cdt.examples.dsf.pda.PDAPlugin;
+import org.eclipse.cdt.tests.dsf.IViewerUpdatesListenerConstants;
+import org.eclipse.cdt.tests.dsf.vm.TestModelUpdatesListener;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDeltaVisitor;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.VirtualTreeModelViewer;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.swt.widgets.Display;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class VMTest1 extends VMTestBase implements IViewerUpdatesListenerConstants {
+
+ @Override
+ protected String getProgramPath() {
+ File programFile = PDAPlugin.getFileInPlugin(new Path("samples/example.pda"));
+ return programFile.getPath();
+ }
+
+ @Test
+ public void testRun() throws Throwable {
+
+ Display display = Display.getDefault();
+
+ final VirtualTreeModelViewer dv = new VirtualTreeModelViewer(
+ display, 0, new PresentationContext(IDebugUIConstants.ID_DEBUG_VIEW));
+
+ TestModelUpdatesListener listener = new TestModelUpdatesListener(dv, false, false);
+
+ // Wait for container expand delta, sent by the model upon DV install event.
+ final boolean[] containerExpandReceived = new boolean[1];
+ containerExpandReceived[0] = false;
+ dv.addModelChangedListener(new IModelChangedListener() {
+ public void modelChanged(IModelDelta delta, IModelProxy proxy) {
+ delta.accept(new IModelDeltaVisitor() {
+ public boolean visit(IModelDelta delta, int depth) {
+ if (delta.getElement() instanceof IDMVMContext &&
+ ((IDMVMContext)delta.getElement()).getDMContext() instanceof IContainerDMContext &&
+ (delta.getFlags() & IModelDelta.EXPAND) != 0)
+ {
+ containerExpandReceived[0] = true;
+ return false;
+ }
+ return true;
+ }
+ });
+ }
+ });
+
+ dv.setInput(DebugPlugin.getDefault().getLaunchManager());
+
+ while(!containerExpandReceived[0]) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+
+ listener.reset();
+
+ // TODO: need to wait for the install delta for the launch to be processed
+ while (!listener.isFinished(CONTENT_SEQUENCE_COMPLETE)) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+
+ // Find our launch
+ int launchIdx = dv.findElementIndex(TreePath.EMPTY, getLaunch());
+ Assert.assertTrue(-1 != launchIdx);
+
+ // Find the debug container
+ TreePath launchPath = TreePath.EMPTY.createChildPath(getLaunch());
+ int launchChildCount = dv.getChildCount(launchPath);
+ IDMVMContext _containerVMC = null;
+ for (int i = 0; i < launchChildCount; i++) {
+ Object launchChild = dv.getChildElement(launchPath, i);
+ if (launchChild instanceof IDMVMContext &&
+ ((IDMVMContext)launchChild).getDMContext() instanceof IContainerDMContext)
+ {
+ _containerVMC = (IDMVMContext)launchChild;
+ }
+ }
+ Assert.assertNotNull(_containerVMC);
+ final IDMVMContext containerVMC = _containerVMC;
+ final TreePath containerPath = launchPath.createChildPath(containerVMC);
+ final IElementPropertiesProvider containerPropProvider =
+ (IElementPropertiesProvider)containerVMC.getAdapter(IElementPropertiesProvider.class);
+ Assert.assertNotNull(containerPropProvider);
+
+ // Check if container is suspended.
+ Query<Map<String,Object>> suspendedQuery = new Query<Map<String,Object>>() {
+ @Override
+ protected void execute(DataRequestMonitor<Map<String, Object>> rm) {
+ Set<String> properties = new HashSet<String>();
+ properties.add(ILaunchVMConstants.PROP_IS_SUSPENDED);
+
+ containerPropProvider.update( new VMPropertiesUpdate[] {
+ new VMPropertiesUpdate(properties, containerPath, dv.getInput(), dv.getPresentationContext(), rm) });
+ }
+ };
+ suspendedQuery.run();
+
+ // Wait for the properties update to complete
+ while (!suspendedQuery.isDone()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+
+ Map<String,Object> properties = suspendedQuery.get();
+ Assert.assertEquals(Boolean.TRUE, properties.get(ILaunchVMConstants.PROP_IS_SUSPENDED));
+
+ }
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTestBase.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTestBase.java
new file mode 100644
index 00000000000..8bb546446fc
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/debug/vm/launch/VMTestBase.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Ericsson 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:
+ * Ericsson - Initial Implementation
+ *******************************************************************************/
+package org.eclipse.cdt.tests.dsf.debug.vm.launch;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.cdt.dsf.debug.service.IRunControl.IStartedDMEvent;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.dsf.service.DsfSession.SessionStartedListener;
+import org.eclipse.cdt.examples.dsf.pda.PDAPlugin;
+import org.eclipse.cdt.examples.dsf.pda.launch.PDALaunch;
+import org.eclipse.cdt.tests.dsf.ServiceEventWaitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.DebugPlugin;
+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.debug.core.ILaunchManager;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
+import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+/**
+ * This is the base class for the GDB/MI Unit tests.
+ * It provides the @Before and @After methods which setup
+ * and teardown the launch, for each test.
+ * If these methods are overwridden by a subclass, the new method
+ * must call super.baseSetup or super.baseTeardown itself, if this
+ * code is to be run.
+ */
+public class VMTestBase {
+
+ private PDALaunch fLaunch;
+ public PDALaunch getPDALaunch() { return fLaunch; }
+
+ @BeforeClass
+ public static void baseBeforeClassMethod() {
+ DebugUIPlugin.getDefault().getPreferenceStore().setValue(
+ IInternalDebugUIConstants.PREF_SWITCH_TO_PERSPECTIVE, MessageDialogWithToggle.NEVER);
+ DebugUIPlugin.getDefault().getPreferenceStore().setValue(
+ IInternalDebugUIConstants.PREF_SWITCH_PERSPECTIVE_ON_SUSPEND, MessageDialogWithToggle.NEVER);
+ }
+
+ @Before
+ public void baseBeforeMethod() throws Exception {
+ Map<String, Object> attrs = new HashMap<String, Object>();
+
+ initLaunchAttributes(attrs);
+
+ System.out.println("====================================================================");
+ System.out.println("Launching test application: " + attrs.get(PDAPlugin.ATTR_PDA_PROGRAM));
+ System.out.println("====================================================================");
+
+ ILaunchManager launchMgr = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType lcType = launchMgr.getLaunchConfigurationType("org.eclipse.cdt.examples.dsf.pda.launchType");
+ assert lcType != null;
+
+ ILaunchConfigurationWorkingCopy lcWorkingCopy = lcType.newInstance(
+ null,
+ launchMgr.generateUniqueLaunchConfigurationNameFrom("Test Launch")); //$NON-NLS-1$
+ assert lcWorkingCopy != null;
+ lcWorkingCopy.setAttributes(attrs);
+
+ final ILaunchConfiguration lc = lcWorkingCopy.doSave();
+ assert lc != null;
+
+ final ServiceEventWaitor<?> eventWaitor[] = new ServiceEventWaitor<?>[1];
+
+ SessionStartedListener newSessionListener = new SessionStartedListener() {
+ public void sessionStarted(DsfSession session) {
+ eventWaitor[0] = new ServiceEventWaitor<IStartedDMEvent>(session, IStartedDMEvent.class);
+ }
+ };
+
+ DsfSession.addSessionStartedListener(newSessionListener);
+ try {
+ fLaunch = (PDALaunch)lc.launch(ILaunchManager.DEBUG_MODE, new NullProgressMonitor());
+ Assert.assertNotNull(fLaunch);
+ Assert.assertNotNull(eventWaitor[0]);
+ Assert.assertSame(fLaunch.getSession(), eventWaitor[0].getSession());
+ eventWaitor[0].waitForEvent(60000);
+ } finally {
+ DsfSession.removeSessionStartedListener(newSessionListener);
+ if (eventWaitor[0] != null) {
+ eventWaitor[0].dispose();
+ }
+ }
+ }
+
+ protected void initLaunchAttributes(Map<String, Object> attrs) {
+ attrs.put(PDAPlugin.ATTR_PDA_PROGRAM, getProgramPath());
+ }
+
+ protected String getProgramPath() {
+ File programFile = PDAPlugin.getFileInPlugin(new Path("samples/example.pda"));
+ return programFile.getPath();
+ }
+
+ protected ILaunch getLaunch() {
+ return fLaunch;
+ }
+
+ @After
+ public void baseAfterMethod() throws Exception {
+ if (fLaunch != null) {
+ fLaunch.terminate();
+ fLaunch = null;
+ }
+
+ }
+
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/DummyFormattedValueService.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/DummyFormattedValueService.java
new file mode 100644
index 00000000000..ae105165c4f
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/DummyFormattedValueService.java
@@ -0,0 +1,58 @@
+package org.eclipse.cdt.tests.dsf.vm;
+
+import java.util.Hashtable;
+
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
+import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
+import org.eclipse.cdt.dsf.service.AbstractDsfService;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.tests.dsf.DsfTestPlugin;
+import org.osgi.framework.BundleContext;
+
+public class DummyFormattedValueService extends AbstractDsfService implements IFormattedValues {
+
+ public static String DUMMY_FORMAT = "dummy";
+ public static String[] AVAILABLE_FORMATS = new String[] { DUMMY_FORMAT, HEX_FORMAT, OCTAL_FORMAT, BINARY_FORMAT, NATURAL_FORMAT, DECIMAL_FORMAT, STRING_FORMAT };
+
+ public DummyFormattedValueService(DsfSession session) {
+ super(session);
+ }
+
+ @Override
+ public void initialize(RequestMonitor rm) {
+ super.initialize(new RequestMonitor(getExecutor(), rm) {
+ @Override
+ protected void handleSuccess() {
+ register(new String[0], new Hashtable<String, String>() );
+ super.handleSuccess();
+ }
+ });
+ }
+
+ @Override
+ public void shutdown(RequestMonitor rm) {
+ unregister();
+ super.shutdown(rm);
+ }
+
+ @Override
+ protected BundleContext getBundleContext() {
+ return DsfTestPlugin.getBundleContext();
+ }
+
+ public void getAvailableFormats(IFormattedDataDMContext dmc, DataRequestMonitor<String[]> rm) {
+ rm.setData(AVAILABLE_FORMATS);
+ rm.done();
+ }
+
+ public FormattedValueDMContext getFormattedValueContext(IFormattedDataDMContext dmc, String formatId) {
+ return new FormattedValueDMContext(this, dmc, formatId);
+ }
+
+ public void getFormattedExpressionValue(FormattedValueDMContext dmc, DataRequestMonitor<FormattedValueDMData> rm) {
+ rm.setData(new FormattedValueDMData(dmc.getFormatID()));
+ rm.done();
+ }
+
+} \ No newline at end of file
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java
new file mode 100644
index 00000000000..60d127311a7
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValueTests.java
@@ -0,0 +1,372 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 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.eclipse.cdt.tests.dsf.vm;
+
+import java.util.concurrent.ExecutionException;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor;
+import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
+import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
+import org.eclipse.cdt.dsf.concurrent.Query;
+import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.dsf.service.IDsfService;
+import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMProvider;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.PropertiesUpdateStatus;
+import org.eclipse.cdt.dsf.ui.viewmodel.update.IVMUpdatePolicy;
+import org.eclipse.cdt.dsf.ui.viewmodel.update.ManualUpdatePolicy;
+import org.eclipse.cdt.tests.dsf.IViewerUpdatesListenerConstants;
+import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
+import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElementValidator;
+import org.eclipse.cdt.tests.dsf.vm.TestModel.TestEvent;
+import org.eclipse.debug.internal.ui.viewers.model.ITreeModelContentProviderTarget;
+import org.eclipse.debug.internal.ui.viewers.model.ITreeModelViewer;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.ViewerLabel;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Tests to verify the operation of FormattedValuesVMUtil
+ * @since 2.2
+ */
+abstract public class FormattedValueTests extends TestCase implements IViewerUpdatesListenerConstants, IDebugVMConstants {
+
+ Display fDisplay;
+ Shell fShell;
+ DsfExecutor fDsfExecutor;
+ DsfSession fDsfSession;
+ ITreeModelViewer fViewer;
+ TestModelUpdatesListener fViewerListener;
+ TestModelUpdatesListener fVMListener;
+ FormattedValuesListener fFormattedValuesListener;
+ TestModel fModel;
+ DummyFormattedValueService fDummyValuesService;
+ AbstractVMAdapter fVMAdapter;
+ TestModelCachingVMProvider fVMProvider;
+
+ public FormattedValueTests(String name) {
+ super(name);
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Override
+ protected void setUp() throws Exception {
+ fDsfExecutor = new DefaultDsfExecutor();
+ fDsfSession = DsfSession.startSession(fDsfExecutor, getClass().getName());
+
+ fDisplay = PlatformUI.getWorkbench().getDisplay();
+ fShell = new Shell(fDisplay/*, SWT.ON_TOP | SWT.SHELL_TRIM*/);
+ fShell.setMaximized(true);
+ fShell.setLayout(new FillLayout());
+
+ fViewer = createViewer(fDisplay, fShell);
+
+ fModel = new TestModel(fDsfSession);
+ initializeService(fModel);
+ fDummyValuesService = new DummyFormattedValueService(fDsfSession);
+ initializeService(fDummyValuesService);
+
+ fViewerListener = new TestModelUpdatesListener(fViewer, true, false);
+
+ fModel.setRoot( new TestElement(fModel, "root", new TestElement[0] ) );
+ fModel.setElementChildren(TreePath.EMPTY, makeModelElements(fModel, getTestModelDepth(), "model"));
+
+ fVMAdapter = new AbstractVMAdapter() {
+ @Override
+ protected IVMProvider createViewModelProvider(IPresentationContext context) {
+ return fVMProvider;
+ }
+ };
+ fVMProvider = new TestModelCachingVMProvider(fVMAdapter, fViewer.getPresentationContext(), fDsfSession);
+
+ fVMListener = new TestModelUpdatesListener();
+ fVMProvider.getNode().setVMUpdateListener(fVMListener);
+ fVMProvider.getNode().getLabelProvider().addPropertiesUpdateListener(fViewerListener);
+
+ fFormattedValuesListener = new FormattedValuesListener(fModel);
+ fVMProvider.getNode().setFormattedValuesListener(fFormattedValuesListener);
+ fModel.setTestModelListener(fFormattedValuesListener);
+
+ fShell.open ();
+ }
+
+ private void initializeService(final IDsfService service) throws InterruptedException, ExecutionException {
+ Query<Object> initQuery = new Query<Object>() {
+ @Override
+ protected void execute(DataRequestMonitor<Object> rm) {
+ rm.setData(new Object());
+ service.initialize(rm);
+ }
+ };
+ fDsfExecutor.execute(initQuery);
+ initQuery.get();
+ }
+
+ abstract protected ITreeModelContentProviderTarget createViewer(Display display, Shell shell);
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ fVMProvider.getNode().setFormattedValuesListener(null);
+ fModel.setTestModelListener(null);
+
+ fVMProvider.getNode().getLabelProvider().removePropertiesUpdateListener(fViewerListener);
+ fVMProvider.getNode().setVMUpdateListener(null);
+
+ fVMAdapter.dispose();
+
+ fVMListener.dispose();
+ fViewerListener.dispose();
+
+ shutdownService(fDummyValuesService);
+ shutdownService(fModel);
+ fViewer.getPresentationContext().dispose();
+ // Close the shell and exit.
+ fShell.close();
+ while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+ DsfSession.endSession(fDsfSession);
+ fDsfExecutor.shutdown();
+ }
+
+ private void shutdownService(final IDsfService service) throws InterruptedException, ExecutionException {
+ Query<Object> shutdownQuery = new Query<Object>() {
+ @Override
+ protected void execute(DataRequestMonitor<Object> rm) {
+ rm.setData(new Object());
+ service.shutdown(rm);
+ }
+ };
+ fDsfExecutor.execute(shutdownQuery);
+ shutdownQuery.get();
+ }
+
+ /**
+ * Depth (size) of the test model to be used in the tests. This number allows
+ * the jface based tests to use a small enough model to fit on the screen, and
+ * for the virtual viewer to exercise the content provider to a greater extent.
+ */
+ abstract protected int getTestModelDepth();
+
+ public void testValidate() {
+ setInput(IFormattedValues.NATURAL_FORMAT);
+ setFormatAndValidate(IFormattedValues.HEX_FORMAT, false, false, false);
+ }
+
+ public void testChangeFormat() {
+ setInput(IFormattedValues.NATURAL_FORMAT);
+ setFormatAndValidate(IFormattedValues.HEX_FORMAT, false, false, false);
+ setFormatAndValidate(IFormattedValues.NATURAL_FORMAT, false, false, false);
+ }
+
+ public void testChangeFormatManualUpdateMode() {
+ setInput(IFormattedValues.NATURAL_FORMAT);
+ setUpdatePolicy(ManualUpdatePolicy.MANUAL_UPDATE_POLICY_ID);
+
+ // Chenge to a new format, this does not cause the cache entries to be
+ // set to dirty. Retrieving new format values should happen from the service.
+ setFormatAndValidate(IFormattedValues.HEX_FORMAT, true, false, false);
+
+ // Change _back_ to natural format. Values should be retrieved from cache.
+ setFormatAndValidate(IFormattedValues.NATURAL_FORMAT, true, true, false);
+
+ // Generate an event which will cause all cache entries to be marked dirty.
+ postEventInManualUpdateMode();
+
+ // Change back again to hex format. Values should be retrieved from cache.
+ setFormatAndValidate(IFormattedValues.HEX_FORMAT, true, true, false);
+
+ // Change to a decimal, which is not cached, values should come with an error.
+ setFormatAndValidate(IFormattedValues.DECIMAL_FORMAT, true, true, true);
+
+ }
+
+ private void postEventInManualUpdateMode() {
+ // Generate an event which will cause all cache entries to be marked dirty.
+ fViewerListener.reset();
+ fViewerListener.addUpdates(TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
+ fVMListener.reset();
+ fFormattedValuesListener.reset();
+ fVMProvider.postEvent(new TestEvent(fModel.getRootElement(), IModelDelta.CONTENT));
+ while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES))
+ if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+ Assert.assertTrue(fFormattedValuesListener.getFormattedValuesCompleted().isEmpty());
+ }
+
+ public void testInvalidFormat() {
+ setInput(IFormattedValues.NATURAL_FORMAT);
+
+ fViewerListener.reset();
+ fViewerListener.addUpdates(TreePath.EMPTY, ((TestElementVMContext)fViewer.getInput()).getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
+
+ fVMListener.reset();
+ fVMListener.addUpdates(TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
+
+ // Set the new number format to the viewer.
+ fViewer.getPresentationContext().setProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, "invalid format");
+
+ while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES) || !fVMListener.isFinished(CONTENT_UPDATES | PROPERTY_UPDATES))
+ if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ validateModel(IFormattedValues.HEX_FORMAT, " (" + FormattedValueVMUtil.getFormatLabel(IFormattedValues.HEX_FORMAT) + ")");
+ }
+
+ /**
+ * Initial format is NATURAL.
+ */
+ private void setInput(String formatId) {
+ // Set the new number format to the viewer.
+ fViewer.getPresentationContext().setProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, formatId);
+
+ fViewer.setAutoExpandLevel(-1);
+ TestElementVMContext rootVMC = fVMProvider.getElementVMContext(fViewer.getPresentationContext(), fModel.getRootElement());
+
+ // Create the listener
+ fViewerListener.reset();
+ fViewerListener.addUpdates(TreePath.EMPTY, rootVMC.getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
+ fVMListener.reset();
+ fVMListener.addUpdates(TreePath.EMPTY, rootVMC.getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
+ fFormattedValuesListener.reset();
+
+ fViewer.setInput(rootVMC);
+ while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES) || !fVMListener.isFinished(CONTENT_COMPLETE | PROPERTY_UPDATES))
+ if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ Assert.assertTrue(fFormattedValuesListener.isFinished());
+ }
+
+ private void setUpdatePolicy(String policyId) {
+ IVMUpdatePolicy[] policies = fVMProvider.getAvailableUpdatePolicies();
+ IVMUpdatePolicy newPolicy = null;
+ for (IVMUpdatePolicy policy : policies) {
+ if (policyId.equals(policy.getID())) {
+ newPolicy = policy;
+ break;
+ }
+ }
+ if (newPolicy != null) {
+ fVMProvider.setActiveUpdatePolicy(newPolicy);
+ } else {
+ throw new RuntimeException("Update policy " + policyId + " not available");
+ }
+ fViewerListener.reset();
+ fViewerListener.addUpdates(TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
+ fVMListener.setFailOnRedundantUpdates(false);
+ while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES))
+ if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ fVMListener.setFailOnRedundantUpdates(true);
+ }
+
+ private void setFormatAndValidate(
+ String formatId,
+ boolean expectContentCached,
+ boolean expectFormattedValuesCached,
+ boolean expectCacheMissError)
+ {
+ fViewerListener.reset();
+ fViewerListener.addUpdates(TreePath.EMPTY, ((TestElementVMContext)fViewer.getInput()).getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
+
+ fVMListener.reset();
+ int vmUpdateFlags = PROPERTY_UPDATES;
+ if (!expectContentCached) {
+ vmUpdateFlags |= ALL_UPDATES_COMPLETE;
+ }
+ fVMListener.addUpdates(TreePath.EMPTY, fModel.getRootElement(), -1, vmUpdateFlags);
+
+ fFormattedValuesListener.reset();
+ if (expectFormattedValuesCached && !expectCacheMissError) {
+ fFormattedValuesListener.setCachedFormats(new String[] {formatId} );
+ }
+
+ // Set the new number format to the viewer.
+ fViewer.getPresentationContext().setProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, formatId);
+
+ while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES) || !fVMListener.isFinished(CONTENT_UPDATES | PROPERTY_UPDATES))
+ if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+
+ if (expectCacheMissError) {
+ try {
+ validateModel(formatId, "");
+ throw new RuntimeException("Expected validateModel to fail");
+ }
+ catch(AssertionFailedError e) {
+ // expected
+ }
+ } else {
+ validateModel(formatId, "");
+ }
+
+ if (expectCacheMissError) {
+ String formatProperty = FormattedValueVMUtil.getPropertyForFormatId(formatId);
+
+ Assert.assertTrue(fFormattedValuesListener.getFormattedValuesCompleted().isEmpty());
+ Assert.assertFalse(fFormattedValuesListener.getPropertiesUpdates().isEmpty());
+ for (IPropertiesUpdate update : fFormattedValuesListener.getPropertiesUpdates()) {
+ PropertiesUpdateStatus status = (PropertiesUpdateStatus)update.getStatus();
+ assertEquals(IDsfStatusConstants.INVALID_STATE, status.getCode());
+ assertEquals("Cache contains stale data. Refresh view.", status.getStatus(formatProperty).getMessage());
+ assertEquals(
+ "Cache contains stale data. Refresh view.",
+ status.getStatus(PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE).getMessage());
+ assertEquals(1, status.getChildren().length);
+
+ }
+
+ } else {
+ Assert.assertTrue(fFormattedValuesListener.isFinished());
+ }
+
+ }
+
+ private void validateModel(final String formatId, final String suffix) {
+ fModel.validateData(
+ fViewer, TreePath.EMPTY,
+ new TestElementValidator() {
+ public void validate(TestElement modelElement, TestElement viewerElement, TreePath viewerPath) {
+ ViewerLabel label = fViewer.getElementLabel(viewerPath, TestModelCachingVMProvider.COLUMN_ID);
+ assertEquals(modelElement.getID(), label.getText());
+
+ label = fViewer.getElementLabel(viewerPath, TestModelCachingVMProvider.COLUMN_FORMATTED_VALUE);
+ assertEquals(fModel.getFormattedValueText(modelElement, formatId) + suffix, label.getText());
+
+ label = fViewer.getElementLabel(viewerPath, TestModelCachingVMProvider.COLUMN_DUMMY_VALUE);
+ assertEquals(formatId, label.getText());
+ }
+ });
+ }
+
+ private TestElement[] makeModelElements(TestModel model, int depth, String prefix) {
+ TestElement[] elements = new TestElement[depth];
+ for (int i = 0; i < depth; i++) {
+ String name = prefix + "." + i;
+ elements[i] = new TestElement(model, name, makeModelElements(model, i, name));
+ }
+ return elements;
+ }
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValuesListener.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValuesListener.java
new file mode 100644
index 00000000000..cb87bde7334
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/FormattedValuesListener.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.cdt.tests.dsf.vm;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
+import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdateListener;
+import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
+import org.junit.Assert;
+
+/**
+ *
+ */
+public class FormattedValuesListener implements IFormattedValuesListener, IPropertiesUpdateListener {
+
+ private static final String ANY_FORMAT = "ANY_FORMAT";
+
+ private final TestModel fModel;
+
+ private List<IPropertiesUpdate> fPropertiesUpdates = new ArrayList<IPropertiesUpdate>();
+ private List<List<FormattedValueDMContext>> fFormattedValuesInPending = new ArrayList<List<FormattedValueDMContext>>();
+ private List<FormattedValueDMContext> fFormattedValuesInProgress = new LinkedList<FormattedValueDMContext>();
+ private List<FormattedValueDMContext> fFormattedValuesCompleted = new ArrayList<FormattedValueDMContext>();
+
+ private DsfRunnable fProcessUpdatedFormattedValuesRunnable = null;
+
+ private Set<String> fCachedFormats = new HashSet<String>();
+
+ public FormattedValuesListener(TestModel model) {
+ fModel = model;
+ }
+
+ public void setCachedFormats(String[] cachedFormats) {
+ fCachedFormats.clear();
+ fCachedFormats.addAll(Arrays.asList(cachedFormats));
+ }
+
+ public void propertiesUpdatesStarted(IPropertiesUpdate[] updates) {
+ fPropertiesUpdates.addAll(Arrays.asList(updates));
+ List<FormattedValueDMContext> pending = new ArrayList<FormattedValueDMContext>(updates.length);
+ for (IPropertiesUpdate update : updates) {
+ List<String> formatIds = getRequestedFormatIDs(update);
+ for (String formatId : formatIds) {
+ TestElement te = getPropertyUpdateTestElement(update);
+ pending.add(new FormattedValueDMContext(fModel, te, formatId));
+ }
+ }
+ if (!pending.isEmpty()) {
+ fFormattedValuesInPending.add(pending);
+ }
+ }
+
+ private List<String> getRequestedFormatIDs(IPropertiesUpdate update) {
+ List<String> formatIds = new ArrayList<String>(1);
+ for (String property : update.getProperties()) {
+ if (property.equals(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE)) {
+ formatIds.add(ANY_FORMAT);
+ }
+ if (property.startsWith(IDebugVMConstants.PROP_FORMATTED_VALUE_BASE)) {
+ formatIds.add(FormattedValueVMUtil.getFormatFromProperty(property, null));
+ }
+ }
+ return formatIds;
+ }
+
+ public void reset() {
+ reset(new String[0]);
+ }
+
+ public void reset(String[] cachedFormats) {
+ fPropertiesUpdates.clear();
+ fFormattedValuesInPending.clear();
+ fFormattedValuesInProgress.clear();
+ fFormattedValuesCompleted.clear();
+ setCachedFormats(cachedFormats);
+ }
+
+ public List<FormattedValueDMContext> getFormattedValuesCompleted() {
+ return fFormattedValuesCompleted;
+ }
+
+ public List<IPropertiesUpdate> getPropertiesUpdates() {
+ return fPropertiesUpdates;
+ }
+
+ public boolean isFinished() {
+ if ( !fFormattedValuesInProgress.isEmpty() ) {
+ return false;
+ }
+
+ if (!fFormattedValuesInPending.isEmpty() && fCachedFormats.isEmpty()) {
+ return false;
+ }
+
+ for (List<FormattedValueDMContext> pendingList : fFormattedValuesInPending) {
+ for (FormattedValueDMContext pending : pendingList) {
+ String pendingFormat = pending.getFormatID();
+ if (!pendingFormat.equals(ANY_FORMAT) && !fCachedFormats.contains(pendingFormat)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public void propertiesUpdateCompleted(IPropertiesUpdate update) {}
+
+ public void formattedValueUpdated(FormattedValueDMContext formattedValueDmc) {
+ Assert.assertFalse("Expected values with formats " + fCachedFormats + " to be cached.",
+ fCachedFormats.contains(formattedValueDmc.getFormatID()));
+
+ if (fProcessUpdatedFormattedValuesRunnable == null) {
+ fProcessUpdatedFormattedValuesRunnable = new DsfRunnable() {
+ public void run() {
+ fProcessUpdatedFormattedValuesRunnable = null;
+ processFormattedValuesInProgress();
+ }
+ };
+ fModel.getExecutor().execute(fProcessUpdatedFormattedValuesRunnable);
+ }
+ fFormattedValuesInProgress.add(formattedValueDmc);
+ }
+
+ private void processFormattedValuesInProgress() {
+ while (!fFormattedValuesInProgress.isEmpty()) {
+ List<FormattedValueDMContext> pendingList = findPendingList(fFormattedValuesInProgress.get(0));
+
+ for (FormattedValueDMContext pending : pendingList) {
+ int progressIdx = indexOfFormattedValueDMContext(fFormattedValuesInProgress, pending);
+
+ if (progressIdx != -1) {
+ // The pending DMC may contain the ANY_FORMAT format ID.
+ // The progress DMC must contain the exact format retrieved.
+ // To have a more accurate record, add the progress DMC to
+ // the completed updates list.
+ FormattedValueDMContext progress = fFormattedValuesInProgress.remove(progressIdx);
+ fFormattedValuesCompleted.add(progress);
+ } else {
+ Assert.fail("Pending Updates not processed in bulk \n " + pendingList);
+ }
+ }
+ }
+ }
+
+ private List<FormattedValueDMContext> findPendingList(FormattedValueDMContext dmc) {
+ for (Iterator<List<FormattedValueDMContext>> itr = fFormattedValuesInPending.iterator(); itr.hasNext();) {
+ List<FormattedValueDMContext> pendingList = itr.next();
+ int pendingIdx = indexOfFormattedValueDMContext(pendingList, dmc);
+ if (pendingIdx != -1) {
+ itr.remove();
+ return pendingList;
+ }
+ }
+ throw new RuntimeException("Pending update not found for element: " + dmc);
+ }
+
+ private int indexOfFormattedValueDMContext(List<FormattedValueDMContext> list, FormattedValueDMContext dmc) {
+ for (int i = 0; i < list.size(); i++) {
+ if (dmc.getParentValueDMContext().equals(list.get(i).getParentValueDMContext())) {
+ if ( ANY_FORMAT.equals(dmc.getFormatID()) ||
+ ANY_FORMAT.equals(list.get(i).getFormatID()) ||
+ dmc.getFormatID().equals(list.get(i).getFormatID()) )
+ {
+ return i;
+ }
+ }
+ }
+ return -1;
+ }
+
+ private TestElement getPropertyUpdateTestElement(IPropertiesUpdate update) {
+ Object element = update.getElement();
+ if (element instanceof TestElement) {
+ return (TestElement)element;
+ } else if (element instanceof TestElementVMContext) {
+ return ((TestElementVMContext)element).getElement();
+ }
+ throw new RuntimeException("Invalid element in properties update: " + update.getElement());
+ }
+
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/IFormattedValuesListener.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/IFormattedValuesListener.java
new file mode 100644
index 00000000000..ce919f87603
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/IFormattedValuesListener.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.cdt.tests.dsf.vm;
+
+import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
+
+/**
+ * @since 2.2
+ */
+public interface IFormattedValuesListener {
+
+ public void formattedValueUpdated(FormattedValueDMContext formattedValueDmc);
+
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/ITestModelUpdatesListenerConstants.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/ITestModelUpdatesListenerConstants.java
deleted file mode 100644
index 162d955e681..00000000000
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/ITestModelUpdatesListenerConstants.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, 2010 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.eclipse.cdt.tests.dsf.vm;
-
-/**
- * Convenience interface with constants used by the test model update listener.
- *
- * @since 3.6
- */
-public interface ITestModelUpdatesListenerConstants {
-
- public static final int LABEL_UPDATES_COMPLETE = 0X0001;
- public static final int CONTENT_UPDATES_COMPLETE = 0X0002;
- public static final int LABEL_UPDATES = 0X0004;
- public static final int HAS_CHILDREN_UPDATES = 0X0008;
- public static final int CHILDREN_COUNT_UPDATES = 0X0010;
- public static final int CHILDREN_UPDATES = 0X0020;
- public static final int MODEL_CHANGED_COMPLETE = 0X0040;
- public static final int MODEL_PROXIES_INSTALLED = 0X0080;
- public static final int STATE_SAVE_COMPLETE = 0X0100;
- public static final int STATE_RESTORE_COMPLETE = 0X0200;
- public static final int STATE_UPDATES = 0X0400;
-
- public static final int VIEWER_UPDATES_RUNNING = 0X0800;
- public static final int LABEL_UPDATES_RUNNING = 0X1000;
-
- public static final int LABEL_COMPLETE = LABEL_UPDATES_COMPLETE | LABEL_UPDATES;
- public static final int CONTENT_COMPLETE =
- CONTENT_UPDATES_COMPLETE | HAS_CHILDREN_UPDATES | CHILDREN_COUNT_UPDATES | CHILDREN_UPDATES;
-
- public static final int ALL_UPDATES_COMPLETE = LABEL_COMPLETE | CONTENT_COMPLETE | LABEL_UPDATES_RUNNING | VIEWER_UPDATES_RUNNING;
-}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/JFaceViewerFormattedValueTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/JFaceViewerFormattedValueTests.java
new file mode 100644
index 00000000000..c28a1b2d0be
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/JFaceViewerFormattedValueTests.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 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.eclipse.cdt.tests.dsf.vm;
+
+import org.eclipse.debug.internal.ui.viewers.model.ITreeModelContentProviderTarget;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * @since 2.2
+ */
+public class JFaceViewerFormattedValueTests extends FormattedValueTests {
+
+ public JFaceViewerFormattedValueTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected ITreeModelContentProviderTarget createViewer(Display display, Shell shell) {
+ return new TreeModelViewer(fShell, SWT.VIRTUAL, new PresentationContext("TestViewer"));
+ }
+
+ @Override
+ protected int getTestModelDepth() {
+ return 5;
+ }
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/PerformanceTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/PerformanceTests.java
index 73c1cf543ec..3438d076bcb 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/PerformanceTests.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/PerformanceTests.java
@@ -12,6 +12,10 @@ package org.eclipse.cdt.tests.dsf.vm;
import junit.framework.TestCase;
+import org.eclipse.cdt.dsf.concurrent.DefaultDsfExecutor;
+import org.eclipse.cdt.dsf.concurrent.DsfExecutor;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.tests.dsf.IViewerUpdatesListenerConstants;
import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
import org.eclipse.debug.internal.ui.viewers.model.ITreeModelContentProviderTarget;
import org.eclipse.debug.internal.ui.viewers.model.ITreeModelViewer;
@@ -28,9 +32,11 @@ import org.eclipse.ui.PlatformUI;
/**
* Tests to measure the performance of the viewer updates.
*/
-abstract public class PerformanceTests extends TestCase implements ITestModelUpdatesListenerConstants {
+abstract public class PerformanceTests extends TestCase implements IViewerUpdatesListenerConstants {
Display fDisplay;
Shell fShell;
+ DsfExecutor fDsfExecutor;
+ DsfSession fDsfSession;
ITreeModelViewer fViewer;
TestModelUpdatesListener fListener;
TestModel fModel;
@@ -46,6 +52,9 @@ abstract public class PerformanceTests extends TestCase implements ITestModelUpd
*/
@Override
protected void setUp() throws Exception {
+ fDsfExecutor = new DefaultDsfExecutor();
+ fDsfSession = DsfSession.startSession(fDsfExecutor, getClass().getName());
+
fDisplay = PlatformUI.getWorkbench().getDisplay();
fShell = new Shell(fDisplay/*, SWT.ON_TOP | SWT.SHELL_TRIM*/);
fShell.setMaximized(true);
@@ -55,7 +64,7 @@ abstract public class PerformanceTests extends TestCase implements ITestModelUpd
fListener = new TestModelUpdatesListener(fViewer, false, false);
- fModel = new TestModel();
+ fModel = new TestModel(fDsfSession);
fModel.setRoot( new TestElement(fModel, "root", new TestElement[0] ) );
fModel.setElementChildren(TreePath.EMPTY, makeModelElements(fModel, getTestModelDepth(), "model"));
fVMAdapter = new TestModelVMAdapter();
@@ -78,6 +87,8 @@ abstract public class PerformanceTests extends TestCase implements ITestModelUpd
// Close the shell and exit.
fShell.close();
while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
+ DsfSession.endSession(fDsfSession);
+ fDsfExecutor.shutdown();
}
/**
@@ -166,32 +177,31 @@ abstract public class PerformanceTests extends TestCase implements ITestModelUpd
}
public void _x_testRefreshStructReplaceElements() {
- TestModel model = new TestModel();
- model.setRoot( new TestElement(model, "root", new TestElement[0] ) );
- model.setElementChildren(TreePath.EMPTY, makeModelElements(model, getTestModelDepth(), "model"));
+ fModel.setRoot( new TestElement(fModel, "root", new TestElement[0] ) );
+ fModel.setElementChildren(TreePath.EMPTY, makeModelElements(fModel, getTestModelDepth(), "model"));
fViewer.setAutoExpandLevel(-1);
// Create the listener
- fListener.reset(TreePath.EMPTY, model.getRootElement(), -1, true, false);
+ fListener.reset(TreePath.EMPTY, fModel.getRootElement(), -1, true, false);
// Set the input into the view and update the view.
- fViewer.setInput(model.getRootElement());
+ fViewer.setInput(fModel.getRootElement());
while (!fListener.isFinished()) if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
- model.validateData(fViewer, TreePath.EMPTY);
+ fModel.validateData(fViewer, TreePath.EMPTY);
Performance perf = Performance.getDefault();
PerformanceMeter meter = perf.createPerformanceMeter(perf.getDefaultScenarioId(this));
try {
for (int i = 0; i < 2000; i++) {
// Update the model
- model.setElementChildren(TreePath.EMPTY, makeModelElements(model, getTestModelDepth(), "pass " + i));
+ fModel.setElementChildren(TreePath.EMPTY, makeModelElements(fModel, getTestModelDepth(), "pass " + i));
- TestElement element = model.getRootElement();
+ TestElement element = fModel.getRootElement();
fListener.reset(TreePath.EMPTY, element, -1, false, false);
meter.start();
- model.postDelta(new ModelDelta(element, IModelDelta.CONTENT));
+ //fModel.postDelta(new ModelDelta(element, IModelDelta.CONTENT));
while (!fListener.isFinished(ALL_UPDATES_COMPLETE | MODEL_CHANGED_COMPLETE))
if (!fDisplay.readAndDispatch ()) fDisplay.sleep ();
//model.validateData(fViewer, TreePath.EMPTY);
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestElementVMContext.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestElementVMContext.java
index 3d7360975df..e6ec468cc85 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestElementVMContext.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestElementVMContext.java
@@ -10,17 +10,20 @@
*******************************************************************************/
package org.eclipse.cdt.tests.dsf.vm;
+import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMContext;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
+import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
/**
- *
+ * @since 2.2
*/
-public class TestElementVMContext extends AbstractVMContext {
+public class TestElementVMContext extends AbstractVMContext implements IDMVMContext {
final private TestElement fElement;
- public TestElementVMContext(TestModelVMNode node, TestElement element) {
+ public TestElementVMContext(IVMNode node, TestElement element) {
super(node);
fElement = element;
}
@@ -38,5 +41,13 @@ public class TestElementVMContext extends AbstractVMContext {
public TestElement getElement() {
return fElement;
}
+
+ public IDMContext getDMContext() {
+ return getElement();
+ }
+ @Override
+ public String toString() {
+ return getDMContext().toString();
+ }
}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModel.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModel.java
index cbae0a9d6f7..da475627ad1 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModel.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModel.java
@@ -11,38 +11,45 @@
package org.eclipse.cdt.tests.dsf.vm;
import java.util.Arrays;
+import java.util.Hashtable;
import junit.framework.Assert;
-import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
+import org.eclipse.cdt.dsf.datamodel.AbstractDMContext;
+import org.eclipse.cdt.dsf.datamodel.DMContexts;
+import org.eclipse.cdt.dsf.datamodel.IDMContext;
+import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
+import org.eclipse.cdt.dsf.service.AbstractDsfService;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.tests.dsf.DsfTestPlugin;
import org.eclipse.debug.internal.ui.viewers.model.ITreeModelCheckProviderTarget;
import org.eclipse.debug.internal.ui.viewers.model.ITreeModelContentProviderTarget;
import org.eclipse.debug.internal.ui.viewers.model.ITreeModelViewer;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ICheckUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoRequest;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.ModelDelta;
-import org.eclipse.debug.internal.ui.viewers.provisional.AbstractModelProxy;
import org.eclipse.jface.viewers.TreePath;
-import org.eclipse.jface.viewers.Viewer;
+import org.osgi.framework.BundleContext;
/**
* Test model for the use in unit tests. This test model contains a set of
* elements in a tree structure. It contains utility methods for modifying the
* model and for verifying that the viewer content matches the model.
*
- * @since 3.6
+ * @since 2.2
*/
-public class TestModel {
+public class TestModel extends AbstractDsfService implements IFormattedValues {
- public static class TestElement extends PlatformObject {
+ public interface TestElementValidator {
+ public void validate(TestElement modelElement, TestElement viewerElement, TreePath viewerPath);
+ }
+
+ public static class TestElement extends AbstractDMContext implements IFormattedDataDMContext {
private final TestModel fModel;
private final String fID;
TestElement[] fChildren;
@@ -51,18 +58,37 @@ public class TestModel {
boolean fChecked;
boolean fGrayed;
+ private TestElement[] fParents = new TestElement[1];
+
public TestElement(TestModel model, String text, TestElement[] children) {
this (model, text, false, false, children);
}
public TestElement(TestModel model, String text, boolean checked, boolean grayed, TestElement[] children) {
+ super(model, EMPTY_PARENTS_ARRAY);
fModel = model;
fID = text;
fChildren = children;
+ for (TestElement child : children) {
+ child.setParent(this);
+ }
fChecked = checked;
fGrayed = grayed;
}
+ public void setParent(TestElement parent) {
+ fParents[0] = parent;
+ }
+
+ public TestElement getParent() {
+ return fParents[0];
+ }
+
+ @Override
+ public IDMContext[] getParents() {
+ return fParents;
+ }
+
public TestModel getModel() {
return fModel;
}
@@ -129,39 +155,72 @@ public class TestModel {
}
}
- private class ModelProxy extends AbstractModelProxy {
- @Override
- public void installed(Viewer viewer) {
- super.installed(viewer);
- ModelDelta rootDelta = TestModel.this.getBaseDelta(new ModelDelta(fInput, IModelDelta.NO_CHANGE));
- installSubModelProxies(fRootPath, rootDelta);
- fireModelChanged(rootDelta);
- }
-
- private void installSubModelProxies(TreePath path, ModelDelta delta) {
- TestElement element = getElement(path);
- if (element.fModel != TestModel.this) {
- // Found an element from a different model. Install its proxy and return.
- delta.setFlags(delta.getFlags() | IModelDelta.INSTALL);
- } else {
- TestElement[] children = element.getChildren();
-
- for (int i = 0; i < children.length; i++) {
- installSubModelProxies(path.createChildPath(children[i]), delta.addNode(children[i], IModelDelta.NO_CHANGE));
- }
- }
+ public static final class TestEvent {
+ private final TestElement fElement;
+ private final int fType;
+
+ public TestEvent(TestElement element, int type) {
+ fElement = element;
+ fType = type;
+ }
+
+ public TestElement getElement() {
+ return fElement;
+ }
+
+ /**
+ * @see IModelDelta#getFlags()
+ */
+ public int getType() {
+ return fType;
}
}
-
+
+ private static final IFormattedValuesListener NULL_LISTENER = new IFormattedValuesListener() {
+ public void formattedValueUpdated(FormattedValueDMContext formattedValueDmc) {}
+ };
+
private TestElement fRoot;
private Object fInput = null;
private TreePath fRootPath = TreePath.EMPTY;
- private ModelProxy fModelProxy;
+ private IFormattedValuesListener fListener = NULL_LISTENER;
/**
* Constructor private. Use static factory methods instead.
*/
- public TestModel() {}
+ public TestModel(DsfSession session) {
+ super(session);
+ }
+
+ @Override
+ protected BundleContext getBundleContext() {
+ return DsfTestPlugin.getBundleContext();
+ }
+
+ @Override
+ public void initialize(RequestMonitor rm) {
+ super.initialize(new RequestMonitor(getExecutor(), rm) {
+ @Override
+ protected void handleSuccess() {
+ register(new String[0], new Hashtable<String, String>() );
+ super.handleSuccess();
+ }
+ });
+ }
+
+ @Override
+ public void shutdown(RequestMonitor rm) {
+ unregister();
+ super.shutdown(rm);
+ }
+
+ public void setTestModelListener(IFormattedValuesListener listener) {
+ if (listener != null) {
+ fListener = listener;
+ } else {
+ fListener = NULL_LISTENER;
+ }
+ }
public TestElement getRootElement() {
return fRoot;
@@ -197,48 +256,6 @@ public class TestModel {
return depth;
}
- public void update(IHasChildrenUpdate[] updates) {
- for (int i = 0; i < updates.length; i++) {
- TestElement element = (TestElement)updates[i].getElement();
- updates[i].setHasChilren(element.getChildren().length > 0);
- updates[i].done();
- }
- }
-
- public void update(IChildrenCountUpdate[] updates) {
- for (int i = 0; i < updates.length; i++) {
- TestElement element = (TestElement)updates[i].getElement();
- updates[i].setChildCount(element.getChildren().length);
- updates[i].done();
- }
- }
-
- public void update(IChildrenUpdate[] updates) {
- for (int i = 0; i < updates.length; i++) {
- TestElement element = (TestElement)updates[i].getElement();
- int endOffset = updates[i].getOffset() + updates[i].getLength();
- for (int j = updates[i].getOffset(); j < endOffset; j++) {
- if (j < element.getChildren().length) {
- updates[i].setChild(element.getChildren()[j], j);
- }
- }
- updates[i].done();
- }
- }
-
- public void update(ILabelUpdate[] updates) {
- for (int i = 0; i < updates.length; i++) {
- TestElement element = (TestElement)updates[i].getElement();
- updates[i].setLabel(element.fID, 0);
- if (updates[i] instanceof ICheckUpdate &&
- Boolean.TRUE.equals(updates[i].getPresentationContext().getProperty(ICheckUpdate.PROP_CHECK)))
- {
- ((ICheckUpdate)updates[i]).setChecked(element.getChecked(), element.getGrayed());
- }
- updates[i].done();
- }
- }
-
public final static String ELEMENT_MEMENTO_ID = "id";
public void compareElements(IElementCompareRequest[] updates) {
@@ -259,24 +276,12 @@ public class TestModel {
}
}
-
public void elementChecked(IPresentationContext context, Object viewerInput, TreePath path, boolean checked) {
TestElement element = getElement(path);
Assert.assertFalse(element.getGrayed());
element.setChecked(checked, false);
}
- public IModelProxy createTreeModelProxy(Object input, TreePath path, IPresentationContext context) {
- fModelProxy = new ModelProxy();
- fInput = input;
- fRootPath = path;
- return fModelProxy;
- }
-
- public IModelProxy getModelProxy() {
- return fModelProxy;
- }
-
public TestElement getElement(TreePath path) {
if (path.getSegmentCount() == 0) {
return getRootElement();
@@ -289,6 +294,14 @@ public class TestModel {
return null;
}
}
+
+ public TestElement getElementFromViewer(ITreeModelContentProviderTarget viewer, TreePath parentPath, int index) {
+ Object element = viewer.getChildElement(parentPath, index);
+ if (element instanceof TestElementVMContext) {
+ return ((TestElementVMContext)element).getElement();
+ }
+ return null;
+ }
public void setAllExpanded() {
doSetExpanded(fRoot);
@@ -314,10 +327,16 @@ public class TestModel {
public void validateData(ITreeModelViewer viewer, TreePath path) {
- validateData(viewer, path, false);
+ validateData(viewer, path, null, false);
}
- public void validateData(ITreeModelViewer _viewer, TreePath path, boolean expandedElementsOnly) {
+ public void validateData(ITreeModelViewer viewer, TreePath path, TestElementValidator validator) {
+
+ validateData(viewer, path, validator, false);
+ }
+
+ public void validateData(ITreeModelViewer _viewer, TreePath path, TestElementValidator validator, boolean expandedElementsOnly) {
+
ITreeModelContentProviderTarget viewer = (ITreeModelContentProviderTarget)_viewer;
TestElement element = getElement(path);
if ( Boolean.TRUE.equals(_viewer.getPresentationContext().getProperty(ICheckUpdate.PROP_CHECK)) ) {
@@ -331,8 +350,17 @@ public class TestModel {
Assert.assertEquals(children.length, viewer.getChildCount(path));
for (int i = 0; i < children.length; i++) {
- Assert.assertEquals(children[i], viewer.getChildElement(path, i));
- validateData(viewer, path.createChildPath(children[i]), expandedElementsOnly);
+ Object viewerObject = viewer.getChildElement(path, i);
+ if (viewerObject instanceof TestElementVMContext) {
+ TreePath childPath = path.createChildPath(viewerObject);
+ TestElement viewerElement = ((TestElementVMContext)viewerObject).getElement();
+ Assert.assertEquals(children[i], viewerElement);
+ if (validator != null) {
+ validator.validate(children[i], viewerElement, childPath);
+ }
+
+ validateData(viewer, childPath, validator, expandedElementsOnly);
+ }
}
} else if (!viewer.getExpandedState(path)) {
// If element not expanded, verify the plus sign.
@@ -344,10 +372,6 @@ public class TestModel {
fRoot = root;
}
- public void postDelta(IModelDelta delta) {
- fModelProxy.fireModelChanged(delta);
- }
-
/** Create or retrieve delta for given path
* @param combine if then new deltas for the given path are created. If false existing ones are reused.
*/
@@ -560,6 +584,27 @@ public class TestModel {
return null;
}
+ public void getAvailableFormats(IFormattedDataDMContext dmc, DataRequestMonitor<String[]> rm) {
+ rm.setData(new String[] { HEX_FORMAT, DECIMAL_FORMAT, OCTAL_FORMAT, BINARY_FORMAT, NATURAL_FORMAT });
+ rm.done();
+ }
+
+ public void getFormattedExpressionValue(FormattedValueDMContext dmc, DataRequestMonitor<FormattedValueDMData> rm) {
+ TestElement te = DMContexts.getAncestorOfType(dmc, TestElement.class);
+ rm.setData(new FormattedValueDMData( getFormattedValueText(te, dmc.getFormatID())));
+ rm.done();
+ fListener.formattedValueUpdated(dmc);
+ }
+
+ public FormattedValueDMContext getFormattedValueContext(IFormattedDataDMContext dmc, String formatId) {
+ // Creates a context that can be used to retrieve a formatted value.
+ return new FormattedValueDMContext(this, dmc, formatId);
+ }
+
+ public String getFormattedValueText(TestElement te, String formatId) {
+ return te.getLabel() + " (" + formatId + ")";
+ }
+
@Override
public String toString() {
return getElementString(fRoot, "");
@@ -577,8 +622,7 @@ public class TestModel {
return builder.toString();
}
- public static TestModel simpleSingleLevel() {
- TestModel model = new TestModel();
+ public static void simpleSingleLevel(TestModel model) {
model.setRoot( new TestElement(model, "root", new TestElement[] {
new TestElement(model, "1", true, true, new TestElement[0]),
new TestElement(model, "2", true, false, new TestElement[0]),
@@ -587,11 +631,9 @@ public class TestModel {
new TestElement(model, "5", new TestElement[0]),
new TestElement(model, "6", new TestElement[0])
}) );
- return model;
}
- public static TestModel simpleMultiLevel() {
- TestModel model = new TestModel();
+ public static void simpleMultiLevel(TestModel model) {
model.setRoot( new TestElement(model, "root", new TestElement[] {
new TestElement(model, "1", new TestElement[0]),
new TestElement(model, "2", true, false, new TestElement[] {
@@ -617,53 +659,6 @@ public class TestModel {
}),
})
}) );
- return model;
}
-
- public static TestModel compositeMultiLevel() {
- TestModel m2 = new TestModel();
- m2.setRoot( new TestElement(m2, "m2.root", new TestElement[] {
- new TestElement(m2, "m2.1", new TestElement[0]),
- new TestElement(m2, "m2.2", true, false, new TestElement[] {
- new TestElement(m2, "m2.2.1", true, true, new TestElement[0]),
- new TestElement(m2, "m2.2.2", false, true, new TestElement[0]),
- new TestElement(m2, "m2.2.3", true, false, new TestElement[0]),
- }),
- }) );
-
- TestModel m3 = new TestModel();
- m3.setRoot( new TestElement(m3, "m3.root", new TestElement[] {
- new TestElement(m3, "m3.1", new TestElement[0]),
- new TestElement(m3, "m3.2", true, false, new TestElement[] {
- new TestElement(m3, "m3.2.1", true, true, new TestElement[0]),
- new TestElement(m3, "m3.2.2", false, true, new TestElement[0]),
- new TestElement(m3, "m3.2.3", true, false, new TestElement[0]),
- }),
- }) );
-
- TestModel m4 = new TestModel();
- m4.setRoot( new TestElement(m4, "m4.root", new TestElement[] {
- new TestElement(m4, "m4.1", new TestElement[0]),
- new TestElement(m4, "m4.2", true, false, new TestElement[] {
- new TestElement(m4, "m4.2.1", true, true, new TestElement[0]),
- new TestElement(m4, "m4.2.2", false, true, new TestElement[0]),
- new TestElement(m4, "m4.2.3", true, false, new TestElement[0]),
- }),
- }) );
-
- TestModel m1 = new TestModel();
- m1.setRoot( new TestElement(m1, "m1.root", new TestElement[] {
- new TestElement(m1, "m1.1", new TestElement[0]),
- new TestElement(m1, "m1.2", true, false, new TestElement[] {
- m2.fRoot,
- m3.fRoot,
- m4.fRoot,
- }),
- }) );
-
-
- return m1;
- }
-
}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelCachingVMProvider.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelCachingVMProvider.java
new file mode 100644
index 00000000000..5279e4afb79
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelCachingVMProvider.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.eclipse.cdt.tests.dsf.vm;
+
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.update.BreakpointHitUpdatePolicy;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.update.DebugManualUpdatePolicy;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
+import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.AbstractDMVMProvider;
+import org.eclipse.cdt.dsf.ui.viewmodel.update.AutomaticUpdatePolicy;
+import org.eclipse.cdt.dsf.ui.viewmodel.update.IVMUpdatePolicy;
+import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+/**
+ * @since 2.2
+ */
+public class TestModelCachingVMProvider extends AbstractDMVMProvider {
+
+ public static final String COLUMN_ID = "COLUMN_ID";
+ public static final String COLUMN_FORMATTED_VALUE = "COLUMN_FORMATTED_VALUE";
+ public static final String COLUMN_DUMMY_VALUE = "COLUMN_DUMMY_VALUE";
+ private static final String[] COLUMNS = new String[] { COLUMN_ID, COLUMN_FORMATTED_VALUE, COLUMN_DUMMY_VALUE };
+
+ private IPropertyChangeListener fPresentationContextListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ handleEvent(event);
+ }
+ };
+
+ private static IColumnPresentation COLUMN_PRESENTATION = new IColumnPresentation() {
+ public void init(IPresentationContext context) {}
+ public void dispose() {};
+
+ public String[] getAvailableColumns() {
+ return COLUMNS;
+ };
+
+ public String getHeader(String id) {
+ return id;
+ };
+
+ public String getId() { return "ID"; }
+
+ public ImageDescriptor getImageDescriptor(String id) {
+ return null;
+ }
+ public String[] getInitialColumns() {
+ return COLUMNS;
+ }
+ public boolean isOptional() {
+ return false;
+ }
+ };
+
+ public TestModelCachingVMProvider(AbstractVMAdapter adapter, IPresentationContext context, DsfSession session) {
+ super(adapter, context, session);
+
+ setRootNode(new TestModelDMVMNode(this, session));
+ addChildNodes(getRootVMNode(), new IVMNode[] { getRootVMNode() });
+
+ context.addPropertyChangeListener(fPresentationContextListener);
+ }
+
+ @Override
+ protected IVMUpdatePolicy[] createUpdateModes() {
+ return new IVMUpdatePolicy[] {
+ new AutomaticUpdatePolicy(),
+ new DebugManualUpdatePolicy(new String[] { TestModelDMVMNode.PROP_PREFIX_DUMMY }),
+ new BreakpointHitUpdatePolicy() };
+ }
+
+ public TestModelDMVMNode getNode() {
+ return (TestModelDMVMNode)getRootVMNode();
+ }
+
+ @Override
+ public void dispose() {
+ getPresentationContext().removePropertyChangeListener(fPresentationContextListener);
+ super.dispose();
+ }
+
+ public void postEvent(Object event) {
+ super.handleEvent(event);
+ }
+
+ public TestElementVMContext getElementVMContext(IPresentationContext context, TestElement element) {
+ return ((TestModelDMVMNode)getRootVMNode()).createVMContext(element);
+ }
+
+ @Override
+ public String getColumnPresentationId(IPresentationContext context, Object element) {
+ return COLUMN_PRESENTATION.getId();
+ }
+
+ @Override
+ public IColumnPresentation createColumnPresentation(IPresentationContext context, Object element) {
+ return COLUMN_PRESENTATION;
+ }
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelDMVMNode.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelDMVMNode.java
new file mode 100644
index 00000000000..19f15555ec8
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelDMVMNode.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 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.eclipse.cdt.tests.dsf.vm;
+
+import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueLabelText;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueRetriever;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.dsf.ui.viewmodel.IRootVMNode;
+import org.eclipse.cdt.dsf.ui.viewmodel.VMDelta;
+import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.AbstractDMVMNode;
+import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.AbstractDMVMProvider;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IElementPropertiesProvider;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelAttribute;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelColumnInfo;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelText;
+import org.eclipse.cdt.dsf.ui.viewmodel.properties.PropertiesBasedLabelProvider;
+import org.eclipse.cdt.tests.dsf.ViewerUpdatesListener;
+import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
+import org.eclipse.cdt.tests.dsf.vm.TestModel.TestEvent;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+/**
+ * @since 2.2
+ */
+public class TestModelDMVMNode extends AbstractDMVMNode implements IRootVMNode, IElementLabelProvider, IElementPropertiesProvider {
+
+ final public static String PROP_PREFIX_DUMMY = "dummy.";
+
+ final private static String PROP_TEST_ELEMENT_LABEL = "PROP_TEST_ELEMENT_LABEL";
+
+ private ViewerUpdatesListener fViewerUpdateListener = NULL_VIEWER_UPDATE_LISTENER;
+ private FormattedValuesListener fFormattedValuesListener;
+
+ private static final ViewerUpdatesListener NULL_VIEWER_UPDATE_LISTENER = new ViewerUpdatesListener();
+
+ final private static PropertiesBasedLabelProvider fLabelProvider = new PropertiesBasedLabelProvider();
+ {
+ LabelColumnInfo idLabelInfo = new LabelColumnInfo(new LabelAttribute[] {
+ new LabelText("{0}", new String[] { PROP_TEST_ELEMENT_LABEL })
+ });
+
+ fLabelProvider.setColumnInfo(PropertiesBasedLabelProvider.ID_COLUMN_NO_COLUMNS, idLabelInfo);
+ fLabelProvider.setColumnInfo(TestModelCachingVMProvider.COLUMN_ID, idLabelInfo);
+ fLabelProvider.setColumnInfo(
+ TestModelCachingVMProvider.COLUMN_FORMATTED_VALUE,
+ new LabelColumnInfo(new LabelAttribute[] {
+ new FormattedValueLabelText()
+ }));
+ fLabelProvider.setColumnInfo(
+ TestModelCachingVMProvider.COLUMN_DUMMY_VALUE,
+ new LabelColumnInfo(new LabelAttribute[] {
+ new FormattedValueLabelText(PROP_PREFIX_DUMMY)
+ }));
+ }
+
+ private final FormattedValueRetriever fFormattedValueRetriever;
+ private final FormattedValueRetriever fDummyFormattedValueRetriever;
+
+ public TestModelDMVMNode(AbstractDMVMProvider provider, DsfSession session) {
+ super(provider, session, TestElement.class);
+ fFormattedValueRetriever = new FormattedValueRetriever(this, getSession(), TestModel.class, TestElement.class);
+ fDummyFormattedValueRetriever = new FormattedValueRetriever(this, getSession(), DummyFormattedValueService.class, TestElement.class, PROP_PREFIX_DUMMY);
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ fFormattedValueRetriever.dispose();
+ fDummyFormattedValueRetriever.dispose();
+ }
+
+ public void setVMUpdateListener(ViewerUpdatesListener viewerUpdateListener) {
+ if (viewerUpdateListener != null) {
+ fViewerUpdateListener = viewerUpdateListener;
+ } else {
+ fViewerUpdateListener = NULL_VIEWER_UPDATE_LISTENER;
+ }
+ }
+
+ public void setFormattedValuesListener(FormattedValuesListener formattedValuesListener) {
+ fFormattedValuesListener = formattedValuesListener;
+ }
+
+ public PropertiesBasedLabelProvider getLabelProvider() {
+ return fLabelProvider;
+ }
+
+ public void update(final ILabelUpdate[] updates) {
+ fLabelProvider.update(updates);
+ }
+
+ @Override
+ public void update(IHasChildrenUpdate[] updates) {
+ fViewerUpdateListener.viewerUpdatesBegin();
+ for (IHasChildrenUpdate update : updates) {
+ fViewerUpdateListener.updateStarted(update);
+ if (update.getElement() instanceof TestElementVMContext) {
+ TestElement element = ((TestElementVMContext)update.getElement()).getElement();
+ update.setHasChilren(element.getChildren().length != 0);
+ }
+ update.done();
+ fViewerUpdateListener.updateComplete(update);
+ }
+ fViewerUpdateListener.viewerUpdatesComplete();
+ }
+
+ @Override
+ public void update(IChildrenCountUpdate[] updates) {
+ fViewerUpdateListener.viewerUpdatesBegin();
+ for (IChildrenCountUpdate update : updates) {
+ fViewerUpdateListener.updateStarted(update);
+ if (update.getElement() instanceof TestElementVMContext) {
+ TestElement element = ((TestElementVMContext)update.getElement()).getElement();
+ update.setChildCount(element.getChildren().length);
+ }
+ update.done();
+ fViewerUpdateListener.updateComplete(update);
+ }
+ fViewerUpdateListener.viewerUpdatesComplete();
+ }
+
+ @Override
+ public void update(IChildrenUpdate[] updates) {
+ fViewerUpdateListener.viewerUpdatesBegin();
+ for (IChildrenUpdate update : updates) {
+ fViewerUpdateListener.updateStarted(update);
+ if (update.getElement() instanceof TestElementVMContext) {
+ TestElement element = ((TestElementVMContext)update.getElement()).getElement();
+ fillUpdateWithTestElements(update, element.getChildren());
+ }
+ update.done();
+ fViewerUpdateListener.updateComplete(update);
+ }
+ fViewerUpdateListener.viewerUpdatesComplete();
+ }
+
+
+ @Override
+ protected void updateElementsInSessionThread(IChildrenUpdate update) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void update(final IPropertiesUpdate[] updates) {
+ fViewerUpdateListener.propertiesUpdatesStarted(updates);
+ if (fFormattedValuesListener != null) fFormattedValuesListener.propertiesUpdatesStarted(updates);
+
+ CountingRequestMonitor crm = new CountingRequestMonitor(getExecutor(), null) {
+ @Override
+ protected void handleSuccess() {
+ for (IPropertiesUpdate update : updates) {
+ if (update.getElement() instanceof TestElementVMContext) {
+ TestElement element = ((TestElementVMContext)update.getElement()).getElement();
+ update.setProperty(PROP_TEST_ELEMENT_LABEL, element.getLabel());
+ }
+ update.done();
+ fViewerUpdateListener.propertiesUpdateCompleted(update);
+ if (fFormattedValuesListener != null) fFormattedValuesListener.propertiesUpdateCompleted(update);
+ }
+ }
+ };
+ int count = 0;
+
+ fFormattedValueRetriever.update(updates, crm);
+ count++;
+ fDummyFormattedValueRetriever.update(updates, crm);
+ count++;
+ crm.setDoneCount(count);
+ }
+
+ private void fillUpdateWithTestElements(IChildrenUpdate update, TestElement[] modelElements) {
+ int updateIdx = update.getOffset() != -1 ? update.getOffset() : 0;
+ int endIdx = updateIdx + (update.getLength() != -1 ? update.getLength() : modelElements.length);
+ while (updateIdx < endIdx && updateIdx < modelElements.length) {
+ update.setChild(createVMContext(modelElements[updateIdx]), updateIdx);
+ updateIdx++;
+ }
+ }
+
+ public TestElementVMContext createVMContext(TestElement element) {
+ return new TestElementVMContext(this, element);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.cdt.dsf.ui.viewmodel.IVMNode#getDeltaFlags(java.lang.Object)
+ */
+ public int getDeltaFlags(Object e) {
+ if ( e instanceof PropertyChangeEvent &&
+ ((PropertyChangeEvent)e).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE)
+ {
+ return IModelDelta.CONTENT;
+ }
+ if (e instanceof TestEvent) {
+ return ((TestEvent)e).getType();
+ }
+
+ return IModelDelta.NO_CHANGE;
+ }
+
+ public void buildDelta(Object e, VMDelta parent, int nodeOffset, RequestMonitor rm) {
+ if ( e instanceof PropertyChangeEvent &&
+ ((PropertyChangeEvent)e).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE)
+ {
+ parent.setFlags(parent.getFlags() | IModelDelta.CONTENT);
+ }
+ rm.done();
+ }
+
+
+ public boolean isDeltaEvent(Object rootObject, Object event) {
+ return getDeltaFlags(event) != IModelDelta.NO_CHANGE;
+ }
+
+ public void createRootDelta(Object rootObject, Object event, DataRequestMonitor<VMDelta> rm) {
+ int flags = IModelDelta.NO_CHANGE;
+ if ( event instanceof PropertyChangeEvent &&
+ ((PropertyChangeEvent)event).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE)
+ {
+ flags |= IModelDelta.CONTENT;
+ }
+
+ // TODO: make more sophisticated to update specific elements.
+ if (event instanceof TestEvent) {
+ flags|= ((TestEvent)event).getType();
+ }
+
+ rm.setData( new VMDelta(rootObject, 0, flags) );
+ rm.done();
+ }
+
+
+}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelUpdatesListener.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelUpdatesListener.java
index 8684a81d038..a98d0a4f97f 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelUpdatesListener.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelUpdatesListener.java
@@ -11,34 +11,21 @@
package org.eclipse.cdt.tests.dsf.vm;
import java.util.Comparator;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
-import junit.framework.Assert;
-
+import org.eclipse.cdt.tests.dsf.ViewerUpdatesListener;
import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
-import org.eclipse.debug.internal.ui.viewers.model.ILabelUpdateListener;
import org.eclipse.debug.internal.ui.viewers.model.ITreeModelContentProviderTarget;
import org.eclipse.debug.internal.ui.viewers.model.ITreeModelViewer;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IStateUpdateListener;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
-import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdateListener;
import org.eclipse.jface.viewers.TreePath;
-public class TestModelUpdatesListener
- implements IViewerUpdateListener, ILabelUpdateListener, IModelChangedListener, ITestModelUpdatesListenerConstants,
- IStateUpdateListener
+/**
+ * @since 2.2
+ */
+public class TestModelUpdatesListener extends ViewerUpdatesListener
{
private final static Comparator<String> fStringComparator = new Comparator<String>() {
@@ -116,74 +103,28 @@ public class TestModelUpdatesListener
};
- private final ITreeModelViewer fViewer;
-
- private boolean fFailOnRedundantUpdates;
- private boolean fFailOnMultipleModelUpdateSequences;
- private boolean fFailOnMultipleLabelUpdateSequences;
-
- private Set<TreePath> fHasChildrenUpdates = new TreeSet<TreePath>(fTestElementVMCComparator);
- private Map<TreePath, Set<Integer>> fChildrenUpdates = new TreeMap<TreePath, Set<Integer>>(fTestElementVMCComparator);
- private Set<TreePath> fChildCountUpdates = new TreeSet<TreePath>(fTestElementVMCComparator);
- private Set<TreePath> fLabelUpdates = new TreeSet<TreePath>(fTestElementVMCComparator);
- private Set<TestModel> fProxyModels = new HashSet<TestModel>();
- private Set<TreePath> fStateUpdates = new TreeSet<TreePath>(fTestElementVMCComparator);
- private boolean fViewerUpdatesComplete;
- private boolean fLabelUpdatesComplete;
- private boolean fModelChangedComplete;
- private boolean fStateSaveComplete;
- private boolean fStateRestoreComplete;
- private int fViewerUpdatesRunning;
- private int fLabelUpdatesRunning;
- private int fTimeoutInterval = 60000;
- private long fTimeoutTime;
+ @Override
+ protected Set<TreePath> makeTreePathSet() {
+ return new TreeSet<TreePath>(fTestElementVMCComparator);
+ }
-
- public TestModelUpdatesListener(ITreeModelViewer viewer, boolean failOnRedundantUpdates, boolean failOnMultipleModelUpdateSequences) {
- setFailOnRedundantUpdates(failOnRedundantUpdates);
- setFailOnMultipleModelUpdateSequences(failOnMultipleModelUpdateSequences);
- fViewer = viewer;
- fViewer.addLabelUpdateListener(this);
- fViewer.addModelChangedListener(this);
- fViewer.addStateUpdateListener(this);
- fViewer.addViewerUpdateListener(this);
- }
-
- public void dispose() {
- fViewer.removeLabelUpdateListener(this);
- fViewer.removeModelChangedListener(this);
- fViewer.removeStateUpdateListener(this);
- fViewer.removeViewerUpdateListener(this);
- }
-
-
- public void setFailOnRedundantUpdates(boolean failOnRedundantUpdates) {
- fFailOnRedundantUpdates = failOnRedundantUpdates;
- }
-
- public void setFailOnMultipleModelUpdateSequences(boolean failOnMultipleLabelUpdateSequences) {
- fFailOnMultipleModelUpdateSequences = failOnMultipleLabelUpdateSequences;
+ @Override
+ protected <V> Map<TreePath, V> makeTreePathMap() {
+ return new TreeMap<TreePath, V>(fTestElementVMCComparator);
}
+
- public void setFailOnMultipleLabelUpdateSequences(boolean failOnMultipleLabelUpdateSequences) {
- fFailOnMultipleLabelUpdateSequences = failOnMultipleLabelUpdateSequences;
+ public TestModelUpdatesListener() {
+ super();
}
- /**
- * Sets the the maximum amount of time (in milliseconds) that the update listener
- * is going to wait. If set to -1, the listener will wait indefinitely.
- */
- public void setTimeoutInterval(int milis) {
- fTimeoutInterval = milis;
+ public TestModelUpdatesListener(ITreeModelViewer viewer, boolean failOnRedundantUpdates, boolean failOnMultipleModelUpdateSequences) {
+ super(viewer, failOnRedundantUpdates, failOnMultipleModelUpdateSequences);
}
public void reset(TreePath path, TestElement element, int levels, boolean failOnRedundantUpdates, boolean failOnMultipleUpdateSequences) {
- reset();
+ reset(failOnRedundantUpdates, failOnMultipleUpdateSequences);
addUpdates(path, element, levels);
- addProxies(element);
- setFailOnRedundantUpdates(failOnRedundantUpdates);
- setFailOnMultipleModelUpdateSequences(failOnMultipleUpdateSequences);
- setFailOnMultipleLabelUpdateSequences(false);
}
public void reset(boolean failOnRedundantUpdates, boolean failOnMultipleUpdateSequences) {
@@ -193,67 +134,6 @@ public class TestModelUpdatesListener
setFailOnMultipleLabelUpdateSequences(false);
}
- public void reset() {
- fHasChildrenUpdates.clear();
- fChildrenUpdates.clear();
- fChildCountUpdates.clear();
- fLabelUpdates.clear();
- fProxyModels.clear();
- fViewerUpdatesComplete = false;
- fLabelUpdatesComplete = false;
- fStateSaveComplete = false;
- fStateRestoreComplete = false;
- fTimeoutTime = System.currentTimeMillis() + fTimeoutInterval;
- resetModelChanged();
- }
-
- public void resetModelChanged() {
- fModelChangedComplete = false;
- }
-
- public void addHasChildrenUpdate(TreePath path) {
- fHasChildrenUpdates.add(path);
- }
-
- public void removeHasChildrenUpdate(TreePath path) {
- fHasChildrenUpdates.remove(path);
- }
-
- public void addChildreCountUpdate(TreePath path) {
- fChildCountUpdates.add(path);
- }
-
- public void removeChildreCountUpdate(TreePath path) {
- fChildCountUpdates.remove(path);
- }
-
- public void addChildreUpdate(TreePath path, int index) {
- Set<Integer> childrenIndexes = fChildrenUpdates.get(path);
- if (childrenIndexes == null) {
- childrenIndexes = new TreeSet<Integer>();
- fChildrenUpdates.put(path, childrenIndexes);
- }
- childrenIndexes.add(new Integer(index));
- }
-
- public void removeChildrenUpdate(TreePath path, int index) {
- Set<Integer> childrenIndexes = fChildrenUpdates.get(path);
- if (childrenIndexes != null) {
- childrenIndexes.remove(new Integer(index));
- if (childrenIndexes.isEmpty()) {
- fChildrenUpdates.remove(path);
- }
- }
- }
-
- public void addLabelUpdate(TreePath path) {
- fLabelUpdates.add(path);
- }
-
- public void removeLabelUpdate(TreePath path) {
- fLabelUpdates.remove(path);
- }
-
public void addUpdates(TreePath path, TestElement element, int levels) {
addUpdates(path, element, levels, ALL_UPDATES_COMPLETE);
}
@@ -269,29 +149,30 @@ public class TestModelUpdatesListener
public void addUpdates(ITreeModelContentProviderTarget viewer, TreePath path, TestElement element, int levels, int flags) {
if (!path.equals(TreePath.EMPTY)) {
if ((flags & LABEL_UPDATES) != 0) {
- fLabelUpdates.add(path);
+ addLabelUpdate(path);
+ }
+ if ((flags & PROPERTY_UPDATES) != 0) {
+ addPropertiesUpdate(path);
}
if ((flags & HAS_CHILDREN_UPDATES) != 0) {
- fHasChildrenUpdates.add(path);
+ addHasChildrenUpdate(path);
}
}
if (levels-- != 0) {
TestElement[] children = element.getChildren();
if (children.length > 0 && (viewer == null || path.getSegmentCount() == 0 || viewer.getExpandedState(path))) {
- if ((flags & CHILDREN_COUNT_UPDATES) != 0) {
- fChildCountUpdates.add(path);
+ if ((flags & CHILD_COUNT_UPDATES) != 0) {
+ addChildCountUpdate(path);
}
if ((flags & CHILDREN_UPDATES) != 0) {
- Set<Integer> childrenIndexes = new HashSet<Integer>();
for (int i = 0; i < children.length; i++) {
- childrenIndexes.add(new Integer(i));
+ addChildreUpdate(path, i);
}
- fChildrenUpdates.put(path, childrenIndexes);
}
if ((flags & STATE_UPDATES) != 0 && viewer != null) {
- fStateUpdates.add(path);
+ addStateUpdate(path);
}
for (int i = 0; i < children.length; i++) {
@@ -301,284 +182,6 @@ public class TestModelUpdatesListener
}
}
-
- private void addProxies(TestElement element) {
- TestModel model = element.getModel();
- if (model.getModelProxy() == null) {
- fProxyModels.add(element.getModel());
- }
- TestElement[] children = element.getChildren();
- for (int i = 0; i < children.length; i++) {
- addProxies(children[i]);
- }
- }
-
- public boolean isFinished() {
- return isFinished(ALL_UPDATES_COMPLETE);
- }
-
- public boolean isFinished(int flags) {
- if (fTimeoutInterval > 0 && fTimeoutTime < System.currentTimeMillis()) {
- throw new RuntimeException("Timed Out: " + toString(flags));
- }
-
- if ( (flags & LABEL_UPDATES_COMPLETE) != 0) {
- if (!fLabelUpdatesComplete) return false;
- }
- if ( (flags & LABEL_UPDATES) != 0) {
- if (!fLabelUpdates.isEmpty()) return false;
- }
- if ( (flags & CONTENT_UPDATES_COMPLETE) != 0) {
- if (!fViewerUpdatesComplete) return false;
- }
- if ( (flags & HAS_CHILDREN_UPDATES) != 0) {
- if (!fHasChildrenUpdates.isEmpty()) return false;
- }
- if ( (flags & CHILDREN_COUNT_UPDATES) != 0) {
- if (!fChildCountUpdates.isEmpty()) return false;
- }
- if ( (flags & CHILDREN_UPDATES) != 0) {
- if (!fChildrenUpdates.isEmpty()) return false;
- }
- if ( (flags & MODEL_CHANGED_COMPLETE) != 0) {
- if (!fModelChangedComplete) return false;
- }
- if ( (flags & STATE_SAVE_COMPLETE) != 0) {
- if (!fStateSaveComplete) return false;
- }
- if ( (flags & STATE_RESTORE_COMPLETE) != 0) {
- if (!fStateRestoreComplete) return false;
- }
- if ( (flags & MODEL_PROXIES_INSTALLED) != 0) {
- if (fProxyModels.size() != 0) return false;
- }
- if ( (flags & VIEWER_UPDATES_RUNNING) != 0) {
- if (fViewerUpdatesRunning != 0) {
- return false;
- }
- }
- if ( (flags & LABEL_UPDATES_RUNNING) != 0) {
- if (fLabelUpdatesRunning != 0) {
- return false;
- }
- }
-
- return true;
- }
-
- public void updateStarted(IViewerUpdate update) {
- synchronized (this) {
- fViewerUpdatesRunning++;
- }
- }
-
- public void updateComplete(IViewerUpdate update) {
- synchronized (this) {
- fViewerUpdatesRunning--;
- }
-
- if (!update.isCanceled()) {
- if (update instanceof IHasChildrenUpdate) {
- if (!fHasChildrenUpdates.remove(update.getElementPath()) && fFailOnRedundantUpdates) {
- Assert.fail("Redundant update: " + update);
- }
- } if (update instanceof IChildrenCountUpdate) {
- if (!fChildCountUpdates.remove(update.getElementPath()) && fFailOnRedundantUpdates) {
- Assert.fail("Redundant update: " + update);
- }
- } else if (update instanceof IChildrenUpdate) {
- int start = ((IChildrenUpdate)update).getOffset();
- int end = start + ((IChildrenUpdate)update).getLength();
-
- Set<Integer> childrenIndexes = fChildrenUpdates.get(update.getElementPath());
- if (childrenIndexes != null) {
- for (int i = start; i < end; i++) {
- childrenIndexes.remove(new Integer(i));
- }
- if (childrenIndexes.isEmpty()) {
- fChildrenUpdates.remove(update.getElementPath());
- }
- } else if (fFailOnRedundantUpdates) {
- Assert.fail("Redundant update: " + update);
- }
- }
- }
- }
-
- public void viewerUpdatesBegin() {
-
- }
-
- public void viewerUpdatesComplete() {
- if (fFailOnMultipleModelUpdateSequences && fViewerUpdatesComplete) {
- Assert.fail("Multiple viewer update sequences detected");
- }
- fViewerUpdatesComplete = true;
- }
-
- public void labelUpdateComplete(ILabelUpdate update) {
- synchronized (this) {
- fLabelUpdatesRunning--;
- }
- if (!fLabelUpdates.remove(update.getElementPath()) && fFailOnRedundantUpdates) {
- Assert.fail("Redundant update: " + update);
- }
- }
-
- public void labelUpdateStarted(ILabelUpdate update) {
- synchronized (this) {
- fLabelUpdatesRunning++;
- }
- }
-
- public void labelUpdatesBegin() {
- }
-
- public void labelUpdatesComplete() {
- if (fFailOnMultipleLabelUpdateSequences && fLabelUpdatesComplete) {
- Assert.fail("Multiple label update sequences detected");
- }
- fLabelUpdatesComplete = true;
- }
-
- public void modelChanged(IModelDelta delta, IModelProxy proxy) {
- fModelChangedComplete = true;
-
- for (Iterator<TestModel> itr = fProxyModels.iterator(); itr.hasNext();) {
- TestModel model = itr.next();
- if (model.getModelProxy() == proxy) {
- itr.remove();
- break;
- }
- }
- }
-
- public void stateRestoreUpdatesBegin(Object input) {
- }
-
- public void stateRestoreUpdatesComplete(Object input) {
- fStateRestoreComplete = true;
- }
-
- public void stateSaveUpdatesBegin(Object input) {
- }
-
- public void stateSaveUpdatesComplete(Object input) {
- fStateSaveComplete = true;
- }
-
- public void stateUpdateComplete(Object input, IViewerUpdate update) {
- }
-
- public void stateUpdateStarted(Object input, IViewerUpdate update) {
- }
-
- private String toString(int flags) {
- StringBuffer buf = new StringBuffer("Viewer Update Listener");
-
- if ( (flags & LABEL_UPDATES_COMPLETE) != 0) {
- buf.append("\n\t");
- buf.append("fLabelUpdatesComplete = " + fLabelUpdatesComplete);
- }
- if ( (flags & LABEL_UPDATES_RUNNING) != 0) {
- buf.append("\n\t");
- buf.append("fLabelUpdatesRunning = " + fLabelUpdatesRunning);
- }
- if ( (flags & LABEL_UPDATES) != 0) {
- buf.append("\n\t");
- buf.append("fLabelUpdates = ");
- buf.append( toString(fLabelUpdates) );
- }
- if ( (flags & CONTENT_UPDATES_COMPLETE) != 0) {
- buf.append("\n\t");
- buf.append("fViewerUpdatesComplete = " + fViewerUpdatesComplete);
- }
- if ( (flags & VIEWER_UPDATES_RUNNING) != 0) {
- buf.append("\n\t");
- buf.append("fViewerUpdatesRunning = " + fViewerUpdatesRunning);
- }
- if ( (flags & HAS_CHILDREN_UPDATES) != 0) {
- buf.append("\n\t");
- buf.append("fHasChildrenUpdates = ");
- buf.append( toString(fHasChildrenUpdates) );
- }
- if ( (flags & CHILDREN_COUNT_UPDATES) != 0) {
- buf.append("\n\t");
- buf.append("fChildCountUpdates = ");
- buf.append( toString(fChildCountUpdates) );
- }
- if ( (flags & CHILDREN_UPDATES) != 0) {
- buf.append("\n\t");
- buf.append("fChildrenUpdates = ");
- buf.append( toString(fChildrenUpdates) );
- }
- if ( (flags & MODEL_CHANGED_COMPLETE) != 0) {
- buf.append("\n\t");
- buf.append("fModelChangedComplete = " + fModelChangedComplete);
- }
- if ( (flags & STATE_SAVE_COMPLETE) != 0) {
- buf.append("\n\t");
- buf.append("fStateSaveComplete = " + fStateSaveComplete);
- }
- if ( (flags & STATE_RESTORE_COMPLETE) != 0) {
- buf.append("\n\t");
- buf.append("fStateRestoreComplete = " + fStateRestoreComplete);
- }
- if ( (flags & MODEL_PROXIES_INSTALLED) != 0) {
- buf.append("\n\t");
- buf.append("fProxyModels = " + fProxyModels);
- }
- if (fTimeoutInterval > 0) {
- buf.append("\n\t");
- buf.append("fTimeoutInterval = " + fTimeoutInterval);
- }
- return buf.toString();
- }
-
- private String toString(Set<TreePath> set) {
- if (set.isEmpty()) {
- return "(EMPTY)";
- }
- StringBuffer buf = new StringBuffer();
- for (Iterator<TreePath> itr = set.iterator(); itr.hasNext(); ) {
- buf.append("\n\t\t");
- buf.append(toString(itr.next()));
- }
- return buf.toString();
- }
-
- private String toString(Map<TreePath, Set<Integer>> map) {
- if (map.isEmpty()) {
- return "(EMPTY)";
- }
- StringBuffer buf = new StringBuffer();
- for (Iterator<TreePath> itr = map.keySet().iterator(); itr.hasNext(); ) {
- buf.append("\n\t\t");
- TreePath path = itr.next();
- buf.append(toString(path));
- Set<?> updates = map.get(path);
- buf.append(" = ");
- buf.append(updates.toString());
- }
- return buf.toString();
- }
-
- private String toString(TreePath path) {
- if (path.getSegmentCount() == 0) {
- return "/";
- }
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < path.getSegmentCount(); i++) {
- buf.append("/");
- buf.append(path.getSegment(i));
- }
- return buf.toString();
- }
-
- @Override
- public String toString() {
- return toString(ALL_UPDATES_COMPLETE | MODEL_CHANGED_COMPLETE | STATE_RESTORE_COMPLETE);
- }
}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMAdapter.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMAdapter.java
index 2e610714c79..90d37eb6dfb 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMAdapter.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMAdapter.java
@@ -15,7 +15,7 @@ import org.eclipse.cdt.dsf.ui.viewmodel.IVMProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
/**
- *
+ * @since 2.2
*/
public class TestModelVMAdapter extends AbstractVMAdapter {
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMNode.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMNode.java
index 959dd2d5b4b..c7f11ac9988 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMNode.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMNode.java
@@ -13,9 +13,10 @@ package org.eclipse.cdt.tests.dsf.vm;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueLabelText;
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMNode;
+import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.IRootVMNode;
-import org.eclipse.cdt.dsf.ui.viewmodel.IVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.VMDelta;
import org.eclipse.cdt.dsf.ui.viewmodel.properties.IElementPropertiesProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate;
@@ -23,6 +24,7 @@ import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelAttribute;
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelColumnInfo;
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelText;
import org.eclipse.cdt.dsf.ui.viewmodel.properties.PropertiesBasedLabelProvider;
+import org.eclipse.cdt.tests.dsf.DsfTestPlugin;
import org.eclipse.cdt.tests.dsf.vm.TestModel.TestElement;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -33,7 +35,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdat
import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
/**
- *
+ * @since 2.2
*/
public class TestModelVMNode extends AbstractVMNode implements IRootVMNode, IElementLabelProvider, IElementPropertiesProvider {
@@ -41,10 +43,16 @@ public class TestModelVMNode extends AbstractVMNode implements IRootVMNode, IEle
final private static PropertiesBasedLabelProvider fLabelProvider = new PropertiesBasedLabelProvider();
{
+ LabelColumnInfo idLabelInfo = new LabelColumnInfo(new LabelAttribute[] {
+ new LabelText("{0}", new String[] { PROP_TEST_ELEMENT_LABEL })
+ });
+
+ fLabelProvider.setColumnInfo(PropertiesBasedLabelProvider.ID_COLUMN_NO_COLUMNS, idLabelInfo);
+ fLabelProvider.setColumnInfo(TestModelCachingVMProvider.COLUMN_ID, idLabelInfo);
fLabelProvider.setColumnInfo(
- PropertiesBasedLabelProvider.ID_COLUMN_NO_COLUMNS,
- new LabelColumnInfo(new LabelAttribute[] {
- new LabelText("{0}", new String[] { PROP_TEST_ELEMENT_LABEL })
+ TestModelCachingVMProvider.COLUMN_FORMATTED_VALUE,
+ new LabelColumnInfo(new LabelAttribute[] {
+ new FormattedValueLabelText()
}));
}
@@ -52,7 +60,7 @@ public class TestModelVMNode extends AbstractVMNode implements IRootVMNode, IEle
fLabelProvider.update(updates);
}
- public TestModelVMNode(IVMProvider provider) {
+ public TestModelVMNode(AbstractVMProvider provider) {
super(provider);
}
@@ -123,7 +131,7 @@ public class TestModelVMNode extends AbstractVMNode implements IRootVMNode, IEle
}
public void createRootDelta(Object rootObject, Object event, DataRequestMonitor<VMDelta> rm) {
- rm.setStatus(new Status(IStatus.ERROR, TestDsfVMPlugin.PLUGIN_ID, IDsfStatusConstants.NOT_SUPPORTED, "Not implemented", null));
+ rm.setStatus(new Status(IStatus.ERROR, DsfTestPlugin.PLUGIN_ID, IDsfStatusConstants.NOT_SUPPORTED, "Not implemented", null));
rm.done();
}
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMProvider.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMProvider.java
index b8265593367..a53186d1b8e 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMProvider.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/TestModelVMProvider.java
@@ -19,9 +19,10 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
/**
- *
+ * @since 2.2
*/
public class TestModelVMProvider extends AbstractVMProvider {
+
public TestModelVMProvider(AbstractVMAdapter adapter, IPresentationContext context) {
super(adapter, context);
diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/VirtualViewerPerformanceTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/VirtualViewerPerformanceTests.java
index 072fa267240..91cca156730 100644
--- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/VirtualViewerPerformanceTests.java
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/vm/VirtualViewerPerformanceTests.java
@@ -17,7 +17,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
- * @since 3.6
+ * @since 2.2
*/
public class VirtualViewerPerformanceTests extends PerformanceTests {

Back to the top