Ejemplo n.º 1
0
        public void ExtractShouldThrowExceptionWhenDisposed()
        {
            BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralOneFileArchive);

            archive.Dispose();

            var dir = SharedData.CreateTempDirectory();

            using (var stream = new MemoryStream())
            {
                Assert.Throws <ObjectDisposedException>(() => archive.Extract(0, dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.Extract("test.txt", dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractToStream(0, stream));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractAll("", false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractAll("", false, CancellationToken.None, null));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new int[] { 0 }, dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new int[] { 0 }, dir, false,
                                                                                   CancellationToken.None, null));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new string[] { "test.txt" }, dir, false));
                Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new string[] { "test.txt" }, dir, false,
                                                                                   CancellationToken.None, null));

                // These methods should not throw ObjectDisposedException
                Assert.DoesNotThrow(() => {
                    var files = archive.FileList;
                    archive.GetIndexFromFilename("test.txt");
                    archive.GetIndexFromFilename("ajkkfajsdlkfjlkasdf");
                    var total  = archive.TotalFiles;
                    var header = archive.Header;
                });
            }
        }
Ejemplo n.º 2
0
        public void ExtractByIndexFromTwoFileArchive()
        {
            BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralTwoFilesArchive);

            TestUtils.AssertExtractedTextFile(archive, 0, "test text");
            TestUtils.AssertExtractedTextFile(archive, 1, "wazzup dude bro?");

            archive.Dispose();
        }
Ejemplo n.º 3
0
        public void ExtractAllFromTwoFileArchive()
        {
            BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralTwoFilesArchive);

            string temp = SharedData.CreateTempDirectory();

            archive.ExtractAll(temp, false);
            Assert.IsTrue(File.Exists(Path.Combine(temp, "test.txt")));
            Assert.IsTrue(File.Exists(Path.Combine(temp, "wazzup.bin")));

            archive.Dispose();
        }
Ejemplo n.º 4
0
        public void ExtractByIndexFromOneFileArchive()
        {
            BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralOneFileArchive);

            using (MemoryStream stream = new MemoryStream())
            {
                Assert.IsTrue(archive.ExtractToStream(0, stream));
                TestUtils.AssertExtractedTextFile(stream, "test text");
            }

            archive.Dispose();
        }
Ejemplo n.º 5
0
        public void ExtractFilesByIndexesFromTwoFileArchiveMultithreaded()
        {
            BA2GeneralArchive archive =
                BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralTwoFilesArchive, BA2LoaderFlags.Multithreaded);

            string temp = SharedData.CreateTempDirectory();

            archive.ExtractFiles(new int[] { 0, 1 }, temp, false);
            Assert.IsTrue(File.Exists(Path.Combine(temp, "test.txt")));
            Assert.IsTrue(File.Exists(Path.Combine(temp, "wazzup.bin")));

            archive.Dispose();
        }
Ejemplo n.º 6
0
        public void TestGenericArchiveLoader()
        {
            BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralOneFileArchive);

            archive.Dispose();
        }