From c4edb588811adf7a974c8fca12383261f372ce87 Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Fri, 10 Mar 2017 04:41:19 +0000 Subject: [PATCH] Re-order declarations in CSharp test generator. --- tests/CSharp/CSharp.cs | 116 +++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/tests/CSharp/CSharp.cs b/tests/CSharp/CSharp.cs index 7c9b6701..09b0dea9 100644 --- a/tests/CSharp/CSharp.cs +++ b/tests/CSharp/CSharp.cs @@ -11,6 +11,63 @@ using Type = CppSharp.AST.Type; namespace CppSharp.Tests { + public class CSharpTestsGenerator : GeneratorTest + { + public CSharpTestsGenerator(GeneratorKind kind) + : base("CSharp", kind) + { + } + + public override void SetupPasses(Driver driver) + { + driver.Context.TranslationUnitPasses.AddPass(new TestAttributesPass()); + driver.Options.MarshalCharAsManagedChar = true; + driver.Options.GenerateDefaultValuesForArguments = true; + } + + public override void Preprocess(Driver driver, ASTContext ctx) + { + ctx.SetClassAsValueType("TestCopyConstructorVal"); + ctx.SetClassAsValueType("QGenericArgument"); + ctx.SetClassAsValueType("StructWithPrivateFields"); + ctx.SetClassAsValueType("QPoint"); + ctx.SetClassAsValueType("QSize"); + ctx.SetClassAsValueType("QRect"); + + ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); + } + + public override void Postprocess(Driver driver, ASTContext ctx) + { + } + + public static void Main(string[] args) + { + ConsoleDriver.Run(new CSharpTestsGenerator(GeneratorKind.CSharp)); + } + } + + public class TestAttributesPass : TranslationUnitPass + { + public override bool VisitFunctionDecl(Function function) + { + if (AlreadyVisited(function) || function.Name != "obsolete") + return false; + + var attribute = new Attribute + { + Type = typeof(ObsoleteAttribute), + Value = string.Format("\"{0} is obsolete.\"", function.Name) + }; + + function.Attributes.Add(attribute); + + return base.VisitFunctionDecl(function); + } + } + + #region Type Maps + [TypeMap("QFlags")] public class QFlags : TypeMap { @@ -59,7 +116,7 @@ namespace CppSharp.Tests if (templateSpecializationType != null) classTemplateSpecialization = templateSpecializationType.GetClassTemplateSpecialization(); else - classTemplateSpecialization = (ClassTemplateSpecialization) ((TagType) type).Declaration; + classTemplateSpecialization = (ClassTemplateSpecialization)((TagType)type).Declaration; return classTemplateSpecialization.Arguments[0].Type.Type; } } @@ -100,7 +157,7 @@ namespace CppSharp.Tests { get { - var type = (TemplateSpecializationType) Type; + var type = (TemplateSpecializationType)Type; var pointeeType = type.Arguments[0].Type; var checker = new TypeIgnoreChecker(TypeMapDatabase); pointeeType.Visit(checker); @@ -151,59 +208,6 @@ namespace CppSharp.Tests } } - public class TestAttributesPass : TranslationUnitPass - { - public override bool VisitFunctionDecl(Function function) - { - if (AlreadyVisited(function) || function.Name != "obsolete") - return false; - - var attribute = new Attribute - { - Type = typeof(ObsoleteAttribute), - Value = string.Format("\"{0} is obsolete.\"", function.Name) - }; - - function.Attributes.Add(attribute); - - return base.VisitFunctionDecl(function); - } - } - - public class CSharpTestsGenerator : GeneratorTest - { - public CSharpTestsGenerator(GeneratorKind kind) - : base("CSharp", kind) - { - } - - public override void SetupPasses(Driver driver) - { - driver.Context.TranslationUnitPasses.AddPass(new TestAttributesPass()); - driver.Options.MarshalCharAsManagedChar = true; - driver.Options.GenerateDefaultValuesForArguments = true; - } - - public override void Preprocess(Driver driver, ASTContext ctx) - { - ctx.SetClassAsValueType("TestCopyConstructorVal"); - ctx.SetClassAsValueType("QGenericArgument"); - ctx.SetClassAsValueType("StructWithPrivateFields"); - ctx.SetClassAsValueType("QPoint"); - ctx.SetClassAsValueType("QSize"); - ctx.SetClassAsValueType("QRect"); - - ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); - } - - public override void Postprocess(Driver driver, ASTContext ctx) - { - } - - public static void Main(string[] args) - { - ConsoleDriver.Run(new CSharpTestsGenerator(GeneratorKind.CSharp)); - } - } + #endregion }