Beispiel #1
0
        public void LzaResultConstructor_Works(LzmaResult result, string expectedMessage)
        {
            var ex = new LzmaException(result);

            Assert.Equal(result, (LzmaResult)ex.HResult);
            Assert.Equal(expectedMessage, ex.Message);
        }
Beispiel #2
0
        public void Xz_LzmaException()
        {
            using (MemoryStream compressed = new MemoryStream())
            {
                XzEncoder encoder = new XzEncoder();
                encoder.CompressionLevel = LzmaCompressionLevel.Optimal;
                encoder.Encode(s_sampledata, compressed);
                compressed.Flush();

                byte[]        buffer       = new byte[8192];
                LzmaException thrown       = null;
                LzmaException deserialized = null;

                // Create a decompressor to test exception cases
                using (XzReader decompressor = new XzReader(compressed, true))
                {
                    // Attempting to read from the middle of the compressed stream should throw a LzmaException
                    compressed.Position = compressed.Length / 2;
                    try { decompressor.Read(buffer, 0, 8192); Assert.Fail("Method call should have thrown an exception"); }
                    catch (LzmaException ex) { thrown = ex; }

                    Assert.IsNotNull(thrown);
                    Assert.IsInstanceOfType(thrown, typeof(LzmaException));

                    // Check the error code property
                    Assert.AreEqual(17, thrown.ErrorCode);                          // SZ_ERROR_NO_ARCHIVE (17)

                    // Serialize and de-serialize the exception with a BinaryFormatter
                    BinaryFormatter formatter = new BinaryFormatter();
                    using (MemoryStream memstream = new MemoryStream())
                    {
                        formatter.Serialize(memstream, thrown);
                        memstream.Seek(0, 0);
                        deserialized = (LzmaException)formatter.Deserialize(memstream);
                    }

                    // Check that the exceptions are equivalent
                    Assert.AreEqual(thrown.ErrorCode, deserialized.ErrorCode);
                    Assert.AreEqual(thrown.StackTrace, deserialized.StackTrace);
                    Assert.AreEqual(thrown.ToString(), deserialized.ToString());
                }
            }
        }
Beispiel #3
0
        public void ThrowOnError_ThrowOnError()
        {
            var ex = Assert.Throws <LzmaException>(() => LzmaException.ThrowOnError(LzmaResult.MemError));

            Assert.Equal(LzmaResult.MemError, (LzmaResult)ex.HResult);
        }
Beispiel #4
0
 public void ThrowOnError_DoesNotThrowOnOK()
 {
     // This should not throw.
     LzmaException.ThrowOnError(LzmaResult.OK);
 }
Beispiel #5
0
        public void StringConstructor_Works()
        {
            var ex = new LzmaException("test");

            Assert.Equal("test", ex.Message);
        }
Beispiel #6
0
        public void DefaultConstructor_Works()
        {
            var ex = new LzmaException();

            Assert.Equal("An LZMA error occurred.", ex.Message);
        }