public static void TestBadPackStreamContexts( CompressionEngine engine, string archiveName, string[] testFiles) { Exception caughtEx; Console.WriteLine("Testing streamContext that returns null from GetName."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, false, false, true, true, true, true), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsTrue(caughtEx is FileNotFoundException, "Caught exception: " + caughtEx); Console.WriteLine("Testing streamContext that returns null from OpenArchive."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, false, true, false, true, true, true), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsTrue(caughtEx is FileNotFoundException, "Caught exception: " + caughtEx); Console.WriteLine("Testing streamContext that returns null from OpenFile."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, false, true, true, true, false, true), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsNull(caughtEx, "Caught exception: " + caughtEx); Console.WriteLine("Testing streamContext that throws on GetName."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, true, false, true, true, true, true), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsTrue(caughtEx != null && caughtEx.Message == MisbehavingStreamContext.EXCEPTION, "Caught exception: " + caughtEx); Console.WriteLine("Testing streamContext that throws on OpenArchive."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, true, true, false, true, true, true), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsTrue(caughtEx != null && caughtEx.Message == MisbehavingStreamContext.EXCEPTION, "Caught exception: " + caughtEx); Console.WriteLine("Testing streamContext that throws on CloseArchive."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, true, true, true, false, true, true), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsTrue(caughtEx != null && caughtEx.Message == MisbehavingStreamContext.EXCEPTION, "Caught exception: " + caughtEx); Console.WriteLine("Testing streamContext that throws on OpenFile."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, true, true, true, true, false, true), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsTrue(caughtEx != null && caughtEx.Message == MisbehavingStreamContext.EXCEPTION, "Caught exception: " + caughtEx); Console.WriteLine("Testing streamContext that throws on CloseFile."); caughtEx = null; try { engine.Pack( new MisbehavingStreamContext(archiveName, null, null, true, true, true, true, true, false), testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsTrue(caughtEx != null && caughtEx.Message == MisbehavingStreamContext.EXCEPTION, "Caught exception: " + caughtEx); }
public Stream OpenArchiveReadStream(int archiveNumber, string archiveName, CompressionEngine compressionEngine) => new DuplicateStream(_stream);
public static void TestCompressionEngineNullParams( CompressionEngine engine, ArchiveFileStreamContext streamContext, string[] testFiles) { Exception caughtEx; Console.WriteLine("Testing null streamContext."); caughtEx = null; try { engine.Pack(null, testFiles); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.Pack(null, testFiles, 0); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null files."); caughtEx = null; try { engine.Pack(streamContext, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null files."); caughtEx = null; try { engine.Pack(streamContext, null, 0); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null stream."); caughtEx = null; try { engine.IsArchive(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.FindArchiveOffset(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.GetFiles(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.GetFileInfo(null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.Unpack(null, "testUnpack.txt"); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); Console.WriteLine("Testing null streamContext."); caughtEx = null; try { engine.GetFiles(null, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.GetFileInfo(null, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); caughtEx = null; try { engine.Unpack((IUnpackStreamContext)null, null); } catch (Exception ex) { caughtEx = ex; } Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx); }