Browse Source

added a test for MyMacroTestEnum + split LINQ to different lines

pull/821/head
Gilad Levi 8 years ago
parent
commit
9425beab96
  1. 16
      tests/CSharp/CSharp.Tests.cs
  2. 15
      tests/CSharp/CSharp.cs

16
tests/CSharp/CSharp.Tests.cs

@ -68,7 +68,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
} }
#pragma warning restore 0168 #pragma warning restore 0168
#pragma warning restore 0219 #pragma warning restore 0219
} }
[Test] [Test]
@ -81,7 +81,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.That(foo[0], Is.EqualTo(250)); Assert.That(foo[0], Is.EqualTo(250));
Assert.That(foo[(uint) 0], Is.EqualTo(15)); Assert.That(foo[(uint) 0], Is.EqualTo(15));
var bar = new Bar(); var bar = new Bar();
Assert.That(bar[0].A, Is.EqualTo(10)); Assert.That(bar[0].A, Is.EqualTo(10));
bar[0] = new Foo { A = 25 }; bar[0] = new Foo { A = 25 };
@ -399,7 +399,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
Assert.AreEqual(100, p[0]); Assert.AreEqual(100, p[0]);
Assert.AreEqual(200, p[1]); Assert.AreEqual(200, p[1]);
Assert.AreEqual(300, p[2]); Assert.AreEqual(300, p[2]);
int[] array = { 1, 2, 3 }; int[] array = { 1, 2, 3 };
fixed (int* p1 = array) fixed (int* p1 = array)
{ {
@ -532,7 +532,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
} }
Assert.IsTrue(VirtualDtorAddedInDerived.DtorCalled); Assert.IsTrue(VirtualDtorAddedInDerived.DtorCalled);
} }
[Test] [Test]
public void TestGetEnumFromNativePointer() public void TestGetEnumFromNativePointer()
{ {
@ -722,4 +722,12 @@ public unsafe class CSharpTests : GeneratorTestFixture
var i = CSharp.CSharp.UseDuplicateDeclaredStruct(duplicateDeclaredIncompleteStruct); var i = CSharp.CSharp.UseDuplicateDeclaredStruct(duplicateDeclaredIncompleteStruct);
Assert.AreEqual(10, i); Assert.AreEqual(10, i);
} }
[Test]
public void TestMyMacroTestEnum()
{
var a = (MyMacroTestEnum)'1';
var b = (MyMacroTestEnum)'2';
Assert.IsTrue(a == MyMacroTestEnum.MY_MACRO_TEST_1 && b == MyMacroTestEnum.MY_MACRO_TEST_2);
}
} }

15
tests/CSharp/CSharp.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using CppSharp.AST; using CppSharp.AST;
@ -39,8 +40,18 @@ namespace CppSharp.Tests
ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor");
var macroRegex = new Regex(@"(MY_MACRO_TEST_.*)"); var macroRegex = new Regex(@"(MY_MACRO_TEST_.*)");
var enumTest = ctx.GenerateEnumFromMacros("MyMacroTestEnum", (from unit in ctx.TranslationUnits where unit.FilePath == "<invalid>" || unit.FileName == "CSharp.h" from macro in unit.PreprocessedEntities.OfType<MacroDefinition>() let match = macroRegex.Match(macro.Name) where match.Success select macro.Name).ToArray()); List<string> list = new List<string>();
enumTest.Namespace = new Namespace() {Name = "MacroTest"}; foreach (TranslationUnit unit in ctx.TranslationUnits)
{
if (unit.FilePath == "<invalid>" || unit.FileName == "CSharp.h")
foreach (var macro in unit.PreprocessedEntities.OfType<MacroDefinition>())
{
Match match = macroRegex.Match(macro.Name);
if (match.Success) list.Add(macro.Name);
}
}
var enumTest = ctx.GenerateEnumFromMacros("MyMacroTestEnum", list.ToArray());
enumTest.Namespace = new Namespace() {Name = "MacroTest"};
} }
public override void Postprocess(Driver driver, ASTContext ctx) public override void Postprocess(Driver driver, ASTContext ctx)

Loading…
Cancel
Save