Skip to content

Commit 4454a50

Browse files
committed
Update testing framework for C#
Merge duplicate code under a new class CXXMethodDeclarationCSharpTest
1 parent 9812081 commit 4454a50

File tree

11 files changed

+597
-4303
lines changed

11 files changed

+597
-4303
lines changed

tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationCSharpTest.cs

Lines changed: 579 additions & 0 deletions
Large diffs are not rendered by default.

tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationTest.cs

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public abstract class CXXMethodDeclarationTest : PInvokeGeneratorTest
2525
[Test]
2626
public Task InstanceTest() => InstanceTestImpl();
2727

28+
[Test]
29+
public Task MacrosExpansionTest() => MacrosExpansionTestImpl();
30+
2831
[Test]
2932
public Task MemberCallTest() => MemberCallTestImpl();
3033

@@ -64,46 +67,6 @@ public abstract class CXXMethodDeclarationTest : PInvokeGeneratorTest
6467
[Test]
6568
public Task VirtualWithVtblIndexAttributeTest() => VirtualWithVtblIndexAttributeTestImpl();
6669

67-
[Test]
68-
public virtual Task MacrosExpansionTest()
69-
{
70-
var inputContents = @"typedef struct
71-
{
72-
unsigned char *buf;
73-
int size;
74-
} context_t;
75-
76-
int buf_close(void *pContext)
77-
{
78-
((context_t*)pContext)->buf=0;
79-
return 0;
80-
}
81-
";
82-
83-
var expectedOutputContents = @"namespace ClangSharp.Test
84-
{
85-
public unsafe partial struct context_t
86-
{
87-
[NativeTypeName(""unsigned char *"")]
88-
public byte* buf;
89-
90-
public int size;
91-
}
92-
93-
public static unsafe partial class Methods
94-
{
95-
public static int buf_close(void* pContext)
96-
{
97-
((context_t*)(pContext))->buf = null;
98-
return 0;
99-
}
100-
}
101-
}
102-
";
103-
104-
return ValidateBindingsAsync(inputContents, expectedOutputContents);
105-
}
106-
10770
protected abstract Task ConstructorTestImpl();
10871

10972
protected abstract Task ConstructorWithInitializeTestImpl();
@@ -116,6 +79,8 @@ public static int buf_close(void* pContext)
11679

11780
protected abstract Task InstanceTestImpl();
11881

82+
protected abstract Task MacrosExpansionTestImpl();
83+
11984
protected abstract Task MemberCallTestImpl();
12085

12186
protected abstract Task MemberTestImpl();

tests/ClangSharp.PInvokeGenerator.UnitTests/Base/CXXMethodDeclarationXmlTest.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
22

33
using System.Threading.Tasks;
4-
using NUnit.Framework;
54

65
namespace ClangSharp.UnitTests;
76

87
public abstract class CXXMethodDeclarationXmlTest: CXXMethodDeclarationTest
98
{
10-
[Test]
11-
public override Task MacrosExpansionTest()
9+
protected override Task MacrosExpansionTestImpl()
1210
{
1311
var inputContents = @"typedef struct
1412
{
15-
unsigned char *buf;
16-
int size;
13+
unsigned char *buf;
14+
int size;
1715
} context_t;
1816
1917
int buf_close(void *pcontext)
2018
{
21-
((context_t*)pcontext)->buf=0;
22-
return 0;
19+
((context_t*)pcontext)->buf=0;
20+
return 0;
2321
}
2422
";
2523

0 commit comments

Comments
 (0)