Esempio n. 1
0
        public void CanFinalizeShortTag()
        {
            var artist = "Bob";
            var tag    = new Tag <char>
            {
                DataType = TagDataType.ASCII,
                ID       = (ushort)BaselineTags.Artist,
                Length   = (uint)artist.Length + 1,
                Values   = artist.ToASCIIArray()
            };

            using (var stream = new TiffStreamWriter())
            {
                stream.WriteDWord(1);
                stream.WriteTagPlaceholder(tag);
                stream.FinalizeTag(tag);

                var data = stream.ToArray();

                Assert.Equal(4u, tag.Offset);
                Assert.Equal(4u, tag.Length);
                Assert.Equal(16, data.Length);
                Assert.Equal(artist, Encoding.ASCII.GetString(tag.RawValue).Trim('\0'));
            }
        }
Esempio n. 2
0
        public void CanFinalizeLongTag()
        {
            var artist = "Ansel Adams";
            var tag    = new Tag <char>
            {
                DataType = TagDataType.ASCII,
                ID       = (ushort)BaselineTags.Artist,
                Length   = (uint)artist.Length + 1,
                Values   = artist.ToASCIIArray()
            };

            using (var stream = new TiffStreamWriter())
            {
                stream.WriteDWord(1);
                stream.WriteTagPlaceholder(tag);
                stream.FinalizeTag(tag);

                var data = stream.ToArray();

                Assert.Equal(4u, tag.Offset);
                Assert.Equal(12u, tag.Length);
                Assert.Equal(28, data.Length);
                Assert.True(tag.RawValue.SequenceEqual(BitConverter.GetBytes(16u)));
            }
        }
Esempio n. 3
0
        public void CanWriteDWord()
        {
            using (var stream = new TiffStreamWriter())
            {
                stream.WriteDWord(42);

                var data = stream.ToArray();
                Assert.True(data.SequenceEqual(new byte[] { 0x2a, 0x00, 0x00, 0x00 }));
            }

            using (var stream = new TiffStreamWriter(forceBigEndian: true))
            {
                stream.WriteDWord(42);

                var data = stream.ToArray();
                Assert.True(data.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x2a }));
            }
        }