Browse Source

Fixed a regression of overridden setters not turning into properties.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/838/merge
Dimitar Dobrev 8 years ago
parent
commit
9f4d501d0b
  1. 3
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  2. 10
      tests/Common/Common.Tests.cs
  3. 33
      tests/Common/Common.cpp
  4. 14
      tests/Common/Common.h

3
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -85,7 +85,8 @@ namespace CppSharp.Passes @@ -85,7 +85,8 @@ namespace CppSharp.Passes
if (!type.IsInterface && baseProperty != null && baseProperty.IsVirtual && setter.IsVirtual)
{
bool isReadOnly = baseProperty.SetMethod == null;
GenerateProperty(setter.Namespace, baseProperty.GetMethod,
var name = GetReadWritePropertyName(baseProperty.GetMethod, afterSet);
GenerateProperty(name, setter.Namespace, baseProperty.GetMethod,
readOnly || isReadOnly ? null : setter);
}
next:

10
tests/Common/Common.Tests.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Reflection;
using CommonTest;
using CppSharp.Utils;
using NUnit.Framework;
@ -775,4 +776,13 @@ This is a very long string. This is a very long string. This is a very long stri @@ -775,4 +776,13 @@ This is a very long string. This is a very long string. This is a very long stri
Assert.That(VirtFuncWithStringParam.VirtualFunctionWithStringParam("anyRandomString").Equals(5));
}
}
[Test]
public void TestOverriddenSetter()
{
var propertyInfo = typeof(HasOverridenSetter).GetProperty("Virtual",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
Assert.That(propertyInfo, Is.Not.Null);
Assert.That(propertyInfo.CanWrite);
}
}

33
tests/Common/Common.cpp

@ -489,6 +489,37 @@ std::string& HasStdString::getStdString() @@ -489,6 +489,37 @@ std::string& HasStdString::getStdString()
return s;
}
TestProperties::TestProperties() : Field(0)
{
}
int TestProperties::getFieldValue()
{
return Field;
}
void TestProperties::setFieldValue(int Value)
{
Field = Value;
}
bool TestProperties::isVirtual()
{
return false;
}
void TestProperties::setVirtual(bool value)
{
}
HasOverridenSetter::HasOverridenSetter()
{
}
void HasOverridenSetter::setVirtual(bool value)
{
}
TypeMappedIndex::TypeMappedIndex()
{
}
@ -780,4 +811,4 @@ void ImplementsVirtualFunctionsWithStringParams::PureVirtualFunctionWithStringPa @@ -780,4 +811,4 @@ void ImplementsVirtualFunctionsWithStringParams::PureVirtualFunctionWithStringPa
int HasVirtualFunctionsWithStringParams::VirtualFunctionWithStringParam(std::string testString)
{
return 5;
}
}

14
tests/Common/Common.h

@ -578,13 +578,19 @@ public: @@ -578,13 +578,19 @@ public:
int getFieldValue();
void setFieldValue(int Value);
bool isVirtual();
virtual void setVirtual(bool value);
private:
int FieldValue;
};
TestProperties::TestProperties() : Field(0) {}
int TestProperties::getFieldValue() { return Field; }
void TestProperties::setFieldValue(int Value) { Field = Value; }
class DLL_API HasOverridenSetter : public TestProperties
{
public:
HasOverridenSetter();
void setVirtual(bool value);
};
class DLL_API TypeMappedIndex
{
@ -1297,4 +1303,4 @@ public: @@ -1297,4 +1303,4 @@ public:
ImplementsVirtualFunctionsWithStringParams();
~ImplementsVirtualFunctionsWithStringParams();
virtual void PureVirtualFunctionWithStringParams(std::string testString);
};
};

Loading…
Cancel
Save