Browse Source

Check symbols in tests

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1398/head
Dimitar Dobrev 6 years ago
parent
commit
b5ca0635be
  1. 12
      src/AST/SymbolContext.cs
  2. 6
      src/AST/TargetTriple.cs
  3. 12
      src/AST/VariableExtensions.cs
  4. 33
      src/CppParser/Parser.cpp
  5. 4
      src/CppParser/Parser.h
  6. 93
      src/Generator/Generators/CSharp/CSharpSources.cs
  7. 2
      tests/CSharp/CSharp.Tests.cs
  8. 16
      tests/CSharp/CSharp.cpp
  9. 8
      tests/CSharp/CSharp.h
  10. 8
      tests/CSharp/CSharpTemplates.cpp
  11. 3
      tests/CSharp/CSharpTemplates.h
  12. 8
      tests/Common/Common.Tests.cs
  13. 46
      tests/Common/Common.cpp
  14. 20
      tests/Common/Common.h
  15. 4
      tests/NamespacesDerived/NamespacesDerived.cs

12
src/AST/SymbolContext.cs

@ -94,37 +94,35 @@ namespace CppSharp.AST
public bool FindSymbol(ref string symbol) public bool FindSymbol(ref string symbol)
{ {
NativeLibrary lib; if (FindLibraryBySymbol(symbol, out _))
if (FindLibraryBySymbol(symbol, out lib))
return true; return true;
string alternativeSymbol; string alternativeSymbol;
// Check for C symbols with a leading underscore. // Check for C symbols with a leading underscore.
alternativeSymbol = "_" + symbol; alternativeSymbol = "_" + symbol;
if (FindLibraryBySymbol(alternativeSymbol, out lib)) if (FindLibraryBySymbol(alternativeSymbol, out _))
{ {
symbol = alternativeSymbol; symbol = alternativeSymbol;
return true; return true;
} }
alternativeSymbol = symbol.TrimStart('_'); alternativeSymbol = symbol.TrimStart('_');
if (FindLibraryBySymbol(alternativeSymbol, out lib)) if (FindLibraryBySymbol(alternativeSymbol, out _))
{ {
symbol = alternativeSymbol; symbol = alternativeSymbol;
return true; return true;
} }
alternativeSymbol = "_imp_" + symbol; alternativeSymbol = "_imp_" + symbol;
if (FindLibraryBySymbol(alternativeSymbol, out lib)) if (FindLibraryBySymbol(alternativeSymbol, out _))
{ {
symbol = alternativeSymbol; symbol = alternativeSymbol;
return true; return true;
} }
alternativeSymbol = "__imp_" + symbol; alternativeSymbol = "__imp_" + symbol;
if (FindLibraryBySymbol("__imp_" + symbol, out lib)) if (FindLibraryBySymbol("__imp_" + symbol, out _))
{ {
symbol = alternativeSymbol; symbol = alternativeSymbol;
return true; return true;

6
src/Parser/TargetTriple.cs → src/AST/TargetTriple.cs

@ -1,19 +1,19 @@
using System.Linq; using System.Linq;
namespace CppSharp.Parser namespace CppSharp.AST
{ {
// over time we should turn this into a real class // over time we should turn this into a real class
// like http://llvm.org/docs/doxygen/html/classllvm_1_1Triple.html // like http://llvm.org/docs/doxygen/html/classllvm_1_1Triple.html
public static class TargetTriple public static class TargetTriple
{ {
public static bool IsWindows(string targetTriple) public static bool IsWindows(this string targetTriple)
{ {
var parts = targetTriple.Split('-'); var parts = targetTriple.Split('-');
return parts.Contains("windows") || return parts.Contains("windows") ||
parts.Contains("win32") || parts.Contains("win64"); parts.Contains("win32") || parts.Contains("win64");
} }
public static bool IsMacOS(string targetTriple) public static bool IsMacOS(this string targetTriple)
{ {
var parts = targetTriple.Split('-'); var parts = targetTriple.Split('-');
return parts.Contains("apple") || return parts.Contains("apple") ||

12
src/AST/VariableExtensions.cs

@ -0,0 +1,12 @@
namespace CppSharp.AST
{
public static class VariableExtensions
{
public static string GetMangled(this Variable variable, string targetTriple) =>
variable.Mangled[0] == '_' && variable.Namespace is TranslationUnit &&
targetTriple.IsMacOS() ?
// the symbol name passed to dlsym() must NOT be prepended with an underscore
// https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dlsym.3.html
variable.Mangled.TrimStart('_') : variable.Mangled;
}
}

33
src/CppParser/Parser.cpp

@ -4286,13 +4286,12 @@ ParserResult* Parser::Parse(const std::vector<std::string>& SourceFiles)
return res; return res;
} }
ParserResultKind Parser::ParseArchive(llvm::StringRef File, ParserResultKind Parser::ParseArchive(const std::string& File,
llvm::object::Archive* Archive, llvm::object::Archive* Archive,
std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs) std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs)
{ {
auto LibName = File;
auto NativeLib = new NativeLibrary(); auto NativeLib = new NativeLibrary();
NativeLib->fileName = LibName.str(); NativeLib->fileName = File;
for (const auto& Symbol : Archive->symbols()) for (const auto& Symbol : Archive->symbols())
{ {
@ -4324,13 +4323,12 @@ static void ReadELFDependencies(const llvm::object::ELFFile<ELFT>* ELFFile, CppS
NativeLib->Dependencies.push_back(Dependency.str()); NativeLib->Dependencies.push_back(Dependency.str());
} }
ParserResultKind Parser::ParseSharedLib(llvm::StringRef File, ParserResultKind Parser::ParseSharedLib(const std::string& File,
llvm::object::ObjectFile* ObjectFile, llvm::object::ObjectFile* ObjectFile,
std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs) std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs)
{ {
auto LibName = File;
auto NativeLib = new NativeLibrary(); auto NativeLib = new NativeLibrary();
NativeLib->fileName = LibName.str(); NativeLib->fileName = File;
NativeLib->archType = ConvertArchType(ObjectFile->getArch()); NativeLib->archType = ConvertArchType(ObjectFile->getArch());
NativeLibs.push_back(NativeLib); NativeLibs.push_back(NativeLib);
@ -4450,29 +4448,34 @@ ParserResult* Parser::ParseLibrary(const LinkerOptions* Opts)
{ {
auto res = new ParserResult(); auto res = new ParserResult();
for (const auto& Library : Opts->Libraries) for (const auto& Lib : Opts->Libraries)
{ {
if (Library.empty()) if (Lib.empty())
{ {
res->kind = ParserResultKind::FileNotFound; res->kind = ParserResultKind::FileNotFound;
return res; return res;
} }
std::string PrefixedLib = "lib" + Lib;
std::string FileName;
std::string FileEntry; std::string FileEntry;
using namespace llvm::sys;
for (const auto& LibDir : Opts->LibraryDirs) for (const auto& LibDir : Opts->LibraryDirs)
{ {
using namespace llvm::sys;
std::error_code ErrorCode; std::error_code ErrorCode;
fs::directory_iterator Dir(LibDir, ErrorCode); fs::directory_iterator Dir(LibDir, ErrorCode);
for (const auto& File = Dir; for (const auto& File = Dir;
Dir != fs::directory_iterator() && !ErrorCode; Dir != fs::directory_iterator() && !ErrorCode;
Dir = Dir.increment(ErrorCode)) Dir = Dir.increment(ErrorCode))
{ {
if (path::filename(File->path()) == Library || FileName = path::filename(File->path()).str();
path::stem(File->path()) == Library || if (FileName == Lib ||
path::stem(path::stem(File->path())) == Library) FileName == PrefixedLib ||
path::stem(FileName) == Lib ||
path::stem(FileName) == PrefixedLib ||
path::stem(path::stem(FileName)) == Lib ||
path::stem(path::stem(FileName)) == PrefixedLib)
{ {
FileEntry = File->path(); FileEntry = File->path();
goto found; goto found;
@ -4498,14 +4501,14 @@ ParserResult* Parser::ParseLibrary(const LinkerOptions* Opts)
auto OwningBinary = std::move(BinaryOrErr.get()); auto OwningBinary = std::move(BinaryOrErr.get());
auto Bin = OwningBinary.getBinary(); auto Bin = OwningBinary.getBinary();
if (auto Archive = llvm::dyn_cast<llvm::object::Archive>(Bin)) { if (auto Archive = llvm::dyn_cast<llvm::object::Archive>(Bin)) {
res->kind = ParseArchive(Library, Archive, res->Libraries); res->kind = ParseArchive(FileName, Archive, res->Libraries);
if (res->kind == ParserResultKind::Error) if (res->kind == ParserResultKind::Error)
return res; return res;
} }
if (auto ObjectFile = llvm::dyn_cast<llvm::object::ObjectFile>(Bin)) if (auto ObjectFile = llvm::dyn_cast<llvm::object::ObjectFile>(Bin))
{ {
res->kind = ParseSharedLib(Library, ObjectFile, res->Libraries); res->kind = ParseSharedLib(FileName, ObjectFile, res->Libraries);
if (res->kind == ParserResultKind::Error) if (res->kind == ParserResultKind::Error)
return res; return res;
} }

4
src/CppParser/Parser.h

@ -159,9 +159,9 @@ private:
llvm::object::basic_symbol_iterator End, llvm::object::basic_symbol_iterator End,
CppSharp::CppParser::NativeLibrary*& NativeLib); CppSharp::CppParser::NativeLibrary*& NativeLib);
Declaration* GetDeclarationFromFriend(clang::NamedDecl* FriendDecl); Declaration* GetDeclarationFromFriend(clang::NamedDecl* FriendDecl);
static ParserResultKind ParseArchive(llvm::StringRef File, static ParserResultKind ParseArchive(const std::string& File,
llvm::object::Archive* Archive, std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs); llvm::object::Archive* Archive, std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs);
static ParserResultKind ParseSharedLib(llvm::StringRef File, static ParserResultKind ParseSharedLib(const std::string& File,
llvm::object::ObjectFile* ObjectFile, std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs); llvm::object::ObjectFile* ObjectFile, std::vector<CppSharp::CppParser::NativeLibrary*>& NativeLibs);
ParserTargetInfo* GetTargetInfo(); ParserTargetInfo* GetTargetInfo();

93
src/Generator/Generators/CSharp/CSharpSources.cs

@ -837,25 +837,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateVariableSetter(Variable var) private void GenerateVariableSetter(Variable var)
{ {
TypePrinter.PushContext(TypePrinterContextKind.Native); string ptr = GetPointerTo(var);
var location = $@"CppSharp.SymbolResolver.ResolveSymbol(""{
GetLibraryOf(var)}"", ""{var.Mangled}"")";
string ptr = Generator.GeneratedIdentifier("ptr");
Type varType = var.Type.Desugar();
var arrayType = varType as ArrayType;
var @class = var.Namespace as Class;
var isRefTypeArray = arrayType != null && @class != null && @class.IsRefType;
if (isRefTypeArray)
WriteLine($@"var {ptr} = {
(arrayType.Type.IsPrimitiveType(PrimitiveType.Char) &&
arrayType.QualifiedType.Qualifiers.IsConst ?
string.Empty : "(byte*)")}{location};");
else
WriteLine($"var {ptr} = ({varType}*){location};");
TypePrinter.PopContext();
var param = new Parameter var param = new Parameter
{ {
@ -867,7 +849,7 @@ namespace CppSharp.Generators.CSharp
{ {
Parameter = param, Parameter = param,
ArgName = param.Name, ArgName = param.Name,
ReturnType = new QualifiedType(varType) ReturnType = var.QualifiedType
}; };
ctx.PushMarshalKind(MarshalKind.Variable); ctx.PushMarshalKind(MarshalKind.Variable);
@ -887,6 +869,36 @@ namespace CppSharp.Generators.CSharp
UnindentAndWriteCloseBrace(); UnindentAndWriteCloseBrace();
} }
private string GetPointerTo(Variable var)
{
TypePrinter.PushContext(TypePrinterContextKind.Native);
string mangled = var.GetMangled(Context.ParserOptions.TargetTriple);
var location = $@"CppSharp.SymbolResolver.ResolveSymbol(""{
GetLibraryOf(var)}"", ""{mangled}"")";
var arrayType = var.Type as ArrayType;
string ptr = Generator.GeneratedIdentifier("ptr");
if (arrayType != null && var.Namespace is Class @class && @class.IsRefType)
{
WriteLine($@"var {ptr} = {
(arrayType.Type.IsPrimitiveType(PrimitiveType.Char) &&
arrayType.QualifiedType.Qualifiers.IsConst ?
string.Empty : "(byte*)")}{location};");
}
else
{
TypePrinter.PushMarshalKind(MarshalKind.ReturnVariableArray);
var varReturnType = var.Type.Visit(TypePrinter);
TypePrinter.PopMarshalKind();
WriteLine($"var {ptr} = ({varReturnType}*){location};");
}
TypePrinter.PopContext();
return ptr;
}
private void GenerateFunctionSetter(Class @class, Property property) private void GenerateFunctionSetter(Class @class, Property property)
{ {
var actualProperty = GetActualProperty(property, @class); var actualProperty = GetActualProperty(property, @class);
@ -1125,42 +1137,18 @@ namespace CppSharp.Generators.CSharp
private void GenerateVariableGetter(Variable var) private void GenerateVariableGetter(Variable var)
{ {
TypePrinter.PushContext(TypePrinterContextKind.Native); string ptr = GetPointerTo(var);
string library = GetLibraryOf(var);
var location = $"CppSharp.SymbolResolver.ResolveSymbol(\"{library}\", \"{var.Mangled}\")";
var ptr = Generator.GeneratedIdentifier("ptr");
Type varType = var.Type.Desugar();
var arrayType = varType as ArrayType;
var elementType = arrayType?.Type.Desugar();
var @class = var.Namespace as Class;
var isRefTypeArray = arrayType != null && @class != null && @class.IsRefType;
if (isRefTypeArray)
{
string cast = elementType.IsPrimitiveType(PrimitiveType.Char) &&
arrayType.QualifiedType.Qualifiers.IsConst
? string.Empty : "(byte*)";
WriteLine($"var {ptr} = {cast}{location};");
}
else
{
TypePrinter.PushMarshalKind(MarshalKind.ReturnVariableArray);
var varReturnType = varType.Visit(TypePrinter);
TypePrinter.PopMarshalKind();
WriteLine($"var {ptr} = ({varReturnType}*){location};");
}
TypePrinter.PopContext();
var ctx = new CSharpMarshalContext(Context, CurrentIndentation) var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{ {
ArgName = var.Name, ArgName = var.Name,
ReturnType = new QualifiedType(var.Type) ReturnType = var.QualifiedType
}; };
ctx.PushMarshalKind(MarshalKind.ReturnVariableArray); ctx.PushMarshalKind(MarshalKind.ReturnVariableArray);
var arrayType = var.Type.Desugar() as ArrayType;
var isRefTypeArray = arrayType != null && var.Namespace is Class @class && @class.IsRefType;
var elementType = arrayType?.Type.Desugar();
if (!isRefTypeArray && elementType == null) if (!isRefTypeArray && elementType == null)
ctx.ReturnVarName = $"*{ptr}"; ctx.ReturnVarName = $"*{ptr}";
else if (elementType == null || elementType.IsPrimitiveType() || else if (elementType == null || elementType.IsPrimitiveType() ||
@ -3238,18 +3226,17 @@ namespace CppSharp.Generators.CSharp
if (library != null) if (library != null)
libName = Path.GetFileNameWithoutExtension(library.FileName); libName = Path.GetFileNameWithoutExtension(library.FileName);
if (Options.StripLibPrefix && libName != null && libName.Length > 3 && if (Options.StripLibPrefix && libName?.Length > 3 &&
libName.StartsWith("lib", StringComparison.Ordinal)) libName.StartsWith("lib", StringComparison.Ordinal))
{
libName = libName.Substring(3); libName = libName.Substring(3);
}
if (libName == null) if (libName == null)
libName = declaration.TranslationUnit.Module.SharedLibraryName; libName = declaration.TranslationUnit.Module.SharedLibraryName;
var targetTriple = Context.ParserOptions.TargetTriple; var targetTriple = Context.ParserOptions.TargetTriple;
if (Options.GenerateInternalImports) if (Options.GenerateInternalImports)
libName = "__Internal"; libName = "__Internal";
else if (TargetTriple.IsWindows(targetTriple) && else if (targetTriple.IsWindows() &&
libName.Contains('.') && Path.GetExtension(libName) != ".dll") libName.Contains('.') && Path.GetExtension(libName) != ".dll")
libName += ".dll"; libName += ".dll";

2
tests/CSharp/CSharp.Tests.cs

@ -804,7 +804,7 @@ public unsafe class CSharpTests : GeneratorTestFixture
[Test] [Test]
public void TestTemplateCopyConstructor() public void TestTemplateCopyConstructor()
{ {
using (var original = new IndependentFields<int>(5)) using (var original = new IndependentFields<int>(5.0f))
{ {
using (var copy = new IndependentFields<int>(original)) using (var copy = new IndependentFields<int>(original))
{ {

16
tests/CSharp/CSharp.cpp

@ -1153,6 +1153,10 @@ int OverrideFromIndirectSecondaryBase::property()
return 1; return 1;
} }
TestOutTypeInterfaces::TestOutTypeInterfaces()
{
}
void TestOutTypeInterfaces::funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfacePassBaseTwo* classTry) void TestOutTypeInterfaces::funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfacePassBaseTwo* classTry)
{ {
} }
@ -1578,6 +1582,18 @@ DLL_API int useDuplicateDeclaredStruct(DuplicateDeclaredStruct* s)
return s->i; return s->i;
} }
ComplexArrayElement::ComplexArrayElement() : BoolField(false), IntField(0), FloatField(0)
{
}
HasComplexArray::HasComplexArray()
{
}
TestIndexedProperties::TestIndexedProperties() : field(0)
{
}
void useStdStringJustAsParameter(std::string s) void useStdStringJustAsParameter(std::string s)
{ {
} }

8
tests/CSharp/CSharp.h

@ -857,6 +857,7 @@ public:
class DLL_API TestOutTypeInterfaces class DLL_API TestOutTypeInterfaces
{ {
public: public:
TestOutTypeInterfaces();
void funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfacePassBaseTwo* classTry); void funcTryInterfaceTypePtrOut(CS_OUT TestParamToInterfacePassBaseTwo* classTry);
void funcTryInterfaceTypeOut(CS_OUT TestParamToInterfacePassBaseTwo classTry); void funcTryInterfaceTypeOut(CS_OUT TestParamToInterfacePassBaseTwo classTry);
}; };
@ -1252,8 +1253,9 @@ struct StructTestArrayTypeFromTypedef
#define MY_MACRO_TEST2_4 (1 << 3) #define MY_MACRO_TEST2_4 (1 << 3)
#define MY_MACRO_TEST2_ALL (1 << 4) - 1 #define MY_MACRO_TEST2_ALL (1 << 4) - 1
struct ComplexArrayElement struct DLL_API ComplexArrayElement
{ {
ComplexArrayElement();
bool BoolField; bool BoolField;
uint32_t IntField; uint32_t IntField;
float FloatField; float FloatField;
@ -1261,14 +1263,16 @@ struct ComplexArrayElement
#define ARRAY_LENGTH_MACRO 10 #define ARRAY_LENGTH_MACRO 10
struct HasComplexArray struct DLL_API HasComplexArray
{ {
HasComplexArray();
ComplexArrayElement complexArray[ARRAY_LENGTH_MACRO]; ComplexArrayElement complexArray[ARRAY_LENGTH_MACRO];
}; };
class DLL_API TestIndexedProperties class DLL_API TestIndexedProperties
{ {
public: public:
TestIndexedProperties();
mutable int field; mutable int field;
int operator[](const int& key); int operator[](const int& key);
void* operator[](size_t n) const; void* operator[](size_t n) const;

8
tests/CSharp/CSharpTemplates.cpp

@ -4,6 +4,10 @@ T1::T1()
{ {
} }
T1::T1(const T1& other) : field(other.field)
{
}
T1::T1(int f) T1::T1(int f)
{ {
field = f; field = f;
@ -18,6 +22,10 @@ int T1::getField() const
return field; return field;
} }
T2::T2()
{
}
DerivedFromSpecializationOfUnsupportedTemplate::DerivedFromSpecializationOfUnsupportedTemplate() DerivedFromSpecializationOfUnsupportedTemplate::DerivedFromSpecializationOfUnsupportedTemplate()
{ {
} }

3
tests/CSharp/CSharpTemplates.h

@ -14,6 +14,7 @@ class DLL_API T1
{ {
public: public:
T1(); T1();
T1(const T1& other);
T1(int f); T1(int f);
~T1(); ~T1();
int getField() const; int getField() const;
@ -23,6 +24,8 @@ private:
class DLL_API T2 class DLL_API T2
{ {
public:
T2();
}; };
class DLL_API Ignored class DLL_API Ignored

8
tests/Common/Common.Tests.cs

@ -1075,10 +1075,10 @@ This is a very long string. This is a very long string. This is a very long stri
using (var nonPrimitiveFixedArray = new TestFixedNonPrimitiveArrays()) using (var nonPrimitiveFixedArray = new TestFixedNonPrimitiveArrays())
{ {
nonPrimitiveFixedArray.NonPrimitiveTypeArray = new NonPrimitiveType[] nonPrimitiveFixedArray.NonPrimitiveTypeArray = new NonPrimitiveType[]
{ {
new NonPrimitiveType{ foo = 1 }, new NonPrimitiveType { foo = 1 },
new NonPrimitiveType{ foo = 2 }, new NonPrimitiveType { foo = 2 },
new NonPrimitiveType{ foo = 3 } new NonPrimitiveType { foo = 3 }
}; };
Assert.AreEqual(3, nonPrimitiveFixedArray.NonPrimitiveTypeArray.Length); Assert.AreEqual(3, nonPrimitiveFixedArray.NonPrimitiveTypeArray.Length);

46
tests/Common/Common.cpp

@ -50,6 +50,10 @@ Foo::Foo()
SomePointerPointer = &SomePointer; SomePointerPointer = &SomePointer;
} }
Foo::Foo(const Foo& other) : A(other.A), B(other.B)
{
}
Foo::Foo(Private p) Foo::Foo(Private p)
{ {
} }
@ -94,6 +98,8 @@ char16_t Foo::returnChar16()
Foo2::Foo2() {} Foo2::Foo2() {}
Foo2::Foo2(const Foo2& other) : Foo(other), C(other.C), valueTypeField(other.valueTypeField) {}
Foo2 Foo2::operator<<(signed int i) Foo2 Foo2::operator<<(signed int i)
{ {
Foo2 foo; Foo2 foo;
@ -149,6 +155,10 @@ bool operator ==(Bar::Item item, const Bar& bar)
return item == bar.RetItem1(); return item == bar.RetItem1();
} }
Bar2::Nested::Nested()
{
}
Bar2::Nested::operator int() const Bar2::Nested::operator int() const
{ {
return 300; return 300;
@ -405,6 +415,10 @@ Ex2* DerivedException::clone()
return 0; return 0;
} }
DefaultParameters::DefaultParameters()
{
}
void DefaultParameters::Foo(int a, int b) void DefaultParameters::Foo(int a, int b)
{ {
} }
@ -421,6 +435,10 @@ void DefaultParameters::Bar()
{ {
} }
common::common()
{
}
int test(common& s) int test(common& s)
{ {
return 5; return 5;
@ -826,9 +844,17 @@ Bar& TestIndexedProperties::operator[](const Foo& key)
return bar; return bar;
} }
TestVariables::TestVariables()
{
}
int TestVariables::VALUE; int TestVariables::VALUE;
void TestVariables::SetValue(int value) { VALUE = value; } void TestVariables::SetValue(int value) { VALUE = value; }
TestWideStrings::TestWideStrings()
{
}
InternalCtorAmbiguity::InternalCtorAmbiguity(void* param) InternalCtorAmbiguity::InternalCtorAmbiguity(void* param)
{ {
// cause a crash to indicate this is the incorrect ctor to invoke // cause a crash to indicate this is the incorrect ctor to invoke
@ -938,11 +964,19 @@ void ChangedAccessOfInheritedProperty::setProtectedProperty(int value)
{ {
} }
ReturnsEmpty::ReturnsEmpty()
{
}
Empty ReturnsEmpty::getEmpty() Empty ReturnsEmpty::getEmpty()
{ {
return Empty(); return Empty();
} }
RefTypeClassPassTry::RefTypeClassPassTry()
{
}
void funcTryRefTypePtrOut(CS_OUT RefTypeClassPassTry* classTry) void funcTryRefTypePtrOut(CS_OUT RefTypeClassPassTry* classTry)
{ {
} }
@ -1307,6 +1341,10 @@ DerivedCovariant::~DerivedCovariant()
{ {
} }
NonPrimitiveType::NonPrimitiveType()
{
}
int NonPrimitiveType::GetFoo() int NonPrimitiveType::GetFoo()
{ {
return foo; return foo;
@ -1316,6 +1354,14 @@ TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays()
{ {
} }
TestGetterSetterToProperties::TestGetterSetterToProperties()
{
}
PointerToTypedefPointerTest::PointerToTypedefPointerTest()
{
}
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet) void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet)
{ {
(*(*lp)).val = valToSet; (*(*lp)).val = valToSet;

20
tests/Common/Common.h

@ -84,6 +84,7 @@ public:
}; };
Foo(); Foo();
Foo(const Foo& other);
Foo(Private p); Foo(Private p);
Foo(const float& f); Foo(const float& f);
int A; int A;
@ -147,6 +148,7 @@ class DLL_API Foo2 : public Foo
public: public:
Foo2(); Foo2();
Foo2(const Foo2& other);
int C; int C;
@ -165,6 +167,7 @@ struct DLL_API Bar2 : public Bar
struct DLL_API Nested struct DLL_API Nested
{ {
Nested();
operator int() const; operator int() const;
}; };
@ -304,6 +307,7 @@ struct DLL_API DerivedException : public Exception
// Tests for ambiguous call to native functions with default parameters // Tests for ambiguous call to native functions with default parameters
struct DLL_API DefaultParameters struct DLL_API DefaultParameters
{ {
DefaultParameters();
void Foo(int a, int b = 0); void Foo(int a, int b = 0);
void Foo(int a); void Foo(int a);
@ -326,7 +330,8 @@ class Derived : public Base<Derived>
// Tests the MoveFunctionToClassPass // Tests the MoveFunctionToClassPass
class DLL_API common class DLL_API common
{ {
public:
common();
}; };
DLL_API int test(common& s); DLL_API int test(common& s);
@ -724,6 +729,7 @@ int TestIndexedPropertiesInValueType::operator[](int i) { return i; }
// Tests variables // Tests variables
struct DLL_API TestVariables struct DLL_API TestVariables
{ {
TestVariables();
static int VALUE; static int VALUE;
void SetValue(int value = VALUE); void SetValue(int value = VALUE);
}; };
@ -731,6 +737,7 @@ struct DLL_API TestVariables
typedef const wchar_t * LPCWSTR; typedef const wchar_t * LPCWSTR;
struct DLL_API TestWideStrings struct DLL_API TestWideStrings
{ {
TestWideStrings();
LPCWSTR GetWidePointer(); LPCWSTR GetWidePointer();
LPCWSTR GetWideNullPointer(); LPCWSTR GetWideNullPointer();
}; };
@ -771,8 +778,8 @@ TestArraysPointers::TestArraysPointers(MyEnum *values, int count)
class DLL_API NonPrimitiveType class DLL_API NonPrimitiveType
{ {
public: public:
NonPrimitiveType();
int GetFoo(); int GetFoo();
int foo; int foo;
@ -787,6 +794,7 @@ public:
struct DLL_API TestGetterSetterToProperties struct DLL_API TestGetterSetterToProperties
{ {
TestGetterSetterToProperties();
int getWidth(); int getWidth();
int getHeight(); int getHeight();
}; };
@ -951,7 +959,11 @@ public:
} ct; } ct;
}; };
class DLL_API RefTypeClassPassTry { }; class DLL_API RefTypeClassPassTry
{
public:
RefTypeClassPassTry();
};
void DLL_API funcTryRefTypePtrOut(CS_OUT RefTypeClassPassTry* classTry); void DLL_API funcTryRefTypePtrOut(CS_OUT RefTypeClassPassTry* classTry);
void DLL_API funcTryRefTypeOut(CS_OUT RefTypeClassPassTry classTry); void DLL_API funcTryRefTypeOut(CS_OUT RefTypeClassPassTry classTry);
@ -994,6 +1006,7 @@ class DLL_API Empty
class DLL_API ReturnsEmpty class DLL_API ReturnsEmpty
{ {
public: public:
ReturnsEmpty();
Empty getEmpty(); Empty getEmpty();
}; };
@ -1608,6 +1621,7 @@ QScopedPointer<QObjectData> d_ptr;
struct DLL_API PointerToTypedefPointerTest struct DLL_API PointerToTypedefPointerTest
{ {
PointerToTypedefPointerTest();
int val; int val;
}; };
typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest; typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest;

4
tests/NamespacesDerived/NamespacesDerived.cs

@ -1,4 +1,5 @@
using System.IO; using System.IO;
using System.Reflection;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Utils; using CppSharp.Utils;
@ -24,7 +25,8 @@ namespace CppSharp.Tests
module.IncludeDirs.Add(Path.GetFullPath(GetTestsDirectory(@base))); module.IncludeDirs.Add(Path.GetFullPath(GetTestsDirectory(@base)));
module.Headers.Add($"{@base}.h"); module.Headers.Add($"{@base}.h");
module.OutputNamespace = @base; module.OutputNamespace = @base;
module.SharedLibraryName = $"{@base}.Native"; module.LibraryDirs.Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
module.Libraries.Add($"{@base}.Native");
driver.Options.Modules[1].Dependencies.Add(module); driver.Options.Modules[1].Dependencies.Add(module);
} }

Loading…
Cancel
Save