1 // BufferTest.cs - NUnit Test Cases for the Buffer class.
3 // Cesar Octavio Lopez Nataren (cesar@ciencias.unam.mx)
5 // (C) Cesar Octavio Lopez Nataren 2002
12 namespace MonoTests.System
14 public class BufferTest : TestCase
17 byte [] byteArray = new byte [SIZE]; // 8-bits unsigned integer array
18 float [] floatArray = new float [SIZE];
20 public BufferTest () {}
22 protected override void SetUp () {}
25 protected override void TearDown () {}
27 public void TestBlockCopy ()
30 int [] myArray1 = new int [5] {1, 2, 3, 4, 5};
31 int [] myArray2 = new int [10] { 0, 0, 0, 0, 0, 6, 7, 8, 9, 10 };
33 Buffer.BlockCopy (myArray1, 0, myArray2, 0, SizeOfInt32 * myArray1.Length);
35 for (int i = 0; i < myArray1.Length; i++)
36 AssertEquals ("TestBlockCopy Error at i=" + i, i + 1, myArray2 [i]);
40 public void TestByteLength ()
43 float [] floatArray = new float [10];
44 TestCase [] someArray = new TestCase [3];
47 Buffer.ByteLength (null);
48 Fail ("TestByteLength: ArgumentNullException not thrown");
49 } catch (ArgumentNullException) {
50 // do nothing, this is expected
51 } catch (Exception e) {
52 Fail ("Unexpected exception on Buffer.ByteLength (null):" + e);
56 Buffer.ByteLength (someArray);
57 Fail ("TestByteLength: ArgumentException not thrown");
58 } catch (ArgumentException) {
59 // do nothing, this is expected
60 } catch (Exception e) {
61 Fail ("Unexpected exception on Buffer.ByteLength (non primitive array):" + e);
64 numBytes = Buffer.ByteLength (floatArray);
65 AssertEquals ("TestByteLength: wrong byteLength", 40, numBytes);
68 public void TestGetByte ()
71 bool errorThrown = false;
72 byteArray = new byte [10];
74 TestCase [] someArray = new TestCase [3];
77 Buffer.GetByte (null, 5);
78 } catch (ArgumentNullException) {
81 Assert ("TestGetByte: ArgumentNullException not thrown",
87 Buffer.GetByte (byteArray, -1);
88 } catch (ArgumentOutOfRangeException) {
91 Assert ("TestGetByte: ArgumentOutOfRangeException (negative index) not implemented",
97 Buffer.GetByte (byteArray, 12);
98 } catch (ArgumentOutOfRangeException) {
101 Assert ("TestGetByte: ArgumentOutOfRangeException (index bigger/equal than array's size not thrown", errorThrown);
106 Buffer.GetByte (someArray, 0);
107 Fail ("TestGetByte: ArgumentException not thrown");
108 } catch (ArgumentException) {
109 // do nothing, this is expected
110 } catch (Exception e) {
111 Fail ("Unexpected exception on Buffer.GetByte (non primitive array):" + e);
114 AssertEquals ("TestGetByte Error", (Byte)8, Buffer.GetByte (byteArray, 5));
118 public void TestSetByte ()
120 bool errorThrown = false;
121 TestCase [] someArray = new TestCase [3];
124 Buffer.SetByte (null, 5, 12);
125 } catch (ArgumentNullException) {
128 Assert ("TestSetByte: ArgumentNullException not thrown", errorThrown);
132 Buffer.SetByte (byteArray, -1, 32);
133 } catch (ArgumentOutOfRangeException) {
136 Assert ("TestSetByte: ArgumentOutOfRangeException (case: negative index) not thrown",
141 Buffer.SetByte (byteArray, 12, 43);
142 } catch (ArgumentOutOfRangeException) {
145 Assert ("TestSetByte: ArgumentOutOfRangeException (case: index bigger/equal than array'size",
150 Buffer.SetByte (someArray, 0, 42);
151 Fail ("TestSetByte: ArgumentException not thrown");
152 } catch (ArgumentException) {
153 // do nothing, this is expected
154 } catch (Exception e) {
155 Fail ("Unexpected exception on Buffer.SetByte (non primitive array):" + e);
158 Buffer.SetByte (byteArray, 3, (byte) 10);
159 AssertEquals ("TestSetByte", (Byte)10, Buffer.GetByte (byteArray, 3));