public void MtdImageTableRecordBuilderBuildMtdImageTableRecordAttributeNullTest()
        {
            MtdImageTableRecordBuilder   builder   = new MtdImageTableRecordBuilder();
            MtdImageTableRecordAttribute attribute = null;

            Assert.ThrowsException <AttributeNullException>(() => builder.Build(attribute));
        }
        public void MtdImageTableRecordBuilderBuildMtdImageTableRecordNullBytesTest()
        {
            MtdImageTableRecordBuilder builder = new MtdImageTableRecordBuilder();

            byte[] bytes = null;
            Assert.ThrowsException <ArgumentNullException>(() => builder.Build(bytes));
        }
예제 #3
0
        internal MtdImageTable(MtdImageTableAttribute attribute)
        {
            MtdImageTableRecordBuilder builder = new MtdImageTableRecordBuilder();

            foreach (MtdImageTableRecordAttribute mtdImageTableRecordAttribute in attribute.Images)
            {
                MtdImageTableRecord record = builder.Build(mtdImageTableRecordAttribute);
                _mtdImageTableRecords.Add(record);
            }
        }
        public void MtdImageTableRecordBuilderBuildMtdImageTableRecordTest(string name, uint posX, uint posY, uint exX,
                                                                           uint exY, bool alpha)
        {
            List <byte> inputAsBytes = new List <byte>();

            byte[] n       = Encoding.ASCII.GetBytes(name);
            byte[] nPadded = new byte[64];
            for (int i = 0; i < nPadded.Length; i++)
            {
                nPadded[i] = 0;
            }

            for (int i = 0; i < n.Length && i < nPadded.Length; i++)
            {
                nPadded[i] = n[i];
            }

            inputAsBytes.AddRange(nPadded);
            inputAsBytes.AddRange(BitConverter.GetBytes(posX));
            inputAsBytes.AddRange(BitConverter.GetBytes(posY));
            inputAsBytes.AddRange(BitConverter.GetBytes(exX));
            inputAsBytes.AddRange(BitConverter.GetBytes(exY));
            inputAsBytes.AddRange(BitConverter.GetBytes(alpha));
            byte[] inAsByteArray = inputAsBytes.ToArray();

            MtdImageTableRecordBuilder   builder   = new MtdImageTableRecordBuilder();
            MtdImageTableRecordAttribute attribute = new MtdImageTableRecordAttribute
            {
                Name      = name,
                XPosition = posX,
                YPosition = posY,
                XExtend   = exX,
                YExtend   = exY,
                Alpha     = alpha
            };
            MtdImageTableRecord record          = builder.Build(attribute);
            MtdImageTableRecord recordFromBytes = builder.Build(inAsByteArray);

            byte[] bytesFromAttributes = record.GetBytes();
            byte[] bytesFromBytes      = recordFromBytes.GetBytes();
            Assert.IsNotNull(bytesFromAttributes);
            Assert.IsNotNull(bytesFromBytes);
            Assert.AreEqual(MTD_IMAGE_TABLE_RECORD_SIZE, bytesFromAttributes.Length);
            Assert.AreEqual(MTD_IMAGE_TABLE_RECORD_SIZE, bytesFromBytes.Length);
            for (int i = 0; i < bytesFromAttributes.Length; i++)
            {
                Assert.AreEqual(bytesFromAttributes[i], inAsByteArray[i]);
            }

            for (int i = 0; i < bytesFromBytes.Length; i++)
            {
                Assert.AreEqual(bytesFromBytes[i], inAsByteArray[i]);
            }
        }
        public void MtdImageTableRecordBuilderTest()
        {
            string s = Path.Combine(Directory.GetCurrentDirectory(), MTD_RECORD);

            byte[] array = File.ReadAllBytes(Path.Combine(Directory.GetCurrentDirectory(), MTD_RECORD));
            MtdImageTableRecordBuilder builder = new MtdImageTableRecordBuilder();
            MtdImageTableRecord        e       = builder.Build(array);

            Assert.IsNotNull(e);
            Assert.IsNotNull(e.GetBytes());
            Assert.AreEqual(MTD_IMAGE_TABLE_RECORD_SIZE, e.GetBytes().Length);
        }
        public void MtdImageTableRecordBuilderBuildMtdImageTableRecordInvalidBytesTest(int arrayLength)
        {
            MtdImageTableRecordBuilder builder = new MtdImageTableRecordBuilder();

            Assert.ThrowsException <InvalidByteArrayException>(() => builder.Build(new byte[arrayLength]));
        }