Beispiel #1
0
        public void WriteLongTagDataTest()
        {
            const SwfTagType tagType = SwfTagType.ExportAssets;
            var data = new byte[4096];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = (byte)(i & 0xff);
            }
            var tagData = new SwfTagData {
                Type = tagType, Data = data
            };
            var mem    = new MemoryStream();
            var writer = new SwfStreamWriter(mem);

            writer.WriteTagData(tagData);

            var       array  = mem.ToArray();
            const int header = ((int)tagType << 6) | 0x3f;

            Assert.AreEqual(header & 0xff, array[0]);
            Assert.AreEqual(header >> 8, array[1]);
            var len = data.Length;

            Assert.AreEqual((byte)((len >> 0) & 0xff), array[2]);
            Assert.AreEqual((byte)((len >> 8) & 0xff), array[3]);
            Assert.AreEqual((byte)((len >> 16) & 0xff), array[4]);
            Assert.AreEqual((byte)((len >> 24) & 0xff), array[5]);
            array = array.Skip(6).ToArray();
            AssertExt.AreEqual(data, array, "Data should be equal");
            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
Beispiel #2
0
        public void WriteShortTagDataTest()
        {
            const SwfTagType tagType = SwfTagType.ExportAssets;
            var data = new byte[10];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = (byte)(i & 0xff);
            }
            var tagData = new SwfTagData {
                Type = tagType, Data = data
            };
            var mem    = new MemoryStream();
            var writer = new SwfStreamWriter(mem);

            writer.WriteTagData(tagData);

            var array  = mem.ToArray();
            var header = ((int)tagType << 6) | data.Length;

            Assert.AreEqual((byte)(header & 0xff), array[0]);
            Assert.AreEqual((byte)(header >> 8), array[1]);
            array = array.Skip(2).ToArray();
            AssertExt.AreEqual(data, array, "Data should be equal");
            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
Beispiel #3
0
        public void DefineBitsJPEG2Test()
        {
            var file = new SwfFile();

            file.FileInfo.Version = 10;

            var tag = new DefineBitsJPEG2Tag();

            tag.CharacterID = 1;
            tag.ImageData   = GetEmbeddedResourceData("DefineBitsJPEG2.jpg");
            var visitor = new SwfTagSerializer(file);
            var res     = visitor.GetTagData(tag);
            var mem     = new MemoryStream();
            var writer  = new SwfStreamWriter(mem);

            writer.WriteTagData(res);

            var etalon = GetTagFullBinariesFromSwfResource("DefineBitsJPEG2.swf")
                         .FirstOrDefault(item => item.Type == SwfTagType.DefineBitsJPEG2);

            if (etalon.Binary == null)
            {
                throw new InvalidOperationException("Couldn't find etalon tag");
            }

            AssertExt.AreEqual(etalon.Binary, mem.ToArray(), "Checking DefineBitsJPEG2");
        }
        public void DefineBitsJPEG2Test()
        {
            var file = new SwfFile();
            file.FileInfo.Version = 10;

            var tag = new DefineBitsJPEG2Tag();
            tag.CharacterID = 1;
            tag.ImageData = GetEmbeddedResourceData("DefineBitsJPEG2.jpg");
            var visitor = new SwfTagSerializer(file);
            var res = visitor.GetTagData(tag);
            var mem = new MemoryStream();
            var writer = new SwfStreamWriter(mem);
            writer.WriteTagData(res);

            var etalon = GetTagFullBinariesFromSwfResource("DefineBitsJPEG2.swf")
                .FirstOrDefault(item => item.Type == SwfTagType.DefineBitsJPEG2);
            if (etalon.Binary == null) throw new InvalidOperationException("Couldn't find etalon tag");

            AssertExt.AreEqual(etalon.Binary, mem.ToArray(), "Checking DefineBitsJPEG2");
        }
Beispiel #5
0
        public void WriteShortTagDataTest()
        {
            const SwfTagType tagType = SwfTagType.ExportAssets;
            var data = new byte[10];
            for (var i = 0; i < data.Length; i++) {
                data[i] = (byte)(i & 0xff);
            }
            var tagData = new SwfTagData { Type = tagType, Data = data };
            var mem = new MemoryStream();
            var writer = new SwfStreamWriter(mem);
            writer.WriteTagData(tagData);

            var array = mem.ToArray();
            var header = ((int)tagType << 6) | data.Length;
            Assert.AreEqual((byte)(header & 0xff), array[0]);
            Assert.AreEqual((byte)(header >> 8), array[1]);
            array = array.Skip(2).ToArray();
            AssertExt.AreEqual(data, array, "Data should be equal");
            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
Beispiel #6
0
        public void WriteLongTagDataTest()
        {
            const SwfTagType tagType = SwfTagType.ExportAssets;
            var data = new byte[4096];
            for (var i = 0; i < data.Length; i++) {
                data[i] = (byte)(i & 0xff);
            }
            var tagData = new SwfTagData { Type = tagType, Data = data };
            var mem = new MemoryStream();
            var writer = new SwfStreamWriter(mem);
            writer.WriteTagData(tagData);

            var array = mem.ToArray();
            const int header = ((int)tagType << 6) | 0x3f;
            Assert.AreEqual(header & 0xff, array[0]);
            Assert.AreEqual(header >> 8, array[1]);
            var len = data.Length;
            Assert.AreEqual((byte)((len >> 0) & 0xff), array[2]);
            Assert.AreEqual((byte)((len >> 8) & 0xff), array[3]);
            Assert.AreEqual((byte)((len >> 16) & 0xff), array[4]);
            Assert.AreEqual((byte)((len >> 24) & 0xff), array[5]);
            array = array.Skip(6).ToArray();
            AssertExt.AreEqual(data, array, "Data should be equal");
            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }