diff --git a/src/Generator.Tests/TestCLITypePrinter.cs b/src/Generator.Tests/TestCLITypePrinter.cs index 4dd0514d..0e5aeeeb 100644 --- a/src/Generator.Tests/TestCLITypePrinter.cs +++ b/src/Generator.Tests/TestCLITypePrinter.cs @@ -1,21 +1,103 @@ -using Cxxi.Generators.CLI; +using Cxxi; +using Cxxi.Generators.CLI; +using Cxxi.Types; using NUnit.Framework; namespace Generator.Tests { + [TypeMap("FnPtr3")] + public class CLITypePrinterTypeMap : TypeMap + { + public override string Signature() { return "TypedefFn3"; } + } + [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 decl, string check) where T : ITypedDecl + { + var type = decl.Type.Visit(printer); + Assert.That(type, Is.EqualTo(check)); + } + + public void CheckDecl(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^"); + 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^"); + CheckType(library.Typedef("FnPtr2"), "System::Action^"); + CheckType(library.Typedef("FnPtr3"), "System::Action^"); } [Test] - public void Test() + public void TestTags() { + var p = library.Class("Tag"); + CheckType(p.Field("p"), "::Primitives^"); + CheckType(p.Field("e"), "::E"); } } } \ No newline at end of file diff --git a/tests/Native/CLITypes.h b/tests/Native/CLITypes.h new file mode 100644 index 00000000..efcb5523 --- /dev/null +++ b/tests/Native/CLITypes.h @@ -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; +}; +