Add failing virtual dispatch tests

This commit is contained in:
Alex Corrado 2011-06-14 00:10:36 -04:00
Родитель 515b3c7295
Коммит 601ef7f28f
2 изменённых файлов: 46 добавлений и 2 удалений

Просмотреть файл

@ -35,6 +35,7 @@ class ClassWithNonVirtualBases : public AdderClass, public MultiplierClass {
public:
// num is not shared between AdderClass and MultiplierClass; Add and Multiply should operate on different numbers
ClassWithNonVirtualBases (int addN, int multN) : AdderClass (addN), MultiplierClass (multN) {}
virtual void CallMultiply (int n) { this->Multiply (n); }
};
class ClassWithVirtualBases : public AdderClassWithVirtualBase, public MultiplierClassWithVirtualBase {
public:

Просмотреть файл

@ -25,7 +25,6 @@ namespace Tests {
}
[Test]
[Ignore ("virtual inheritance not implemented yet")]
public void TestVirtualCallOnVirtualBaseClass ()
{
var cls = new AdderClassWithVirtualBase (8);
@ -52,7 +51,6 @@ namespace Tests {
}
[Test]
[Ignore ("virtual inheritance not implemented yet")]
public void TestMultipleVirtualBases ()
{
var cls = new ClassWithVirtualBases (4);
@ -78,6 +76,51 @@ namespace Tests {
Assert.AreEqual (5, cls.BaseNumber, "#4");
}
class ManagedOverride1 : NumberClass {
public ManagedOverride1 () : base (3)
{
}
public override int Number {
get {
return 25;
}
}
}
[Test]
public void TestManagedOverride1 ()
{
var cls = new ManagedOverride1 ();
Assert.AreEqual (-25, cls.NegativeNumber, "#1");
}
class ManagedOverride2 : ClassWithNonVirtualBases {
public ManagedOverride2 () : base (5, 3)
{
}
// override virtual member inherited from non-primary base
public override void Multiply (int n)
{
this.MultiplierClass.Multiply (10);
}
}
[Test]
public void TestManagedOverride2 ()
{
var cls = new ManagedOverride2 ();
cls.Multiply (3);
Assert.AreEqual (5, cls.Number, "#1");
Assert.AreEqual (30, ((MultiplierClass)cls).Number, "#2");
cls.CallMultiply (2);
Assert.AreEqual (5, cls.Number, "#3");
Assert.AreEqual (300, ((MultiplierClass)cls).Number, "#4");
}
}
}