From 7817b52ce3a79d7f2f99fd3b92ce0a864e8da32e Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 15 Jan 2019 01:42:55 +0200 Subject: [PATCH] Tested indirect calls from native code of overrides in the target language. Signed-off-by: Dimitar Dobrev --- tests/CSharp/CSharp.Tests.cs | 21 +++++++++++++++++++++ tests/CSharp/CSharp.cpp | 36 ++++++++++++++++++++++++++++++++++++ tests/CSharp/CSharp.h | 25 +++++++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index cd9fb01209..d2d64a605f 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -1217,6 +1217,27 @@ public void TestHasFixedArrayOfPointers() } } + [Test] + public void TestVirtualIndirectCallInNative() + { + using (Inter i = new Inter()) + { + using (InterfaceTester tester = new InterfaceTester()) + { + tester.SetInterface(i); + Assert.That(tester.Get(10), Is.EqualTo(IntPtr.Zero)); + } + } + } + + public class Inter : SimpleInterface + { + public override int Size => s; + public override int Capacity => s; + public override IntPtr Get(int n) { return new IntPtr(0); } + private int s = 0; + } + private class OverrideVirtualTemplate : VirtualTemplate { public override int Function diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 77bbb2f77e..85752135a2 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -1495,3 +1495,39 @@ HasFixedArrayOfPointers::HasFixedArrayOfPointers() HasFixedArrayOfPointers::~HasFixedArrayOfPointers() { } + +SimpleInterface::SimpleInterface() +{ +} + +SimpleInterface::~SimpleInterface() +{ +} + +InterfaceTester::InterfaceTester() : interface(0) +{ +} + +InterfaceTester::~InterfaceTester() +{ +} + +int InterfaceTester::capacity() +{ + return interface->capacity(); +} + +int InterfaceTester::size() +{ + return interface->size(); +} + +void* InterfaceTester::get(int n) +{ + return interface->get(n); +} + +void InterfaceTester::setInterface(SimpleInterface* i) +{ + interface = i; +} diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index fddda75598..119c3f1ba2 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -1262,3 +1262,28 @@ struct DLL_API CSharp }; static int FOOBAR_CONSTANT = 42; + + + +class DLL_API SimpleInterface +{ +public: + SimpleInterface(); + ~SimpleInterface(); + virtual int size() const = 0; + virtual int capacity() const = 0; + virtual void* get(int n) = 0; +}; + +class DLL_API InterfaceTester +{ +public: + InterfaceTester(); + ~InterfaceTester(); + int capacity(); + int size(); + void* get(int n); + void setInterface(SimpleInterface* i); +private: + SimpleInterface* interface; +};