Ejemplo n.º 1
0
        public void OTFileReadInt32Test()
        {
            byte[] b = new byte[32] { 0, 1, 0, 0, 0, 0x0F, 0, 0x80, 0, 3, 0, 0x70, 0x44, 0x53, 0x49, 0x47, 0xF0, 0x54, 0x3E, 0x26, 0, 0, 0x91, 0xE4, 0, 0, 0x1A, 0xDC, 0x47, 0x44, 0x45, 0x46 };
            MemoryStream ms = new MemoryStream(b);

            ms.Position = 5; // 0x0F, 0x00, 0x80, 0x00
            Assert.IsTrue(OTFile.ReadInt32(ms) == 0x0F00_8000, "Error: unexpected value read");
            ms.Position = 16; // 0xF0, 0x54, 0x3E, 0x26
            Assert.IsTrue(OTFile.ReadInt32(ms) == -262_914_522, "Error: unexpected value read");

            bool caughtExpectedException = false;
            ms.Position = ms.Length;
            try
            {
                OTFile.ReadInt32(ms);
            }
            catch (OTDataIncompleteReadException)
            {
                caughtExpectedException = true;
            }
            catch (Exception)
            {
                // unexpected exception
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");

            ms.Position = ms.Length - 3;
            caughtExpectedException = false;
            try
            {
                OTFile.ReadInt32(ms);
            }
            catch (OTDataIncompleteReadException)
            {
                caughtExpectedException = true;
            }
            catch (Exception)
            {
                // unexpected exception
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");

            ms.Position = ms.Length - 4;
            Int32 expected = 0x4744_4546;
            Assert.IsTrue(OTFile.ReadInt32(ms) == expected, "Error: expected value read");

            ms.Close();
            caughtExpectedException = false;
            try
            {
                OTFile.ReadInt32(ms);
            }
            catch (ObjectDisposedException)
            {
                caughtExpectedException = true;
            }
            catch (Exception)
            {
                // unexpected exception
            }
            Assert.IsTrue(caughtExpectedException, "Error: expected exception not caught");
        }