Browse Source

Stubbed in MSVC ABI. Started writing test cases.

git-svn-id: https://mono-soc-2010.googlecode.com/svn/trunk/cppinterop@41 a470b8cb-0e6f-1642-1b45-71e107334c4b
pull/1/head
alexander.corrado 16 years ago
parent
commit
9a052844b3
  1. 2
      Mono.VisualC.Interop/ABI/CppAbi.cs
  2. 34
      Mono.VisualC.Interop/ABI/Impl/MsvcAbi.cs
  3. 1
      Mono.VisualC.Interop/Mono.VisualC.Interop.csproj
  4. 48
      Tests/CppInstancePtrTests.cs
  5. 55
      Tests/CppLibraryTests.cs
  6. 26
      Tests/ItaniumAbiTests.cs
  7. 26
      Tests/MsvcAbiTests.cs
  8. 39
      Tests/Support/CPPTestLibBase.cs
  9. 16
      Tests/Support/CSimpleClass.cs
  10. 4
      Tests/Tests.csproj

2
Mono.VisualC.Interop/ABI/CppAbi.cs

@ -137,7 +137,7 @@ namespace Mono.VisualC.Interop.ABI {
protected virtual void DefineImplType () protected virtual void DefineImplType ()
{ {
impl_type = impl_module.DefineType (impl_module.Name + "_" + interface_type.Name + "_Impl", impl_type = impl_module.DefineType (interface_type.Name + "_" + layout_type.Name + "_Impl",
TypeAttributes.Class | TypeAttributes.Sealed); TypeAttributes.Class | TypeAttributes.Sealed);
impl_type.AddInterfaceImplementation (interface_type); impl_type.AddInterfaceImplementation (interface_type);

34
Mono.VisualC.Interop/ABI/Impl/MsvcAbi.cs

@ -0,0 +1,34 @@
//
// Mono.VisualC.Interop.ABI.MsvcAbi.cs: An implementation of the Microsoft Visual C++ ABI
//
// Author:
// Alexander Corrado (alexander.corrado@gmail.com)
//
// Copyright (C) 2010 Alexander Corrado
//
using System;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Mono.VisualC.Interop.ABI {
public class MsvcAbi : CppAbi {
public MsvcAbi ()
{
}
public override CallingConvention DefaultCallingConvention {
get {
throw new System.NotImplementedException ();
}
}
public override string GetMangledMethodName (MethodInfo methodInfo)
{
throw new System.NotImplementedException ();
}
}
}

1
Mono.VisualC.Interop/Mono.VisualC.Interop.csproj

@ -48,6 +48,7 @@
<Compile Include="ABI\MethodType.cs" /> <Compile Include="ABI\MethodType.cs" />
<Compile Include="ABI\Impl\ItaniumAbi.cs" /> <Compile Include="ABI\Impl\ItaniumAbi.cs" />
<Compile Include="ABI\Impl\VirtualOnlyAbi.cs" /> <Compile Include="ABI\Impl\VirtualOnlyAbi.cs" />
<Compile Include="ABI\Impl\MsvcAbi.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

48
Tests/CppInstancePtrTests.cs

@ -8,15 +8,61 @@
// //
using System; using System;
using System.Runtime.InteropServices;
using NUnit.Framework; using NUnit.Framework;
using Mono.VisualC.Interop;
using Tests.Support;
namespace Tests { namespace Tests {
[TestFixture] [TestFixture]
public class CppInstancePtrTests : CPPTestLibBase { public class CppInstancePtrTests : CPPTestLibBase {
static CppInstancePtr uninitialized;
[Test] [Test]
public void TestCase () [ExpectedException (typeof (ObjectDisposedException))]
public void TestUninitialized ()
{ {
Assert.IsFalse (uninitialized.IsManagedAlloc, "cppip.IsManagedAlloc");
Assert.AreEqual (IntPtr.Zero, uninitialized.Native, "cppip.Native wasn't null pointer");
} }
[Test]
public void TestForManagedObject ()
{
CppInstancePtr cppip = CppInstancePtr.ForManagedObject<EmptyTestInterface,CPPTestLibBase> (this);
Assert.AreNotEqual (IntPtr.Zero, cppip.Native, "cppip.Native was null pointer");
Assert.IsTrue (cppip.IsManagedAlloc, "cppip.IsManagedAlloc was not true");
cppip.Dispose ();
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void TestDisposed ()
{
CppInstancePtr cppip = CppInstancePtr.ForManagedObject<EmptyTestInterface,CPPTestLibBase> (this);
cppip.Dispose ();
// should throw
Console.WriteLine (cppip.Native);
}
[Test]
public void TestFromNativePtr ()
{
IntPtr native = CreateCSimpleSubClass (0);
CppInstancePtr cppip = new CppInstancePtr (native);
Assert.AreEqual (native, cppip.Native);
Assert.IsFalse (cppip.IsManagedAlloc, "cppip.IsManagedAlloc was not false");
cppip.Dispose ();
DestroyCSimpleSubClass (native);
}
[DllImport("CPPTestLib")]
private static extern IntPtr CreateCSimpleSubClass (int x);
[DllImport("CPPTestLib")]
private static extern void DestroyCSimpleSubClass (IntPtr cppip);
} }
} }

55
Tests/CppLibraryTests.cs

@ -0,0 +1,55 @@
//
// CppLibraryTests.cs: Test cases to exercise CppLibrary
//
// Author:
// Alexander Corrado (alexander.corrado@gmail.com)
//
// Copyright (C) 2010 Alexander Corrado
//
using System;
using NUnit.Framework;
using Mono.VisualC.Interop;
using Mono.VisualC.Interop.ABI;
using Tests.Support;
namespace Tests {
[TestFixture]
public class CppLibraryTests : CPPTestLibBase {
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestCreateNullAbi ()
{
CppLibrary cppl = new CppLibrary ("foo", null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestCreateNullLibName ()
{
CppLibrary cppl = new CppLibrary (null, new VirtualOnlyAbi ());
}
[Test]
public void TestProperties ()
{
VirtualOnlyAbi abi = new VirtualOnlyAbi ();
CppLibrary cppl = new CppLibrary ("FooLib", abi);
Assert.AreEqual ("FooLib", cppl.Name, "#A1");
Assert.AreSame (abi, cppl.Abi, "#A2");
}
[Test]
public void TestGetClass ()
{
VirtualOnlyAbi abi = new VirtualOnlyAbi ();
CppLibrary cppl = new CppLibrary ("FooLib", abi);
EmptyTestInterface klass = cppl.GetClass<EmptyTestInterface,EmptyTestStruct,CPPTestLibBase> ("FooClass");
Assert.IsNotNull (klass, "#A1");
}
}
}

26
Tests/ItaniumAbiTests.cs

@ -0,0 +1,26 @@
//
// ItaniumAbiTests.cs: Test cases to exercise the ItaniumAbi
//
// Author:
// Alexander Corrado (alexander.corrado@gmail.com)
//
// Copyright (C) 2010 Alexander Corrado
//
using System;
using NUnit.Framework;
using Mono.VisualC.Interop;
using Mono.VisualC.Interop.ABI;
using Tests.Support;
namespace Tests {
[TestFixture]
public class ItaniumAbiTests : CPPTestLibBase {
public ItaniumAbiTests () : base (new ItaniumAbi ())
{
}
}
}

26
Tests/MsvcAbiTests.cs

@ -0,0 +1,26 @@
//
// MsvcAbiTests.cs: Test cases to exercise the MsvcAbi
//
// Author:
// Alexander Corrado (alexander.corrado@gmail.com)
//
// Copyright (C) 2010 Alexander Corrado
//
using System;
using NUnit.Framework;
using Mono.VisualC.Interop;
using Mono.VisualC.Interop.ABI;
using Tests.Support;
namespace Tests {
[TestFixture]
public class MsvcAbiTests : CPPTestLibBase {
public MsvcAbiTests () : base (new MsvcAbi ())
{
}
}
}

39
Tests/Support/CPPTestLibBase.cs

@ -4,15 +4,46 @@ using NUnit.Framework;
using Mono.VisualC.Interop; using Mono.VisualC.Interop;
using Mono.VisualC.Interop.ABI; using Mono.VisualC.Interop.ABI;
namespace Tests { namespace Tests.Support {
public class CPPTestLibBase { public class CPPTestLibBase : ICppObject {
protected CppLibrary CPPTestLib { get; private set; } protected CppLibrary TestLib { get; private set; }
protected CPPTestLibBase ()
{
}
protected CPPTestLibBase (CppAbi abi) protected CPPTestLibBase (CppAbi abi)
{ {
this.CPPTestLib = new CppLibrary ("CPPTestLib", abi); this.TestLib = new CppLibrary ("CPPTestLib", abi);
}
protected CSimpleClass.ICSimpleClass Klass {
get {
if (CSimpleClass._impl == null)
CSimpleClass.Bind (TestLib);
return CSimpleClass._impl;
}
} }
public IntPtr Native {
get {
throw new System.NotImplementedException ();
}
}
public void Dispose ()
{
throw new System.NotImplementedException ();
}
}
public interface EmptyTestInterface : ICppClassOverridable<CPPTestLibBase> {
}
public struct EmptyTestStruct {
} }
} }

16
Tests/Support/CSimpleClass.cs

@ -7,13 +7,13 @@ using System.Runtime.InteropServices;
using Mono.VisualC.Interop; using Mono.VisualC.Interop;
namespace CPPPOC { namespace Tests.Support {
public class CSimpleClass : ICppObject { public class CSimpleClass : ICppObject {
#region C++ Header #region C++ Header
// This interface is analogous to the C++ class public header -- it defines the // This interface is analogous to the C++ class public header -- it defines the
// C++ class's interface. The order of methods must be the same as in the C++ header. // C++ class's interface. The order of methods must be the same as in the C++ header.
private interface __ICSimpleClass : ICppClassOverridable<CSimpleClass> { public interface ICSimpleClass : ICppClassOverridable<CSimpleClass> {
// constructor // constructor
void CSimpleClass(CppInstancePtr ths, int value); void CSimpleClass(CppInstancePtr ths, int value);
@ -30,15 +30,15 @@ namespace CPPPOC {
// This struct defines the C++ class's memory footprint. // This struct defines the C++ class's memory footprint.
// Basically, it includes both the class's public and private fields. // Basically, it includes both the class's public and private fields.
// Again, the order must be the same as in the C++ header. // Again, the order must be the same as in the C++ header.
private struct __CSimpleClass { public struct _CSimpleClass {
public int value; public int value;
} }
#endregion #endregion
private static __ICSimpleClass _impl; public static ICSimpleClass _impl;
public static void Bind(CppLibrary lib) { public static void Bind(CppLibrary lib) {
_impl = lib.GetClass<__ICSimpleClass,__CSimpleClass,CSimpleClass>("CSimpleClass"); _impl = lib.GetClass<ICSimpleClass,_CSimpleClass,CSimpleClass>("CSimpleClass");
} }
private CppInstancePtr _native; private CppInstancePtr _native;
@ -91,12 +91,6 @@ namespace CPPPOC {
_impl.V1(_native, x); _impl.V1(_native, x);
} }
[OverrideNative]
public virtual void V2() {
Console.WriteLine("Managed V2()");
_impl.V2(_native);
}
public void Dispose() { public void Dispose() {
_impl.Destruct(_native); _impl.Destruct(_native);
_native.Dispose(); _native.Dispose();

4
Tests/Tests.csproj

@ -39,6 +39,10 @@
<ItemGroup> <ItemGroup>
<Compile Include="CppInstancePtrTests.cs" /> <Compile Include="CppInstancePtrTests.cs" />
<Compile Include="Support\CPPTestLibBase.cs" /> <Compile Include="Support\CPPTestLibBase.cs" />
<Compile Include="Support\CSimpleClass.cs" />
<Compile Include="CppLibraryTests.cs" />
<Compile Include="ItaniumAbiTests.cs" />
<Compile Include="MsvcAbiTests.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions> <ProjectExtensions>

Loading…
Cancel
Save