public void Lzma_Flush() { // Verify behavior of flushing a decompression stream using (LzmaReader stream = new LzmaReader(new MemoryStream(s_sampledata))) { // Flush has no effect on decompression streams, just ensure it doesn't throw stream.Flush(); } }
public void Lzma_Dispose() { byte[] buffer = new byte[8192]; // 8KiB data buffer // Create a memorystream to hold the compressed sample data using (MemoryStream ms = new MemoryStream()) { LzmaEncoder encoder = new LzmaEncoder(); encoder.Encode(s_sampledata, ms); // Create a decompression stream and immediately dispose of it LzmaReader stream = new LzmaReader(ms); stream.Dispose(); // Test double dispose stream.Dispose(); // All properties and methods should throw an ObjectDisposedException try { var bs = stream.BaseStream; Assert.Fail("Property access should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { var b = stream.CanRead; Assert.Fail("Property access should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { var b = stream.CanSeek; Assert.Fail("Property access should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { var b = stream.CanWrite; Assert.Fail("Property access should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { stream.Flush(); Assert.Fail("Method call should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { var l = stream.Length; Assert.Fail("Property access should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { var l = stream.Position; Assert.Fail("Property access should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { stream.Position = 12345L; Assert.Fail("Property access should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { stream.Read(buffer, 0, 8192); Assert.Fail("Method call should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { stream.Seek(0, SeekOrigin.Current); Assert.Fail("Method call should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { stream.SetLength(12345L); Assert.Fail("Method call should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } try { stream.Write(buffer, 0, 8192); Assert.Fail("Method call should have thrown an exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ObjectDisposedException)); } } }