Permalink
Browse files

Merge pull request #21 from benpye/clang6

Update for Clang 6 and .NET standard
  • Loading branch information...
mjsabby committed Jul 7, 2018
2 parents 7435449 + a878bb4 commit b52de9c08f7243a8f060d511e1d9ed1a901d3cb3
View
@@ -0,0 +1,6 @@
root = true
charset = utf-8
# Make git happy
end_of_line = lf
insert_final_newline = true
View
@@ -5,6 +5,7 @@
*.suo
*.user
*.sln.docstates
.vs/
# Build results
[Dd]ebug/
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClangSharp\ClangSharp.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,34 @@
using System;
using System.Runtime.InteropServices;
using Xunit;
namespace ClangSharp.Test
{
public class ModuleMapDescriptor
{
[Fact]
public void Basic()
{
var contents =
"framework module TestFrame {\n"
+ " umbrella header \"TestFrame.h\"\n"
+ "\n"
+ " export *\n"
+ " module * { export * }\n"
+ "}\n";
CXModuleMapDescriptor mmd = clang.ModuleMapDescriptor_create(0);
clang.ModuleMapDescriptor_setFrameworkModuleName(mmd, "TestFrame");
clang.ModuleMapDescriptor_setUmbrellaHeader(mmd, "TestFrame.h");
IntPtr bufPtr;
uint bufSize = 0;
clang.ModuleMapDescriptor_writeToBuffer(mmd, 0, out bufPtr, out bufSize);
var bufStr = Marshal.PtrToStringAnsi(bufPtr, (int)bufSize);
Assert.Equal(contents, bufStr);
clang.free(bufPtr);
clang.ModuleMapDescriptor_dispose(mmd);
}
}
}
@@ -0,0 +1,40 @@
using System;
using System.IO;
using Xunit;
namespace ClangSharp.Test
{
// This is not ported from libclangtest but instead created to test Unicode stuff
public class TranslationUnit
{
[Theory]
[InlineData("basic")]
[InlineData("example with spaces")]
[InlineData("")]
public void Basic(string name)
{
// Create a unique directory
var dir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(dir);
try
{
// Create a file with the right name
var file = new FileInfo(Path.Combine(dir, name + ".c"));
File.WriteAllText(file.FullName, "int main() { return 0; }");
var index = clang.createIndex(0, 0);
var translationUnit = clang.parseTranslationUnit(index, file.FullName, new string[0], 0, new CXUnsavedFile[0], 0, 0);
var clangFile = clang.getFile(translationUnit, file.FullName);
var clangFileName = clang.getFileName(clangFile);
var clangFileNameString = clang.getCString(clangFileName);
Assert.Equal(file.FullName, clangFileNameString);
}
finally
{
Directory.Delete(dir, true);
}
}
}
}
Oops, something went wrong.

0 comments on commit b52de9c

Please sign in to comment.