Ejemplo n.º 1
0
        public void ByteLength()
        {
            int numBytes;

            float [] floatArray = new float [10];
            float [,] floatArray2   = new float [10, 10];
            float [,,] floatArray3  = new float [10, 10, 10];
            float [,,,] floatArray4 = new float [10, 0, 10, 10];
            float [,,,] floatArray5 = new float [0, 0, 0, 0];
            float []      floatArray6 = new float [0];
            BufferTest [] someArray   = new BufferTest [3];

            try {
                Buffer.ByteLength(null);
                Assert.Fail("TestByteLength: ArgumentNullException not thrown");
            } catch (ArgumentNullException) {
                // do nothing, this is expected
            } catch (Exception e) {
                Assert.Fail("Unexpected exception on Buffer.ByteLength (null):" + e);
            }

            try {
                Buffer.ByteLength(someArray);
                Assert.Fail("TestByteLength: ArgumentException not thrown");
            } catch (ArgumentException) {
                // do nothing, this is expected
            } catch (Exception e) {
                Assert.Fail("Unexpected exception on Buffer.ByteLength (non primitive array):" + e);
            }

            numBytes = Buffer.ByteLength(floatArray);
            Assert.AreEqual(40, numBytes, "TestByteLength: wrong byteLength for floatArray");

#if TODO_FOR_DOT42
            numBytes = Buffer.ByteLength(floatArray2);
            Assert.AreEqual(400, numBytes, "TestByteLength: wrong byteLength for floatArray2");

            numBytes = Buffer.ByteLength(floatArray3);
            Assert.AreEqual(4000, numBytes, "TestByteLength: wrong byteLength for floatArray3");

            numBytes = Buffer.ByteLength(floatArray4);
            Assert.AreEqual(0, numBytes, "TestByteLength: wrong byteLength for floatArray4");

            numBytes = Buffer.ByteLength(floatArray5);
            Assert.AreEqual(0, numBytes, "TestByteLength: wrong byteLength for floatArray5");

            numBytes = Buffer.ByteLength(floatArray6);
            Assert.AreEqual(0, numBytes, "TestByteLength: wrong byteLength for floatArray6");
#endif
        }
Ejemplo n.º 2
0
        public void GetByte()
        {
            Byte [] byteArray;
            bool    errorThrown = false;

            byteArray     = new byte [10];
            byteArray [5] = 8;
            BufferTest [] someArray = new BufferTest [3];

            try {
                Buffer.GetByte(null, 5);
            } catch (ArgumentNullException) {
                errorThrown = true;
            }
            Assert.IsTrue(errorThrown, "TestGetByte: ArgumentNullException not thrown");

            errorThrown = false;

            try {
                Buffer.GetByte(byteArray, -1);
            } catch (ArgumentOutOfRangeException) {
                errorThrown = true;
            }
            Assert.IsTrue(errorThrown, "TestGetByte: ArgumentOutOfRangeException (negative index) not implemented");

            errorThrown = false;

            try {
                Buffer.GetByte(byteArray, 12);
            } catch (ArgumentOutOfRangeException) {
                errorThrown = true;
            }
            Assert.IsTrue(errorThrown, "TestGetByte: ArgumentOutOfRangeException (index bigger/equal than array's size not thrown");

            errorThrown = false;

            try {
                Buffer.GetByte(someArray, 0);
                Assert.Fail("TestGetByte: ArgumentException not thrown");
            } catch (ArgumentException) {
                // do nothing, this is expected
            } catch (Exception e) {
                Assert.Fail("Unexpected exception on Buffer.GetByte (non primitive array):" + e);
            }

            Assert.AreEqual((Byte)8, Buffer.GetByte(byteArray, 5), "TestGetByte Error");
        }
Ejemplo n.º 3
0
        public void SetByte()
        {
            bool errorThrown = false;

            BufferTest [] someArray = new BufferTest [3];

            try {
                Buffer.SetByte(null, 5, 12);
            } catch (ArgumentNullException) {
                errorThrown = true;
            }
            Assert.IsTrue(errorThrown, "TestSetByte: ArgumentNullException not thrown");
            errorThrown = false;

            try {
                Buffer.SetByte(byteArray, -1, 32);
            } catch (ArgumentOutOfRangeException) {
                errorThrown = true;
            }
            Assert.IsTrue(errorThrown, "TestSetByte: ArgumentOutOfRangeException (case: negative index) not thrown");
            errorThrown = false;

            try {
                Buffer.SetByte(byteArray, 12, 43);
            } catch (ArgumentOutOfRangeException) {
                errorThrown = true;
            }
            Assert.IsTrue(errorThrown, "TestSetByte: ArgumentOutOfRangeException (case: index bigger/equal than array'size");
            errorThrown = false;

            try {
                Buffer.SetByte(someArray, 0, 42);
                Assert.Fail("TestSetByte: ArgumentException not thrown");
            } catch (ArgumentException) {
                // do nothing, this is expected
            } catch (Exception e) {
                Assert.Fail("Unexpected exception on Buffer.SetByte (non primitive array):" + e);
            }

            Buffer.SetByte(byteArray, 3, (byte)10);
            Assert.AreEqual((Byte)10, Buffer.GetByte(byteArray, 3), "TestSetByte");
        }
