Exemple #1
0
        public void TestReadFromBytes()
        {
            LongField field = new LongField(1);
            byte[]    array = new byte[ 8 ];

            try
            {
                field.ReadFromBytes(array);
                Assert.Fail("should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }
            field = new LongField(0);
            for (int j = 0; j < _test_array.Length; j++)
            {
                array[ 0 ] = ( byte ) (_test_array[ j ] % 256);
                array[ 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256);
                array[ 2 ] = ( byte ) ((_test_array[ j ] >> 16) % 256);
                array[ 3 ] = ( byte ) ((_test_array[ j ] >> 24) % 256);
                array[ 4 ] = ( byte ) ((_test_array[ j ] >> 32) % 256);
                array[ 5 ] = ( byte ) ((_test_array[ j ] >> 40) % 256);
                array[ 6 ] = ( byte ) ((_test_array[ j ] >> 48) % 256);
                array[ 7 ] = ( byte ) ((_test_array[ j ] >> 56) % 256);
                field.ReadFromBytes(array);
                Assert.AreEqual(_test_array[j], field.Value, "testing " + j);
            }
        }