diff --git a/tests/NamespacesBase/Base.cpp b/tests/NamespacesBase/Base.cpp new file mode 100644 index 00000000..898b50d5 --- /dev/null +++ b/tests/NamespacesBase/Base.cpp @@ -0,0 +1,13 @@ +#include "Base.h" + + +Base::Base(int i) +{ + b = i; +} + + +Base::Base() +{ + +} \ No newline at end of file diff --git a/tests/NamespacesBase/Base.h b/tests/NamespacesBase/Base.h new file mode 100644 index 00000000..b431de6c --- /dev/null +++ b/tests/NamespacesBase/Base.h @@ -0,0 +1,11 @@ +#include "../Tests.h" + +class DLL_API Base +{ +public: + Base(int i); + Base(); + +private: + int b; +}; \ No newline at end of file diff --git a/tests/NamespacesBase/NamespacesBase.Tests.cs b/tests/NamespacesBase/NamespacesBase.Tests.cs new file mode 100644 index 00000000..e69de29b diff --git a/tests/NamespacesBase/NamespacesBase.cs b/tests/NamespacesBase/NamespacesBase.cs new file mode 100644 index 00000000..26c70277 --- /dev/null +++ b/tests/NamespacesBase/NamespacesBase.cs @@ -0,0 +1,81 @@ +?using System; +using CppSharp.AST; +using CppSharp.AST.Extensions; +using CppSharp.Generators; +using CppSharp.Generators.CSharp; +using CppSharp.Passes; +using CppSharp.Types; +using CppSharp.Utils; +using Attribute = CppSharp.AST.Attribute; +using Type = CppSharp.AST.Type; + +namespace CppSharp.Tests +{ + public class TestAttributesPass : TranslationUnitPass + { + public override bool VisitFunctionDecl(Function function) + { + if (AlreadyVisited(function) || function.Name != "obsolete") + return false; + + var attribute = new Attribute + { + Type = typeof(ObsoleteAttribute), + Value = string.Format("\"{0} is obsolete.\"", function.Name) + }; + + function.Attributes.Add(attribute); + + return base.VisitFunctionDecl(function); + } + } + + public class NamespacesBaseTests : GeneratorTest + { + public NamespacesBaseTests(GeneratorKind kind) + : base("NamespacesBase", kind) + { + } + + public override void SetupPasses(Driver driver) + { + driver.Options.GenerateAbstractImpls = true; + driver.Options.GenerateInterfacesForMultipleInheritance = true; + driver.Options.GeneratePropertiesAdvanced = true; + driver.Options.GenerateVirtualTables = true; + driver.Options.GenerateCopyConstructors = true; + // To ensure that calls to constructors in conversion operators + // are not ambiguous with multiple inheritance pass enabled. + driver.Options.GenerateConversionOperators = true; + driver.TranslationUnitPasses.AddPass(new TestAttributesPass()); + driver.Options.MarshalCharAsManagedChar = true; + driver.Options.GenerateDefaultValuesForArguments = true; + driver.Options.GenerateSingleCSharpFile = true; + } + + public override void Preprocess(Driver driver, ASTContext ctx) + { + ctx.SetClassAsValueType("TestCopyConstructorVal"); + ctx.SetClassAsValueType("QGenericArgument"); + + ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); + } + + public override void Postprocess(Driver driver, ASTContext ctx) + { + new CaseRenamePass( + RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate, + RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext); + } + + } + public class Namespaces { + + public static void Main(string[] args) + { + ConsoleDriver.Run(new NamespacesBaseTests(GeneratorKind.CSharp)); + } + + } +} + diff --git a/tests/NamespacesBase/premake4.lua b/tests/NamespacesBase/premake4.lua new file mode 100644 index 00000000..0b7fc694 --- /dev/null +++ b/tests/NamespacesBase/premake4.lua @@ -0,0 +1,2 @@ +group "Tests/Namespaces" + SetupTestCSharp("NamespacesBase") \ No newline at end of file diff --git a/tests/NamespacesDerived/Derived.cpp b/tests/NamespacesDerived/Derived.cpp new file mode 100644 index 00000000..66c6422e --- /dev/null +++ b/tests/NamespacesDerived/Derived.cpp @@ -0,0 +1,6 @@ +#include "Derived.h" + + +Derived::Derived() : Base(10), component(5) +{ +} diff --git a/tests/NamespacesDerived/Derived.h b/tests/NamespacesDerived/Derived.h new file mode 100644 index 00000000..bc1103ed --- /dev/null +++ b/tests/NamespacesDerived/Derived.h @@ -0,0 +1,13 @@ +#include "../Tests.h" +#include "../NamespacesBase/Base.h" + +class DLL_API Derived : public Base +{ +public: + Derived(); + + Base component; + +private: + int d; +}; \ No newline at end of file diff --git a/tests/NamespacesDerived/NamespacesDerived.Tests.cs b/tests/NamespacesDerived/NamespacesDerived.Tests.cs new file mode 100644 index 00000000..e69de29b diff --git a/tests/NamespacesDerived/NamespacesDerived.cs b/tests/NamespacesDerived/NamespacesDerived.cs new file mode 100644 index 00000000..3fb00665 --- /dev/null +++ b/tests/NamespacesDerived/NamespacesDerived.cs @@ -0,0 +1,91 @@ +?using System; +using CppSharp.AST; +using CppSharp.AST.Extensions; +using CppSharp.Generators; +using CppSharp.Generators.CSharp; +using CppSharp.Passes; +using CppSharp.Types; +using CppSharp.Utils; +using Attribute = CppSharp.AST.Attribute; +using Type = CppSharp.AST.Type; + +namespace CppSharp.Tests +{ + public class TestAttributesPass : TranslationUnitPass + { + public override bool VisitFunctionDecl(Function function) + { + if (AlreadyVisited(function) || function.Name != "obsolete") + return false; + + var attribute = new Attribute + { + Type = typeof(ObsoleteAttribute), + Value = string.Format("\"{0} is obsolete.\"", function.Name) + }; + + function.Attributes.Add(attribute); + + return base.VisitFunctionDecl(function); + } + } + + public class NamespacesDerivedTests : GeneratorTest + { + public NamespacesDerivedTests(GeneratorKind kind) + : base("NamespacesDerived", kind) + { + } + + public override void SetupPasses(Driver driver) + { + driver.Options.GenerateAbstractImpls = true; + driver.Options.GenerateInterfacesForMultipleInheritance = true; + driver.Options.GeneratePropertiesAdvanced = true; + driver.Options.GenerateVirtualTables = true; + driver.Options.GenerateCopyConstructors = true; + // To ensure that calls to constructors in conversion operators + // are not ambiguous with multiple inheritance pass enabled. + driver.Options.GenerateConversionOperators = true; + driver.TranslationUnitPasses.AddPass(new TestAttributesPass()); + driver.Options.MarshalCharAsManagedChar = true; + driver.Options.GenerateDefaultValuesForArguments = true; + driver.Options.GenerateSingleCSharpFile = true; + driver.Options.DependentNameSpaces.Add("NamespacesBase"); + } + + public override void Preprocess(Driver driver, ASTContext ctx) + { + foreach (TranslationUnit unit in ctx.TranslationUnits) + { + if (unit.FileName != "Derived.h") + { + unit.ExplicityIgnored = true; + } + } + + ctx.SetClassAsValueType("TestCopyConstructorVal"); + ctx.SetClassAsValueType("QGenericArgument"); + + ctx.IgnoreClassWithName("IgnoredTypeInheritingNonIgnoredWithNoEmptyCtor"); + } + + public override void Postprocess(Driver driver, ASTContext ctx) + { + new CaseRenamePass( + RenameTargets.Function | RenameTargets.Method | RenameTargets.Property | RenameTargets.Delegate, + RenameCasePattern.UpperCamelCase).VisitLibrary(driver.ASTContext); + } + + } + + public class Namespaces { + + public static void Main(string[] args) + { + ConsoleDriver.Run(new NamespacesDerivedTests(GeneratorKind.CSharp)); + } + + } +} + diff --git a/tests/NamespacesDerived/premake4.lua b/tests/NamespacesDerived/premake4.lua new file mode 100644 index 00000000..de66eb52 --- /dev/null +++ b/tests/NamespacesDerived/premake4.lua @@ -0,0 +1,2 @@ +group "Tests/Namespaces" + SetupTestCSharp("NamespacesDerived") \ No newline at end of file