Пример #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));
        }
Пример #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));
        }