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
passBuilder = new PassBuilder<TranslationUnitPass>(Driver.Context); 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] [Test]
public void TestCheckFlagEnumsPass() public void TestCheckFlagEnumsPass()
{ {

8
src/Generator/Passes/ExtractInterfacePass.cs

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

6
tests/Native/Passes.h

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

Loading…
Cancel
Save