Add failing virtual dispatch tests
This commit is contained in:
Родитель
515b3c7295
Коммит
601ef7f28f
|
@ -35,6 +35,7 @@ class ClassWithNonVirtualBases : public AdderClass, public MultiplierClass {
|
||||||
public:
|
public:
|
||||||
// num is not shared between AdderClass and MultiplierClass; Add and Multiply should operate on different numbers
|
// 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) {}
|
ClassWithNonVirtualBases (int addN, int multN) : AdderClass (addN), MultiplierClass (multN) {}
|
||||||
|
virtual void CallMultiply (int n) { this->Multiply (n); }
|
||||||
};
|
};
|
||||||
class ClassWithVirtualBases : public AdderClassWithVirtualBase, public MultiplierClassWithVirtualBase {
|
class ClassWithVirtualBases : public AdderClassWithVirtualBase, public MultiplierClassWithVirtualBase {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -25,7 +25,6 @@ namespace Tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore ("virtual inheritance not implemented yet")]
|
|
||||||
public void TestVirtualCallOnVirtualBaseClass ()
|
public void TestVirtualCallOnVirtualBaseClass ()
|
||||||
{
|
{
|
||||||
var cls = new AdderClassWithVirtualBase (8);
|
var cls = new AdderClassWithVirtualBase (8);
|
||||||
|
@ -52,7 +51,6 @@ namespace Tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore ("virtual inheritance not implemented yet")]
|
|
||||||
public void TestMultipleVirtualBases ()
|
public void TestMultipleVirtualBases ()
|
||||||
{
|
{
|
||||||
var cls = new ClassWithVirtualBases (4);
|
var cls = new ClassWithVirtualBases (4);
|
||||||
|
@ -78,6 +76,51 @@ namespace Tests {
|
||||||
Assert.AreEqual (5, cls.BaseNumber, "#4");
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче