Пример #1
0
        public void OTFileGetOTLongDateTimeAsInt64()
        {
            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, 0x03, 0x00, 0x70, 0x44
            Assert.IsTrue(OTFile.ReadOTLongDateTimeAsInt64(ms) == 0x0F00_8000_0300_7044, "Error: unexpected value read");
            ms.Position = 16; //  0xF0, 0x54, 0x3E, 0x26, 0x00, 0x00, 0x91, 0xE4
            Assert.IsTrue(OTFile.ReadOTLongDateTimeAsInt64(ms) == -1_129_209_273_633_435_164, "Error: unexpected value read");

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

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

            ms.Position = ms.Length - 8; // 0x00, 0x00, 0x1A, 0xDC, 0x47, 0x44, 0x45, 0x46
            Assert.IsTrue(OTFile.ReadOTLongDateTimeAsInt64(ms) == 0x0000_1ADC_4744_4546, "Error: expected value read");

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