From 3fee9dd5b9a238811cf20098ff3261200d089af5 Mon Sep 17 00:00:00 2001 From: Matt Key Date: Wed, 27 Jan 2021 15:32:50 +0000 Subject: [PATCH] Adding test for new pass --- src/Generator.Tests/Passes/TestPasses.cs | 14 ++++++++++++++ src/Generator/Passes/ExtractInterfacePass.cs | 8 ++------ tests/Native/Passes.h | 6 ++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Generator.Tests/Passes/TestPasses.cs b/src/Generator.Tests/Passes/TestPasses.cs index 6eb251d5..63a7cb74 100644 --- a/src/Generator.Tests/Passes/TestPasses.cs +++ b/src/Generator.Tests/Passes/TestPasses.cs @@ -18,6 +18,20 @@ namespace CppSharp.Generator.Tests.Passes passBuilder = new PassBuilder(Driver.Context); } + [Test] + public void TestExtractInterfacePass() + { + var c = AstContext.Class("TestExtractInterfacePass"); + + Assert.IsNull(c.GetInterface()); + + passBuilder.AddPass(new ExtractInterfacePass()); + passBuilder.RunPasses(pass => pass.VisitASTContext(AstContext)); + + Assert.IsNotNull(c.GetInterface()); + Assert.AreEqual("ITestExtractInterfacePass", c.GetInterface().Name); + } + [Test] public void TestCheckFlagEnumsPass() { diff --git a/src/Generator/Passes/ExtractInterfacePass.cs b/src/Generator/Passes/ExtractInterfacePass.cs index 18c1271e..c23f5a88 100644 --- a/src/Generator/Passes/ExtractInterfacePass.cs +++ b/src/Generator/Passes/ExtractInterfacePass.cs @@ -9,15 +9,12 @@ namespace CppSharp.Passes public class ExtractInterfacePass : TranslationUnitPass { /// - /// Collects all interfaces in a unit to be added at the end - /// because the unit cannot be changed while it's being iterated though. - /// We also need it to check if a class already has a complementary interface - /// because different classes may have the same secondary bases. + /// Creates interface from generated classes /// private readonly HashSet interfaces = new HashSet(); /// - /// Change and implement secondary bases at the end to avoid processing implementations. + /// Classes that require interfaces to be created /// private readonly HashSet classesNeedingInterface = new HashSet(); @@ -56,7 +53,6 @@ namespace CppSharp.Passes } classesNeedingInterface.Add(@class); - Console.WriteLine(@class.Name); GetInterface(@class); return true; } diff --git a/tests/Native/Passes.h b/tests/Native/Passes.h index c7687806..0cf2579e 100644 --- a/tests/Native/Passes.h +++ b/tests/Native/Passes.h @@ -105,3 +105,9 @@ protected: int Protected; }; }; + +class TestExtractInterfacePass +{ +public: + void DoSomething(); +};