Ejemplo n.º 4
0
		public void SetByte ()
		{
			bool errorThrown = false;
			BufferTest [] someArray = new BufferTest [3];
		
			try {
				Buffer.SetByte (null, 5, 12);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert.IsTrue (errorThrown, "TestSetByte: ArgumentNullException not thrown");
			errorThrown = false;
		
			try {
				Buffer.SetByte (byteArray, -1, 32);
			} catch (ArgumentOutOfRangeException) {
				errorThrown = true;
			}
			Assert.IsTrue (errorThrown, "TestSetByte: ArgumentOutOfRangeException (case: negative index) not thrown");
			errorThrown = false;
		
			try {
				Buffer.SetByte (byteArray, 12, 43);
			} catch (ArgumentOutOfRangeException) {
				errorThrown = true;
			}
			Assert.IsTrue (errorThrown, "TestSetByte: ArgumentOutOfRangeException (case: index bigger/equal than array'size");
			errorThrown = false;
		
			try {
				Buffer.SetByte (someArray, 0, 42);	
				Assert.Fail ("TestSetByte: ArgumentException not thrown");
			} catch (ArgumentException) {
				// do nothing, this is expected
			} catch (Exception e) {
				Assert.Fail ("Unexpected exception on Buffer.SetByte (non primitive array):" + e);
			}
		
			Buffer.SetByte (byteArray, 3, (byte) 10);
			Assert.AreEqual ((Byte)10, Buffer.GetByte (byteArray, 3), "TestSetByte");
		}
Ejemplo n.º 5
0
		public void GetByte () 
		{
			Byte [] byteArray;
			bool errorThrown = false;
			byteArray = new byte [10];
			byteArray [5] = 8;
			BufferTest [] someArray = new BufferTest [3];
		
			try {
				Buffer.GetByte (null, 5);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert.IsTrue (errorThrown, "TestGetByte: ArgumentNullException not thrown");
		
			errorThrown = false;
		
			try {
				Buffer.GetByte (byteArray, -1);
			} catch (ArgumentOutOfRangeException) {
				errorThrown = true;
			}
			Assert.IsTrue (errorThrown, "TestGetByte: ArgumentOutOfRangeException (negative index) not implemented");
		
			errorThrown = false;
		
			try {
				Buffer.GetByte (byteArray, 12); 
			} catch (ArgumentOutOfRangeException) {
				errorThrown = true;
			}
			Assert.IsTrue (errorThrown, "TestGetByte: ArgumentOutOfRangeException (index bigger/equal than array's size not thrown");
		
			errorThrown = false;
		
			try {
				Buffer.GetByte (someArray, 0);	
				Assert.Fail ("TestGetByte: ArgumentException not thrown");
			} catch (ArgumentException) {
				// do nothing, this is expected
			} catch (Exception e) {
				Assert.Fail ("Unexpected exception on Buffer.GetByte (non primitive array):" + e);
			}
		
			Assert.AreEqual ((Byte)8, Buffer.GetByte (byteArray, 5), "TestGetByte Error");
		}
Ejemplo n.º 6
0
		public void ByteLength ()
		{
			int numBytes;	
			float [] floatArray = new float [10];
			float [,] floatArray2 = new float [10,10];
			float [,,] floatArray3 = new float [10,10,10];
			float [,,,] floatArray4 = new float [10,0,10,10];
			float [,,,] floatArray5 = new float [0,0,0,0];
			float [] floatArray6 = new float [0];
			BufferTest [] someArray = new BufferTest [3];
		
			try {
				Buffer.ByteLength (null);	
				Assert.Fail ("TestByteLength: ArgumentNullException not thrown");
			} catch (ArgumentNullException) {
				// do nothing, this is expected
			} catch (Exception e) {
				Assert.Fail ("Unexpected exception on Buffer.ByteLength (null):" + e);
			}
		
			try {
				Buffer.ByteLength (someArray);	
				Assert.Fail ("TestByteLength: ArgumentException not thrown");
			} catch (ArgumentException) {
				// do nothing, this is expected
			} catch (Exception e) {
				Assert.Fail ("Unexpected exception on Buffer.ByteLength (non primitive array):" + e);
			}
		
			numBytes = Buffer.ByteLength (floatArray);
			Assert.AreEqual (40, numBytes, "TestByteLength: wrong byteLength for floatArray");

			numBytes = Buffer.ByteLength (floatArray2);
			Assert.AreEqual (400, numBytes, "TestByteLength: wrong byteLength for floatArray2");

			numBytes = Buffer.ByteLength (floatArray3);
			Assert.AreEqual (4000, numBytes, "TestByteLength: wrong byteLength for floatArray3");

			numBytes = Buffer.ByteLength (floatArray4);
			Assert.AreEqual (0, numBytes, "TestByteLength: wrong byteLength for floatArray4");

			numBytes = Buffer.ByteLength (floatArray5);
			Assert.AreEqual (0, numBytes, "TestByteLength: wrong byteLength for floatArray5");

			numBytes = Buffer.ByteLength (floatArray6);
			Assert.AreEqual (0, numBytes, "TestByteLength: wrong byteLength for floatArray6");
		}