blob: 109eb3e2c1546ef787511fecc9121b0cf1bd3bd3 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010 Nokia 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:
* Nokia - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.debug.edc.debugger.tests;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.debug.edc.internal.EDCDebugger;
import org.eclipse.cdt.debug.edc.internal.services.dsf.Breakpoints;
import org.eclipse.cdt.debug.edc.services.EDCServicesTracker;
import org.eclipse.cdt.debug.edc.tests.EDCTestPlugin;
import org.eclipse.cdt.debug.edc.tests.TestReflectionHelper;
import org.eclipse.cdt.debug.edc.tests.TestUtils;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.model.ISourceLocator;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test that we can recover expressions from stack frames other than the TOS
*/
public class BreakpointsServiceTest {
private static final String dbg_derived_types_cpp
= "C:\\myprog\\BlackFlagWascana\\src\\dbg_derived_types.cpp"; //$NON-NLS-1$
private static Breakpoints breakpointsService;
private static IBreakpoints.IBreakpointDMContext testUserBreakpoint;
private static IBreakpoints.IBreakpointsTargetDMContext breakDMC;
private static BaseLaunchTest simpleLaunch;
@BeforeClass
public static void setUpClass() throws Exception {
simpleLaunch = new BaseLaunchTest() {
@Override
protected String getExeFileName() {
// This is the executable built by Cygwin gcc 3.4.4
// All source files are built from this folder:
// "C:\\myprog\\BlackFlagWascana\\src\\"
// Note we don't need any source file to perform the test.
//
// used because the locations of certain line numbers are known,
// not because there's no hardcoded break
return "BlackFlagMinGW_NoHardcodedBreak.exe"; //$NON-NLS-1$
}
@Override
protected boolean getStopAtMain() {
return true;
}
};
simpleLaunch.basicLaunch();
EDCServicesTracker edcTracker
= new EDCServicesTracker(
EDCDebugger.getBundleContext(), simpleLaunch.session.getId());
Assert.assertNotNull(edcTracker);
breakpointsService = edcTracker.getService(Breakpoints.class);
Assert.assertNotNull(breakpointsService);
breakDMC = DMContexts.getAncestorOfType(simpleLaunch.threadDMC, IBreakpoints.IBreakpointsTargetDMContext.class);
testUserBreakpoint = simpleLaunch.setUserBreakpoint(breakpointsService, dbg_derived_types_cpp, 57);
Assert.assertNotNull(testUserBreakpoint);
}
@AfterClass
public static void shutdown() {
TestUtils.shutdownDebugSession(simpleLaunch.launch, simpleLaunch.session);
breakDMC = null;
breakpointsService = null;
testUserBreakpoint = null;
simpleLaunch = null;
}
@Test
public void testBreakpointDMContextToString() {
Assert.assertTrue(testUserBreakpoint.toString().startsWith("BreakpointDMContext [id="));
}
@Test
public void testGetBreakpointDMData() throws Exception {
Query<IBreakpoints.IBreakpointDMData> query = new Query<IBreakpoints.IBreakpointDMData>() {
@Override
protected void execute(final DataRequestMonitor<IBreakpoints.IBreakpointDMData> drm) {
breakpointsService.getBreakpointDMData(testUserBreakpoint, drm);
}
};
simpleLaunch.session.getExecutor().execute(query);
IBreakpoints.IBreakpointDMData dmData = query.get(3, TimeUnit.SECONDS);
Assert.assertTrue(query.isDone());
Assert.assertTrue(dmData instanceof Breakpoints.BreakpointDMData);
Breakpoints.BreakpointDMData breakData = (Breakpoints.BreakpointDMData)dmData;
IAddress testUserBreakpointAddress = simpleLaunch.waitGetLineAddress(dbg_derived_types_cpp, 57);
Assert.assertTrue(dmData.equals(breakpointsService.findBreakpoint(testUserBreakpointAddress)));
Assert.assertEquals(testUserBreakpointAddress, breakData.getAddresses()[0]);
Assert.assertEquals(Breakpoints.BREAKPOINT, breakData.getBreakpointType());
Assert.assertEquals("", breakData.getCondition());
Assert.assertSame(testUserBreakpoint, breakData.getContext());
Assert.assertNull(breakData.getExpression());
Assert.assertEquals(dbg_derived_types_cpp, breakData.getFileName());
Assert.assertNull(breakData.getFunctionName());
Assert.assertFalse(-1 == breakData.getID()); // yuck, a coverage call
Assert.assertEquals(0, breakData.getIgnoreCount());
Assert.assertEquals(57, breakData.getLineNumber());
if (! breakpointsService.usesTCFBreakpointService())
Assert.assertNotNull(breakData.getOriginalInstruction());
else
Assert.assertNull(breakData.getOriginalInstruction());
Assert.assertEquals(dmData.hashCode(), breakData.hashCode());
Assert.assertTrue(breakData.isEnabled());
breakData.incrementHitCount();
Assert.assertEquals(1, breakData.getHitCount());
Map<String, Object> props = breakData.getProperties();
props.put("BreakpointServiceTestKey", "BreakpointsServiceTestValue");
breakData.setProperties(props);
Assert.assertEquals(props, breakData.getProperties());
}
@Test
public void testGetBreakpoints() throws Exception {
Query<IBreakpoints.IBreakpointDMContext[]> query = new Query<IBreakpoints.IBreakpointDMContext[]>() {
@Override
protected void execute(final DataRequestMonitor<IBreakpoints.IBreakpointDMContext[]> drm) {
breakpointsService.getBreakpoints(breakDMC, drm);
}
};
simpleLaunch.session.getExecutor().execute(query);
IBreakpoints.IBreakpointDMContext[] userBreakpoints
= query.get(3, TimeUnit.SECONDS);
Assert.assertTrue(query.isDone());
Assert.assertEquals(1, userBreakpoints.length);
Assert.assertSame(testUserBreakpoint, userBreakpoints[0]);
}
/**
* TODO coverage test only
* - Breakpoints#addBreakpointProblemMarker() isn't yet properly set up to
* to create a problem marker for something that's not a platform breakpoint
* @throws Exception
*/
@Test
public void coverageAddBreakpointProblemMarker() throws Exception {
final Object[] args
= new Object[] {testUserBreakpoint, "Test problem marker", IMarker.SEVERITY_INFO};
final Class<?>[] argClasses
= new Class<?>[] { IBreakpoints.IBreakpointDMContext.class, String.class, int.class };
Query<Boolean> query = new Query<Boolean>() {
@Override
protected void execute(final DataRequestMonitor<Boolean> drm) {
try {
TestReflectionHelper.objectFromPrivateFunctionWithArgs(
breakpointsService, "addBreakpointProblemMarker",
args, argClasses);
} catch (Exception e) {
drm.setStatus(new Status(IStatus.ERROR, EDCTestPlugin.PLUGIN_ID,
"exception thrown invoking Breakpoints#addBreakpointProblemMarker()"//$NON-NLS-1$
+ e.getLocalizedMessage()));
}
drm.done();
}
};
simpleLaunch.session.getExecutor().execute(query);
query.get(3, TimeUnit.SECONDS);
Assert.assertTrue(query.isDone());
}
/**
* TODO coverage test only
* - just see if it's the expected class on top for now
* @throws Exception
*/
@Test
public void coverageGetSourceLocator() {
ISourceLocator sourceLocator = breakpointsService.getSourceLocator();
Assert.assertEquals("class org.eclipse.cdt.dsf.debug.sourcelookup.DsfSourceLookupDirector",
sourceLocator.getClass().toString());
}
/**
* TODO coverage test only
* - this does a little work, but it's really only a coverage test,
* the breakpoint really hasn't been updated, and even if the
* event is propagated, this test isn't equipped to tell how
* @throws Exception
*/
@Test
public void coverageBreakpointsBreakpointUpdatedEvent() {
Breakpoints.BreakpointUpdatedEvent breakUpdated
= breakpointsService.new BreakpointUpdatedEvent(testUserBreakpoint);
IBreakpoints.IBreakpointDMContext[] eventBreakpoints = breakUpdated.getBreakpoints();
Assert.assertEquals(1, eventBreakpoints.length);
Assert.assertSame(testUserBreakpoint, eventBreakpoints[0]);
Assert.assertSame(breakDMC, breakUpdated.getDMContext());
}
/**
* TODO coverage test only
* - this does a little work, but it's really only a coverage test,
* the breakpoint really hasn't been removed, and even if the
* event is propagated, this test isn't equipped to tell how
* @throws Exception
*/
@Test
public void coverageBreakpointsBreakpointRemovedEvent() {
Breakpoints.BreakpointRemovedEvent breakRemoved
= breakpointsService.new BreakpointRemovedEvent(testUserBreakpoint);
IBreakpoints.IBreakpointDMContext[] eventBreakpoints = breakRemoved.getBreakpoints();
Assert.assertEquals(1, eventBreakpoints.length);
Assert.assertSame(testUserBreakpoint, eventBreakpoints[0]);
Assert.assertSame(breakDMC, breakRemoved.getDMContext());
}
}