Browse Source

Enabled the tests for std::string.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/780/head
Dimitar Dobrev 8 years ago
parent
commit
422b98a0fd
  1. 8
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std-symbols.cpp
  2. 9
      src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs
  3. 8
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std-symbols.cpp
  4. 9
      src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs
  5. 8
      src/Generator/AST/Utils.cs
  6. 7
      src/Generator/Passes/SymbolsCodeGenerator.cs
  7. 4
      src/Generator/Passes/TrimSpecializationsPass.cs
  8. 7
      src/Parser/TargetTriple.cs
  9. 2
      tests/CSharp/AnotherUnit.cpp
  10. 4
      tests/CSharp/AnotherUnit.h
  11. 6
      tests/CSharp/CSharp.Tests.cs
  12. 2
      tests/Common/Common.Tests.cs
  13. 10
      tests/Common/Common.cpp
  14. 4
      tests/Common/Common.h

8
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std-symbols.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#include <string>
template std::__1::allocator<char>::allocator() noexcept;
template std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string(const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type*, const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::allocator_type&);
template std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string();
template const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type* std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::c_str() const noexcept;
template __attribute__((visibility("default"))) std::__1::allocator<char>::allocator() noexcept;
template __attribute__((visibility("default"))) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string(const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type*, const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::allocator_type&);
template __attribute__((visibility("default"))) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string();
template __attribute__((visibility("default"))) const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type* std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::c_str() const noexcept;

9
src/CppParser/Bindings/CSharp/i686-apple-darwin12.4.0/Std.cs

@ -1235,6 +1235,15 @@ namespace Std @@ -1235,6 +1235,15 @@ namespace Std
[FieldOffset(0)]
internal global::Std.__1.Tree.__Internal __tree_;
}
public unsafe partial class ValueCompare
{
[StructLayout(LayoutKind.Explicit, Size = 0)]
public partial struct __Internal
{
}
}
}
}
}

8
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std-symbols.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#include <string>
template std::__1::allocator<char>::allocator() noexcept;
template std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string(const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type*, const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::allocator_type&);
template std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string();
template const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type* std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::c_str() const noexcept;
template __attribute__((visibility("default"))) std::__1::allocator<char>::allocator() noexcept;
template __attribute__((visibility("default"))) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::basic_string(const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type*, const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::allocator_type&);
template __attribute__((visibility("default"))) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string();
template __attribute__((visibility("default"))) const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::value_type* std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::c_str() const noexcept;

9
src/CppParser/Bindings/CSharp/x86_64-apple-darwin12.4.0/Std.cs

@ -1235,6 +1235,15 @@ namespace Std @@ -1235,6 +1235,15 @@ namespace Std
[FieldOffset(0)]
internal global::Std.__1.Tree.__Internal __tree_;
}
public unsafe partial class ValueCompare
{
[StructLayout(LayoutKind.Explicit, Size = 0)]
public partial struct __Internal
{
}
}
}
}
}

8
src/Generator/AST/Utils.cs

@ -91,9 +91,13 @@ namespace CppSharp.AST @@ -91,9 +91,13 @@ namespace CppSharp.AST
type = type.Desugar();
type = type.GetFinalPointee() ?? type;
ClassTemplateSpecialization specialization;
if (!type.TryGetDeclaration(out specialization) ||
specialization.IsExplicitlyGenerated)
type.TryGetDeclaration(out specialization);
if (specialization == null || specialization.IsExplicitlyGenerated)
{
if (specialization != null)
addSpecialization(specialization);
return;
}
TypeMap typeMap;
typeMaps.FindTypeMap(specialization, out typeMap);

7
src/Generator/Passes/SymbolsCodeGenerator.cs

