[Mono-list] System.BufferTest file

Cesar Octavio Lopez Nataren cesar@ciencias.unam.mx
19 Jul 2002 21:54:09 -0500


--=-/BwiAeQMSneXf2YRSfa2
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

hello!
I wrote this little testSuite for the System.Buffer class.
Hope someone can test it, and hope to receive comments and suggestions
(mostly about the exceptions that the functions throw).

Best regards.
Cesar


--=-/BwiAeQMSneXf2YRSfa2
Content-Disposition: attachment; filename=BufferTest.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=BufferTest.cs; charset=ISO-8859-15

// BufferTest.cs - NUnit Test Cases for the Buffer class.
//
// Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
//
// (C) Cesar Octavio Lopez Nataren 2002
//=20

using NUnit.Framework;
using System;


namespace MonoTests.System
{
	public class BufferTest : TestCase {
=09
	public BufferTest () : base ("System.Buffer test") {}
	public BufferTest (string name) : base(name) {}

	protected override void SetUp()=20
	{
		const int SIZE =3D 10;
		byte [] byteArray;   // 8-bits unsigned integer array
		float [] floatArray;
	=09
		byteArray =3D new byte [SIZE];
		floatArray =3D new float [SIZE];			=09
	}

	protected override void TearDown() {}

	public static ITest Suite {
		get {=20
			return new TestSuite(typeof(BufferTest));=20
		}
	}

=09
	public void TestBlockCopy ()
	{
		int [] myArray1 =3D new int [5] {1, 2, 3, 4, 5};
		int [] myArray2 =3D new int [10] { 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 };
	=09
		Buffer.BlockCopy (myarr1, 0, myarr2, 0, 20);
	=09
		for (i =3D 0; i < 10; i++)=20
			AssertEquals ("TestBlockCopy Error", i + 1, myArray1 [i]);	=09
	}
=09
=09
	public void TestByteLength ()
	{
		int numBytes;=09
		bool errorThrown =3D false;
		floatArray =3D new float [10];
	=09
		try {
			Buffer.ByteLength (null);=09
		} catch (ArgumentNullException e) {
			errorThrown =3D true;
		}
		Assert ("TestByteLength: ArgumentNullException not thrown", errorThrown);
	=09
		errorThrown =3D false;
	=09
		// FIXME: test the case when the ArgumentException is thrown.
	=09
		numBytes =3D Buffer.ByteLength (floatArray);
		AssertEquals ("TestByteLength: wrong byteLength", 40, numBytes);
	}
	=09
	public void TestGetByte ()=20
	{
		Byte [] byteArray;
		bool errorThrown =3D false;
		byteArray =3D new byte [10];
		byteArray [5] =3D 8;
	=09
		try {
			Buffer.GetByte (null, 5);
		} catch (ArgumentNullException e) {
			errorThrown =3D true;
		}
		Assert ("TestGetByte: ArgumentNullException not thrown",
		        errorThrown);
	=09
		errorThrown =3D false;
	=09
		try {
			Buffer.GetByte (byteArray, -1);
		} catch (ArgumentOutOfRangeException e) {
			errorThrown =3D true;
		}
		Assert ("TestGetByte: ArgumentOutOfRangeException (negative index) not im=
plemented",
		        errorThrown);
	=09
		errorThrown =3D false;
	=09
		try {
			Buffer.GetByte (byteArray, 12);=20
		} catch (ArgumentOutOfRangeException e) {
			errorThrown =3D true;
		}
		Assert ("TestGetByte: ArgumentOutOfRangeException (index bigger/equal tha=
n array's size not thrown", errorThrown);
	=09
		errorThrown =3D false;
	=09
		// FIXME: test the case when the ArgumentException is thrown.
	=09
		AssertEquals ("TestGetByte Error", 8, Buffer.GetByte (byteArray, 5));
	}
=09
=09
	public void TestSetByte ()
	{
		char foo;
		foo =3D 255;
		bool errorThrown =3D false;
	=09
		try {
			Buffer.SetByte (null, 5, 12);
		} catch (ArgumentNullException e) {
			errorThown =3D true;
		}
		Assert ("TestSetByte: ArgumentNullException not thrown", errorThrown);
		errorThrown =3D false;
	=09
		try {
			Buffer.SetByte (byteArray, -1, 32);
		} catch (ArgumentOutOfRangeException e) {
			errorThown =3D true;
		}
		Assert ("TestSetByte: ArgumentOutOfRangeException (case: negative index) =
not thrown",
		        errorThrown);
		errorThrown =3D false;
	=09
		try {
			Buffer.SetByte (byteArray, 12, 43);
		} catch (ArgumentOutOfRangeException e) {
			errorThrown =3D true;
		}
		Assert ("TestSetByte: ArgumentOutOfRangeException (case: index bigger/equ=
al than array'size",
		        errorThrown);
		errorThrown =3D false;
	=09
		// FIXME: test the case when the ArgumentException is thrown
		=09
		Buffer.SetByte (byteArray, 3, (byte) 10);
		AssertEquals ("TestSetByte", 10, Buffer.GetByte (byteArray, 3));
	}
	}
}

--=-/BwiAeQMSneXf2YRSfa2--