コード例 #1
0
        public void ReadDataTypeInvalidSize()
        {
            Random random = new Random(10);

            for (int dataSize = 0; dataSize < 8; dataSize++)
            {
                // Random stream data
                byte[] streamData = new byte[dataSize];
                for (int index = 0; index < dataSize; index++)
                {
                    streamData[index] = (byte)random.Next();
                }

                WangStream stream = new WangStream(streamData);
                WangAnnotationsReader.WangDataType dataType;
                int outputDataSize;
                Assert.IsFalse(WangAnnotationsReader.ReadDataType(out dataType, out outputDataSize, stream));
                Assert.AreEqual(WangAnnotationsReader.WangDataType.Invalid, dataType);
                Assert.AreEqual(0, outputDataSize);
            }
        }
コード例 #2
0
        public void ReadDataTypeInvalid()
        {
            int[] invalidDataTypes =
            {
                0, 1, 3, 4, 7, 8, 9, 10
            };

            foreach (var expectedDataType in invalidDataTypes)
            {
                // Valid stream data but invalid data type
                byte[] streamData = new byte[8];
                Array.Copy(BitConverter.GetBytes((int)expectedDataType), streamData, 4);
                Array.Copy(BitConverter.GetBytes((int)8), 0, streamData, 4, 4);

                WangStream stream = new WangStream(streamData);
                WangAnnotationsReader.WangDataType dataType;
                int dataSize;
                Assert.IsTrue(WangAnnotationsReader.ReadDataType(out dataType, out dataSize, stream));
                Assert.AreEqual(WangAnnotationsReader.WangDataType.Invalid, dataType);
                Assert.AreEqual(8, dataSize);
                Assert.AreEqual(0, stream.AvailableBytes());
            }
        }
コード例 #3
0
        public void ReadDataTypeStd()
        {
            // The int values for the data types which will be tested.
            int[] intTypes =
            {
                2, 5, 6
            };
            // The data types which will be tested, aligned with the corresponding entry
            // in the intTypes array.
            WangAnnotationsReader.WangDataType[] dataTypes =
            {
                WangAnnotationsReader.WangDataType.DefaultNamedBlock, WangAnnotationsReader.WangDataType.Attributes,
                WangAnnotationsReader.WangDataType.NamedBlock
            };

            // The test runs with different data size. At least 8 bytes
            // are required for the stream to be valid.
            for (int expectedDataSize = 8; expectedDataSize < 40; expectedDataSize++)
            {
                for (int dataTypeIndex = 0; dataTypeIndex < intTypes.Length; dataTypeIndex++)
                {
                    // Valid stream data
                    byte[] streamData = new byte[expectedDataSize];
                    Array.Copy(BitConverter.GetBytes(intTypes[dataTypeIndex]), streamData, 4);
                    Array.Copy(BitConverter.GetBytes((int)expectedDataSize), 0, streamData, 4, 4);

                    WangStream stream = new WangStream(streamData);
                    WangAnnotationsReader.WangDataType dataType;
                    int dataSize;
                    Assert.IsTrue(WangAnnotationsReader.ReadDataType(out dataType, out dataSize, stream));
                    Assert.AreEqual(expectedDataSize, dataSize);
                    Assert.AreEqual(dataTypes[dataTypeIndex], dataType);
                    Assert.AreEqual(expectedDataSize - 8, stream.AvailableBytes());
                }
            }
        }