Пример #1
0
        public void ReadPointsReadFailure()
        {
            // Well formed data
            byte[] streamData =
            {
                // max is 2
                2,   0, 0, 0,
                // count is 2
                2,   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,
            };

            // The stream contains exactly the correct amount of data.
            // With fewer data, an error should rise.
            for (int dataSize = 0; dataSize < streamData.Length - 1; dataSize++)
            {
                WangStream stream = new WangStream(streamData);
                int[]      read   = WangAnnotationStructureReader.ReadPoints(stream, dataSize);
                Assert.IsTrue(read == null);
            }
        }
Пример #2
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));
            }
        }
Пример #3
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));
            }
        }
Пример #4
0
        public void ReadPointsMalformed()
        {
            // Mall formed data: count is 2 while max is 1
            byte[] streamData =
            {
                // max is 1
                1,   0, 0, 0,
                // count is 2
                2,   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,
            };

            WangStream stream = new WangStream(streamData);

            int[] read = WangAnnotationStructureReader.ReadPoints(stream, streamData.Length);
            Assert.IsTrue(read == null);
        }