Browse Source

Fixed the getting of values mapped to enums, from pointers.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/658/head
Dimitar Dobrev 9 years ago
parent
commit
f7707629ef
  1. 18
      tests/CSharp/CSharp.Tests.cs
  2. 19
      tests/CSharp/CSharp.cpp
  3. 32
      tests/CSharp/CSharp.cs
  4. 10
      tests/CSharp/CSharp.h

18
tests/CSharp/CSharp.Tests.cs

@ -505,6 +505,16 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.IsTrue(VirtualDtorAddedInDerived.DtorCalled); Assert.IsTrue(VirtualDtorAddedInDerived.DtorCalled);
} }
[Test]
public void TestGetEnumFromNativePointer()
{
using (var getEnumFromNativePointer = new GetEnumFromNativePointer())
{
Assert.That(UsesPointerToEnumInParamOfVirtual.CallOverrideOfHasPointerToEnumInParam(
getEnumFromNativePointer, Flags.Flag3), Is.EqualTo(Flags.Flag3));
}
}
// HACK: the completion of types is temporarily suspended because of problems with QtWidgets // HACK: the completion of types is temporarily suspended because of problems with QtWidgets
[Test, Ignore] [Test, Ignore]
public void TestTemplateInternals() public void TestTemplateInternals()
@ -539,4 +549,12 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.That(fieldOffsetValue.Value, Is.EqualTo(Marshal.SizeOf(IntPtr.Zero))); Assert.That(fieldOffsetValue.Value, Is.EqualTo(Marshal.SizeOf(IntPtr.Zero)));
} }
} }
private class GetEnumFromNativePointer : UsesPointerToEnumInParamOfVirtual
{
public override Flags HasPointerToEnumInParam(Flags pointerToEnum)
{
return base.HasPointerToEnumInParam(pointerToEnum);
}
}
} }

19
tests/CSharp/CSharp.cpp

@ -350,6 +350,25 @@ TestCopyConstructorVal::TestCopyConstructorVal(const TestCopyConstructorVal& oth
B = other.B; B = other.B;
} }
UsesPointerToEnumInParamOfVirtual::UsesPointerToEnumInParamOfVirtual()
{
}
UsesPointerToEnumInParamOfVirtual::~UsesPointerToEnumInParamOfVirtual()
{
}
QFlags<Flags> UsesPointerToEnumInParamOfVirtual::hasPointerToEnumInParam(const QFlags<Flags>& pointerToEnum) const
{
return pointerToEnum;
}
QFlags<Flags> UsesPointerToEnumInParamOfVirtual::callOverrideOfHasPointerToEnumInParam(
const UsesPointerToEnumInParamOfVirtual* object, const QFlags<Flags>& pointerToEnum)
{
return object->hasPointerToEnumInParam(pointerToEnum);
}
Flags operator|(Flags lhs, Flags rhs) Flags operator|(Flags lhs, Flags rhs)
{ {
return static_cast<Flags>(static_cast<int>(lhs) | static_cast<int>(rhs)); return static_cast<Flags>(static_cast<int>(lhs) | static_cast<int>(rhs));

32
tests/CSharp/CSharp.cs

@ -21,14 +21,7 @@ namespace CppSharp.Tests
public override Type CSharpSignatureType(CSharpTypePrinterContext ctx) public override Type CSharpSignatureType(CSharpTypePrinterContext ctx)
{ {
var type = ctx.Type.Desugar(); return GetEnumType(ctx.Type);
ClassTemplateSpecialization classTemplateSpecialization;
var templateSpecializationType = type as TemplateSpecializationType;
if (templateSpecializationType != null)
classTemplateSpecialization = templateSpecializationType.GetClassTemplateSpecialization();
else
classTemplateSpecialization = (ClassTemplateSpecialization) ((TagType) type).Declaration;
return classTemplateSpecialization.Arguments[0].Type.Type;
} }
public override string CSharpSignature(CSharpTypePrinterContext ctx) public override string CSharpSignature(CSharpTypePrinterContext ctx)
@ -38,18 +31,39 @@ namespace CppSharp.Tests
public override void CSharpMarshalToNative(MarshalContext ctx) public override void CSharpMarshalToNative(MarshalContext ctx)
{ {
if (ctx.Parameter.Type.IsAddress()) if (ctx.Parameter.Type.Desugar().IsAddress())
ctx.Return.Write("new global::System.IntPtr(&{0})", ctx.Parameter.Name); ctx.Return.Write("new global::System.IntPtr(&{0})", ctx.Parameter.Name);
else else
ctx.Return.Write(ctx.Parameter.Name); ctx.Return.Write(ctx.Parameter.Name);
} }
public override void CSharpMarshalToManaged(MarshalContext ctx) public override void CSharpMarshalToManaged(MarshalContext ctx)
{
if (ctx.ReturnType.Type.Desugar().IsAddress())
{
var finalType = ctx.ReturnType.Type.GetFinalPointee() ?? ctx.ReturnType.Type;
var enumType = GetEnumType(finalType);
ctx.Return.Write("*({0}*) {1}", enumType, ctx.ReturnVarName);
}
else
{ {
ctx.Return.Write(ctx.ReturnVarName); ctx.Return.Write(ctx.ReturnVarName);
} }
} }
private static Type GetEnumType(Type mappedType)
{
var type = mappedType.Desugar();
ClassTemplateSpecialization classTemplateSpecialization;
var templateSpecializationType = type as TemplateSpecializationType;
if (templateSpecializationType != null)
classTemplateSpecialization = templateSpecializationType.GetClassTemplateSpecialization();
else
classTemplateSpecialization = (ClassTemplateSpecialization) ((TagType) type).Declaration;
return classTemplateSpecialization.Arguments[0].Type.Type;
}
}
[TypeMap("QList")] [TypeMap("QList")]
public class QList : TypeMap public class QList : TypeMap
{ {

10
tests/CSharp/CSharp.h

@ -267,6 +267,16 @@ enum class Flags
Flag3 = 4 Flag3 = 4
}; };
class DLL_API UsesPointerToEnumInParamOfVirtual
{
public:
UsesPointerToEnumInParamOfVirtual();
virtual ~UsesPointerToEnumInParamOfVirtual();
virtual QFlags<Flags> hasPointerToEnumInParam(const QFlags<Flags>& pointerToEnum) const;
static QFlags<Flags> callOverrideOfHasPointerToEnumInParam(
const UsesPointerToEnumInParamOfVirtual* object, const QFlags<Flags>& pointerToEnum);
};
DLL_API Flags operator|(Flags lhs, Flags rhs); DLL_API Flags operator|(Flags lhs, Flags rhs);
enum UntypedFlags enum UntypedFlags

Loading…
Cancel
Save