Esempio n. 1
0
        public void TestGeneralTwoFiles()
        {
            var archive = BA2Loader.Load(SharedData.GetDataPath("GeneralTwoFiles.ba2"));
            var header  = archive.Header;

            Assert.IsTrue(header.Signature.SequenceEqual(SharedData.ArchiveMagic));
            Assert.AreEqual(1U, header.Version);
            Assert.IsTrue(BA2Loader.GetArchiveType(header.ArchiveType) == BA2Type.General);
            Assert.AreEqual(2U, header.TotalFiles);
            Assert.AreEqual(121UL, header.NameTableOffset);

            var files = archive.FileList;

            Assert.AreEqual(2, files.Count);
            Assert.AreEqual("test.txt", files[0]);
            Assert.AreEqual("wazzup.bin", files[1]);

            var folder = SharedData.CreateTempDirectory();

            archive.Extract("test.txt", folder, false);

            var testPath = Path.Combine(folder, "test.txt");

            Assert.IsTrue(File.Exists(testPath));

            TestUtils.AssertExtractedTextFile(archive, archive.GetIndexFromFilename("test.txt"), "test text");
            TestUtils.AssertExtractedTextFile(archive, archive.GetIndexFromFilename("wazzup.bin"), "wazzup dude bro?");

            // Assert.IsTrue(File.ReadAllLines)
        }
Esempio n. 2
0
        public void TestGeneralArchiveType()
        {
            var archive = BA2Loader.Load(SharedData.GetDataPath("GeneralOneFile.ba2"));

            Assert.IsInstanceOf <BA2GeneralArchive>(archive);
            Assert.IsTrue(BA2Loader.GetArchiveType(archive) == BA2Type.General);
        }
Esempio n. 3
0
        public void TestStreamExtraction()
        {
            var archive = BA2Loader.Load(SharedData.GetDataPath("GeneralOneFile.ba2"));

            using (var stream = new MemoryStream())
            {
                bool status = archive.ExtractToStream("test.txt", stream);
                Assert.IsTrue(status);

                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, (int)stream.Length);

                Assert.IsTrue(Encoding.ASCII.GetString(buffer).Equals("test text", StringComparison.OrdinalIgnoreCase));
            }
        }
Esempio n. 4
0
        public void TestGeneralOneFile()
        {
            var archive = BA2Loader.Load(SharedData.GetDataPath("GeneralOneFile.ba2"));
            var header  = archive.Header;

            Assert.IsTrue(header.Signature.SequenceEqual(SharedData.ArchiveMagic));
            Assert.AreEqual(1U, header.Version);
            Assert.IsTrue(BA2Loader.GetArchiveType(header.ArchiveType) == BA2Type.General);
            Assert.AreEqual(1U, header.TotalFiles);
            Assert.AreEqual(69UL, header.NameTableOffset);

            var files = archive.FileList;

            Assert.AreEqual(1, files.Count);
            Assert.AreEqual(true, archive.ContainsFile("test.txt"));

            var folder = SharedData.CreateTempDirectory();

            archive.Extract("test.txt", folder, false);
            string path = Path.Combine(folder, "test.txt");

            Assert.IsTrue(File.Exists(path));
            Assert.AreEqual("test text", File.ReadAllText(path));
        }
Esempio n. 5
0
 public void InvalidDataExceptionThrownWhenInvalidNametableProviden()
 {
     Assert.Throws <InvalidDataException>(() => BA2Loader.Load(SharedData.GetDataPath("GeneralHeaderOnly.ba2")));
 }
Esempio n. 6
0
 public void TestKnownInvalidArchiveType()
 {
     Assert.DoesNotThrow(
         () => BA2Loader.Load(SharedData.GetDataPath("GeneralOneFileInvalidType.ba2"), BA2LoaderFlags.IgnoreArchiveType));
 }
Esempio n. 7
0
 public void TestKnownInvalidVersion()
 {
     Assert.DoesNotThrow(
         () => BA2Loader.Load(SharedData.GetDataPath("GeneralOneFileInvalidVersion.ba2"), BA2LoaderFlags.IgnoreVersion));
 }
Esempio n. 8
0
 public void LoadExceptionThrownWhenArchiveHasInvalidType()
 {
     Assert.Throws <BA2LoadException>(() => BA2Loader.Load(SharedData.GetDataPath("GeneralHeaderOnlyInvalidType.ba2")));
 }