Skip to content

Commit

Permalink
call by value test code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Anderegg committed Nov 22, 2022
1 parent 54a6fb0 commit 57f6046
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
12 changes: 6 additions & 6 deletions tests/CSharp/CSharp.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,17 +1986,17 @@ public void TestCallByValueCppToCSharpPointer()
}

[Test]
public void TestObjectPassByValue1451()
public void TestCallByValueCopyConstructor()
{
using (var s = new Issue1451())
using (var s = new CallByValueCopyConstructor())
{
s.A = 500;
Assert.IsTrue(CSharp.CSharp.TestObjectPassByValue(s));
CSharp.CSharp.CallByValueCopyConstructorFunction(s);
Assert.That(s.A, Is.EqualTo(500));
}

Assert.That(Issue1451.ConstructorCalls, Is.EqualTo(1));
Assert.That(Issue1451.CopyConstructorCalls, Is.EqualTo(1));
Assert.That(Issue1451.DestructorCalls, Is.EqualTo(2));
Assert.That(CallByValueCopyConstructor.ConstructorCalls, Is.EqualTo(1));
Assert.That(CallByValueCopyConstructor.CopyConstructorCalls, Is.EqualTo(1));
Assert.That(CallByValueCopyConstructor.DestructorCalls, Is.EqualTo(2));
}
}
15 changes: 7 additions & 8 deletions tests/CSharp/CSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1751,29 +1751,28 @@ void CallCallByValueInterfacePointer(CallByValueInterface* interface)
interface->CallByPointer(&value);
}

int Issue1451::constructorCalls = 0;
int Issue1451::destructorCalls = 0;
int Issue1451::copyConstructorCalls = 0;
int CallByValueCopyConstructor::constructorCalls = 0;
int CallByValueCopyConstructor::destructorCalls = 0;
int CallByValueCopyConstructor::copyConstructorCalls = 0;

Issue1451::Issue1451()
CallByValueCopyConstructor::CallByValueCopyConstructor()
{
a = 0;
constructorCalls++;
}

Issue1451::Issue1451(const Issue1451& other)
CallByValueCopyConstructor::CallByValueCopyConstructor(const CallByValueCopyConstructor& other)
{
a = other.a;
copyConstructorCalls++;
}

Issue1451::~Issue1451()
CallByValueCopyConstructor::~CallByValueCopyConstructor()
{
destructorCalls++;
}

bool TestObjectPassByValue(Issue1451 s)
void CallByValueCopyConstructorFunction(CallByValueCopyConstructor s)
{
s.a = 99999;
return true;
}
10 changes: 5 additions & 5 deletions tests/CSharp/CSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1583,15 +1583,15 @@ void DLL_API CallCallByValueInterfaceValue(CallByValueInterface*);
void DLL_API CallCallByValueInterfaceReference(CallByValueInterface*);
void DLL_API CallCallByValueInterfacePointer(CallByValueInterface*);

struct DLL_API Issue1451 {
struct DLL_API CallByValueCopyConstructor {
int a;
static int constructorCalls;
static int destructorCalls;
static int copyConstructorCalls;

Issue1451();
~Issue1451();
Issue1451(const Issue1451& other);
CallByValueCopyConstructor();
~CallByValueCopyConstructor();
CallByValueCopyConstructor(const CallByValueCopyConstructor& other);
};

bool DLL_API TestObjectPassByValue(Issue1451 s);
DLL_API void CallByValueCopyConstructorFunction(CallByValueCopyConstructor s);

0 comments on commit 57f6046

Please sign in to comment.