Browse Source

Adding test for new pass

pull/1574/head
Matt Key 5 years ago committed by João Matos
parent
commit
3fee9dd5b9
  1. 14
      src/Generator.Tests/Passes/TestPasses.cs
  2. 8
      src/Generator/Passes/ExtractInterfacePass.cs
  3. 6
      tests/Native/Passes.h

14
src/Generator.Tests/Passes/TestPasses.cs

@ -18,6 +18,20 @@ namespace CppSharp.Generator.Tests.Passes @@ -18,6 +18,20 @@ namespace CppSharp.Generator.Tests.Passes
passBuilder = new PassBuilder<TranslationUnitPass>(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()
{

8
src/Generator/Passes/ExtractInterfacePass.cs

@ -9,15 +9,12 @@ namespace CppSharp.Passes @@ -9,15 +9,12 @@ namespace CppSharp.Passes
public class ExtractInterfacePass : TranslationUnitPass
{
/// <summary>
/// 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
/// </summary>
private readonly HashSet<Class> interfaces = new HashSet<Class>();
/// <summary>
/// Change and implement secondary bases at the end to avoid processing implementations.
/// Classes that require interfaces to be created
/// </summary>
private readonly HashSet<Class> classesNeedingInterface = new HashSet<Class>();
@ -56,7 +53,6 @@ namespace CppSharp.Passes @@ -56,7 +53,6 @@ namespace CppSharp.Passes
}
classesNeedingInterface.Add(@class);
Console.WriteLine(@class.Name);
GetInterface(@class);
return true;
}

6
tests/Native/Passes.h

@ -105,3 +105,9 @@ protected: @@ -105,3 +105,9 @@ protected:
int Protected;
};
};
class TestExtractInterfacePass
{
public:
void DoSomething();
};

Loading…
Cancel
Save