Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Marchi2017-01-27 16:39:27 -0500
committerMarc Khouzam2017-03-06 10:44:14 -0500
commit808df2490bc97661df61739b7e178c285b7cdd4f (patch)
tree8f5f1c33b4ae92c05f27a27833ae0b205983f315 /dsf-gdb
parent277a96f7b762fe3e18abed7bb9d7caf299ac251f (diff)
downloadorg.eclipse.cdt-808df2490bc97661df61739b7e178c285b7cdd4f.tar.gz
org.eclipse.cdt-808df2490bc97661df61739b7e178c285b7cdd4f.tar.xz
org.eclipse.cdt-808df2490bc97661df61739b7e178c285b7cdd4f.zip
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>
Diffstat (limited to 'dsf-gdb')
-rw-r--r--dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java26
-rw-r--r--dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java260
2 files changed, 58 insertions, 228 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java
index c6a61a4b2a..4c441f15c3 100644
--- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java
+++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/framework/SyncUtil.java
@@ -494,6 +494,32 @@ public class SyncUtil {
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)
throws Throwable {
Query<String> query = new Query<String>() {
diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java
index de9d816596..64407ed909 100644
--- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java
+++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIExpressionsTest.java
@@ -11,7 +11,9 @@
*******************************************************************************/
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.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -2577,244 +2579,46 @@ public class MIExpressionsTest extends BaseParametrizedTestCase {
*/
@Test
public void testUpdateOfPointer() throws Throwable {
- SyncUtil.runToLocation("testUpdateOfPointer");
- MIStoppedEvent stoppedEvent = SyncUtil.step(3, StepType.STEP_OVER);
- final IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
-
- final String firstValue = "1";
- final String secondValue = "2";
- final String thirdValue = "3";
-
- final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();
-
- fExpService.getExecutor().submit(new Runnable() {
- @Override
- public void run() {
-
- IExpressionDMContext parentDmc = fExpService.createExpression(frameDmc, "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(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
- 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 {
- wait.setReturnInfo(getData().getFormattedValue());
- wait.waitFinished();
- }
- }
- });
- }
- }
- });
- }
- });
-
- wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
- assertTrue(wait.getMessage(), wait.isOK());
- final String pointerValue = (String)wait.getReturnInfo();
- wait.waitReset();
+ SyncUtil.runToLocation("testUpdateOfPointer");
+ MIStoppedEvent stoppedEvent = SyncUtil.step(3, StepType.STEP_OVER);
+ IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
- fExpService.getExecutor().submit(new Runnable() {
- @Override
- public void run() {
+ /* Create expression for the structure. */
+ IExpressionDMContext structDmc = SyncUtil.createExpression(frameDmc, "z");
- // 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));
- }
- }
- });
- }
- }
- });
- }
- });
+ /* Create sub-expressions for the structure field. */
+ IExpressionDMContext[] fieldsDmc = SyncUtil.getSubExpressions(structDmc);
+ assertThat(fieldsDmc.length, is(2));
- 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");
+ /* Get the value of the integer. */
+ String integerValue = SyncUtil.getExpressionValue(fieldsDmc[0], IFormattedValues.NATURAL_FORMAT);
+ assertThat(integerValue, is("1"));
- 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 integer pointer. */
+ String pointerFirstValue = SyncUtil.getExpressionValue(fieldsDmc[1], IFormattedValues.NATURAL_FORMAT);
- // 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));
- }
- }
- });
- }
- }
- });
- }
- });
+ /* Get the value pointed by the pointer field. */
+ IExpressionDMContext pointeeDmc = SyncUtil.getSubExpression(fieldsDmc[1]);
+ String pointeeActualValue = SyncUtil.getExpressionValue(pointeeDmc, IFormattedValues.NATURAL_FORMAT);
+ assertThat(pointeeActualValue, is("1"));
- wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
- assertTrue(wait.getMessage(), wait.isOK());
- wait.waitReset();
+ /* Now, step to change the values of all the children. */
+ SyncUtil.step(2, StepType.STEP_OVER);
- fExpService.getExecutor().submit(new Runnable() {
- @Override
- public void run() {
+ /* Get the value of the integer. */
+ integerValue = SyncUtil.getExpressionValue(fieldsDmc[0], IFormattedValues.NATURAL_FORMAT);
+ assertThat(integerValue, is("2"));
- // 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));
- }
- }
- });
- }
- }
- });
- }
- });
+ /* Get the value of the integer pointer. It should have changed from
+ last time. */
+ String pointerSecondValue = SyncUtil.getExpressionValue(fieldsDmc[1], IFormattedValues.NATURAL_FORMAT);
+ assertThat(pointerSecondValue, is(not(equalTo(pointerFirstValue))));
- wait.waitUntilDone(AsyncCompletionWaitor.WAIT_FOREVER);
- assertTrue(wait.getMessage(), wait.isOK());
- wait.waitReset();
+ /* Get the value pointed by the pointer field. */
+ pointeeActualValue = SyncUtil.getExpressionValue(pointeeDmc, IFormattedValues.NATURAL_FORMAT);
+ assertThat(pointeeActualValue, is("3"));
}
-
+
/**
* This test verifies that we properly return if we can write to different expressions
*/

Back to the top