Browse Source

Import native DLL-s (tests and parser) with MSVC

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1389/head
Dimitar Dobrev 5 years ago
parent
commit
0e39ab705a
  1. 1
      build/Tests.lua
  2. 2
      src/CppParser/premake5.lua
  3. 1
      src/Generator.Tests/GeneratorTest.cs
  4. 31
      tests/CSharp/CSharpTemplates.h
  5. 70
      tests/Common/Common.cpp
  6. 71
      tests/Common/Common.h
  7. 5
      tests/Tests.h

1
build/Tests.lua

@ -118,6 +118,7 @@ function SetupTestNativeProject(name, depends) @@ -118,6 +118,7 @@ function SetupTestNativeProject(name, depends)
files { "**.h", "**.cpp" }
vpaths { ["*"] = "*" }
defines { "DLL_EXPORT" }
if depends ~= nil then
links { depends .. ".Native" }

2
src/CppParser/premake5.lua

@ -14,6 +14,7 @@ project "CppSharp.CppParser" @@ -14,6 +14,7 @@ project "CppSharp.CppParser"
language "C++"
SetupNativeProject()
rtti "Off"
defines { "DLL_EXPORT" }
filter "action:vs*"
buildoptions { clang_msvc_flags }
@ -44,6 +45,7 @@ project "Std-symbols" @@ -44,6 +45,7 @@ project "Std-symbols"
language "C++"
SetupNativeProject()
rtti "Off"
defines { "DLL_EXPORT" }
filter { "action:vs*" }
buildoptions { clang_msvc_flags }

1
src/Generator.Tests/GeneratorTest.cs

@ -42,6 +42,7 @@ namespace CppSharp.Utils @@ -42,6 +42,7 @@ namespace CppSharp.Utils
var path = Path.GetFullPath(GetTestsDirectory(name));
parserOptions.AddIncludeDirs(path);
parserOptions.AddDefines("DLL_EXPORT");
Diagnostics.Message("Looking for tests in: {0}", path);
var files = Directory.EnumerateFiles(path, "*.h");

31
tests/CSharp/CSharpTemplates.h

