Beispiel #1
0
        public void ImportStreamShouldIndexExistingUserStrings()
        {
            var existingUserStringsStream = new SerializedUserStringsStream(UserStringsStream.DefaultName, new byte[]
            {
                0x00,

                // "User string"
                0x17,
                0x55, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x73, 0x00, 0x74, 0x00,
                0x72, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x00,

                // "A longer user string"
                0x29,
                0x41, 0x00, 0x20, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x65, 0x00,
                0x72, 0x00, 0x20, 0x00, 0x75, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00,
                0x73, 0x00, 0x74, 0x00, 0x72, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x00,

                // "An even longer user string"
                0x35,
                0x41, 0x00, 0x6E, 0x00, 0x20, 0x00, 0x65, 0x00, 0x76, 0x00, 0x65, 0x00, 0x6E, 0x00,
                0x20, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x65, 0x00, 0x72, 0x00,
                0x20, 0x00, 0x75, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x73, 0x00,
                0x74, 0x00, 0x72, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00
            });

            var buffer = new UserStringsStreamBuffer();

            buffer.ImportStream(existingUserStringsStream);
            var newStream = buffer.CreateStream();

            Assert.Equal("User string", newStream.GetStringByIndex(1));
            Assert.Equal("A longer user string", newStream.GetStringByIndex(25));
            Assert.Equal("An even longer user string", newStream.GetStringByIndex(67));
        }
Beispiel #2
0
        public void ImportStreamWithGarbageData()
        {
            var existingUserStringsStream = new SerializedUserStringsStream(UserStringsStream.DefaultName, new byte[]
            {
                0x00,

                // "User string"
                0x17,
                0x55, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x73, 0x00, 0x74, 0x00,
                0x72, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x00,

                0xAA,

                // "User string"
                0x17,
                0x55, 0x00, 0x73, 0x00, 0x65, 0x00, 0x72, 0x00, 0x20, 0x00, 0x73, 0x00, 0x74, 0x00,
                0x72, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x00,
            });

            var buffer = new UserStringsStreamBuffer();

            buffer.ImportStream(existingUserStringsStream);
            var newStream = buffer.CreateStream();

            Assert.Equal("User string", newStream.GetStringByIndex(1));
            Assert.Equal("User string", newStream.GetStringByIndex(26));
        }
Beispiel #3
0
        public void AddRaw()
        {
            var buffer = new UserStringsStreamBuffer();

            const string string1 = "String 1";
            var          rawData = Encoding.UTF8.GetBytes(string1);

            uint index1 = buffer.AppendRawData(rawData);
            uint index2 = buffer.GetStringIndex(string1);

            Assert.NotEqual(index1, index2);

            var usStream = buffer.CreateStream();

            Assert.Equal(string1, usStream.GetStringByIndex(index2));
        }
Beispiel #4
0
        public void AddDuplicate()
        {
            var buffer = new UserStringsStreamBuffer();

            const string string1 = "String 1";
            uint         index1  = buffer.GetStringIndex(string1);

            const string string2 = "String 1";
            uint         index2  = buffer.GetStringIndex(string2);

            Assert.Equal(index1, index2);

            var usStream = buffer.CreateStream();

            Assert.Equal(string1, usStream.GetStringByIndex(index1));
        }
Beispiel #5
0
        public void SpecialCharactersTerminatorByte(char specialChar, byte terminatorByte)
        {
            string value = "My String" + specialChar;

            var  buffer   = new UserStringsStreamBuffer();
            uint index    = buffer.GetStringIndex(value);
            var  usStream = buffer.CreateStream();

            Assert.Equal(value, usStream.GetStringByIndex(index));

            var reader = usStream.CreateReader();

            reader.Offset = (uint)(index + Encoding.Unicode.GetByteCount(value) + 1);
            byte b = reader.ReadByte();

            Assert.Equal(terminatorByte, b);
        }