Exemplo n.º 1
0
        public void ReadPointsStdShort()
        {
            // Well formed data with 4 extra last byte
            byte[] streamData =
            {
                // max is 2
                2,   0, 0, 0,
                // count is 2
                2,   0, 0, 0,
                // x0 = 0
                0,   0, 0, 0,
                // y0 = 0
                0,   0, 0, 0,
                // x1 = 729
                217, 2, 0, 0,
                // y1 = 446
                190, 1, 0, 0,
                // extra
                1,   2, 3, 4
            };

            int expectedPointsCount = 2;

            int[] expectedPoints =
            {
                // X0, Y0
                0,   0,
                // X1, Y1
                729, 446
            };

            WangStream stream = new WangStream(streamData);

            int[] read = WangAnnotationStructureReader.ReadPoints(stream, 24);
            Assert.IsTrue(read != null);

            Assert.AreEqual(2, WangAnnotationTranslation.PointsLength(read));
            Assert.AreEqual(4, stream.AvailableBytes());

            for (int index = 0; index < expectedPointsCount; index++)
            {
                Assert.AreEqual(expectedPoints[index * 2], WangAnnotationTranslation.PointX(index, read));
                Assert.AreEqual(expectedPoints[index * 2 + 1], WangAnnotationTranslation.PointY(index, read));
            }
        }
Exemplo n.º 2
0
        public void ReadPointsStdGreaterMax()
        {
            // Well formed data
            byte[] streamData =
            {
                // max is 2
                2,   0, 0, 0,
                // count is 1
                1,   0, 0, 0,
                // x0 = 729
                217, 2, 0, 0,
                // y0 = 446
                190, 1, 0, 0,
                // x1 = 0
                0,   0, 0, 0,
                // y1 = 0
                0,   0, 0, 0,
            };

            int expectedPointsCount = 1;

            int[] expectedPoints =
            {
                // X1, Y1
                729, 446
            };

            WangStream stream = new WangStream(streamData);

            int[] read = WangAnnotationStructureReader.ReadPoints(stream, 24);
            Assert.IsTrue(read != null);

            Assert.AreEqual(1, WangAnnotationTranslation.PointsLength(read));
            Assert.AreEqual(0, stream.AvailableBytes());

            for (int index = 0; index < expectedPointsCount; index++)
            {
                Assert.AreEqual(expectedPoints[index * 2], WangAnnotationTranslation.PointX(index, read));
                Assert.AreEqual(expectedPoints[index * 2 + 1], WangAnnotationTranslation.PointY(index, read));
            }
        }