Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 76f2aef2721dd862a02ba3efe86a3903ea02c98b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*******************************************************************************
 * Copyright (c) 2008, 2015 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() {
            @Override
	    public void modelChanged(IModelDelta delta, IModelProxy proxy) {
                delta.accept(new IModelDeltaVisitor() {
                    @Override
		    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 = 
            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));
        
    }
}

Back to the top