Browse Source

Added failing test for the CheckAmbiguousFunctionsPass.

Test shows that all methods get ignored instead of just the two const overloads.
pull/253/head
Elias Holzer 11 years ago
parent
commit
79f0d41d5c
  1. 31
      src/Generator.Tests/Passes/TestPasses.cs
  2. 9
      tests/Native/Passes.h

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

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System.Linq;
using CppSharp;
using CppSharp.Passes;
using CppSharp.AST;
using NUnit.Framework;
namespace CppSharp.Generator.Tests.Passes
@ -158,5 +159,35 @@ namespace CppSharp.Generator.Tests.Passes @@ -158,5 +159,35 @@ namespace CppSharp.Generator.Tests.Passes
Assert.IsFalse(AstContext.FindClass(className).First().Properties.Find(
m => m.Name == "ReadOnlyPropertyMethod").HasSetter);
}
[Test]
public void TestCheckAmbiguousFunctionsPass()
{
passBuilder.AddPass(new CheckAmbiguousFunctions());
passBuilder.RunPasses(pass => pass.VisitLibrary(AstContext));
var @class = AstContext.FindClass("TestCheckAmbiguousFunctionsPass").FirstOrDefault();
Assert.IsNotNull(@class);
var overloads = @class.Methods.Where(m => m.Name == "Method");
var constMethod = overloads
.Where(m => m.IsConst && m.Parameters.Count == 0)
.FirstOrDefault();
var nonConstMethod = overloads
.Where(m => !m.IsConst && m.Parameters.Count == 0)
.FirstOrDefault();
Assert.IsNotNull(constMethod);
Assert.IsNotNull(nonConstMethod);
Assert.IsTrue(constMethod.GenerationKind == GenerationKind.None);
Assert.IsTrue(nonConstMethod.GenerationKind == GenerationKind.Generate);
var constMethodWithParam = overloads
.Where(m => m.IsConst && m.Parameters.Count == 1)
.FirstOrDefault();
var nonConstMethodWithParam = overloads
.Where(m => !m.IsConst && m.Parameters.Count == 1)
.FirstOrDefault();
Assert.IsNotNull(constMethodWithParam);
Assert.IsNotNull(nonConstMethodWithParam);
Assert.IsTrue(constMethodWithParam.GenerationKind == GenerationKind.None);
Assert.IsTrue(nonConstMethodWithParam.GenerationKind == GenerationKind.Generate);
}
}
}

9
tests/Native/Passes.h

@ -52,3 +52,12 @@ enum @@ -52,3 +52,12 @@ enum
UnnamedEnumB1,
EnumUnnamedB2
};
struct TestCheckAmbiguousFunctionsPass
{
// Tests removal of const method overloads
int Method();
int Method() const;
int Method(int x);
int Method(int x) const;
};

Loading…
Cancel
Save