Browse Source

Fixed CLI getter/setter property generation (with tests).

pull/224/head
triton 11 years ago
parent
commit
9c07283ff0
  1. 7
      src/Generator/Generators/CLI/CLISourcesTemplate.cs
  2. 20
      tests/Basic/Basic.Tests.cs
  3. 2
      tests/Basic/Basic.cs
  4. 10
      tests/Basic/Basic.h

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

@ -348,8 +348,11 @@ namespace CppSharp.Generators.CLI @@ -348,8 +348,11 @@ namespace CppSharp.Generators.CLI
var args = new List<string>();
if (isIndexer)
args.Add("int index");
args.Add(string.Format("{0} value", type));
args.Add("int index");
var function = decl as Function;
var argName = function != null ? function.Parameters[0].Name : "value";
args.Add(string.Format("{0} {1}", type, argName));
WriteLine("void {0}::{1}::set({2})", QualifiedIdentifier(@class),
name, string.Join(", ", args));

20
tests/Basic/Basic.Tests.cs

@ -94,7 +94,7 @@ public class BasicTests : GeneratorTestFixture @@ -94,7 +94,7 @@ public class BasicTests : GeneratorTestFixture
public void TestAbstractReturnType()
{
var returnsAbstractFoo = new ReturnsAbstractFoo();
var abstractFoo = returnsAbstractFoo.getFoo();
var abstractFoo = returnsAbstractFoo.Foo;
Assert.AreEqual(abstractFoo.pureFunction(1), 5);
Assert.AreEqual(abstractFoo.pureFunction1(), 10);
Assert.AreEqual(abstractFoo.pureFunction2(), 15);
@ -104,7 +104,7 @@ public class BasicTests : GeneratorTestFixture @@ -104,7 +104,7 @@ public class BasicTests : GeneratorTestFixture
public void TestANSI()
{
var foo = new Foo();
Assert.That(foo.GetANSI(), Is.EqualTo("ANSI"));
Assert.That(foo.ANSI, Is.EqualTo("ANSI"));
}
[Test]
@ -241,5 +241,21 @@ public class BasicTests : GeneratorTestFixture @@ -241,5 +241,21 @@ public class BasicTests : GeneratorTestFixture
var ret = Basic.basic.Function();
Assert.That(ret, Is.EqualTo(5));
}
[Test]
public void TestProperties()
{
// Test field property
var prop = new TestProperties();
Assert.That(prop.Field, Is.EqualTo(0));
prop.Field = 10;
Assert.That(prop.Field, Is.EqualTo(10));
// Test getter/setter property
prop.Field = 20;
Assert.That(prop.FieldValue, Is.EqualTo(20));
prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10));
}
}

2
tests/Basic/Basic.cs

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
using CppSharp.Utils;
namespace CppSharp.Tests
@ -22,6 +23,7 @@ namespace CppSharp.Tests @@ -22,6 +23,7 @@ namespace CppSharp.Tests
public override void Preprocess(Driver driver, ASTContext ctx)
{
driver.AddTranslationUnitPass(new GetterSetterToPropertyPass());
ctx.SetClassAsValueType("Bar");
ctx.SetClassAsValueType("Bar2");
ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOut", 1, ParameterUsage.Out);

10
tests/Basic/Basic.h

@ -340,3 +340,13 @@ DLL_API int Function() @@ -340,3 +340,13 @@ DLL_API int Function()
{
return 5;
}
// Tests properties
struct DLL_API TestProperties
{
TestProperties() : Field(0) {}
int Field;
int getFieldValue() { return Field; }
void setFieldValue(int Value) { Field = Value; }
};

Loading…
Cancel
Save