Browse Source

Added virtual table tests.

pull/28/head
triton 12 years ago
parent
commit
e0903d8fac
  1. 32
      tests/VTables/VTables.Tests.cs
  2. 20
      tests/VTables/VTables.cpp
  3. 35
      tests/VTables/VTables.cs
  4. 16
      tests/VTables/VTables.h
  5. 2
      tests/VTables/premake4.lua

32
tests/VTables/VTables.Tests.cs

@ -0,0 +1,32 @@ @@ -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)
{
}
}

20
tests/VTables/VTables.cpp

@ -0,0 +1,20 @@ @@ -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;
}

35
tests/VTables/VTables.cs

@ -0,0 +1,35 @@ @@ -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));
}
}
}
}

16
tests/VTables/VTables.h

@ -0,0 +1,16 @@ @@ -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);

2
tests/VTables/premake4.lua

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
group "Tests/VTables"
SetupTestProject("VTables")
Loading…
Cancel
Save