@ -4,6 +4,7 @@ using System.Text; @@ -4,6 +4,7 @@ using System.Text;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Parser;
namespace CppSharp.Passes
{
@ -30,7 +31,11 @@ namespace CppSharp.Passes @@ -30,7 +31,11 @@ namespace CppSharp.Passes
{
if (method.Namespace is ClassTemplateSpecialization)
{
var exporting = Context.ParserOptions.IsMicrosoftAbi ? "__declspec(dllexport) " : string.Empty;
var exporting = string.Empty;
if (Context.ParserOptions.IsMicrosoftAbi)
exporting = "__declspec(dllexport) ";
else if (TargetTriple.IsMacOS(Context.ParserOptions.TargetTriple))
exporting = "__attribute__((visibility(\"default\"))) ";
WriteLine($"template {exporting}{method.Visit(cppTypePrinter)};");
return true;
}

4
src/Generator/Passes/TrimSpecializationsPass.cs

@ -74,8 +74,8 @@ namespace CppSharp.Passes @@ -74,8 +74,8 @@ namespace CppSharp.Passes
private void CleanSpecializations(Class template)
{
template.Specializations.RemoveAll(s => !s.IsExplicitlyGenerated &&
!specializations.Contains(s) && !internalSpecializations.Contains(s));
template.Specializations.RemoveAll(
s => !specializations.Contains(s) && !internalSpecializations.Contains(s));
foreach (var specialization in template.Specializations.Where(
s => !s.IsExplicitlyGenerated &&

7
src/Parser/TargetTriple.cs

@ -12,5 +12,12 @@ namespace CppSharp.Parser @@ -12,5 +12,12 @@ namespace CppSharp.Parser
return parts.Contains("windows") ||
parts.Contains("win32") || parts.Contains("win64");
}
public static bool IsMacOS(string targetTriple)
{
var parts = targetTriple.Split('-');
return parts.Contains("apple") ||
parts.Contains("darwin") || parts.Contains("osx");
}
}
}

2
tests/CSharp/AnotherUnit.cpp

@ -7,5 +7,5 @@ void functionInAnotherUnit() @@ -7,5 +7,5 @@ void functionInAnotherUnit()
namespace HasFreeConstant
{
extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE = 5;
// extern const std::string DLL_API STD_STRING_CONSTANT = "test";
extern const std::string DLL_API STD_STRING_CONSTANT = "test";
}

4
tests/CSharp/AnotherUnit.h

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
#include "../Tests.h"
//#include <string>
#include <string>
void DLL_API functionInAnotherUnit();
@ -20,5 +20,5 @@ class ForwardInOtherUnitButSameModule @@ -20,5 +20,5 @@ class ForwardInOtherUnitButSameModule
namespace HasFreeConstant
{
extern const int DLL_API FREE_CONSTANT_IN_NAMESPACE;
// extern const std::string DLL_API STD_STRING_CONSTANT;
extern const std::string DLL_API STD_STRING_CONSTANT;
}

6
tests/CSharp/CSharp.Tests.cs

@ -543,12 +543,12 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -543,12 +543,12 @@ public unsafe class CSharpTests : GeneratorTestFixture
}
}
[Test, Ignore("We need symbols for std::string to invoke and auto-compilation of exported templates is not added yet.")]
[Test, Platform(Exclude = "Linux", Reason = "This fails on Linux for no reason at all.")]
public void TestStdStringConstant()
{
//Assert.That(CSharp.HasFreeConstant.AnotherUnit.STD_STRING_CONSTANT, Is.EqualTo("test"));
Assert.That(CSharp.HasFreeConstant.AnotherUnit.STD_STRING_CONSTANT, Is.EqualTo("test"));
// check a second time to ensure it hasn't been improperly freed
//Assert.That(CSharp.HasFreeConstant.AnotherUnit.STD_STRING_CONSTANT, Is.EqualTo("test"));
Assert.That(CSharp.HasFreeConstant.AnotherUnit.STD_STRING_CONSTANT, Is.EqualTo("test"));
}
[Test, Ignore("The completion of types is temporarily suspended because of problems with QtWidgets.")]

2
tests/Common/Common.Tests.cs

@ -711,7 +711,7 @@ public class CommonTests : GeneratorTestFixture @@ -711,7 +711,7 @@ public class CommonTests : GeneratorTestFixture
Assert.That(Foo.ReadWrite, Is.EqualTo(25));
}
[Test, Ignore("We need symbols for std::string to invoke and auto-compilation of exported templates is not added yet.")]
[Test]
public void TestStdString()
{
// when C++ memory is deleted, it's only marked as free but not immediadely freed

10
tests/Common/Common.cpp

@ -435,7 +435,15 @@ void DelegateNamespace::f2(void (*)()) @@ -435,7 +435,15 @@ void DelegateNamespace::f2(void (*)())
{
}
std::string HasStdString::testStdString(std::string s)
HasStdString::HasStdString()
{
}
HasStdString::~HasStdString()
{
}
std::string HasStdString::testStdString(const std::string& s)
{
return s + "_test";
}

4
tests/Common/Common.h

@ -768,7 +768,9 @@ public: @@ -768,7 +768,9 @@ public:
class DLL_API HasStdString
{
public:
std::string testStdString(std::string s);
HasStdString();
~HasStdString();
std::string testStdString(const std::string& s);
std::string s;
std::string& getStdString();
};

Loading…
Cancel
Save