This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
/
TestCLITypePrinter.cs
106 lines (93 loc) · 3.18 KB
/
TestCLITypePrinter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using CppSharp;
using CppSharp.Generators.CLI;
using CppSharp.Types;
using NUnit.Framework;
namespace Generator.Tests
{
[TypeMap("FnPtr3")]
public class CLITypePrinterTypeMap : TypeMap
{
public override string CLISignature(CLITypePrinterContext ctx)
{
return "TypedefFn3";
}
}
[TestFixture]
public class CLITypePrinterTest : HeaderTestFixture
{
CLITypePrinter printer;
[TestFixtureSetUp]
public void Init()
{
ParseLibrary("CLITypes.h");
printer = new CLITypePrinter(Driver, new CLITypePrinterContext());
}
public void CheckType<T>(T decl, string check) where T : ITypedDecl
{
var type = decl.Type.Visit(printer);
Assert.That(type, Is.EqualTo(check));
}
public void CheckDecl<T>(T decl, string check) where T : Declaration
{
var output = decl.Visit(printer);
Assert.That(output, Is.EqualTo(check));
}
[Test]
public void TestPrimitive()
{
var p = Library.Class("Primitives");
CheckType(p.Field("B"), "bool");
CheckType(p.Field("C"), "char");
CheckType(p.Field("UC"), "unsigned char");
CheckType(p.Field("S"), "short");
CheckType(p.Field("US"), "unsigned short");
CheckType(p.Field("I"), "int");
CheckType(p.Field("UI"), "unsigned int");
CheckType(p.Field("L"), "int");
CheckType(p.Field("UL"), "unsigned int");
CheckType(p.Field("LL"), "long long");
CheckType(p.Field("ULL"), "unsigned long long");
CheckType(p.Field("F"), "float");
CheckType(p.Field("D"), "double");
}
[Test]
public void TestArray()
{
var c = Library.Class("Arrays");
CheckType(c.Field("Array"), "cli::array<float>^");
CheckType(c.Field("Prim"), "cli::array<::Primitives^>^");
}
[Test]
public void TestPointers()
{
var p = Library.Class("Pointers");
CheckType(p.Field("pv"), "System::IntPtr");
CheckType(p.Field("pc"), "System::IntPtr");
CheckType(p.Field("puc"), "System::IntPtr");
CheckType(p.Field("cpc"), "System::String^");
CheckType(p.Field("pi"), "System::IntPtr");
}
[Test]
public void TestFunctionPointers()
{
var p = Library.Class("FunctionPointers");
CheckType(p.Field("fn"), "::FnPtr^");
CheckType(p.Field("fn2"), "::FnPtr2^");
CheckType(p.Field("fn3"), "::FnPtr3^");
}
[Test]
public void TestTypedefs()
{
CheckType(Library.Typedef("FnPtr"), "System::Func<int, double>^");
CheckType(Library.Typedef("FnPtr2"), "System::Action<char, float>^");
CheckType(Library.Typedef("FnPtr3"), "System::Action^");
}
[Test]
public void TestTags()
{
var p = Library.Class("Tag");
CheckType(p.Field("p"), "::Primitives^");
CheckType(p.Field("e"), "::E");
}
}
}