1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 376901: JUnit tests for RTTI feature

Change-Id: Id72d0d170b8f78201a36d1f95da5ca7a3d07cfa5
Reviewed-on: https://git.eclipse.org/r/5868
Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com>
Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
Marc Khouzam 2012-05-07 16:08:09 -04:00
parent caf06d61a3
commit cfff2b91fb
3 changed files with 171 additions and 4 deletions

View file

@ -303,6 +303,44 @@ int testArrays() {
return 1;
}
// For bug 376901 RTTI tests
class VirtualBase {
public:
virtual ~VirtualBase() {} // Necessary to force RTTI generation for the base class
int a;
private:
bool b;
};
class Derived: public VirtualBase {
public:
int c;
VirtualBase* ptr;
private:
bool d;
int e[4];
};
class OtherDerived: public VirtualBase {
public:
int d;
private:
bool c;
int f[4];
};
int testRTTI() {
Derived derived;
Derived child1;
OtherDerived child2;
derived.ptr = &child1; // here derived.b is of type bar
derived.ptr = &child2; // here derived.b is of type foo
return 1; // here derived.b is of type Derived
}
// End of bug 376901 RTTI tests
int main() {
printf("Running ExpressionTest App\n");
@ -328,6 +366,7 @@ int main() {
testUpdateOfPointer();
testCanWrite();
testArrays();
testRTTI();
// For bug 320277
BaseTest b; b.test();

View file

@ -11,14 +11,18 @@
package org.eclipse.cdt.tests.dsf.gdb.tests;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.ImmediateDataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.service.IExpressions;
@ -3238,7 +3242,7 @@ public class MIExpressionsTest extends BaseTestCase {
}
// This method tests IExspressions.getSubExpressions(IExpressionDMC, DRM);
private IExpressionDMContext[] getChildren(
protected IExpressionDMContext[] getChildren(
final IExpressionDMContext parentDmc,
String[] expectedValues) throws Throwable {
@ -3288,7 +3292,7 @@ public class MIExpressionsTest extends BaseTestCase {
}
// This method tests IExpressions.getSubExpressions(IExpressionDMC, int, int, DRM);
private IExpressionDMContext[] getChildren(
protected IExpressionDMContext[] getChildren(
final IExpressionDMContext parentDmc,
final int startIndex,
final int length,
@ -3522,8 +3526,49 @@ public class MIExpressionsTest extends BaseTestCase {
getChildren(arrayDoubleSmallChildExprDMC, 3, 2, new String[] { "array_double_small[3][3]", "array_double_small[3][4]" });
getChildren(arrayDoubleSmallChildExprDMC, 19, 3, new String[] { "array_double_small[3][19]","array_double_small[3][20]" });
}
/**
* This test verifies that there is no RTTI support before GDB 7.5.
*/
@Test
public void testRTTI() throws Throwable {
SyncUtil.runToLocation("testRTTI");
MIStoppedEvent stoppedEvent = SyncUtil.step(3, StepType.STEP_OVER);
IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
// The expression we will follow as it changes types: derived.ptr
IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "derived.ptr");
// Now, the expression should be type VirtualBase
getExpressionType(exprDmc, "VirtualBase *");
getChildrenCount(exprDmc, 2);
// get all children
String[] expectedValues = new String[2];
expectedValues[0] = "a";
expectedValues[1] = "b";
getChildren(exprDmc, expectedValues);
// Make the type of our expression change
SyncUtil.step(1, StepType.STEP_OVER);
// Now, the expression should be type Derived, but GDB < 7.5 does not tell us
// so we should still get the base type.
getExpressionType(exprDmc, "VirtualBase *");
getChildrenCount(exprDmc, 2);
// The children are also the same as before
getChildren(exprDmc, expectedValues);
// Make the type of our expression change
SyncUtil.step(1, StepType.STEP_OVER);
// Now, the expression should be type OtherDerived, but GDB < 7.5 does not tell us
// so we should still get the base type.
getExpressionType(exprDmc, "VirtualBase *");
getChildrenCount(exprDmc, 2);
// The children are also the same as before
getChildren(exprDmc, expectedValues);
}
private int getChildrenCount(final IExpressionDMContext parentDmc, final int expectedCount) throws Throwable {
protected int getChildrenCount(final IExpressionDMContext parentDmc, final int expectedCount) throws Throwable {
final AsyncCompletionWaitor wait = new AsyncCompletionWaitor();
@ -3569,4 +3614,31 @@ public class MIExpressionsTest extends BaseTestCase {
return count;
}
protected String getExpressionType(final IExpressionDMContext exprDmc, final String expectedType) throws Throwable {
Query<String> query = new Query<String>() {
@Override
protected void execute(final DataRequestMonitor<String> rm) {
fExpService.getExecutor().submit(new Runnable() {
@Override
public void run() {
fExpService.getExpressionData(
exprDmc,
new ImmediateDataRequestMonitor<IExpressionDMData>(rm) {
@Override
protected void handleCompleted() {
rm.done(getData().getTypeName());
}
});
}
});
}
};
fSession.getExecutor().execute(query);
String type = query.get(500, TimeUnit.MILLISECONDS);
assertEquals(expectedType, type);
return type;
}
}

View file

@ -10,10 +10,16 @@
*******************************************************************************/
package org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_5;
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
import org.eclipse.cdt.dsf.debug.service.IRunControl.StepType;
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext;
import org.eclipse.cdt.dsf.mi.service.command.events.MIStoppedEvent;
import org.eclipse.cdt.tests.dsf.gdb.framework.BackgroundRunner;
import org.eclipse.cdt.tests.dsf.gdb.framework.SyncUtil;
import org.eclipse.cdt.tests.dsf.gdb.tests.ITestConstants;
import org.eclipse.cdt.tests.dsf.gdb.tests.tests_7_4.MIExpressionsTest_7_4;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(BackgroundRunner.class)
@ -21,5 +27,55 @@ public class MIExpressionsTest_7_5 extends MIExpressionsTest_7_4 {
@BeforeClass
public static void beforeClassMethod_7_5() {
setGdbProgramNamesLaunchAttributes(ITestConstants.SUFFIX_GDB_7_5);
}
}
/**
* This test verifies that there is proper RTTI support starting with GDB 7.5.
*/
@Override
@Test
public void testRTTI() throws Throwable {
SyncUtil.runToLocation("testRTTI");
MIStoppedEvent stoppedEvent = SyncUtil.step(3, StepType.STEP_OVER);
IFrameDMContext frameDmc = SyncUtil.getStackFrame(stoppedEvent.getDMContext(), 0);
// The expression we will follow as it changes types: derived.ptr
IExpressionDMContext exprDmc = SyncUtil.createExpression(frameDmc, "derived.ptr");
// Now, the expression should be type VirtualBase
getExpressionType(exprDmc, "VirtualBase *");
getChildrenCount(exprDmc, 2);
// get all children
String[] expectedValues = new String[2];
expectedValues[0] = "a";
expectedValues[1] = "b";
getChildren(exprDmc, expectedValues);
// Make the type of our expression change
SyncUtil.step(1, StepType.STEP_OVER);
// Now, the expression should be type Derived
getExpressionType(exprDmc, "Derived *");
getChildrenCount(exprDmc, 5);
// get all children
expectedValues = new String[5];
expectedValues[0] = "VirtualBase";
expectedValues[1] = "c";
expectedValues[2] = "ptr";
expectedValues[3] = "d";
expectedValues[4] = "e";
getChildren(exprDmc, expectedValues);
// Make the type of our expression change
SyncUtil.step(1, StepType.STEP_OVER);
// Now, the expression should be type OtherDerived
getExpressionType(exprDmc, "OtherDerived *");
getChildrenCount(exprDmc, 4);
// get all children
expectedValues = new String[4];
expectedValues[0] = "VirtualBase";
expectedValues[1] = "d";
expectedValues[2] = "c";
expectedValues[3] = "f";
getChildren(exprDmc, expectedValues);
}
}