Permalink
Browse files

Added virtual table tests.

  • Loading branch information...
1 parent d9eb2f5 commit e0903d8fac303cc95e1af9b3c96b89cb04c7061c @tritao committed Aug 12, 2013
Showing with 105 additions and 0 deletions.
  1. +32 −0 tests/VTables/VTables.Tests.cs
  2. +20 −0 tests/VTables/VTables.cpp
  3. +35 −0 tests/VTables/VTables.cs
  4. +16 −0 tests/VTables/VTables.h
  5. +2 −0 tests/VTables/premake4.lua
@@ -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)
+ {
+ }
+}
View
@@ -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;
+}
View
@@ -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));
+ }
+ }
+ }
+}
View
@@ -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);
@@ -0,0 +1,2 @@
+group "Tests/VTables"
+ SetupTestProject("VTables")

0 comments on commit e0903d8

Please sign in to comment.