From 51fa468cfa40e8053c4fa4426a098c2fcefe7425 Mon Sep 17 00:00:00 2001 From: Tom Spilman Date: Wed, 28 May 2014 20:27:44 -0500 Subject: [PATCH] Added unit test for in/out for primitive parameters. --- tests/Basic/Basic.Tests.cs | 20 ++++++++++++++++++++ tests/Basic/Basic.cpp | 12 ++++++++++++ tests/Basic/Basic.cs | 2 ++ tests/Basic/Basic.h | 3 +++ tests/Tests.h | 3 ++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/Basic/Basic.Tests.cs b/tests/Basic/Basic.Tests.cs index dcf25e84..aa3df3b7 100644 --- a/tests/Basic/Basic.Tests.cs +++ b/tests/Basic/Basic.Tests.cs @@ -77,6 +77,26 @@ public class BasicTests : GeneratorTestFixture Assert.That(f, Is.EqualTo(10.0f)); } + [Test] + public void TestPrimitiveInOutParameters() + { + var hello = new Hello(); + + int i = 10; + Assert.That(hello.TestPrimitiveInOut(ref i), Is.True); + Assert.That(i, Is.EqualTo(20)); + } + + [Test] + public void TestPrimitiveInOutRefParameters() + { + var hello = new Hello(); + + int i = 10; + Assert.That(hello.TestPrimitiveInOutRef(ref i), Is.True); + Assert.That(i, Is.EqualTo(20)); + } + [Test] public void TestNullRef() { diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index 48547de4..90e9d7d3 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -169,6 +169,18 @@ bool Hello::TestPrimitiveOutRef(CS_OUT float& f) return true; } +bool Hello::TestPrimitiveInOut(CS_IN_OUT int* i) +{ + *i += 10; + return true; +} + +bool Hello::TestPrimitiveInOutRef(CS_IN_OUT int& i) +{ + i += 10; + return true; +} + int unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int)) { return ret.A; diff --git a/tests/Basic/Basic.cs b/tests/Basic/Basic.cs index fbf14581..f5dd6e32 100644 --- a/tests/Basic/Basic.cs +++ b/tests/Basic/Basic.cs @@ -31,6 +31,8 @@ namespace CppSharp.Tests ctx.SetClassAsValueType("Bar2"); ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOut", 1, ParameterUsage.Out); ctx.SetMethodParameterUsage("Hello", "TestPrimitiveOutRef", 1, ParameterUsage.Out); + ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOut", 1, ParameterUsage.InOut); + ctx.SetMethodParameterUsage("Hello", "TestPrimitiveInOutRef", 1, ParameterUsage.InOut); } public static void Main(string[] args) diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index cebe6778..4e93f3b7 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -123,6 +123,9 @@ public: bool TestPrimitiveOut(CS_OUT float* f); bool TestPrimitiveOutRef(CS_OUT float& f); + + bool TestPrimitiveInOut(CS_IN_OUT int* i); + bool TestPrimitiveInOutRef(CS_IN_OUT int& i); }; class DLL_API AbstractFoo diff --git a/tests/Tests.h b/tests/Tests.h index 1b493c67..1c2cbaf2 100644 --- a/tests/Tests.h +++ b/tests/Tests.h @@ -22,4 +22,5 @@ #endif #endif -#define CS_OUT \ No newline at end of file +#define CS_OUT +#define CS_IN_OUT \ No newline at end of file