dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/tests/runtime/System/Runtime/Interop


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/tests/runtime/System/Runtime/InteropServices Makefile,NONE,1.1 SuiteInteropServices.cs,NONE,1.1 TestGCHandle.cs,NONE,1.1 TestInteropServices.cs,NONE,1.1 code-review.txt,NONE,1.1
Date: Tue, 03 Jun 2003 08:06:39 -0400

Update of 
/cvsroot/dotgnu-pnet/pnetlib/tests/runtime/System/Runtime/InteropServices
In directory 
subversions:/tmp/cvs-serv3644/tests/runtime/System/Runtime/InteropServices

Added Files:
        Makefile SuiteInteropServices.cs TestGCHandle.cs 
        TestInteropServices.cs code-review.txt 
Log Message:


Test cases for most of the System.Runtime.InteropServices classes.


--- NEW FILE ---

all:
        (cd ../../..; make)

check:
        (cd ../../..; make check)

--- NEW FILE ---
/*
 * SuiteInteropServices.cs - Tests for "System.Runtime.InteropServices".
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using CSUnit;
using System;

public class SuiteInteropServices
{

        public static TestSuite Suite()
                        {
                                TestSuite suite = new 
TestSuite("InteropServices Tests");
                                suite.AddTests(typeof(TestInteropServices));
                                suite.AddTests(typeof(TestGCHandle));
                                return suite;
                        }

}; // class SuiteInteropServices

--- NEW FILE ---
/*
 * TestGCHandle.cs - Test the "GCHandle" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using CSUnit;
using System;
using System.Runtime.InteropServices;

public class TestGCHandle : TestCase
{
        private GCHandle unallocated;

        // Constructor.
        public TestGCHandle(String name)
                        : base(name)
                        {
                                // Nothing to do here.
                        }

        // Set up for the tests.
        protected override void Setup()
                        {
                                // Nothing to do here.
                        }

        // Clean up after the tests.
        protected override void Cleanup()
                        {
                                // Nothing to do here.
                        }

        // Test the properties of uninitialized GCHandle's.
        public void TestGCHandleUninit()
                        {
                                Object target;

                                // IsAllocated == false.
                                Assert("Uninit (1)", 
!(unallocated.IsAllocated));

                                // Cannot get or set the target.
                                try
                                {
                                        target = unallocated.Target;
                                        Fail("Uninit (2)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }
                                try
                                {
                                        unallocated.Target = new Object();
                                        Fail("Uninit (3)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }

                                // Cannot get the pinned address.
                                try
                                {
                                        unallocated.AddrOfPinnedObject();
                                        Fail("Uninit (4)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }

                                // The IntPtr version is zero.
                                AssertEquals("Uninit (5)", IntPtr.Zero, 
(IntPtr)unallocated);
                        }

        // Test allocation of GCHandle's.
        public void TestGCHandleAlloc()
                        {
                                GCHandle handle;
                                Object target;

                                // Allocate a normal handle.
                                handle = GCHandle.Alloc(this);
                                AssertSame("Alloc (1)", this, handle.Target);
                                Assert("Alloc (2)", handle.IsAllocated);
                                handle.Free();

                                // Allocate a weak handle.
                                Object obj = new Object();
                                handle = GCHandle.Alloc(obj, GCHandleType.Weak);
                                AssertSame("Alloc (3)", obj, handle.Target);
                                Assert("Alloc (4)", handle.IsAllocated);
                                handle.Free();

                                // The handle is now invalid.
                                try
                                {
                                        target = handle.Target;
                                        Fail("Alloc (5)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }
                        }

        // Test setting the target of a GCHandle.
        public void TestGCHandleSetTarget()
                        {
                                GCHandle handle;

                                // Allocate a normal handle.
                                handle = GCHandle.Alloc(this);
                                AssertSame("SetTarget (1)", this, 
handle.Target);
                                Assert("SetTarget (2)", handle.IsAllocated);

                                // Change the target to another object.
                                Object obj = new Object();
                                handle.Target = obj;
                                AssertSame("SetTarget (3)", obj, handle.Target);
                                Assert("SetTarget (4)", handle.IsAllocated);

                                // Free the handle.
                                handle.Free();
                        }

        // Test the retrieval of the pinned address.
        public void TestGCHandleAddrOfPinned()
                        {
                                GCHandle handle;

                                // Cannot get the pinned address for normal 
handles.
                                handle = GCHandle.Alloc(this);
                                try
                                {
                                        handle.AddrOfPinnedObject();
                                        Fail("AddrOfPinned (1)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }
                                handle.Free();

                                // Cannot get the pinned address for weak 
handles.
                                handle = GCHandle.Alloc(this, 
GCHandleType.Weak);
                                try
                                {
                                        handle.AddrOfPinnedObject();
                                        Fail("AddrOfPinned (2)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }
                                handle.Free();

                                // Cannot get the pinned address for track 
resurrection handles.
                                handle = GCHandle.Alloc
                                        (this, 
GCHandleType.WeakTrackResurrection);
                                try
                                {
                                        handle.AddrOfPinnedObject();
                                        Fail("AddrOfPinned (3)");
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }
                                handle.Free();

                                // Can get the pinned address for pinned 
handles.
                                handle = GCHandle.Alloc
                                        (this, GCHandleType.Pinned);
                                IntPtr addr = handle.AddrOfPinnedObject();
                                Assert("AddrOfPinned (4)", (addr != 
IntPtr.Zero));
                                handle.Free();
                        }

        // Test conversion between IntPtr and GCHandle forms.
        public void TestGCHandleConvert()
                        {
                                Object obj = new Object();
                                GCHandle handle;
                                GCHandle handle2;
                                GCHandle handle3;
                                IntPtr ptr;

                                // Allocate two normal handles.
                                handle = GCHandle.Alloc(this);
                                AssertSame("Convert (1)", this, handle.Target);
                                Assert("Convert (2)", handle.IsAllocated);
                                handle2 = GCHandle.Alloc(obj);
                                AssertSame("Convert (3)", obj, handle2.Target);
                                Assert("Convert (4)", handle2.IsAllocated);

                                // Make sure that the raw handles are different.
                                Assert("Convert (5)", (((IntPtr)handle) != 
((IntPtr)handle2)));

                                // Extract a handle and then wrap it up again.
                                ptr = (IntPtr)handle;
                                handle3 = (GCHandle)ptr;

                                // Verify that handle and handle3 are identical.
                                AssertSame("Convert (6)", handle.Target, 
handle3.Target);

                                // Free the handles.
                                handle.Free();
                                handle2.Free();

                                // "handle3" should now be invalid.  Because 
this is a
                                // copy of "handle", the target goes null.
                                try
                                {
                                        obj = handle3.Target;
                                        AssertNull("Convert (7)", obj);
                                }
                                catch(InvalidOperationException)
                                {
                                        // Success.
                                }
                        }

}; // class TestGCHandle

--- NEW FILE ---
/*
 * TestInteropServices.cs - Test various System.Runtime.InteropServices classes.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using CSUnit;
using System;
using System.Runtime.InteropServices;

public class TestInteropServices : TestCase
{
        // Constructor.
        public TestInteropServices(String name)
                        : base(name)
                        {
                                // Nothing to do here.
                        }

        // Set up for the tests.
        protected override void Setup()
                        {
                                // Nothing to do here.
                        }

        // Clean up after the tests.
        protected override void Cleanup()
                        {
                                // Nothing to do here.
                        }

#if !ECMA_COMPAT

        // Test the ExternalException class.
        public void TestExternalException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(ExternalException), 
unchecked((int)0x80004005));

                                // Test the fourth constructor.
                                ExternalException e = new ExternalException
                                                ("foobar", 0x0BADBEEF);
                                AssertEquals("COM (1)", "foobar", e.Message);
                                AssertEquals("COM (2)", 0x0BADBEEF, 
e.ErrorCode);

                                // Test that the error code is zero by default.
                                e = new ExternalException("foobar");
                                AssertEquals("COM (3)", "foobar", e.Message);
                                AssertEquals("COM (4)", 0, e.ErrorCode);
                        }

#endif // !ECMA_COMPAT

#if CONFIG_COM_INTEROP

        // Test the COMException class.
        public void TestCOMException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(COMException), 
unchecked((int)0x80004005));

                                // Test the fourth constructor.
                                COMException e = new COMException("foobar", 
0x0BADBEEF);
                                AssertEquals("COM (1)", "foobar", e.Message);
                                AssertEquals("COM (2)", 0x0BADBEEF, 
e.ErrorCode);

                                // Test that the error code is zero by default.
                                e = new COMException("foobar");
                                AssertEquals("COM (3)", "foobar", e.Message);
                                AssertEquals("COM (4)", 0, e.ErrorCode);
                        }

        // Test the InvalidComObjectException class.
        public void TestInvalidComObjectException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(InvalidComObjectException),
                                         unchecked((int)0x80131527));
                        }

        // Test the InvalidOleVariantTypeException class.
        public void TestInvalidOleVariantTypeException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(InvalidOleVariantTypeException),
                                         unchecked((int)0x80131531));
                        }

        // Test the MarshalDirectiveException class.
        public void TestMarshalDirectiveException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(MarshalDirectiveException),
                                         unchecked((int)0x80131535));
                        }

        // Test the SEHException class.
        public void TestSEHException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(SEHException), 
unchecked((int)0x80004005));
                        }

        // Test the SafeArrayRankMismatchException class.
        public void TestSafeArrayRankMismatchException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(SafeArrayRankMismatchException),
                                         unchecked((int)0x80131538));
                        }

        // Test the SafeArrayTypeMismatchException class.
        public void TestSafeArrayTypeMismatchException()
                        {
                                // Check the three main exception constructors.
                                ExceptionTester.CheckMain
                                        (typeof(SafeArrayTypeMismatchException),
                                         unchecked((int)0x80131533));
                        }

#if CONFIG_EXTENDED_NUMERICS

        // Test the CurrencyWrapper class.
        public void TestCurrencyWrapper()
                        {
                                CurrencyWrapper cw;

                                // Test the (Decimal) constructor.
                                cw = new CurrencyWrapper(123.45m);
                                AssertEquals("CurrencyWrapper (1)", 123.45m, 
cw.WrappedObject);

                                // Test the (Object) constructor.
                                cw = new CurrencyWrapper((Object)(6123.45m));
                                AssertEquals("CurrencyWrapper (2)", 6123.45m, 
cw.WrappedObject);

                                // Test the failure cases of the (Object) 
constructor.
                                try
                                {
                                        cw = new CurrencyWrapper(null);
                                        Fail("CurrencyWrapper (3)");
                                }
                                catch(ArgumentException)
                                {
                                        // Success.
                                }
                                try
                                {
                                        cw = new CurrencyWrapper((Object)3);
                                        Fail("CurrencyWrapper (4)");
                                }
                                catch(ArgumentException)
                                {
                                        // Success.
                                }
                        }

#endif // CONFIG_EXTENDED_NUMERICS

        // Test the ErrorWrapper class.
        public void TestErrorWrapper()
                        {
                                ErrorWrapper ew;

                                // Test the (Exception) constructor, which will 
throw
                                // "NotImplementedException" because we don't 
support COM.
                                try
                                {
                                        ew = new ErrorWrapper(new Exception());
                                        Fail("ErrorWrapper (1)");
                                }
                                catch(NotImplementedException)
                                {
                                        // Success.
                                }

                                // Test the (int) constructor.
                                ew = new ErrorWrapper(123);
                                AssertEquals("ErrorWrapper (2)", 123, 
ew.ErrorCode);

                                // Test the (Object) constructor.
                                ew = new ErrorWrapper((Object)(6123));
                                AssertEquals("ErrorWrapper (3)", 6123, 
ew.ErrorCode);

                                // Test the failure cases of the (Object) 
constructor.
                                try
                                {
                                        ew = new ErrorWrapper((Object)null);
                                        Fail("ErrorWrapper (4)");
                                }
                                catch(ArgumentException)
                                {
                                        // Success.
                                }
                                try
                                {
                                        ew = new ErrorWrapper((Object)"foo");
                                        Fail("ErrorWrapper (5)");
                                }
                                catch(ArgumentException)
                                {
                                        // Success.
                                }
                        }

#endif // CONFIG_COM_INTEROP

}; // class TestInteropServices

--- NEW FILE ---

Code review for System.Runtime.InteropServices
==============================================

Last updated: 3 June 2003

Classes that need tests
-----------------------

COMException (done)
CurrencyWrapper (done)
ErrorWrapper (done)
ExternalException (done)
GCHandle (done)
InvalidComObjectException (done)
InvalidOleVariantTypeException (done)
Marshal
MarshalDirectiveException (done)
SEHException (done)
SafeArrayRankMismatchException (done)
SafeArrayTypeMismatchException (done)

Classes that were validated using manual inspection and csdocvalil
------------------------------------------------------------------

ArrayWithOffset
AssemblyRegistrationFlags
AutomationProxyAttribute
BINDPTR
BIND_OPTS
BestFitMappingAttribute
CALLCONV
CONNECTDATA
CallingConvention
CharSet
ClassInterfaceAttribute
ClassInterfaceType
CoClassAttribute
ComAliasNameAttribute
ComCompatibleVersionAttribute
ComConversionLossAttribute
ComEventInterfaceAttribute
ComImportAttribute
ComInterfaceType
ComMemberType
ComRegisterFunctionAttribute
ComSourcesInterfacesAttribute
ComUnregisterFunctionAttribute
ComVisibleAttribute
DESCKIND
DISPPARAMS
DispIdAttribute
DispatchWrapper
DllImportAttribute
ELEMDESC
EXCEPINFO
ExporterEventKind
FILETIME
FUNCDESC
FUNCFLAGS
FUNCKIND
FieldOffsetAttribute
GCHandleType
GuidAttribute
HandleRef
ICustomAdapter
ICustomFactory
ICustomMarshaler
IDLDESC
IDLFLAG
IDispatchImplAttribute
IDispatchImplType
IMPLTYPEFLAGS
INVOKEKIND
IRegistrationServices
ITypeLibConverter
ITypeLibExporterNameProvider
ITypeLibExporterNotifySink
ITypeLibImporterNotifySink
ImportedFromTypeLibAttribute
ImporterEventKind
InAttribute
InterfaceTypeAttribute
LCIDConversionAttribute
LIBFLAGS
LayoutKind
MarshalAsAttribute
ObjectCreationDelegate
OptionalAttribute
OutAttribute
PARAMDESC
PARAMFLAG
PreserveSigAttribute
PrimaryInteropAssemblyAttribute
ProgIdAttribute
STATSTG
SYSKIND
StructLayoutAttribute
TYPEATTR
TYPEDESC
TYPEFLAGS
TYPEKIND
TYPELIBATTR
TypeLibExporterFlags
TypeLibFuncAttribute
TypeLibFuncFlags
TypeLibImporterFlags
TypeLibTypeAttribute
TypeLibTypeFlags
TypeLibVarAttribute
TypeLibVarFlags
TypeLibVersionAttribute
UCOMIBindCtx
UCOMIConnectionPoint
UCOMIConnectionPointContainer
UCOMIEnumConnectionPoints
UCOMIEnumConnections
UCOMIEnumMoniker
UCOMIEnumString
UCOMIEnumVARIANT
UCOMIMoniker
UCOMIPersistFile
UCOMIRunningObjectTable
UCOMIStream
UCOMITypeComp
UCOMITypeInfo
UCOMITypeLib
UnknownWrapper
UnmanagedType
VARDESC
VARFLAGS
VarEnum

Classes that are deliberately not implemented and don't need testing
--------------------------------------------------------------------

ExtensibleClassFactory
RegistrationServices
RuntimeEnvironment
TypeLibConverter





reply via email to

[Prev in Thread] Current Thread [Next in Thread]