Esempio n. 1
0
        public void TestConstructors()
        {
            try
            {
                new IntegerField(-1);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            IntegerField field = new IntegerField(2);

            Assert.AreEqual(0, field.Value);
            try
            {
                new IntegerField(-1, 1);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            field = new IntegerField(2, 0x12345678);
            Assert.AreEqual(0x12345678, field.Value);
            byte[] array = new byte[6];

            try
            {
                new IntegerField(-1, 1, array);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            field = new IntegerField(2, 0x12345678, array);
            Assert.AreEqual(0x12345678, field.Value);
            Assert.AreEqual(( byte )0x78, array[2]);
            Assert.AreEqual(( byte )0x56, array[3]);
            Assert.AreEqual(( byte )0x34, array[4]);
            Assert.AreEqual(( byte )0x12, array[5]);
            array = new byte[5];
            try
            {
                new IntegerField(2, 5, array);
                Assert.Fail("should have gotten IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {
                // as expected
            }
            for (int j = 0; j < _test_array.Length; j++)
            {
                array = new byte[4];
                new IntegerField(0, _test_array[j], array);
                Assert.AreEqual(_test_array[j], new IntegerField(0, array).Value);
            }

            // same test as above, but using the static method
            for (int j = 0; j < _test_array.Length; j++)
            {
                array = new byte[4];
                IntegerField.Write(0, _test_array[j], array);
                Assert.AreEqual(_test_array[j], new IntegerField(0, array).Value);
            }
        }