mirror of https://github.com/mono/CppSharp.git
2 changed files with 139 additions and 6 deletions
@ -1,21 +1,103 @@ |
|||||||
using Cxxi.Generators.CLI; |
using Cxxi; |
||||||
|
using Cxxi.Generators.CLI; |
||||||
|
using Cxxi.Types; |
||||||
using NUnit.Framework; |
using NUnit.Framework; |
||||||
|
|
||||||
namespace Generator.Tests |
namespace Generator.Tests |
||||||
{ |
{ |
||||||
|
[TypeMap("FnPtr3")] |
||||||
|
public class CLITypePrinterTypeMap : TypeMap |
||||||
|
{ |
||||||
|
public override string Signature() { return "TypedefFn3"; } |
||||||
|
} |
||||||
|
|
||||||
[TestFixture] |
[TestFixture] |
||||||
public class CLITypePrinterTest |
public class CLITypePrinterTest : HeaderTestFixture |
||||||
{ |
{ |
||||||
private readonly CLITypePrinter printer; |
CLITypePrinter printer; |
||||||
|
|
||||||
|
[TestFixtureSetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
ParseLibrary("CLITypes.h"); |
||||||
|
printer = new CLITypePrinter(database, library); |
||||||
|
} |
||||||
|
|
||||||
|
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)); |
||||||
|
} |
||||||
|
|
||||||
CLITypePrinterTest() |
[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"), "char"); |
||||||
|
CheckType(p.Field("puc"), "System::IntPtr"); |
||||||
|
//CheckType(p.Field("cpc"), "System::String^");
|
||||||
|
CheckType(p.Field("pi"), "int"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestFunctionPointers() |
||||||
|
{ |
||||||
|
var p = library.Class("FunctionPointers"); |
||||||
|
CheckType(p.Field("fn"), "::FnPtr^"); |
||||||
|
CheckType(p.Field("fn2"), "::FnPtr2^"); |
||||||
|
CheckType(p.Field("fn3"), "TypedefFn3"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TestTypedefs() |
||||||
{ |
{ |
||||||
//printer = new CLITypePrinter();
|
CheckType(library.Typedef("FnPtr"), "System::Func<int, double>^"); |
||||||
|
CheckType(library.Typedef("FnPtr2"), "System::Action<char, float>^"); |
||||||
|
CheckType(library.Typedef("FnPtr3"), "System::Action^"); |
||||||
} |
} |
||||||
|
|
||||||
[Test] |
[Test] |
||||||
public void Test() |
public void TestTags() |
||||||
{ |
{ |
||||||
|
var p = library.Class("Tag"); |
||||||
|
CheckType(p.Field("p"), "::Primitives^"); |
||||||
|
CheckType(p.Field("e"), "::E"); |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
@ -0,0 +1,51 @@ |
|||||||
|
struct Primitives |
||||||
|
{ |
||||||
|
bool B; |
||||||
|
char C; |
||||||
|
unsigned char UC; |
||||||
|
short S; |
||||||
|
unsigned short US; |
||||||
|
int I; |
||||||
|
unsigned int UI; |
||||||
|
long L; |
||||||
|
unsigned long UL; |
||||||
|
long long LL; |
||||||
|
unsigned long long ULL; |
||||||
|
float F; |
||||||
|
double D; |
||||||
|
}; |
||||||
|
|
||||||
|
struct Arrays |
||||||
|
{ |
||||||
|
float Array[2]; |
||||||
|
Primitives Prim[1]; |
||||||
|
}; |
||||||
|
|
||||||
|
struct Pointers |
||||||
|
{ |
||||||
|
void * pv; |
||||||
|
char * pc; |
||||||
|
unsigned char * puc; |
||||||
|
const char * cpc; |
||||||
|
int * pi; |
||||||
|
}; |
||||||
|
|
||||||
|
typedef int (*FnPtr)(double); |
||||||
|
typedef void (*FnPtr2)(char, float); |
||||||
|
typedef void (*FnPtr3)(void); |
||||||
|
|
||||||
|
struct FunctionPointers |
||||||
|
{ |
||||||
|
FnPtr fn; |
||||||
|
FnPtr2 fn2; |
||||||
|
FnPtr3 fn3; |
||||||
|
}; |
||||||
|
|
||||||
|
enum E { E1, E2 }; |
||||||
|
|
||||||
|
struct Tag |
||||||
|
{ |
||||||
|
Primitives p; |
||||||
|
E e; |
||||||
|
}; |
||||||
|
|
Loading…
Reference in new issue