コード例 #1
0
        public void StreamWritting()
        {
            var encoding = Encoding.UTF32;

            _writter.OutputEncoding = encoding;
            using (var stream = new MemoryStream())
            {
                _writter.Write(stream);
                var content = encoding.GetString(stream.ToArray());
                Assert.IsTrue(_headerRegex.IsMatch(content));
            }
        }
コード例 #2
0
 public void StreamUnicode()
 {
     var container = Helpers.GetSimpleStructure();
     container.Add(new BookmarkLink("test", "ƒ"));
     var ms = new MemoryStream();
     var writter = new NetscapeBookmarksWritter(container) { OutputEncoding = Encoding.Unicode };
     writter.Write(ms);
     ms = new MemoryStream(ms.GetBuffer());
     var reader = new NetscapeBookmarksReader { AutoDetectEncoding = true };
     var readed = reader.Read(ms);
     Assert.AreEqual(container.AllItems.Last().Title, readed.AllItems.Last().Title);
 }
コード例 #3
0
 public void OutputEncoding1()
 {
     var encoding = Encoding.BigEndianUnicode;
     var bookmarks = Helpers.GetSimpleStructure();
     var unicodeStr = Helpers.RandomUnicodeString(10240);
     bookmarks.Add(new BookmarkLink("http://example.com", "Unicode title test: <" + unicodeStr));
     var writter = new NetscapeBookmarksWritter(bookmarks) {OutputEncoding = encoding};
     using (var stream = new MemoryStream())
     {
         writter.Write(stream);
         var content = encoding.GetString(stream.ToArray());
         Assert.IsTrue(content.Contains("&lt;" + unicodeStr));
     }
 }
コード例 #4
0
 public void EmbededIconTest()
 {
     var bookmarks = Helpers.GetSimpleStructure();
     var randomBytes = Encoding.UTF8.GetBytes(Helpers.RandomUnicodeString(4096));
     bookmarks.Add(new BookmarkLink("http://example.com", "<\">") {IconContentType = "image/png", IconData = randomBytes});
     var writter = new NetscapeBookmarksWritter(bookmarks);
     using (var stream = new MemoryStream())
     {
         writter.Write(stream);
         var content = writter.OutputEncoding.GetString(stream.ToArray());
         Assert.IsTrue(content.Contains("data:image/png;base64,"));
         Assert.IsTrue(content.Contains(Convert.ToBase64String(randomBytes)));
     }
 }
コード例 #5
0
        public void OutputEncoding1()
        {
            var encoding   = Encoding.BigEndianUnicode;
            var bookmarks  = Helpers.GetSimpleStructure();
            var unicodeStr = Helpers.RandomUnicodeString(10240);

            bookmarks.Add(new BookmarkLink("http://example.com", "Unicode title test: <" + unicodeStr));
            var writter = new NetscapeBookmarksWritter(bookmarks)
            {
                OutputEncoding = encoding
            };

            using (var stream = new MemoryStream())
            {
                writter.Write(stream);
                var content = encoding.GetString(stream.ToArray());
                Assert.IsTrue(content.Contains("&lt;" + unicodeStr));
            }
        }
コード例 #6
0
        public void EmbededIconTest()
        {
            var bookmarks   = Helpers.GetSimpleStructure();
            var randomBytes = Encoding.UTF8.GetBytes(Helpers.RandomUnicodeString(4096));

            bookmarks.Add(new BookmarkLink("http://example.com", "<\">")
            {
                IconContentType = "image/png", IconData = randomBytes
            });
            var writter = new NetscapeBookmarksWritter(bookmarks);

            using (var stream = new MemoryStream())
            {
                writter.Write(stream);
                var content = writter.OutputEncoding.GetString(stream.ToArray());
                Assert.IsTrue(content.Contains("data:image/png;base64,"));
                Assert.IsTrue(content.Contains(Convert.ToBase64String(randomBytes)));
            }
        }
コード例 #7
0
        public void StreamUnicode()
        {
            var container = Helpers.GetSimpleStructure();

            container.Add(new BookmarkLink("test", "ƒ"));
            var ms      = new MemoryStream();
            var writter = new NetscapeBookmarksWritter(container)
            {
                OutputEncoding = Encoding.Unicode
            };

            writter.Write(ms);
            ms = new MemoryStream(ms.GetBuffer());
            var reader = new NetscapeBookmarksReader {
                AutoDetectEncoding = true
            };
            var readed = reader.Read(ms);

            Assert.AreEqual(container.AllItems.Last().Title, readed.AllItems.Last().Title);
        }
コード例 #8
0
        public void OutputEncoding2()
        {
            var encoding  = Encoding.GetEncoding(1257);
            var bookmarks = Helpers.GetSimpleStructure();

            bookmarks.Add(new BookmarkLink("http://example.com", "ASCII title test: ƒ ąčęėįšųūĄŪ"));
            var writter = new NetscapeBookmarksWritter(bookmarks)
            {
                OutputEncoding = encoding
            };

            using (var stream = new MemoryStream())
            {
                writter.Write(stream);
                var content = encoding.GetString(stream.ToArray());
                Assert.IsTrue(content.Contains("? ąčęėįšųūĄŪ"));
                content = Encoding.UTF8.GetString(stream.ToArray());
                Assert.IsFalse(content.Contains("ƒ"));
            }
        }
コード例 #9
0
 public void OutputEncoding2()
 {
     var encoding = Encoding.GetEncoding(1257);
     var bookmarks = Helpers.GetSimpleStructure();
     bookmarks.Add(new BookmarkLink("http://example.com", "ASCII title test: ƒ ąčęėįšųūĄŪ"));
     var writter = new NetscapeBookmarksWritter(bookmarks) {OutputEncoding = encoding};
     using (var stream = new MemoryStream())
     {
         writter.Write(stream);
         var content = encoding.GetString(stream.ToArray());
         Assert.IsTrue(content.Contains("? ąčęėįšųūĄŪ"));
         content = Encoding.UTF8.GetString(stream.ToArray());
         Assert.IsFalse(content.Contains("ƒ"));
     }
 }