From e0903d8fac303cc95e1af9b3c96b89cb04c7061c Mon Sep 17 00:00:00 2001 From: triton Date: Mon, 12 Aug 2013 16:56:28 +0100 Subject: [PATCH] Added virtual table tests. --- tests/VTables/VTables.Tests.cs | 32 +++++++++++++++++++++++++++++++ tests/VTables/VTables.cpp | 20 +++++++++++++++++++ tests/VTables/VTables.cs | 35 ++++++++++++++++++++++++++++++++++ tests/VTables/VTables.h | 16 ++++++++++++++++ tests/VTables/premake4.lua | 2 ++ 5 files changed, 105 insertions(+) create mode 100644 tests/VTables/VTables.Tests.cs create mode 100644 tests/VTables/VTables.cpp create mode 100644 tests/VTables/VTables.cs create mode 100644 tests/VTables/VTables.h create mode 100644 tests/VTables/premake4.lua diff --git a/tests/VTables/VTables.Tests.cs b/tests/VTables/VTables.Tests.cs new file mode 100644 index 00000000..67bc3d15 --- /dev/null +++ b/tests/VTables/VTables.Tests.cs @@ -0,0 +1,32 @@ +using System; +using NUnit.Framework; +using VTables; + +public class FooDerived : Foo +{ + public override int Vfoo() + { + Console.WriteLine("Hello from FooDerived"); + return 10; + } +} + +[TestFixture] +public class VTablesTests +{ + [Test] + public void TestFoo() + { + var foo = new Foo(); + Assert.That(foo.Vfoo(), Is.EqualTo(5)); + Assert.That(foo.Vbar(), Is.EqualTo(3)); + Assert.That(foo.CallFoo(), Is.EqualTo(7)); + + var foo2 = new FooDerived(); + Assert.That(foo2.CallFoo(), Is.EqualTo(12)); + } + + static void Main(string[] args) + { + } +} diff --git a/tests/VTables/VTables.cpp b/tests/VTables/VTables.cpp new file mode 100644 index 00000000..6d3a6a96 --- /dev/null +++ b/tests/VTables/VTables.cpp @@ -0,0 +1,20 @@ +#include "VTables.h" + +Foo::Foo() +{ +} + +int Foo::vfoo() +{ + return 5; +} + +int Foo::vbar() +{ + return 3; +} + +int FooCallFoo(Foo* foo) +{ + return foo->vfoo() + 2; +} \ No newline at end of file diff --git a/tests/VTables/VTables.cs b/tests/VTables/VTables.cs new file mode 100644 index 00000000..7413da80 --- /dev/null +++ b/tests/VTables/VTables.cs @@ -0,0 +1,35 @@ +using CppSharp.AST; +using CppSharp.Generators; +using CppSharp.Passes; +using CppSharp.Utils; + +namespace CppSharp.Tests +{ + public class VTableTests : LibraryTest + { + public VTableTests(LanguageGeneratorKind kind) + : base("VTables", kind) + { + } + + public override void SetupPasses(Driver driver) + { + driver.TranslationUnitPasses.RenameDeclsUpperCase(RenameTargets.Any); + driver.TranslationUnitPasses.AddPass(new FunctionToInstanceMethodPass()); + } + + public override void Preprocess(Driver driver, Library lib) + { + + } + + static class Program + { + public static void Main(string[] args) + { + ConsoleDriver.Run(new VTableTests(LanguageGeneratorKind.CPlusPlusCLI)); + ConsoleDriver.Run(new VTableTests(LanguageGeneratorKind.CSharp)); + } + } + } +} diff --git a/tests/VTables/VTables.h b/tests/VTables/VTables.h new file mode 100644 index 00000000..1d66f211 --- /dev/null +++ b/tests/VTables/VTables.h @@ -0,0 +1,16 @@ +#if defined(_MSC_VER) +#define DLL_API __declspec(dllexport) +#else +#define DLL_API +#endif + +class DLL_API Foo +{ +public: + + Foo(); + virtual int vfoo(); + virtual int vbar(); +}; + +DLL_API int FooCallFoo(Foo* foo); diff --git a/tests/VTables/premake4.lua b/tests/VTables/premake4.lua new file mode 100644 index 00000000..486ef156 --- /dev/null +++ b/tests/VTables/premake4.lua @@ -0,0 +1,2 @@ +group "Tests/VTables" + SetupTestProject("VTables") \ No newline at end of file