Exemplo n.º 1
0
        public void NonUnicodeText()
        {
            var preCp = ZipStrings.CodePage;

            try
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

                foreach ((string language, string filename, string encoding) in StringTesting.GetTestSamples())
                {
                    Console.WriteLine($"{language} filename \"{filename}\" using \"{encoding}\":");

                    // TODO: samples of this test must be reversible
                    // Some samples can't be restored back with their encoding.
                    // test wasn't failing only because SystemDefaultCodepage is 65001 on Net.Core and
                    // old behaviour actually was using Unicode instead of user's passed codepage
                    var encoder        = Encoding.GetEncoding(encoding);
                    var bytes          = encoder.GetBytes(filename);
                    var restoredString = encoder.GetString(bytes);
                    if (string.CompareOrdinal(filename, restoredString) != 0)
                    {
                        Console.WriteLine($"Sample for language {language} with value of {filename} is skipped, because it's irreversable");
                        continue;
                    }

                    ZipStrings.CodePage = Encoding.GetEncoding(encoding).CodePage;
                    TestFileNames(filename);
                }
            }
            finally
            {
                ZipStrings.CodePage = preCp;
            }
        }
Exemplo n.º 2
0
        public void UnicodeNames()
        {
            using (var memStream = new MemoryStream())
            {
                using (ZipFile f = new ZipFile(memStream))
                {
                    f.IsStreamOwner = false;

                    f.BeginUpdate(new MemoryArchiveStorage());
                    foreach ((string language, string name, _) in StringTesting.GetTestSamples())
                    {
                        f.Add(new StringMemoryDataSource(language), name,
                              CompressionMethod.Deflated, true);
                    }
                    f.CommitUpdate();

                    Assert.IsTrue(f.TestArchive(true));
                }
                memStream.Seek(0, SeekOrigin.Begin);
                using (var zf = new ZipFile(memStream))
                {
                    foreach (string name in StringTesting.Filenames)
                    {
                        //int index = zf.FindEntry(name, true);
                        var content = "";
                        var index   = zf.FindEntry(name, true);
                        var entry   = zf[index];

                        using (var entryStream = zf.GetInputStream(entry))
                            using (var sr = new StreamReader(entryStream))
                            {
                                content = sr.ReadToEnd();
                            }

                        //var content =

                        Console.WriteLine($"Entry #{index}: {name}, Content: {content}");

                        Assert.IsTrue(index >= 0);
                        Assert.AreEqual(name, entry.Name);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void NonUnicodeText()
        {
            var preCp = ZipStrings.CodePage;

            try
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

                foreach ((string language, string filename, string encoding) in StringTesting.GetTestSamples())
                {
                    Console.WriteLine($"{language} filename \"{filename}\" using \"{encoding}\":");
                    ZipStrings.CodePage = Encoding.GetEncoding(encoding).CodePage;
                    TestFileNames(filename);
                }
            }
            finally
            {
                ZipStrings.CodePage = preCp;
            }
        }