From 05b57573b68a49eb072a0196e08c7cd72c9962e9 Mon Sep 17 00:00:00 2001 From: triton Date: Mon, 4 Feb 2013 18:17:16 +0000 Subject: [PATCH] Added a new project with generator tests. --- src/Generator.Tests/Generator.Tests.csproj | 67 ---------------------- src/Generator.Tests/Generator.Tests.lua | 24 ++++++++ src/Generator.Tests/HeaderTestFixture.cs | 42 ++++++++++++++ src/Generator.Tests/QueryHelpers.cs | 38 ++++++++++++ 4 files changed, 104 insertions(+), 67 deletions(-) delete mode 100644 src/Generator.Tests/Generator.Tests.csproj create mode 100644 src/Generator.Tests/Generator.Tests.lua create mode 100644 src/Generator.Tests/HeaderTestFixture.cs create mode 100644 src/Generator.Tests/QueryHelpers.cs diff --git a/src/Generator.Tests/Generator.Tests.csproj b/src/Generator.Tests/Generator.Tests.csproj deleted file mode 100644 index ec1567dc..00000000 --- a/src/Generator.Tests/Generator.Tests.csproj +++ /dev/null @@ -1,67 +0,0 @@ - - - - - Debug - AnyCPU - {3EC927F3-5F8D-4D5D-B230-901ED2BB5D32} - Library - Properties - Generator.Tests - Generator.Tests - v4.5 - 512 - - - AnyCPU - true - full - false - bin\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\ - TRACE - prompt - 4 - - - - - - - - - - - - - - ..\..\build\packages\NUnit.2.6.2\lib\nunit.framework.dll - - - - - {6beb8fa2-97aa-40b7-ab92-42f6eddc4490} - CxxBridge - - - {73499B8E-A6A4-42FF-AB8A-754CE2780777} - Generator - - - - - \ No newline at end of file diff --git a/src/Generator.Tests/Generator.Tests.lua b/src/Generator.Tests/Generator.Tests.lua new file mode 100644 index 00000000..7c86d552 --- /dev/null +++ b/src/Generator.Tests/Generator.Tests.lua @@ -0,0 +1,24 @@ +project "Generator.Tests" + + kind "SharedLib" + language "C#" + location "." + + files { "**.cs" } + + libdirs + { + depsdir .. "/NUnit", + depsdir .. "/NSubstitute" + } + + links + { + "System", + "System.Core", + "Bridge", + "Generator", + "Parser", + "NUnit.Framework", + "NSubstitute" + } diff --git a/src/Generator.Tests/HeaderTestFixture.cs b/src/Generator.Tests/HeaderTestFixture.cs new file mode 100644 index 00000000..df6133bc --- /dev/null +++ b/src/Generator.Tests/HeaderTestFixture.cs @@ -0,0 +1,42 @@ +using System; +using System.IO; +using Cxxi; +using Cxxi.Types; + +namespace Generator.Tests +{ + public class HeaderTestFixture + { + protected Library library; + protected TypeMapDatabase database; + + private const string TestsDirectory = @"..\..\..\tests\Native"; + + protected void ParseLibrary(string file) + { + ParseLibrary(TestsDirectory, file); + } + + protected void ParseLibrary(string dir, string file) + { + database = new TypeMapDatabase(); + database.SetupTypeMaps(); + + var options = new Options(); + + var path = Path.Combine(Directory.GetCurrentDirectory(), dir); + options.IncludeDirs.Add(path); + + var parser = new Parser(options); + var result = parser.ParseHeader(file); + + if (!result.Success) + throw new Exception("Could not parse file: " + file); + + library = result.Library; + + foreach (var diag in result.Diagnostics) + Console.WriteLine(diag.Message); + } + } +} diff --git a/src/Generator.Tests/QueryHelpers.cs b/src/Generator.Tests/QueryHelpers.cs new file mode 100644 index 00000000..54684681 --- /dev/null +++ b/src/Generator.Tests/QueryHelpers.cs @@ -0,0 +1,38 @@ +using System.Linq; +using Cxxi; + +namespace Generator.Tests +{ + public static class LibraryQueryExtensions + { + public static Class Class(this Library library, string name) + { + return library.FindClass(name).ToList().First(); + } + + public static Function Function(this Library library, string name) + { + return library.FindFunction(name).ToList().First(); + } + + public static Enumeration Enum(this Library library, string name) + { + return library.FindEnum(name).ToList().First(); + } + + public static TypedefDecl Typedef(this Library library, string name) + { + return library.FindTypedef(name).ToList().First(); + } + + public static Field Field(this Class @class, string name) + { + return @class.Fields.Find(field => field.Name == name); + } + + public static Parameter Param(this Function function, int index) + { + return function.Parameters[index]; + } + } +}