From: Griffin C. <gc...@us...> - 2005-01-01 22:58:21
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock.Tests/Dynamic/Generate Modified Files: ClassGeneratorTests.cs Added Files: ILUtilsTests.cs Log Message: - Merged branch RFE_1001778 into head Index: ClassGeneratorTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate/ClassGeneratorTests.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ClassGeneratorTests.cs 9 Oct 2004 21:14:12 -0000 1.12 --- ClassGeneratorTests.cs 1 Jan 2005 22:57:51 -0000 1.13 *************** *** 7,10 **** --- 7,11 ---- using System.Reflection; using System.Reflection.Emit; + using System.Diagnostics; namespace DotNetMock.Tests.Dynamic.Generate *************** *** 74,77 **** --- 75,172 ---- } + interface IDirectionalParameters + { + void DoWithInParameters(int a, string b); + void DoWithRefParameters(ref int a, ref string b); + void DoWithOutParameters(out int a, out string b, out TimeSpan c); + } + + class DirectionalMockedCallHandler : + IMockedCallHandler + { + public MethodInfo MethodInfo + { + get { return _methodInfo; } + } + public object Call(MethodInfo mi, params object[] args) + { + _methodInfo = mi; + this.MethodName = mi.Name; + this.IncomingArgs = (object[]) args.Clone(); + if ( this.OutgoingArgs!=null ) + { + this.OutgoingArgs.CopyTo(args, 0); + } + return null; + } + + public object Call( string methodName, params object[] args ) + { + return null; + } + + public object[] IncomingArgs = null; + public object[] OutgoingArgs = null; + public string MethodName = null; + private MethodInfo _methodInfo = null; + } + + [Test] public void TestInParameters() + { + DirectionalMockedCallHandler dmch = + new DirectionalMockedCallHandler(); + IDirectionalParameters dp = (IDirectionalParameters) + cg.Generate(typeof(IDirectionalParameters), dmch); + dp.DoWithInParameters(1, "what"); + Assert.AreEqual("DoWithInParameters", dmch.MethodInfo.Name); + Assert.AreEqual("DoWithInParameters", dmch.MethodName); + Assert.AreEqual(2, dmch.IncomingArgs.Length); + Assert.AreEqual(1, dmch.IncomingArgs[0]); + Assert.AreEqual("what", dmch.IncomingArgs[1]); + } + + [Test] public void TestOutParameters() + { + DirectionalMockedCallHandler dmch = + new DirectionalMockedCallHandler(); + dmch.OutgoingArgs + = new object[] { + 2, + "when", + TimeSpan.FromSeconds(123) + }; + IDirectionalParameters dp = (IDirectionalParameters) + cg.Generate(typeof(IDirectionalParameters), dmch); + int a = 1; + string b = "what"; + TimeSpan c = TimeSpan.FromSeconds(321); + dp.DoWithOutParameters(out a, out b, out c); + Assert.AreEqual("DoWithOutParameters", dmch.MethodInfo.Name); + Assert.AreEqual("when", b); + Assert.AreEqual(TimeSpan.FromSeconds(123), c); + Assert.AreEqual(2, a); + Assert.AreEqual("DoWithOutParameters", dmch.MethodName); + Assert.AreEqual(3, dmch.IncomingArgs.Length); + } + + [Test] public void TestRefParameters() + { + DirectionalMockedCallHandler dmch = + new DirectionalMockedCallHandler(); + dmch.OutgoingArgs = new object[] { 2, "when" }; + IDirectionalParameters dp = (IDirectionalParameters) + cg.Generate(typeof(IDirectionalParameters), dmch); + int a = 1; + string b = "what"; + dp.DoWithRefParameters(ref a, ref b); + Assert.AreEqual("DoWithRefParameters", dmch.MethodInfo.Name); + Assert.AreEqual("DoWithRefParameters", dmch.MethodName); + Assert.AreEqual(2, dmch.IncomingArgs.Length); + Assert.AreEqual(1, dmch.IncomingArgs[0]); + Assert.AreEqual("what", dmch.IncomingArgs[1]); + Assert.AreEqual("when", b); + Assert.AreEqual(2, a); + } + [Test] public void CallMethodIsCalled() *************** *** 266,288 **** mock.Verify(); } ! ! [Test] ! public void BoxingOpCodes() ! { ! Assertion.AssertEquals( OpCodes.Ldind_I1, cg.GetBoxingOpCode(typeof(sbyte)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I2, cg.GetBoxingOpCode(typeof(short)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I4, cg.GetBoxingOpCode(typeof(int)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I8, cg.GetBoxingOpCode(typeof(long)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U1, cg.GetBoxingOpCode(typeof(byte)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U2, cg.GetBoxingOpCode(typeof(ushort)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U4, cg.GetBoxingOpCode(typeof(uint)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I8, cg.GetBoxingOpCode(typeof(ulong)) ); ! Assertion.AssertEquals( OpCodes.Ldind_R4, cg.GetBoxingOpCode(typeof(float)) ); ! Assertion.AssertEquals( OpCodes.Ldind_R8, cg.GetBoxingOpCode(typeof(double)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U2, cg.GetBoxingOpCode(typeof(char)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I1, cg.GetBoxingOpCode(typeof(bool)) ); ! Assertion.AssertEquals( OpCodes.Ldobj, cg.GetBoxingOpCode(typeof(Guid)) ); ! } ! [Test] public void ValueTypeParameter() --- 361,365 ---- mock.Verify(); } ! [Test] public void ValueTypeParameter() --- NEW FILE: ILUtilsTests.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. // until we agree on which open-source licnese to use. #endregion #region Imports using System; using System.Collections; using System.Reflection.Emit; using DotNetMock.Dynamic.Generate; using NUnit.Framework; #endregion namespace DotNetMock.Tests.Dynamic.Generate { [TestFixture] public class ILUtilsTests { [Test] public void LdindOpcodes() { Assert.AreEqual( OpCodes.Ldind_I1, ILUtils.GetLdindOpCodeForType(typeof(sbyte)) ); Assert.AreEqual( OpCodes.Ldind_I2, ILUtils.GetLdindOpCodeForType(typeof(short)) ); Assert.AreEqual( OpCodes.Ldind_I4, ILUtils.GetLdindOpCodeForType(typeof(int)) ); Assert.AreEqual( OpCodes.Ldind_I8, ILUtils.GetLdindOpCodeForType(typeof(long)) ); Assert.AreEqual( OpCodes.Ldind_U1, ILUtils.GetLdindOpCodeForType(typeof(byte)) ); Assert.AreEqual( OpCodes.Ldind_U2, ILUtils.GetLdindOpCodeForType(typeof(ushort)) ); Assert.AreEqual( OpCodes.Ldind_U4, ILUtils.GetLdindOpCodeForType(typeof(uint)) ); Assert.AreEqual( OpCodes.Ldind_I8, ILUtils.GetLdindOpCodeForType(typeof(ulong)) ); Assert.AreEqual( OpCodes.Ldind_R4, ILUtils.GetLdindOpCodeForType(typeof(float)) ); Assert.AreEqual( OpCodes.Ldind_R8, ILUtils.GetLdindOpCodeForType(typeof(double)) ); Assert.AreEqual( OpCodes.Ldind_U2, ILUtils.GetLdindOpCodeForType(typeof(char)) ); Assert.AreEqual( OpCodes.Ldind_I1, ILUtils.GetLdindOpCodeForType(typeof(bool)) ); Assert.AreEqual( OpCodes.Ldobj, ILUtils.GetLdindOpCodeForType(typeof(Guid)) ); Assert.AreEqual( OpCodes.Ldind_Ref, ILUtils.GetLdindOpCodeForType(typeof(object)) ); } [Test] public void StindOpcodes() { Assert.AreEqual( OpCodes.Stind_I1, ILUtils.GetStindOpCodeForType(typeof(sbyte)) ); Assert.AreEqual( OpCodes.Stind_I2, ILUtils.GetStindOpCodeForType(typeof(short)) ); Assert.AreEqual( OpCodes.Stind_I4, ILUtils.GetStindOpCodeForType(typeof(int)) ); Assert.AreEqual( OpCodes.Stind_I8, ILUtils.GetStindOpCodeForType(typeof(long)) ); Assert.AreEqual( OpCodes.Stind_I1, ILUtils.GetStindOpCodeForType(typeof(byte)) ); Assert.AreEqual( OpCodes.Stind_I2, ILUtils.GetStindOpCodeForType(typeof(ushort)) ); Assert.AreEqual( OpCodes.Stind_I4, ILUtils.GetStindOpCodeForType(typeof(uint)) ); Assert.AreEqual( OpCodes.Stind_I8, ILUtils.GetStindOpCodeForType(typeof(ulong)) ); Assert.AreEqual( OpCodes.Stind_R4, ILUtils.GetStindOpCodeForType(typeof(float)) ); Assert.AreEqual( OpCodes.Stind_R8, ILUtils.GetStindOpCodeForType(typeof(double)) ); Assert.AreEqual( OpCodes.Stind_I2, ILUtils.GetStindOpCodeForType(typeof(char)) ); Assert.AreEqual( OpCodes.Stind_I1, ILUtils.GetStindOpCodeForType(typeof(bool)) ); Assert.AreEqual( OpCodes.Stobj, ILUtils.GetStindOpCodeForType(typeof(Guid)) ); Assert.AreEqual( OpCodes.Stind_Ref, ILUtils.GetStindOpCodeForType(typeof(object)) ); } } } |