Integrate all tests to use NUnit. Get tests building / running.

This commit is contained in:
Alex Corrado 2011-05-24 17:17:43 -04:00
Родитель 1f3bee8d81
Коммит fa8dde405d
15 изменённых файлов: 117 добавлений и 233 удалений

Просмотреть файл

@ -1,4 +1,3 @@
dnl Warning: This is an automatically generated file, do not edit!
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.54])
AC_INIT([CPPInterop], [0.99.1])
@ -17,6 +16,11 @@ SHAMROCK_EXPAND_DATADIR
AC_PROG_INSTALL
AC_PATH_PROG(MONO, mono, no)
if test "x$MONO" = "xno"; then
AC_MSG_ERROR([mono Not found])
fi
AC_PATH_PROG(GMCS, mcs, no)
if test "x$GMCS" = "xno"; then
AC_MSG_ERROR([mcs Not found])
@ -47,6 +51,8 @@ fi
dnl package checks, common for all configs
PKG_CHECK_MODULES([MONO_NUNIT], [mono-nunit])
dnl package checks, per config

Просмотреть файл

@ -31,8 +31,6 @@ MONO_VISUALC_CODE_DLL_MDB=
endif
COMPILE_TARGET = library
PROJECT_REFERENCES = \
$(BUILD_DIR)/Mono.VisualC.Interop.dll
AL=al2
SATELLITE_ASSEMBLY_NAME=$(notdir $(basename $(ASSEMBLY))).resources.dll
@ -97,6 +95,6 @@ $(build_xamlg_list): %.xaml.g.cs: %.xaml
$(ASSEMBLY_MDB): $(ASSEMBLY)
$(ASSEMBLY): $(build_sources) $(build_resources) $(build_datafiles) $(DLL_REFERENCES) $(PROJECT_REFERENCES) $(build_xamlg_list) $(build_satellite_assembly_list)
$(ASSEMBLY): $(build_sources) $(build_resources) $(build_datafiles) $(DLL_REFERENCES) $(build_xamlg_list) $(build_satellite_assembly_list)
mkdir -p $(shell dirname $(ASSEMBLY))
$(ASSEMBLY_COMPILER_COMMAND) $(ASSEMBLY_COMPILER_FLAGS) -out:$(ASSEMBLY) -target:$(COMPILE_TARGET) $(build_sources_embed) $(build_resources_embed) $(build_references_ref)

Просмотреть файл

@ -31,8 +31,6 @@ GENERATOR_EXE_MDB=
endif
COMPILE_TARGET = exe
PROJECT_REFERENCES = \
$(BUILD_DIR)/Mono.VisualC.Interop.dll
AL=al2
SATELLITE_ASSEMBLY_NAME=$(notdir $(basename $(ASSEMBLY))).resources.dll
@ -93,6 +91,6 @@ $(build_xamlg_list): %.xaml.g.cs: %.xaml
$(ASSEMBLY_MDB): $(ASSEMBLY)
$(ASSEMBLY): $(build_sources) $(build_resources) $(build_datafiles) $(DLL_REFERENCES) $(PROJECT_REFERENCES) $(build_xamlg_list) $(build_satellite_assembly_list)
$(ASSEMBLY): $(build_sources) $(build_resources) $(build_datafiles) $(DLL_REFERENCES) $(build_xamlg_list) $(build_satellite_assembly_list)
mkdir -p $(shell dirname $(ASSEMBLY))
$(ASSEMBLY_COMPILER_COMMAND) $(ASSEMBLY_COMPILER_FLAGS) -out:$(ASSEMBLY) -target:$(COMPILE_TARGET) $(build_sources_embed) $(build_resources_embed) $(build_references_ref)

69
tests/AbiTests.cs Normal file
Просмотреть файл

@ -0,0 +1,69 @@
using System;
using NUnit.Framework;
using Tests.Support;
namespace Tests {
[TestFixture]
public class AbiTests {
[Test]
public void test_0_class_return ()
{
// Section 3.1.4:
// Classes with non-default copy ctors/destructors are returned using a hidden
// argument
var c = ClassWithCopyCtor.Return (42);
Assert.AreEqual (42, c.GetX (), "#1");
var c2 = ClassWithDtor.Return (43);
Assert.AreEqual (43, c2.GetX (), "#2");
// This class is returned normally
var c3 = ClassWithoutCopyCtor.Return (44);
Assert.AreEqual (44, c3.GetX (), "#3");
}
// An object as ref argument
[Test]
public void test_0_class_arg ()
{
var c1 = new Class (4);
var c2 = new Class (5);
c1.CopyTo (c2);
Assert.AreEqual (4, c2.GetX (), "#1");
}
// A null object as ref argument
[Test]
public void test_0_class_arg_null ()
{
var c1 = new Class (4);
Assert.That (c1.IsNull (null), "#1");
}
// An object as byval argument
[Test]
public void test_0_class_arg_byval ()
{
var c1 = new Class (4);
var c2 = new Class (5);
c1.CopyFromValue (c2);
Assert.AreEqual (5, c1.GetX (), "#1");
}
// A null object as byval argument
[Test]
[ExpectedException (typeof (ArgumentException))]
public void test_0_class_arg_byval_null ()
{
var c1 = new Class (4);
c1.CopyFromValue (null);
}
}
}

