Beispiel #1
0
        public void OTFileReadInt16Test()
        {
            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
            Assert.IsTrue(OTFile.ReadInt16(ms) == 0x0F00, "Error: unexpected value read");
            ms.Position = 16; // 0xF0, 0x54
            Assert.IsTrue(OTFile.ReadInt16(ms) == -4012, "Error: unexpected value read");

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

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

            ms.Position = ms.Length - 2; // 0x45, 0x46
            Assert.IsTrue(OTFile.ReadInt16(ms) == 0x4546, "Error: expected value read");

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