1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Use line tags in MIExpressionsTest.testUpdateOfPointer

Running to different points of the test program using line tags is
easier and safer than stepping a certain number of times.  Since I want
to modify this test to add a pointer-behind-typedef test, I thought it
would be good to first convert it to line tags.

I also took the liberty of giving more meaningful names to the structure
fields, even though it doesn't change anything in the test.

Change-Id: Ife7e2ae8557789dfc7403df71ba5126ca84b80e0
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
This commit is contained in:
Simon Marchi 2017-01-27 22:22:36 -05:00 committed by Marc Khouzam
parent 808df2490b
commit e14b87a88f
2 changed files with 31 additions and 13 deletions

View file

@ -283,18 +283,23 @@ int testConcurrentUpdateOutOfScopeChildThenParent() {
int testUpdateOfPointer() { int testUpdateOfPointer() {
struct { struct {
int a; int value;
int* b; int* ptr;
}z; } z;
int c = 3; int otherValue = 3;
z.b = &(z.a); z.ptr = &z.value;
z.a = 1; z.value = 1;
z.b = &c; /* testUpdateOfPointer_1 */
z.a = 2;
z.a = 2; // this redundant line is here to ensure 6 steps after running to this func leaves locals visible z.ptr = &otherValue;
z.value = 2;
/* testUpdateOfPointer_2 */
return 0;
} }
int testCanWrite() { int testCanWrite() {

View file

@ -70,6 +70,7 @@ import org.junit.runners.Parameterized;
@RunWith(Parameterized.class) @RunWith(Parameterized.class)
public class MIExpressionsTest extends BaseParametrizedTestCase { public class MIExpressionsTest extends BaseParametrizedTestCase {
private static final String EXEC_NAME = "ExpressionTestApp.exe"; private static final String EXEC_NAME = "ExpressionTestApp.exe";
private static final String SOURCE_NAME = "ExpressionTestApp.cc";
private DsfSession fSession; private DsfSession fSession;
@ -91,10 +92,19 @@ public class MIExpressionsTest extends BaseParametrizedTestCase {
setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EXEC_PATH + EXEC_NAME); setLaunchAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EXEC_PATH + EXEC_NAME);
} }
/* Line tags in the source file. */
private static final String[] LINE_TAGS = new String[] {
"testUpdateOfPointer_1",
"testUpdateOfPointer_2",
};
@Override @Override
public void doBeforeTest() throws Exception { public void doBeforeTest() throws Exception {
super.doBeforeTest(); super.doBeforeTest();
/* Resolve line tags in source file. */
resolveLineTagLocations(SOURCE_NAME, LINE_TAGS);
fSession = getGDBLaunch().getSession(); fSession = getGDBLaunch().getSession();
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@Override @Override
@ -2579,8 +2589,11 @@ public class MIExpressionsTest extends BaseParametrizedTestCase {
*/ */
@Test @Test
public void testUpdateOfPointer() throws Throwable { public void testUpdateOfPointer() throws Throwable {
SyncUtil.runToLocation("testUpdateOfPointer"); /* Places we're going to run to. */
MIStoppedEvent stoppedEvent = SyncUtil.step(3, StepType.STEP_OVER); String tag1 = String.format("%s:%d", SOURCE_NAME, getLineForTag("testUpdateOfPointer_1"));
String tag2 = String.format("%s:%d", SOURCE_NAME, getLineForTag("testUpdateOfPointer_2"));
MIStoppedEvent stoppedEvent = SyncUtil.runToLocation(tag1);
IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0); IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
/* Create expression for the structure. */ /* Create expression for the structure. */
@ -2602,8 +2615,8 @@ public class MIExpressionsTest extends BaseParametrizedTestCase {
String pointeeActualValue = SyncUtil.getExpressionValue(pointeeDmc, IFormattedValues.NATURAL_FORMAT); String pointeeActualValue = SyncUtil.getExpressionValue(pointeeDmc, IFormattedValues.NATURAL_FORMAT);
assertThat(pointeeActualValue, is("1")); assertThat(pointeeActualValue, is("1"));
/* Now, step to change the values of all the children. */ /* Run to the second tag. */
SyncUtil.step(2, StepType.STEP_OVER); SyncUtil.runToLocation(tag2);
/* Get the value of the integer. */ /* Get the value of the integer. */
integerValue = SyncUtil.getExpressionValue(fieldsDmc[0], IFormattedValues.NATURAL_FORMAT); integerValue = SyncUtil.getExpressionValue(fieldsDmc[0], IFormattedValues.NATURAL_FORMAT);