public void ReadBlockOiAnText()
        {
            const int headerSize = 12;

            // Stream with a named block header and a display text
            byte[] streamData =
            {
                // Named block header
                79,  105,  65, 110, 84, 101, 120, 116,
                24,    0,   0,   0,
                // Display text
                0,     0,   0,   0,
                242,   2,   0,   0,
                104,   1,   0,   0,
                5,     0,   0,   0,
                72,  101, 108, 108,
                111,   0,   0,   0,
                // Extra bytes
                1,     2,   3, 4
            };

            WangAnnotationProperties properties = new WangAnnotationProperties();
            WangStream stream = new WangStream(streamData);

            Assert.IsTrue(WangAnnotationsReader.ReadBlock(properties, stream, headerSize));
            Assert.AreEqual(4, stream.AvailableBytes());
            Assert.AreEqual((uint)360, properties.DisplayText.CreationScale);
            Assert.AreEqual(0, properties.DisplayText.Orientation);
            Assert.AreEqual("Hello", properties.DisplayText.Text);
        }
        public void ReadBlockOiHypLnk()
        {
            const int headerSize = 12;

            // Stream with a named block header and a display text
            byte[] streamData =
            {
                // Named block header
                79,  105,  72, 121, 112, 76, 110, 107, 35, 0, 0, 0,
                // Hyperlink
                1,     0,   0,   0,
                14,    0,   0,   0,
                115, 111, 117, 114,
                99,  101,  92,  48,
                48,   49,  46, 106,
                112, 103,   1,   0,
                0,     0,  49,   0,
                0,     0,   0,   0,
                0,     0,   0,
                // Extra bytes
                1,     2,   3, 4
            };

            WangAnnotationProperties properties = new WangAnnotationProperties();
            WangStream stream = new WangStream(streamData);

            Assert.IsTrue(WangAnnotationsReader.ReadBlock(properties, stream, headerSize));
            Assert.AreEqual(4, stream.AvailableBytes());
            Assert.AreEqual(false, properties.Hyperlink.CanRemoveHyperlink);
            Assert.AreEqual(false, properties.Hyperlink.InternalLink);
            Assert.AreEqual("source\\001.jpg", properties.Hyperlink.Link);
            Assert.AreEqual("1", properties.Hyperlink.Location);
            Assert.AreEqual("", properties.Hyperlink.WorkingDirectory);
        }
        public void ReadBlockOiDib()
        {
            const int headerSize = 12;

            // Stream with a named block header and some bytes for the dib
            byte[] streamData =
            {
                // Named block header
                79, 105, 68, 73, 66, 0, 0, 0, 4, 0, 0, 0,
                // Dummy dib
                0,    1,  2,  3,
                // Extra bytes
                1,    2,  3, 4
            };

            WangAnnotationProperties properties = new WangAnnotationProperties();
            WangStream stream = new WangStream(streamData);

            Assert.IsTrue(WangAnnotationsReader.ReadBlock(properties, stream, headerSize));
            Assert.AreEqual(4, stream.AvailableBytes());
            Assert.IsTrue(properties.HasDib);
            Assert.AreEqual(4, properties.DibInfo.Length);
            for (int index = 0; index < 4; index++)
            {
                Assert.AreEqual((byte)index, properties.DibInfo[index]);
            }
        }
        public void ReadBlockOiFilNam()
        {
            const int headerSize = 12;

            // Stream with a named block header and a file name
            byte[] streamData =
            {
                // Named block header
                79,  105,  70, 105, 108,  78,  97, 109,
                61,    0,   0,   0,
                // Character string for filename
                67,   58,  92,  68, 111,  99, 117,
                109, 101, 110, 116, 115,  32,  97,
                110, 100,  32,  83, 101, 116, 116,
                105, 110, 103, 115,  92,  65, 100,
                109, 105, 110,  92,  68, 101, 115,
                107, 116, 111, 112,  92,  87,  65,
                78,   71,  92, 115, 111, 117, 114,
                99,  101,  92,  48,  48,  49,  46,
                98,  109, 112,   0,   0,
                // Extra bytes
                1,     2,   3, 4
            };

            WangAnnotationProperties properties = new WangAnnotationProperties();
            WangStream stream = new WangStream(streamData);

            Assert.IsTrue(WangAnnotationsReader.ReadBlock(properties, stream, headerSize));
            Assert.AreEqual(4, stream.AvailableBytes());
            Assert.AreEqual("C:\\Documents and Settings\\Admin\\Desktop\\WANG\\source\\001.bmp", properties.Filename);
        }
        public void ReadBlockOiHypLnkReadFailure()
        {
            const int headerSize = 12;

            // Stream with a named block header and a display text too short
            byte[] streamData =
            {
                // Named block header
                79,  105, 72, 121, 112, 76, 110, 107,
                12,    0,  0,   0,
                // Too short display text
                0,     0,  0,   0,
                242,   2,  0,   0,
                104,   1,  0, 0
            };

            WangAnnotationProperties properties = new WangAnnotationProperties();
            WangStream stream = new WangStream(streamData);

            Assert.IsFalse(WangAnnotationsReader.ReadBlock(properties, stream, headerSize));
        }
        public void ReadBlockReadFailure()
        {
            byte[] streamData =
            {
                79, 105, 71, 114, 111, 117, 112,
                0,   11,  0,   0, 0
            };

            // The streamData is well formed.
            // Just using a part of the data should cause an error to rise.
            // Using the full data should cause an error as trailing information are expected.
            for (int dataSize = 0; dataSize <= streamData.Length; dataSize++)
            {
                byte[] streamDataTooShort = new byte[dataSize];
                Array.Copy(streamData, 0, streamDataTooShort, 0, dataSize);

                WangAnnotationProperties properties = new WangAnnotationProperties();
                WangStream stream = new WangStream(streamDataTooShort);
                Assert.IsFalse(WangAnnotationsReader.ReadBlock(properties, stream, streamDataTooShort.Length));
            }
        }
        public void ReadBlockOiAnTextReadFailure()
        {
            const int headerSize = 12;

            // Stream with a named block header and a display text too short
            byte[] streamData =
            {
                // Named block header
                79,  105, 65, 110, 84, 101, 120, 116,
                12,    0,  0,   0,
                // Too short display text
                0,     0,  0,   0,
                242,   2,  0,   0,
                104,   1,  0, 0
            };

            WangAnnotationProperties properties = new WangAnnotationProperties();
            WangStream stream = new WangStream(streamData);

            Assert.IsFalse(WangAnnotationsReader.ReadBlock(properties, stream, headerSize));
            // Only the header should have been read as the rest is not there
            Assert.AreEqual(streamData.Length - 12, stream.AvailableBytes());
        }
        public void ReadBlockOiIndex()
        {
            const int headerSize = 12;

            // Stream with a named block header and a string for the index
            byte[] streamData =
            {
                // Named block header
                79,  105,  73, 110, 100, 101, 120, 0,
                11,    0,   0,   0,
                // Character string for filename
                67,   58,  92,  68, 111,  99, 117,
                109, 101, 110,   0,
                // Extra bytes
                1,     2,   3, 4
            };

            WangAnnotationProperties properties = new WangAnnotationProperties();
            WangStream stream = new WangStream(streamData);

            Assert.IsTrue(WangAnnotationsReader.ReadBlock(properties, stream, headerSize));
            Assert.AreEqual(4, stream.AvailableBytes());
            Assert.AreEqual("C:\\Documen", properties.OiIndex);
        }