Просмотреть файл

@ -37,14 +37,6 @@ namespace Tests {
cppip.Dispose ();
}
[Test]
[ExpectedException (typeof(ArgumentNullException))]
public void TestForNonStaticWrapperWithNull ()
{
CppInstancePtr cppip = CppInstancePtr.ForManagedObject<CSimpleClass.ICSimpleClass,CSimpleClass> (null);
cppip.Dispose ();
}
[Test]
[ExpectedException (typeof (ObjectDisposedException))]
public void TestDisposed ()
@ -52,25 +44,9 @@ namespace Tests {
CppInstancePtr cppip = CppInstancePtr.ForManagedObject<EmptyTestInterface,CppMockObject> (CppMockObject.Instance);
cppip.Dispose ();
// should throw
Console.WriteLine (cppip.Native);
Assert.Fail ();
}
[Test]
public void TestFromNativePtr ()
{
IntPtr native = CreateCSimpleSubClass (0);
CppInstancePtr cppip = new CppInstancePtr (native);
Assert.AreEqual (native, cppip.Native);
Assert.IsFalse (cppip.IsManagedAlloc, "#A1");
cppip.Dispose ();
DestroyCSimpleSubClass (native);
}
[DllImport("CPPTestLib")]
private static extern IntPtr CreateCSimpleSubClass (int x);
[DllImport("CPPTestLib")]
private static extern void DestroyCSimpleSubClass (IntPtr cppip);
}
}

Просмотреть файл

@ -1,25 +0,0 @@
//
// 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.ABI;
namespace Tests {
[TestFixture]
public class ItaniumAbiTests : SharedAbiTests {
public ItaniumAbiTests () : base (new ItaniumAbi ())
{
}
}
}

Просмотреть файл

