Browse Source

Fixed delegate generation regression and added some tests.

pull/144/head
triton 12 years ago
parent
commit
3a74428f94
  1. 7
      src/Generator/Generators/CLI/CLIHeadersTemplate.cs
  2. 8
      tests/Basic/Basic.Tests.cs
  3. 14
      tests/Basic/Basic.h

7
src/Generator/Generators/CLI/CLIHeadersTemplate.cs

@ -615,12 +615,15 @@ namespace CppSharp.Generators.CLI
return false; return false;
FunctionType function; FunctionType function;
if (typedef.Type.IsPointerTo<FunctionType>(out function)) if (typedef.Type.IsPointerTo(out function))
{ {
PushBlock(CLIBlockKind.Typedef, typedef); PushBlock(CLIBlockKind.Typedef, typedef);
GenerateDeclarationCommon(typedef); GenerateDeclarationCommon(typedef);
WriteLine("{0};", var insideClass = typedef.Namespace is Class;
WriteLine("{0}{1};",
!insideClass ? "public " : "",
string.Format(TypePrinter.VisitDelegate(function), string.Format(TypePrinter.VisitDelegate(function),
SafeIdentifier(typedef.Name))); SafeIdentifier(typedef.Name)));
PopBlock(NewLineKind.BeforeNextBlock); PopBlock(NewLineKind.BeforeNextBlock);

8
tests/Basic/Basic.Tests.cs

@ -151,5 +151,13 @@ public class BasicTests
Assert.AreEqual(300, new Bar2.Nested()); Assert.AreEqual(300, new Bar2.Nested());
Assert.AreEqual(500, new Bar2()); Assert.AreEqual(500, new Bar2());
} }
[Test]
public void TestDelegates()
{
var delegates = new TestDelegates();
var doubleSum = delegates.A(2) + delegates.B(2);
Assert.AreEqual(8, doubleSum);
}
} }

14
tests/Basic/Basic.h

@ -120,7 +120,6 @@ public:
virtual int pureFunction(int i) = 0; virtual int pureFunction(int i) = 0;
virtual int pureFunction1() = 0; virtual int pureFunction1() = 0;
virtual int pureFunction2() = 0; virtual int pureFunction2() = 0;
typedef void (*QTextStreamFunction)(int &);
}; };
class DLL_API ImplementsAbstractFoo : public AbstractFoo class DLL_API ImplementsAbstractFoo : public AbstractFoo
@ -194,3 +193,16 @@ class DLL_API basic
DLL_API int test(basic& s); DLL_API int test(basic& s);
// Tests delegates
typedef int (*DelegateInGlobalNamespace)(int);
struct DLL_API TestDelegates
{
typedef int (*DelegateInClass)(int);
TestDelegates() : A(Double), B(Double) {}
static int Double(int N) { return N * 2; }
DelegateInClass A;
DelegateInGlobalNamespace B;
};

Loading…
Cancel
Save