@ -30,7 +30,7 @@ class DLL_API Ignored @@ -30,7 +30,7 @@ class DLL_API Ignored
};
template <typename T>
class DLL_API IndependentFields : public T1
class IndependentFields : public T1
{
typedef T Type;
public:
@ -135,12 +135,12 @@ private: @@ -135,12 +135,12 @@ private:
};
template <typename T>
class DLL_API Base
class Base
{
};
template <typename T>
class DLL_API DependentValueFields : public Base<T>
class DependentValueFields : public Base<T>
{
public:
class Nested;
@ -245,7 +245,7 @@ public: @@ -245,7 +245,7 @@ public:
};
template <typename T>
class DLL_API DependentPointerFields
class DependentPointerFields
{
public:
DependentPointerFields(T t = 0);
@ -284,8 +284,8 @@ public: @@ -284,8 +284,8 @@ public:
class iterator
{
public:
iterator() {}
~iterator() {}
iterator();
~iterator();
};
void takeDependentPtrToFirstTemplateArg(iterator i, const K& k);
void takeDependentPtrToSecondTemplateArg(const V& v);
@ -294,6 +294,16 @@ private: @@ -294,6 +294,16 @@ private:
V value;
};
template <typename K, typename V>
TwoTemplateArgs<K, V>::iterator::iterator()
{
}
template <typename K, typename V>
TwoTemplateArgs<K, V>::iterator::~iterator()
{
}
template <typename K, typename V>
void TwoTemplateArgs<K, V>::takeDependentPtrToFirstTemplateArg(iterator i, const K& k)
{
@ -305,7 +315,7 @@ void TwoTemplateArgs<K, V>::takeDependentPtrToSecondTemplateArg(const V& v) @@ -305,7 +315,7 @@ void TwoTemplateArgs<K, V>::takeDependentPtrToSecondTemplateArg(const V& v)
}
template <typename T, typename D = IndependentFields<T>>
class DLL_API HasDefaultTemplateArgument
class HasDefaultTemplateArgument
{
public:
HasDefaultTemplateArgument();
@ -638,7 +648,7 @@ public: @@ -638,7 +648,7 @@ public:
};
template<typename T>
class DLL_API TemplateDerivedFromRegularDynamic : public RegularDynamic
class TemplateDerivedFromRegularDynamic : public RegularDynamic
{
public:
TemplateDerivedFromRegularDynamic();
@ -675,7 +685,7 @@ enum class UsedInTemplatedIndexer @@ -675,7 +685,7 @@ enum class UsedInTemplatedIndexer
};
template <typename T>
class DLL_API QFlags
class QFlags
{
typedef int Int;
typedef int (*Zero);
@ -792,6 +802,9 @@ template class DLL_API TemplateWithIndexer<float>; @@ -792,6 +802,9 @@ template class DLL_API TemplateWithIndexer<float>;
template class DLL_API TemplateWithIndexer<const char*>;
template class DLL_API TemplateDerivedFromRegularDynamic<RegularDynamic>;
template class DLL_API HasCtorWithMappedToEnum<TestFlag>;
template class DLL_API TwoTemplateArgs<int*, int*>;
template class DLL_API TwoTemplateArgs<int*, int>;
template class DLL_API TwoTemplateArgs<int*, float>;
template class DLL_API TwoTemplateArgs<const char*, int>;
template class DLL_API TwoTemplateArgs<QString, int>;

70
tests/Common/Common.cpp

@ -59,6 +59,10 @@ Foo::Foo(const float& f) @@ -59,6 +59,10 @@ Foo::Foo(const float& f)
B = f;
}
const int Foo::unsafe = 10;
const char Foo::charArray[] = "abc";
int Foo::readWrite = 15;
const char* Foo::GetANSI()
{
return "ANSI";
@ -422,6 +426,33 @@ int test(common& s) @@ -422,6 +426,33 @@ int test(common& s)
return 5;
}
int operator *(TestMoveOperatorToClass klass, int b)
{
return klass.A * b;
}
TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b)
{
TestMoveOperatorToClass nb;
nb.A = -b.A;
nb.B = -b.B;
return nb;
}
TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1,
const TestMoveOperatorToClass& b2)
{
TestMoveOperatorToClass b;
b.A = b1.A + b2.A;
b.B = b1.B + b2.B;
return b;
}
int operator==(const Foo2& a, const Foo2& b)
{
return 0;
}
Bar::Item operator |(Bar::Item left, Bar::Item right)
{
return left | right;
@ -501,6 +532,20 @@ ClassD::ClassD(int value) @@ -501,6 +532,20 @@ ClassD::ClassD(int value)
{
}
decltype(Expr) TestDecltype()
{
return Expr;
}
void TestNullPtrType(decltype(nullptr))
{
}
decltype(nullptr) TestNullPtrTypeRet()
{
return nullptr;
}
void DelegateNamespace::Nested::f1(void (*)())
{
}
@ -545,6 +590,11 @@ SomeNamespace::AbstractClass::~AbstractClass() @@ -545,6 +590,11 @@ SomeNamespace::AbstractClass::~AbstractClass()
{
}
int Function()
{
return 5;
}
TestProperties::TestProperties() : Field(0), ArchiveName(0),
FieldValue(0), _refToPrimitiveInSetter(0),
_getterAndSetterWithTheSameName(0), _setterReturnsBoolean(0),
@ -776,6 +826,9 @@ Bar& TestIndexedProperties::operator[](const Foo& key) @@ -776,6 +826,9 @@ Bar& TestIndexedProperties::operator[](const Foo& key)
return bar;
}
int TestVariables::VALUE;
void TestVariables::SetValue(int value) { VALUE = value; }
InternalCtorAmbiguity::InternalCtorAmbiguity(void* param)
{
// cause a crash to indicate this is the incorrect ctor to invoke
@ -986,10 +1039,27 @@ NonTrivialDtor::~NonTrivialDtor() @@ -986,10 +1039,27 @@ NonTrivialDtor::~NonTrivialDtor()
dtorCalled = true;
}
bool NonTrivialDtor::getDtorCalled()
{
return true;
}
void NonTrivialDtor::setDtorCalled(bool value)
{
dtorCalled = true;
}
bool NonTrivialDtor::dtorCalled = false;
DerivedFromTemplateInstantiationWithVirtual::DerivedFromTemplateInstantiationWithVirtual()
{
}
int func_union(union_t u)
{
return u.c;
}
HasProtectedEnum::HasProtectedEnum()
{
}

