/******************************************************************************* | |
* Copyright (c) 2009, 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.concurrent.TimeUnit; | |
import org.eclipse.cdt.debug.edc.internal.services.dsf.Expressions; | |
import org.eclipse.cdt.debug.edc.services.IEDCExpression; | |
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.debug.service.IExpressions; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class ExpressionsServiceInternalsTest extends SimpleDebuggerTest { | |
@Test | |
public void testBaseEDCExpressionDMCsetEvaluatedValue() throws Exception { | |
openSnapshotAndWaitForSuspendedContext(0); | |
IEDCExpression expr = TestUtils.getExpressionDMC(session, frame, "lstruct.achar"); | |
Assert.assertNotNull(expr); | |
expr.setEvaluatedValue(0); | |
expr.setEvaluatedValueString("2"); | |
} | |
@Test | |
public void testExpressionDMAddressGetLocation() throws Exception { | |
openSnapshotAndWaitForSuspendedContext(0); | |
final Expressions expressionsService = TestUtils.getService(session, Expressions.class); | |
final IExpressions.IExpressionDMContext exprDMC = expressionsService.createExpression(frame, "lstruct"); | |
Query<IExpressions.IExpressionDMAddress> query = new Query<IExpressions.IExpressionDMAddress>() { | |
@Override | |
protected void execute(final DataRequestMonitor<IExpressions.IExpressionDMAddress> drm) { | |
expressionsService.getExpressionAddressData(exprDMC, drm); | |
} | |
}; | |
session.getExecutor().execute(query); | |
IExpressions.IExpressionDMAddress exprDMAddr = query.get(2, TimeUnit.SECONDS); | |
Assert.assertTrue(query.isDone()); | |
Assert.assertTrue(exprDMAddr instanceof Expressions.ExpressionDMAddress); | |
Assert.assertEquals("0x22feb0", ((Expressions.ExpressionDMAddress)exprDMAddr).getLocation()); | |
} | |
@Test | |
public void testExpressionData() throws Exception { | |
openSnapshotAndWaitForSuspendedContext(0); | |
final Expressions expressionsService = TestUtils.getService(session, Expressions.class); | |
final IExpressions.IExpressionDMContext exprDMC = expressionsService.createExpression(frame, "lstruct"); | |
Query<IExpressions.IExpressionDMData> query = new Query<IExpressions.IExpressionDMData>() { | |
@Override | |
protected void execute(final DataRequestMonitor<IExpressions.IExpressionDMData> drm) { | |
expressionsService.getExpressionData(exprDMC, drm); | |
} | |
}; | |
session.getExecutor().execute(query); | |
IExpressions.IExpressionDMData exprDMData = query.get(2, TimeUnit.SECONDS); | |
Assert.assertTrue(query.isDone()); | |
Assert.assertTrue(exprDMData instanceof Expressions.ExpressionData); | |
// TODO Expression$ExpressionData#getEncoding() just returns null | |
Assert.assertNull(exprDMData.getEncoding()); | |
// TODO Expression$ExpressionData#getEnumerations() just returns null | |
Assert.assertNull(exprDMData.getEnumerations()); | |
Assert.assertEquals("lstruct", exprDMData.getName()); | |
// TODO Expression$ExpressionData#getRegister() just returns null | |
Assert.assertNull(exprDMData.getRegister()); | |
Assert.assertEquals(IExpressions.IExpressionDMData.TYPEID_INTEGER, exprDMData.getTypeId()); | |
Assert.assertEquals("struct struct_type", exprDMData.getTypeName()); | |
} | |
// @Test | |
// public void testGetSubExpressions() throws Exception { | |
// openSnapshotAndWaitForSuspendedContext(0); | |
// final Expressions expressionsService = TestUtils.getService(session, Expressions.class); | |
// final IExpressions.IExpressionDMContext exprDMC = expressionsService.createExpression(frame, "lstruct"); | |
// IEDCExpression expr = TestUtils.getExpressionDMC(session, frame, "lstruct"); | |
// | |
// Assert.assertEquals(exprDMC.getExpression(), expr.getExpression()); | |
// | |
// Query<IExpressions.IExpressionDMContext[]> query = new Query<IExpressions.IExpressionDMContext[]>() { | |
// @Override | |
// protected void execute(final DataRequestMonitor<IExpressions.IExpressionDMContext[]> drm) { | |
/// requires a custom type content provider, meaning a Qt or Symbian type for us with what's available | |
/// and the uncovered function is protected, so skip this _one_ uncovered method for now | |
// } | |
// }; | |
// | |
// session.getExecutor().execute(query); | |
// IExpressions.IExpressionDMContext[] baseExpressions = query.get(5, TimeUnit.SECONDS); | |
// Assert.assertNotNull(baseExpressions); | |
// } | |
/// TODO there's some sort of timing problem when calling | |
/// getExpressionValue() like this so immediately after | |
/// creating the expression with createExpression(), | |
/// and most things call getFormattedExpressionValue() | |
/// directly, with the DRM that goes with it, rather | |
/// than this getExpressionValue() . | |
/// | |
/// so ... for coverage, we'll rely on the fact that | |
/// the coverageLoadExpressionValues() below will | |
/// eventually invoke this getExpressionValue() | |
/// | |
// @Test | |
// public void testGetExpressionValue() throws Exception { | |
// openSnapshotAndWaitForSuspendedContext(0); | |
// final Expressions expressionsService = TestUtils.getService(session, Expressions.class); | |
// final IExpressions.IExpressionDMContext exprDMC = expressionsService.createExpression(frame, "lstruct.achar"); | |
// expressionsService. | |
// | |
// Assert.assertEquals("49 ('1')", expressionsService.getExpressionValue(exprDMC)); | |
// } | |
// /** | |
// * TODO method {@link Expressions$CastInfoCachedData} currently is not public | |
// * and has zero references, so is filtered out of emma coverage results | |
// */ | |
// @Test | |
// public void coverageCastInfoCachedData() { | |
// Expressions.CastInfoCachedData cache; | |
// } | |
/** | |
* TODO method {@link Expressions#getModelData} currently almost nothing | |
* except setData(new IDCExpression[0]); | |
* @throws Exception | |
*/ | |
@Test | |
public void coverageGetBaseExpressions() throws Exception { | |
openSnapshotAndWaitForSuspendedContext(0); | |
final Expressions expressionsService = TestUtils.getService(session, Expressions.class); | |
final IExpressions.IExpressionDMContext exprDMC | |
= expressionsService.createExpression(frame, "lstruct.achar"); | |
Query<IExpressions.IExpressionDMContext[]> query = new Query<IExpressions.IExpressionDMContext[]>() { | |
@Override | |
protected void execute(final DataRequestMonitor<IExpressions.IExpressionDMContext[]> drm) { | |
expressionsService.getBaseExpressions(exprDMC, drm); | |
} | |
}; | |
session.getExecutor().execute(query); | |
IExpressions.IExpressionDMContext[] baseExpressions = query.get(2, TimeUnit.SECONDS); | |
Assert.assertTrue(query.isDone()); | |
Assert.assertNotNull(baseExpressions); | |
Assert.assertEquals(0, baseExpressions.length); | |
} | |
/** | |
* TODO method {@link Expressions#getModelData} currently does nothing. | |
* @throws Exception | |
*/ | |
@Test | |
public void coverageGetModelData() throws Exception { | |
openSnapshotAndWaitForSuspendedContext(0); | |
final Expressions expressionsService = TestUtils.getService(session, Expressions.class); | |
final IExpressions.IExpressionDMContext exprDMC = expressionsService.createExpression(frame, "lstruct.achar"); | |
Query<Object> query = new Query<Object>() { | |
@Override | |
protected void execute(final DataRequestMonitor<Object> drm) { | |
expressionsService.getModelData(exprDMC, drm); | |
drm.done(); | |
} | |
}; | |
session.getExecutor().execute(query); | |
query.get(2, TimeUnit.SECONDS); | |
Assert.assertTrue(query.isDone()); | |
} | |
/** | |
* TODO this is listed as coverage only because the attempts to get the evaluated | |
* value after load were failing with null evaluated values. this is probably | |
* because the getExressionValue() inside the nested loadExpressionValues() | |
* isn't normally used, and especially not right after a createExpression() call | |
* @throws Exception | |
*/ | |
@Test | |
public void coverageLoadExpressionValues() throws Exception { | |
openSnapshotAndWaitForSuspendedContext(0); | |
Expressions expressionsService = TestUtils.getService(session, Expressions.class); | |
IExpressions.IExpressionDMContext exprDMC = expressionsService.createExpression(frame, "lstruct"); | |
Assert.assertNull(((IEDCExpression)exprDMC).getEvaluatedValue()); | |
expressionsService.loadExpressionValues(exprDMC, 3); | |
// Assert.assertNotNull("lstruct not yet evaluated after loadExpressionValues() depth 3", ((IEDCExpression)exprDMC).getEvaluatedValue()); | |
// Assert.assertEquals(TODO, ((IEDCExpression)exprDMC).getEvaluatedValue().intValue()); | |
// Assert.assertEquals("TODO", ((IEDCExpression)exprDMC).getEvaluatedValueString()); | |
// IExpressions.IExpressionDMContext subExprDMC = expressionsService.createExpression(frame, "lstruct.aulong"); | |
// Assert.assertNotNull("lstruct.aulong not yet evaluated after loadExpressionValues() depth 3", ((IEDCExpression)subExprDMC).getEvaluatedValue()); | |
// Assert.assertEquals(TODO, ((IEDCExpression)subExprDMC).getEvaluatedValue().intValue()); | |
// Assert.assertEquals("TODO", ((IEDCExpression)subExprDMC).getEvaluatedValueString()); | |
// IExpressions.IExpressionDMContext subSubExprDMC = expressionsService.createExpression(frame, "lstruct.structb.aslong"); | |
// Assert.assertNotNull("lstruct not yet evaluated after loadExpressionValues() depth 3", ((IEDCExpression)subSubExprDMC).getEvaluatedValue()); | |
// Assert.assertEquals(TODO, ((IEDCExpression)subSubExprDMC).getEvaluatedValue().intValue()); | |
// Assert.assertEquals("TODO", ((IEDCExpression)subSubExprDMC).getEvaluatedValueString()); | |
} | |
@Override | |
public String getAlbumName() { | |
return "ExpressionsAggregatesAndEnums.dsa"; | |
} | |
} |