mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 07:25:23 +02:00
Make MIExpressionsTest.testUpdateOfPointer use SyncUtil
Modify MIExpressionsTest.testUpdateOfPointer so that it only uses synchronous methods. There is no change of behavior intended, the test should do pretty much the same thing as before, but should be a bit more readable. One difference is that we don't need to re-create the IExpressionDMContext objects when we want to re-evaluate the expressions (after stepping the 2nd time). We can just call getExpressionValue on the again, which will trigger a -var-update. Change-Id: I09bb914b097888bf3146df0096eb9d824441ffa8 Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
This commit is contained in:
parent
277a96f7b7
commit
808df2490b
2 changed files with 58 additions and 228 deletions
|
@ -494,6 +494,32 @@ public class SyncUtil {
|
||||||
return fSession.getExecutor().submit(callable).get();
|
return fSession.getExecutor().submit(callable).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IExpressionDMContext[] getSubExpressions(final IExpressionDMContext dmc)
|
||||||
|
throws InterruptedException, ExecutionException {
|
||||||
|
Query<IExpressionDMContext[]> query = new Query<IExpressionDMContext[]>() {
|
||||||
|
@Override
|
||||||
|
protected void execute(DataRequestMonitor<IExpressionDMContext[]> rm) {
|
||||||
|
fExpressions.getSubExpressions(dmc, rm);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fSession.getExecutor().execute(query);
|
||||||
|
return query.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like getSubExpressions, but for cases where we know there will be only
|
||||||
|
* one child.
|
||||||
|
*/
|
||||||
|
public static IExpressionDMContext getSubExpression(final IExpressionDMContext dmc)
|
||||||
|
throws InterruptedException, ExecutionException {
|
||||||
|
IExpressionDMContext[] subExpressions = SyncUtil.getSubExpressions(dmc);
|
||||||
|
|
||||||
|
assertEquals(1, subExpressions.length);
|
||||||
|
|
||||||
|
return subExpressions[0];
|
||||||
|
}
|
||||||
|
|
||||||
public static String getExpressionValue(final IExpressionDMContext exprDmc, final String format)
|
public static String getExpressionValue(final IExpressionDMContext exprDmc, final String format)
|
||||||
throws Throwable {
|
throws Throwable {
|
||||||
Query<String> query = new Query<String>() {
|
Query<String> query = new Query<String>() {
|
||||||
|
|
|
@ -11,7 +11,9 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.tests.dsf.gdb.tests;
|
package org.eclipse.cdt.tests.dsf.gdb.tests;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
@ -2579,240 +2581,42 @@ public class MIExpressionsTest extends BaseParametrizedTestCase {
|
||||||
public void testUpdateOfPointer() throws Throwable {
|
public void testUpdateOfPointer() throws Throwable {
|
||||||
SyncUtil.runToLocation("testUpdateOfPointer");
|
SyncUtil.runToLocation("testUpdateOfPointer");
|
||||||
MIStoppedEvent stoppedEvent = SyncUtil.step(3, StepType.STEP_OVER);
|
MIStoppedEvent stoppedEvent = SyncUtil.step(3, StepType.STEP_OVER);
|
||||||
final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
|
IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
|
||||||
|
|
||||||
final String firstValue = "1";
|
/* Create expression for the structure. */
|
||||||
final String secondValue = "2";
|
IExpressionDMContext structDmc = SyncUtil.createExpression(frameDmc, "z");
|
||||||
final String thirdValue = "3";
|
|
||||||
|
|
||||||
final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();
|
/* Create sub-expressions for the structure field. */
|
||||||
|
IExpressionDMContext[] fieldsDmc = SyncUtil.getSubExpressions(structDmc);
|
||||||
|
assertThat(fieldsDmc.length, is(2));
|
||||||
|
|
||||||
fExpService.getExecutor().submit(new Runnable() {
|
/* Get the value of the integer. */
|
||||||
@Override
|
String integerValue = SyncUtil.getExpressionValue(fieldsDmc[0], IFormattedValues.NATURAL_FORMAT);
|
||||||
public void run() {
|
assertThat(integerValue, is("1"));
|
||||||
|
|
||||||
IExpressionDMContext parentDmc = fExpService.createExpression(frameDmc, "z");
|
/* Get the value of the integer pointer. */
|
||||||
|
String pointerFirstValue = SyncUtil.getExpressionValue(fieldsDmc[1], IFormattedValues.NATURAL_FORMAT);
|
||||||
|
|
||||||
fExpService.getSubExpressions(
|
/* Get the value pointed by the pointer field. */
|
||||||
parentDmc,
|
IExpressionDMContext pointeeDmc = SyncUtil.getSubExpression(fieldsDmc[1]);
|
||||||
new DataRequestMonitor<IExpressionDMContext[]>(fExpService.getExecutor(), null) {
|
String pointeeActualValue = SyncUtil.getExpressionValue(pointeeDmc, IFormattedValues.NATURAL_FORMAT);
|
||||||
@Override
|
assertThat(pointeeActualValue, is("1"));
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().length != 2) {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed getting children; expecting 2 got " + getData().length, null));
|
|
||||||
} else {
|
|
||||||
// check that we have the proper value for both children
|
|
||||||
globalExpressionCtx1 = getData()[0];
|
|
||||||
globalExpressionCtx2 = getData()[1];
|
|
||||||
|
|
||||||
// Get the value of the first child
|
/* Now, step to change the values of all the children. */
|
||||||
wait.increment();
|
SyncUtil.step(2, StepType.STEP_OVER);
|
||||||
fExpService.getFormattedExpressionValue(
|
|
||||||
fExpService.getFormattedValueContext(globalExpressionCtx1, IFormattedValues.NATURAL_FORMAT),
|
|
||||||
new DataRequestMonitor<FormattedValueDMData>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().getFormattedValue().equals(firstValue)) {
|
|
||||||
wait.waitFinished();
|
|
||||||
} else {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed evaluating " + globalExpressionCtx1.getExpression() + ", got " + getData().getFormattedValue()
|
|
||||||
+ " instead of " + firstValue, null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get the value of the second child
|
/* Get the value of the integer. */
|
||||||
wait.increment();
|
integerValue = SyncUtil.getExpressionValue(fieldsDmc[0], IFormattedValues.NATURAL_FORMAT);
|
||||||
fExpService.getFormattedExpressionValue(
|
assertThat(integerValue, is("2"));
|
||||||
fExpService.getFormattedValueContext(globalExpressionCtx2, IFormattedValues.NATURAL_FORMAT),
|
|
||||||
new DataRequestMonitor<FormattedValueDMData>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else {
|
|
||||||
wait.setReturnInfo(getData().getFormattedValue());
|
|
||||||
wait.waitFinished();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
|
/* Get the value of the integer pointer. It should have changed from
|
||||||
assertTrue(wait.getMessage(), wait.isOK());
|
last time. */
|
||||||
final String pointerValue = (String)wait.getReturnInfo();
|
String pointerSecondValue = SyncUtil.getExpressionValue(fieldsDmc[1], IFormattedValues.NATURAL_FORMAT);
|
||||||
wait.waitReset();
|
assertThat(pointerSecondValue, is(not(equalTo(pointerFirstValue))));
|
||||||
|
|
||||||
fExpService.getExecutor().submit(new Runnable() {
|
/* Get the value pointed by the pointer field. */
|
||||||
@Override
|
pointeeActualValue = SyncUtil.getExpressionValue(pointeeDmc, IFormattedValues.NATURAL_FORMAT);
|
||||||
public void run() {
|
assertThat(pointeeActualValue, is("3"));
|
||||||
|
|
||||||
// also get the child of the pointer
|
|
||||||
fExpService.getSubExpressions(
|
|
||||||
globalExpressionCtx2,
|
|
||||||
new DataRequestMonitor<IExpressionDMContext[]>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().length != 1) {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed getting children; expecting 1 got " + getData().length, null));
|
|
||||||
} else {
|
|
||||||
// Get the value of the child of the pointer
|
|
||||||
globalExpressionCtx2 = getData()[0];
|
|
||||||
fExpService.getFormattedExpressionValue(
|
|
||||||
fExpService.getFormattedValueContext(globalExpressionCtx2, IFormattedValues.NATURAL_FORMAT),
|
|
||||||
new DataRequestMonitor<FormattedValueDMData>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().getFormattedValue().equals(firstValue)) {
|
|
||||||
wait.waitFinished();
|
|
||||||
} else {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed evaluating " + globalExpressionCtx2.getExpression() + ", got " + getData().getFormattedValue()
|
|
||||||
+ " instead of " + firstValue, null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
|
|
||||||
assertTrue(wait.getMessage(), wait.isOK());
|
|
||||||
wait.waitReset();
|
|
||||||
|
|
||||||
// Now step to change the values of all the children
|
|
||||||
stoppedEvent = SyncUtil.step(2, StepType.STEP_OVER);
|
|
||||||
final IFrameDMContext frameDmc2 = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
|
|
||||||
|
|
||||||
fExpService.getExecutor().submit(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
IExpressionDMContext parentDmc = fExpService.createExpression(frameDmc2, "z");
|
|
||||||
|
|
||||||
fExpService.getSubExpressions(
|
|
||||||
parentDmc,
|
|
||||||
new DataRequestMonitor<IExpressionDMContext[]>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().length != 2) {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed getting children; expecting 2 got " + getData().length, null));
|
|
||||||
} else {
|
|
||||||
// check that we have the proper value for both children
|
|
||||||
globalExpressionCtx1 = getData()[0];
|
|
||||||
globalExpressionCtx2 = getData()[1];
|
|
||||||
|
|
||||||
// Get the value of the first child
|
|
||||||
wait.increment();
|
|
||||||
fExpService.getFormattedExpressionValue(
|
|
||||||
fExpService.getFormattedValueContext(globalExpressionCtx1, IFormattedValues.NATURAL_FORMAT),
|
|
||||||
new DataRequestMonitor<FormattedValueDMData>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().getFormattedValue().equals(secondValue)) {
|
|
||||||
wait.waitFinished();
|
|
||||||
} else {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed evaluating " + globalExpressionCtx1.getExpression() + ", got " + getData().getFormattedValue()
|
|
||||||
+ " instead of " + secondValue, null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get the value of the second child
|
|
||||||
wait.increment();
|
|
||||||
fExpService.getFormattedExpressionValue(
|
|
||||||
fExpService.getFormattedValueContext(globalExpressionCtx2, IFormattedValues.NATURAL_FORMAT),
|
|
||||||
new DataRequestMonitor<FormattedValueDMData>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (!getData().getFormattedValue().equals(pointerValue)) {
|
|
||||||
// The value should have changed
|
|
||||||
wait.waitFinished();
|
|
||||||
} else {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed evaluating " + globalExpressionCtx2.getExpression() + ", got " + getData().getFormattedValue()
|
|
||||||
+ " instead of some other value", null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
|
|
||||||
assertTrue(wait.getMessage(), wait.isOK());
|
|
||||||
wait.waitReset();
|
|
||||||
|
|
||||||
fExpService.getExecutor().submit(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
// also get the child of the pointer
|
|
||||||
fExpService.getSubExpressions(
|
|
||||||
globalExpressionCtx2,
|
|
||||||
new DataRequestMonitor<IExpressionDMContext[]>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().length != 1) {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed getting children; expecting 1 got " + getData().length, null));
|
|
||||||
} else {
|
|
||||||
// Get the value of the child of the pointer
|
|
||||||
globalExpressionCtx2 = getData()[0];
|
|
||||||
fExpService.getFormattedExpressionValue(
|
|
||||||
fExpService.getFormattedValueContext(globalExpressionCtx2, IFormattedValues.NATURAL_FORMAT),
|
|
||||||
new DataRequestMonitor<FormattedValueDMData>(fExpService.getExecutor(), null) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
if (!isSuccess()) {
|
|
||||||
wait.waitFinished(getStatus());
|
|
||||||
} else if (getData().getFormattedValue().equals(thirdValue)) {
|
|
||||||
wait.waitFinished();
|
|
||||||
} else {
|
|
||||||
wait.waitFinished(new Status(IStatus.ERROR, TestsPlugin.PLUGIN_ID,
|
|
||||||
"Failed evaluating " + globalExpressionCtx2.getExpression() + ", got " + getData().getFormattedValue()
|
|
||||||
+ " instead of " + thirdValue, null));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
|
|
||||||
assertTrue(wait.getMessage(), wait.isOK());
|
|
||||||
wait.waitReset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue