public void TarArchiveAccess_CreateEntryWithNullName_ThrowsArgumentNullException() { using (var tar = CompressedArchiveAccess.Open(new MemoryStream(), CompressedArchiveFormat.Tar, CompressedArchiveAccessMode.Create)) { Assert.Throws <ArgumentNullException>(() => tar.CreateEntry(null)); } }
public void GZipAccess_OpenFromDisk_HasExpectedContent(CompressedArchiveAccessImplementation implementation) { string testResourcePath; using (TestResource.TagalongBinCfgNNGZip.ExtractToTemporaryFile(out testResourcePath)) using (var gzip = CompressedArchiveAccess.Open(testResourcePath, CompressedArchiveAccessMode.Read, implementation)) { var expectedCrc32s = new[] { TestRomResources.TestBinCrc, TestRomResources.TestCfgCrc }; var i = 0; foreach (var entry in gzip.Entries) { using (var entryStream = gzip.OpenEntry(entry)) using (var validationStream = new MemoryStream()) { // Some implementations, e.g. SharpZipLib, inflate the ENTIRE contents of ALL members of a multi-member entry into one giant output, // so we need to read to an intermediate stream, then verify the output. entryStream.CopyTo(validationStream); validationStream.SetLength(entry.Length); var crc = Crc32.OfStream(validationStream); Assert.Equal(expectedCrc32s[i], crc); } ++i; } } }
public void CompressedArchiveAccess_RegisterMultipleImplementationsAndCreateWithSpecificImplementation_CreatesUsingSelectedImplementation() { var format = RegisterFakeFormatForTest(registerFormat: true); var implementations = new[] { format.GetPreferredCompressedArchiveImplementation(), this.GetFakeCompressedArchiveAccessImplementationForTest(), this.GetFakeCompressedArchiveAccessImplementationForTest() }; Assert.True(format.AddImplementation(implementations[1], makePreferred: false)); Assert.True(format.AddImplementation(implementations[2], makePreferred: false)); Assert.True(CompressedArchiveAccess.RegisterFactory(format, implementations[1], (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementations[1]))); Assert.True(CompressedArchiveAccess.RegisterFactory(format, implementations[2], (s, m) => TestCompressedArchiveAccess.Create(s, m, format, implementations[2]))); foreach (var implementation in implementations) { using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Create, implementation) as TestCompressedArchiveAccess) { Assert.NotNull(archive); Assert.Equal(implementation, archive.Implementation); } } }
public void ICompressedArchive_ListTgzManyDirsInSubdirRecursivelyWithContainers_ReturnsExpectedItems() { var tgzManyDirs = TestResource.TagalongTgzManyDirs; var tgzFilePath = string.Empty; var location = "tagalong_many_dirs.tar/rootSub/sub0/"; var expectedEntryNames = new[] { "tagalong_many_dirs.tar/rootSub/sub0/._.DS_Store", "tagalong_many_dirs.tar/rootSub/sub0/.DS_Store", "tagalong_many_dirs.tar/rootSub/sub0/subSub0/", "tagalong_many_dirs.tar/rootSub/sub0/subSub0/tagalong_metadata.bin", "tagalong_many_dirs.tar/rootSub/sub0/subSub0/tagalong_metadata.cfg", "tagalong_many_dirs.tar/rootSub/sub0/subSub0/tagalong_metadata.luigi", "tagalong_many_dirs.tar/rootSub/sub0/subSub0/tagalong_metadata.rom", "tagalong_many_dirs.tar/rootSub/sub0/subSub1/", "tagalong_many_dirs.tar/rootSub/sub0/tagalong_any.luigi", }; using (tgzManyDirs.ExtractToTemporaryFile(out tgzFilePath)) using (var tgz = CompressedArchiveAccess.Open(tgzFilePath, CompressedArchiveAccessMode.Read)) { var entries = tgz.ListEntries(location, includeContainers: true, recurse: true); var entryNames = entries.Select(e => e.Name); Assert.Equal(expectedEntryNames, entryNames); } }
public void ICompressedArchive_ListTgzRecursivelyWithContainers_ReturnsExpectedItems() { var tgzNested = TestResource.TagalongWin10TarGz; var tgzFilePath = string.Empty; var expectedEntryNames = new[] { "tagalong_w10.tar", "tagalong_w10.tar/meta/", "tagalong_w10.tar/meta/tagalong_metadata.bin", "tagalong_w10.tar/meta/tagalong_metadata.cfg", "tagalong_w10.tar/meta/tagalong_metadata.luigi", "tagalong_w10.tar/meta/tagalong_metadata.rom", "tagalong_w10.tar/scram/", "tagalong_w10.tar/scram/tagalong_any.luigi", "tagalong_w10.tar/scram/tagalong_dev0.luigi", "tagalong_w10.tar/scram/tagalong_dev1.luigi", "tagalong_w10.tar/tagalong.bin", "tagalong_w10.tar/tagalong.cfg", "tagalong_w10.tar/tagalong.rom", }; using (tgzNested.ExtractToTemporaryFile(out tgzFilePath)) using (var tgz = CompressedArchiveAccess.Open(tgzFilePath, CompressedArchiveAccessMode.Read)) { var entries = tgz.ListEntries(locationInArchive: null, includeContainers: true, recurse: true); var entryNames = entries.Select(e => e.Name); Assert.Equal(expectedEntryNames, entryNames); } }
public void ICompressedArchive_ListFolderRecursivelyWithContainers_ReturnsExpectedItems() { var zipWithMultiNesting = TestResource.TagalongZipWithManyNests; var location = @"extra_nest\"; var expectedEntryNames = new[] { "extra_nest/tagalong_metadata.bin", "extra_nest/tagalong_metadata.cfg", "extra_nest/tagalong_msys2.tgz", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/bin/", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/bin/tagalong.bin", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/bin/tagalong.cfg", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/tagalong.luigi", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/tagalong.rom", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/tagalong.zip", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/tagalong.zip/tagalong.bin", "extra_nest/tagalong_msys2.tgz/tagalong_msys2.tar/tagalong.zip/tagalong.cfg", }; using (var zip = CompressedArchiveAccess.Open(zipWithMultiNesting.OpenResourceForReading(), CompressedArchiveFormat.Zip, CompressedArchiveAccessMode.Read)) { var entries = zip.ListEntries(location, includeContainers: true, recurse: true); var entryNames = entries.Select(e => e.Name); Assert.Equal(expectedEntryNames, entryNames); } }
public void ICompressedArchive_ListRootEntriesWithContanersNonRecursively_ReportsCorrectMetadata() { var zipWithMultiNesting = TestResource.TagalongZipWithManyNests; var expectedEntryNames = new[] { "extra_nest/", "tagalong_dev0.luigi", "tagalong_dev1.luigi", }; using (var zip = CompressedArchiveAccess.Open(zipWithMultiNesting.OpenResourceForReading(), CompressedArchiveFormat.Zip, CompressedArchiveAccessMode.Read)) { var entries = zip.ListEntries(null, includeContainers: true, recurse: false); Assert.Equal(expectedEntryNames.Length, entries.Count()); for (int i = 0; i < expectedEntryNames.Length; ++i) { var entry = entries.ElementAt(i); Assert.Equal(expectedEntryNames[i], entry.Name); if (entry.IsDirectory) { Assert.Equal(-1, entry.Length); Assert.Equal(DateTime.MinValue, entry.LastModificationTime); } else { Assert.True(entry.Length > 0); Assert.NotEqual(DateTime.MinValue, entry.LastModificationTime); } } } }
public void CompressedArchiveAccess_ForceFinalizer() { var format = RegisterFakeFormatForTest(); CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read); GC.Collect(); GC.WaitForPendingFinalizers(); }
public void ICompressedArchiveAccess_ListWithMalformedLocationInContainer_ThrowsArgumentException() { using (var zip = CompressedArchiveAccess.Open(TestResource.TagalongZip.OpenResourceForReading(), CompressedArchiveFormat.Zip, CompressedArchiveAccessMode.Read)) { Assert.Throws <ArgumentException>(() => zip.ListEntries("where's the beef!", includeContainers: true)); Assert.Throws <ArgumentException>(() => zip.ListContents("did you check under the dash?", includeContainers: true)); } }
private static void VerifyNumberOfEntries(string testZipFilePath, int expectedNumberOfEntries, CompressedArchiveAccessImplementation implementation) { using (var zipArchive = CompressedArchiveAccess.Open(testZipFilePath, CompressedArchiveAccessMode.Read, implementation)) { var numberOfEntries = zipArchive.Entries.Count(); Assert.Equal(expectedNumberOfEntries, numberOfEntries); } }
public void ZipArchiveAccess_OpenNonZip_ThrowsInvalidDataException(CompressedArchiveAccessImplementation implementation) { var nonZipResource = TestResource.TextEmbeddedResourceFile; var stream = nonZipResource.OpenResourceForReading(); Assert.Throws <InvalidDataException>(() => CompressedArchiveAccess.Open(stream, CompressedArchiveFormat.Zip, CompressedArchiveAccessMode.Read, implementation)); }
public void CompressedArchiveAccess_OpenFromFileWithUnknownExtension_ThrowsInvalidOperationException() { var format = RegisterFakeFormatForTest(); using (var tempFile = new TemporaryFile(".fake", createFile: true)) { Assert.Throws <InvalidOperationException>(() => CompressedArchiveAccess.Open(tempFile.FilePath, CompressedArchiveAccessMode.Read)); } }
public void TarArchiveAccess_OpenNonTar_ThrowsInvalidDataException() { var nonGZipResource = TestResource.TextEmbeddedResourceFile; using (var stream = nonGZipResource.OpenResourceForReading()) { Assert.Throws <System.IO.InvalidDataException>(() => CompressedArchiveAccess.Open(stream, CompressedArchiveFormat.Tar, CompressedArchiveAccessMode.Read)); } }
public void GZipAccess_IsCompressed_IsTrue(CompressedArchiveAccessImplementation implementation) { var stream = new MemoryStream(); using (var gzip = CompressedArchiveAccess.Open(stream, CompressedArchiveFormat.GZip, CompressedArchiveAccessMode.Create, implementation)) { Assert.True(gzip.IsCompressed); } }
public void GZipAccess_Format_IsGZip(CompressedArchiveAccessImplementation implementation) { var stream = new MemoryStream(); using (var gzip = CompressedArchiveAccess.Open(stream, CompressedArchiveFormat.GZip, CompressedArchiveAccessMode.Create, implementation)) { Assert.Equal(CompressedArchiveFormat.GZip, gzip.Format); } }
public void GZipAccess_OpenNonEmptyGZipForCreate_ThrowsInvalidOperationException(CompressedArchiveAccessImplementation implementation) { var gzipResource = TestResource.TagalongBinGZip; using (var stream = gzipResource.OpenResourceForReading()) { Assert.Throws <InvalidOperationException>(() => CompressedArchiveAccess.Open(stream, CompressedArchiveFormat.GZip, CompressedArchiveAccessMode.Create, implementation)); } }
public void TarArchiveAccess_CreateEntryWhenOpenInReadMode_ThrowsInvalidOperationException() { var tarResource = TestResource.TagalongBinCfgTar; using (var tar = CompressedArchiveAccess.Open(tarResource.OpenResourceForReading(), CompressedArchiveFormat.Tar, CompressedArchiveAccessMode.Read)) { Assert.Throws <InvalidOperationException>(() => tar.CreateEntry("derp")); } }
public void GZipAccess_OpenWithInvalidMode_ThrowsArgumentOutOfRangeException(CompressedArchiveAccessImplementation implementation) { var gzipResource = TestResource.TagalongBinGZip; using (var stream = gzipResource.OpenResourceForReading()) { Assert.Throws <ArgumentOutOfRangeException>(() => CompressedArchiveAccess.Open(stream, CompressedArchiveFormat.GZip, (CompressedArchiveAccessMode)100, implementation)); } }
public void GZipAccess_CreateEntryInEmptyStream_Succeeds(CompressedArchiveAccessImplementation implementation) { var stream = new MemoryStream(); using (var gzip = CompressedArchiveAccess.Open(stream, CompressedArchiveFormat.GZip, CompressedArchiveAccessMode.Create, implementation)) { Assert.NotNull(gzip.CreateEntry("newEntry")); } }
public void TarArchiveAccess_DeleteEntry_ThrowsNotSupportedException() { var tarResource = TestResource.TagalongBinCfgTar; var entryName = tarResource.ArchiveContents.First(); using (var tar = CompressedArchiveAccess.Open(tarResource.OpenResourceForReading(), CompressedArchiveFormat.Tar, CompressedArchiveAccessMode.Read)) { Assert.Throws <NotSupportedException>(() => tar.DeleteEntry(entryName)); } }
public void ICompressedArchive_ListNonexistentNestedArchive_ThrowsFileNotFoundException() { var zipWithMultiNesting = TestResource.TagalongZipWithManyNests; var location = @"extra_nest/tagalong_msys2.tgz/tagalong_mystery.tar/tagalong.zip/"; using (var zip = CompressedArchiveAccess.Open(zipWithMultiNesting.OpenResourceForReading(), CompressedArchiveFormat.Zip, CompressedArchiveAccessMode.Read)) { Assert.Throws <FileNotFoundException>(() => zip.ListEntries(location, includeContainers: false, recurse: false)); } }
public void CompressedArchiveAccess_OpenForReadFromStreamAndDeleteNonexistentEntry_ReturnsFalse() { var format = RegisterFakeFormatForTest(); using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read)) { Assert.NotNull(archive); Assert.False(archive.DeleteEntry("booger")); } }
public void CompressedArchiveAccess_OpenFromStreamIStorageAccessFindNonexistentEntry_ReturnsNull() { var format = RegisterFakeFormatForTest(); using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read)) { Assert.NotNull(archive); Assert.Null(archive.FindEntry("glrb")); } }
public void CompressedArchiveAccess_OpenFromStreamIStorageAccessOpenOnInvalidEntryByName_ReturnsNull() { var format = RegisterFakeFormatForTest(); using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read)) { Assert.NotNull(archive); Assert.Null(archive.Open("fleen")); } }
public void CompressedArchiveAccess_OpenFromStreamIStorageAccessExistsForInvalidEntryByName_ReturnsFalse() { var format = RegisterFakeFormatForTest(); using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read)) { Assert.NotNull(archive); Assert.False(archive.Exists("Klern")); } }
public void CompressedArchiveAccess_OpenFromStreamIStorageAccessSizeOfInvalidEntryByName_ReturnsZero() { var format = RegisterFakeFormatForTest(); using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read)) { Assert.NotNull(archive); Assert.Equal(0L, archive.Size("pLEf")); } }
public void CompressedArchiveAccess_OpenFromStreamIStorageAccessLastWriteTimeUtcOfInvalidEntryByName_ReturnsMin() { var format = RegisterFakeFormatForTest(); using (var archive = CompressedArchiveAccess.Open(Stream.Null, format, CompressedArchiveAccessMode.Read)) { Assert.NotNull(archive); Assert.Equal(DateTime.MinValue, archive.LastWriteTimeUtc("Scrallette")); } }
public void CompressedArchiveAccess_OpenFromFileWithNoFactoryRegistered_ThrowsNotSupportedException() { var format = this.RegisterTestCompressedArchiveFormat(); var fileExtension = format.FileExtensions().First(); using (var tempFile = new TemporaryFile(fileExtension, createFile: true)) { Assert.Throws <NotSupportedException>(() => CompressedArchiveAccess.Open(tempFile.FilePath, CompressedArchiveAccessMode.Read)); } }
public void ICompressedArchiveAccess_ListItemsWithNonexistentLocation_ReturnsEmpty(string location) { using (var zip = CompressedArchiveAccess.Open(TestResource.TagalongZip.OpenResourceForReading(), CompressedArchiveFormat.Zip, CompressedArchiveAccessMode.Read)) { var entries0 = zip.ListEntries(location, includeContainers: false); var entries1 = zip.ListContents(location, includeContainers: false); Assert.Empty(entries0); Assert.Empty(entries1); } }
public void GZipAccess_WriteRomResourceToGZipFile_ProducesExpectedResult(CompressedArchiveAccessImplementation implementation) { var gzipFileName = TemporaryFile.GenerateUniqueFilePath("tagalong", ".luigi.gz"); using (TemporaryFile.CreateTemporaryFileWithPath(gzipFileName, createEmptyFile: false)) { // Create on-disk GZIP var inputLength = 0L; var fileStream = new FileStream(gzipFileName, FileMode.Create, FileAccess.Write); using (var gzip = CompressedArchiveAccess.Open(fileStream, CompressedArchiveFormat.GZip, CompressedArchiveAccessMode.Create, implementation)) { var testResourceName = "INTV.TestHelpers.Core.Resources.tagalong.luigi"; var newGZipEntryName = "tagalong.luigi"; var entry = gzip.CreateEntry(newGZipEntryName); using (var gzipStream = gzip.Open(entry.Name)) using (var sourceStream = typeof(TestRomResources).Assembly.GetManifestResourceStream(testResourceName)) { sourceStream.CopyTo(gzipStream); inputLength = sourceStream.Length; } } // Now, see if we can extract it! var extractedRomPath = Path.Combine(Path.GetDirectoryName(gzipFileName), Path.GetFileNameWithoutExtension(gzipFileName)); using (TemporaryFile.CreateTemporaryFileWithPath(extractedRomPath, createEmptyFile: false)) { var fileInfo = new FileInfo(gzipFileName); Assert.True(fileInfo.Exists); Assert.True(inputLength > fileInfo.Length); // Compressed we must be! On this, all depends. using (var gzip = CompressedArchiveAccess.Open(gzipFileName, CompressedArchiveAccessMode.Read, implementation)) { Assert.True(gzip.Entries.Any()); var entry = gzip.Entries.Single(); Assert.False(string.IsNullOrEmpty(entry.Name)); using (var outputFileStream = new FileStream(extractedRomPath, FileMode.Create, FileAccess.Write)) using (var gzipStream = gzip.OpenEntry(entry)) { gzipStream.CopyTo(outputFileStream); } } // Verify we have a valid LUIGI and it's got what we expect inside. Trust, but verify! LuigiFileHeader header = null; using (var outputFileStream = new FileStream(extractedRomPath, FileMode.Open, FileAccess.Read)) { header = LuigiFileHeader.Inflate(outputFileStream); } Assert.NotNull(header); Assert.Equal(RomFormat.Bin, header.OriginalRomFormat); Assert.Equal(TestRomResources.TestBinCrc, header.OriginalRomCrc32); } } }