@ -7,17 +7,20 @@ INTEROP_DLL = \
TEST_DLL = $(BUILD_DIR)/Test.dll
HDR = \
Native/test.h
Native/AbiTests.h
NATIVE = \
Native/NUnit.cpp \
Native/test.cpp
Native/AbiTests.cpp
MANAGED = \
AbiTests.cs \
CppInstancePtrTests.cs \
Support/CppMockObject.cs \
Support/CppNUnitAsserts.cs \
test.cs
Support/CppNUnitAsserts.cs
REFERENCES = \
-pkg:mono-nunit
all: $(TEST_DLL)
@ -32,10 +35,10 @@ $(BUILD_DIR)/libTest-inline.so: $(HEADERS) $(NATIVE)
generated: test.xml
$(RM) -r generated
mono --debug $(BUILD_DIR)/generator.exe -o=$@ -ns=CppTests -lib=Test test.xml
mono --debug $(BUILD_DIR)/generator.exe -o=$@ -ns=Tests -lib=Test test.xml
$(TEST_DLL): generated $(MANAGED) $(BUILD_DIR)/libTest.so $(BUILD_DIR)/libTest-inline.so
mcs -out:$@ -target:library -unsafe -r:$(INTEROP_DLL) generated/*.cs $(MANAGED)
mcs -out:$@ -target:library -unsafe $(REFERENCES) -r:$(INTEROP_DLL) generated/*.cs $(MANAGED)
clean:
$(RM) -rf $(TEST_DLL) generated $(BUILD_DIR)/libTest.so $(BUILD_DIR)/libTest-inline.so test.xml

Просмотреть файл

@ -1,24 +0,0 @@
//
// 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.ABI;
namespace Tests {
[TestFixture]
public class MsvcAbiTests : SharedAbiTests {
public MsvcAbiTests () : base (new MsvcAbi ())
{
}
}
}

Просмотреть файл

@ -1,5 +1,5 @@
#include "test.h"
#include "AbiTests.h"
ClassWithCopyCtor::ClassWithCopyCtor(const ClassWithCopyCtor& f) {
x = f.x;

Просмотреть файл

Просмотреть файл

@ -1,43 +0,0 @@
//
// SharedAbiTests.cs: Test cases that are shared by all ABIs
//
// 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 {
public class SharedAbiTests {
protected CppLibrary test_lib { get; private set; }
protected IVirtualMethodTestClass virtual_test_class { get; private set; }
protected SharedAbiTests (CppAbi abi)
{
this.test_lib = new CppLibrary ("CPPTestLib", abi);
this.virtual_test_class = test_lib.GetClass<IVirtualMethodTestClass> ("VirtualMethodTestClass");
CppNUnitAsserts.Init ();
}
[Test]
public void TestVirtualMethods ()
{
CppInstancePtr vmtc = VirtualMethodTestClass.Create ();
virtual_test_class.V0 (vmtc, 1, 2, 3);
VirtualMethodTestClass.Destroy (vmtc);
}
}
}

Просмотреть файл

@ -22,7 +22,7 @@ namespace Tests.Support {
{
}
public IntPtr Native {
public CppInstancePtr Native {
get {
throw new System.NotImplementedException ();
}

Просмотреть файл

@ -30,7 +30,6 @@
<IsWebBootstrapper>true</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -56,47 +55,46 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.core, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
</ItemGroup>
<ItemGroup>
<Compile Include="CppInstancePtrTests.cs" />
<Compile Include="Support\CSimpleClass.cs" />
<Compile Include="CppLibraryTests.cs" />
<Compile Include="ItaniumAbiTests.cs" />
<Compile Include="MsvcAbiTests.cs" />
<Compile Include="Support\CppMockObject.cs" />
<Compile Include="Support\CppNUnitAsserts.cs" />
<Compile Include="SharedAbiTests.cs" />
<Compile Include="Support\VirtualMethodTestClass.cs" />
<Compile Include="CppInstancePtrTests.cs" />
<Compile Include="AbiTests.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\CPPTestLib\CPPTestLib.cproj">
<Project>{B01E6282-144E-481A-8E1F-95F708DFBC2D}</Project>
<Name>CPPTestLib</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.VisualC.Interop\Mono.VisualC.Interop.csproj">
<Project>{4A864586-93C5-4DC1-8A80-F094A88506D7}</Project>
<Name>Mono.VisualC.Interop</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="Native\NUnit.cpp" />
<None Include="Native\NUnit.h" />
<None Include="Native\AbiTests.cpp" />
<None Include="Native\AbiTests.h" />
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
<Properties>
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am" IsAutotoolsProject="true" RelativeConfigureInPath="..">
<BuildFilesVar Sync="true" Name="MANAGED" />
<DeployFilesVar />
<ResourcesVar />
<OthersVar />
<GacRefVar Name="REFERENCES" />
<AsmRefVar Name="REFERENCES" />
<ProjectRefVar Name="REFERENCES" />
</MonoDevelop.Autotools.MakefileInfo>
</Properties>
</MonoDevelop>
</ProjectExtensions>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
<Reference Include="System" />
</ItemGroup>
</Project>

Просмотреть файл

@ -1,66 +0,0 @@
using System;
using CppTests;
public class Tests
{
public static void Main (String[] args) {
TestDriver.RunTests (typeof (Tests), args);
}
public static int test_0_class_return () {
// Section 3.1.4:
// Classes with non-default copy ctors/destructors are returned using a hidden
// argument
var c = ClassWithCopyCtor.Return (42);
if (c.GetX () != 42)
return 1;
var c2 = ClassWithDtor.Return (43);
if (c2.GetX () != 43)
return 2;
// This class is returned normally
var c3 = ClassWithoutCopyCtor.Return (44);
if (c3.GetX () != 44)
return 3;
return 0;
}
// An object as ref argument
public static int test_0_class_arg () {
var c1 = new Class (4);
var c2 = new Class (5);
c1.CopyTo (c2);
return c2.GetX () == 4 ? 0 : 1;
}
// A null object as ref argument
public static int test_0_class_arg_null () {
var c1 = new Class (4);
return c1.IsNull (null) ? 0 : 1;
}
// An object as byval argument
public static int test_0_class_arg_byval () {
var c1 = new Class (4);
var c2 = new Class (5);
c1.CopyFromValue (c2);
return c1.GetX () == 5 ? 0 : 1;
}
// A null object as byval argument
public static int test_0_class_arg_byval_null () {
var c1 = new Class (4);
try {
c1.CopyFromValue (null);
} catch (ArgumentException) {
return 0;
}
return 1;
}
}

Просмотреть файл

@ -1,6 +0,0 @@
Name: Tests
Description: Tests
Version: 0.1
Requires:
Libs: -r:@expanded_libdir@/@PACKAGE@/Tests.dll