1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +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() {
struct {
int a;
int* b;
int value;
int* ptr;
} z;
int c = 3;
int otherValue = 3;
z.b = &(z.a);
z.a = 1;
z.ptr = &z.value;
z.value = 1;
z.b = &c;
z.a = 2;
z.a = 2; // this redundant line is here to ensure 6 steps after running to this func leaves locals visible
/* testUpdateOfPointer_1 */
z.ptr = &otherValue;
z.value = 2;
/* testUpdateOfPointer_2 */
return 0;
}
int testCanWrite() {

View file

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