Exemplo n.º 1
0
        public void ProlibraryTestEdgeCases()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath) || UoeUtilities.GetProVersionFromDlc(dlcPath).Major != 11)
            {
                return;
            }

            // test the edge cases were the file entries fill 511/512/513 of the file entries block size
            var filePath = Path.Combine(TestFolder, "test_edge_cases");

            File.WriteAllText($"{filePath}1", "");
            File.WriteAllText($"{filePath}2", "");
            File.WriteAllText($"{filePath}3", "");
            File.WriteAllText($"{filePath}4", "");
            File.WriteAllText($"{filePath}5", "");

            for (int i = 65; i >= 63; i--)
            {
                // progress prolib
                OeProlibArchiver oeArchiver;
                try {
                    oeArchiver = new OeProlibArchiver(dlcPath, Encoding.Default);
                } catch (ArchiverException e) {
                    Console.WriteLine($"Cancelling test, prolib not found! : {e.Message}");
                    return;
                }
                oeArchiver.ArchiveFileSet(new List <IFileToArchive> {
                    new FileInArchive {
                        SourcePath = $"{filePath}1", PathInArchive = new string('a', 83), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}2", PathInArchive = new string('b', 84), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}3", PathInArchive = new string('f', 84), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}4", PathInArchive = new string('c', i), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    },
                    new FileInArchive {
                        SourcePath = $"{filePath}5", PathInArchive = new string('d', 1), ArchivePath = Path.Combine(TestFolder, "test_edge_cases_official.pl")
                    }
                });

                // our prolib
                File.Copy(Path.Combine(TestFolder, "test_edge_cases_official.pl"), Path.Combine(TestFolder, "test_edge_cases.pl"));
                using (var prolib = new ProLibrary(Path.Combine(TestFolder, "test_edge_cases.pl"), null)) {
                    prolib.Save();
                }

                Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "test_edge_cases_official.pl")).SequenceEqual(File.ReadAllBytes(Path.Combine(TestFolder, "test_edge_cases.pl"))), "file not recreated the same way : test_edge_cases.");

                File.Delete(Path.Combine(TestFolder, "test_edge_cases.pl"));
                File.Delete(Path.Combine(TestFolder, "test_edge_cases_official.pl"));
            }
        }
        public void Test()
        {
            if (!TestHelper.GetDlcPath(out string dlcPath))
            {
                return;
            }

            OeProlibArchiver archiver;

            try {
                archiver = new OeProlibArchiver(dlcPath, Encoding.Default);
            } catch (ArchiverException e) {
                Console.WriteLine($"Cancelling test, prolib not found! : {e.Message}");
                return;
            }

            var listFiles = GetPackageTestFilesList(TestFolder, Path.Combine(TestFolder, "archives", "test1.pl"));

            listFiles.AddRange(GetPackageTestFilesList(TestFolder, Path.Combine(TestFolder, "archives", "test2.pl")));

            //WholeTest(archiver, listFiles);
        }
Exemplo n.º 3
0
        public void ReadAllKindsOfLib()
        {
            CreateProlibResources();
            var list = GetProlibResources();

            foreach (var prolibResource in list)
            {
                using (var prolib = new ProLibrary(Path.Combine(TestFolder, prolibResource.FileName), null)) {
                    Assert.AreEqual(prolibResource.ContainedFiles, string.Join(",", prolib.Files.Select(f => f.RelativePath)), $"Wrong file listing for {prolibResource.FileName}.");
                    foreach (var libraryFileEntry in prolib.Files)
                    {
                        if (!File.Exists(Path.Combine(TestFolder, libraryFileEntry.RelativePath)))
                        {
                            prolib.ExtractToFile(libraryFileEntry.RelativePath, Path.Combine(TestFolder, libraryFileEntry.RelativePath));
                        }
                    }
                }
            }

            Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "file")).SequenceEqual(new byte[] { 0xAA }), "file incorrect.");
            Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "file2")).SequenceEqual(new byte[] { 0xAA, 0xAA }), "file2 incorrect.");
            Assert.IsTrue(File.ReadAllBytes(Path.Combine(TestFolder, "file.r")).SequenceEqual(GetBytesFromResource("file.r")), "file.r incorrect.");

            foreach (var prolibResource in list.Where(f => f.IsCompressed))
            {
                File.Copy(Path.Combine(TestFolder, prolibResource.FileName), Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl"));
                using (var prolib = new ProLibrary(Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl"), null)) {
                    prolib.Save();
                    var data = new byte[new FileInfo(Path.Combine(TestFolder, prolibResource.FileName)).Length];
                    File.ReadAllBytes(Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl")).CopyTo(data, 0);

                    Assert.IsTrue(data.SequenceEqual(File.ReadAllBytes(Path.Combine(TestFolder, prolibResource.FileName))), $"file not recreated the same way : {prolibResource.FileName}.");
                }
            }

            if (!TestHelper.GetDlcPath(out string dlcPath) || UoeUtilities.GetProVersionFromDlc(dlcPath).Major != 11)
            {
                return;
            }
            OeProlibArchiver oeArchiver;

            try {
                oeArchiver = new OeProlibArchiver(dlcPath, Encoding.Default);
            } catch (ArchiverException e) {
                Console.WriteLine($"Cancelling test, prolib not found! : {e.Message}");
                return;
            }

            File.WriteAllBytes(Path.Combine(TestFolder, "file3"), new byte[] { 0xAA, 0xAA, 0xAA });
            File.WriteAllBytes(Path.Combine(TestFolder, "file4"), new byte[] { 0xAA, 0xAA, 0xAA, 0xAA });

            foreach (var prolibResource in list.Where(f => f.IsCompressed && f.Version == ProLibraryVersion.V11Standard))
            {
                var path = Path.Combine(TestFolder, $"{prolibResource.FileName}_copy.pl");
                Assert.AreEqual(string.Join(",", prolibResource.ContainedFiles.Split(',').OrderBy(s => s)), string.Join(",", oeArchiver.ListFiles(path).Select(f => f.PathInArchive).OrderBy(s => s)), $"Wrong file listing 2 for {prolibResource.FileName}.");
                oeArchiver.ArchiveFileSet(new List <IFileToArchive> {
                    new FileInArchive {
                        SourcePath = Path.Combine(TestFolder, "file3"), PathInArchive = "sub/file3", ArchivePath = path
                    }
                });
                oeArchiver.ArchiveFileSet(new List <IFileToArchive> {
                    new FileInArchive {
                        SourcePath = Path.Combine(TestFolder, "file4"), PathInArchive = "sub/file4", ArchivePath = path
                    }
                });
                var fileCount = (string.IsNullOrEmpty(prolibResource.ContainedFiles) ? 0 : prolibResource.ContainedFiles.Split(',').Length) + 2;

                using (var prolib = new ProLibrary(path, null)) {
                    Assert.AreEqual(fileCount, prolib.Files.Count, $"Bad count for {prolibResource.FileName}.");
                    prolib.Save();
                }
                Assert.AreEqual(fileCount, oeArchiver.ListFiles(path).Count());
            }
        }