71
tests/Common/Common.h

@ -115,11 +115,6 @@ public: @@ -115,11 +115,6 @@ public:
char16_t returnChar16();
};
// HACK: do not move these to the cpp - C++/CLI is buggy and cannot link static fields initialised in the cpp
const int Foo::unsafe = 10;
int Foo::readWrite = 15;
const char Foo::charArray[] = "abc";
struct DLL_API Bar
{
enum Item
@ -346,33 +341,15 @@ struct DLL_API TestMoveOperatorToClass @@ -346,33 +341,15 @@ struct DLL_API TestMoveOperatorToClass
TestMoveOperatorToClass::TestMoveOperatorToClass() {}
DLL_API int operator *(TestMoveOperatorToClass klass, int b)
{
return klass.A * b;
}
DLL_API int operator *(TestMoveOperatorToClass klass, int b);
DLL_API TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b)
{
TestMoveOperatorToClass nb;
nb.A = -b.A;
nb.B = -b.B;
return nb;
}
DLL_API TestMoveOperatorToClass operator-(const TestMoveOperatorToClass& b);
DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1,
const TestMoveOperatorToClass& b2)
{
TestMoveOperatorToClass b;
b.A = b1.A + b2.A;
b.B = b1.B + b2.B;
return b;
}
const TestMoveOperatorToClass& b2);
// Not a valid operator overload for Foo2 in managed code - comparison operators need to return bool.
DLL_API int operator==(const Foo2& a, const Foo2& b)
{
return 0;
}
DLL_API int operator==(const Foo2& a, const Foo2& b);
// Tests delegates
typedef int (*DelegateInGlobalNamespace)(int);
@ -578,10 +555,7 @@ bool ClassWithOverloadedOperators:: @@ -578,10 +555,7 @@ bool ClassWithOverloadedOperators::
}
// Tests global static function generation
DLL_API int Function()
{
return 5;
}
DLL_API int Function();
// Tests properties
struct DLL_API TestProperties
@ -754,9 +728,6 @@ struct DLL_API TestVariables @@ -754,9 +728,6 @@ struct DLL_API TestVariables
void SetValue(int value = VALUE);
};
int TestVariables::VALUE;
void TestVariables::SetValue(int value) { VALUE = value; }
typedef const wchar_t * LPCWSTR;
struct DLL_API TestWideStrings
{
@ -861,19 +832,11 @@ public: @@ -861,19 +832,11 @@ public:
// Test decltype
int Expr = 0;
DLL_API decltype(Expr) TestDecltype()
{
return Expr;
}
DLL_API decltype(Expr) TestDecltype();
DLL_API void TestNullPtrType(decltype(nullptr))
{
}
DLL_API void TestNullPtrType(decltype(nullptr));
DLL_API decltype(nullptr) TestNullPtrTypeRet()
{
return nullptr;
}
DLL_API decltype(nullptr) TestNullPtrTypeRet();
// Tests dependent name types
template<typename T> struct DependentType
@ -1193,19 +1156,6 @@ private: @@ -1193,19 +1156,6 @@ private:
static bool dtorCalled;
};
// HACK: do not move these to the cpp - C++/CLI is buggy and cannot link static fields initialised in the cpp
bool NonTrivialDtor::dtorCalled = false;
bool NonTrivialDtor::getDtorCalled()
{
return true;
}
void NonTrivialDtor::setDtorCalled(bool value)
{
dtorCalled = true;
}
template <class T> class ForwardedTemplate;
ForwardedTemplate<int> returnsForwardedTemplate();
@ -1255,10 +1205,7 @@ typedef union @@ -1255,10 +1205,7 @@ typedef union
int c;
} union_t;
int DLL_API func_union(union_t u)
{
return u.c;
}
int DLL_API func_union(union_t u);
class DLL_API HasProtectedEnum
{

5
tests/Tests.h

@ -1,7 +1,12 @@ @@ -1,7 +1,12 @@
#pragma once
#if defined(_MSC_VER)
#if defined(DLL_EXPORT)
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
#ifndef STDCALL
#define STDCALL __stdcall

Loading…
Cancel
Save