mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-23 07:25:11 +00:00
Merge branch 'master' into copilot/add-support-empty-directories
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA;
|
||||
|
||||
/// <summary>
|
||||
/// The exception that is thrown when an error in input stream occurs during decoding.
|
||||
/// </summary>
|
||||
internal class DataErrorException : Exception
|
||||
internal class DataErrorException : SharpCompressException
|
||||
{
|
||||
public DataErrorException()
|
||||
: base("Data Error") { }
|
||||
@@ -15,7 +16,7 @@ internal class DataErrorException : Exception
|
||||
/// <summary>
|
||||
/// The exception that is thrown when the value of an argument is outside the allowable range.
|
||||
/// </summary>
|
||||
internal class InvalidParamException : Exception
|
||||
internal class InvalidParamException : SharpCompressException
|
||||
{
|
||||
public InvalidParamException()
|
||||
: base("Invalid Parameter") { }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Xz;
|
||||
|
||||
public class XZIndexMarkerReachedException : Exception { }
|
||||
public class XZIndexMarkerReachedException : SharpCompressException { }
|
||||
|
||||
116
tests/SharpCompress.Test/ExceptionHierarchyTests.cs
Normal file
116
tests/SharpCompress.Test/ExceptionHierarchyTests.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors.Deflate;
|
||||
using SharpCompress.Compressors.LZMA;
|
||||
using SharpCompress.Compressors.Xz;
|
||||
using Xunit;
|
||||
|
||||
namespace SharpCompress.Test;
|
||||
|
||||
public class ExceptionHierarchyTests
|
||||
{
|
||||
[Fact]
|
||||
public void AllSharpCompressExceptions_InheritFromSharpCompressException()
|
||||
{
|
||||
// Verify that ArchiveException inherits from SharpCompressException
|
||||
Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(ArchiveException)));
|
||||
|
||||
// Verify that ExtractionException inherits from SharpCompressException
|
||||
Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(ExtractionException)));
|
||||
|
||||
// Verify that InvalidFormatException inherits from SharpCompressException (through ExtractionException)
|
||||
Assert.True(
|
||||
typeof(SharpCompressException).IsAssignableFrom(typeof(InvalidFormatException))
|
||||
);
|
||||
|
||||
// Verify that CryptographicException inherits from SharpCompressException
|
||||
Assert.True(
|
||||
typeof(SharpCompressException).IsAssignableFrom(typeof(CryptographicException))
|
||||
);
|
||||
|
||||
// Verify that IncompleteArchiveException inherits from SharpCompressException (through ArchiveException)
|
||||
Assert.True(
|
||||
typeof(SharpCompressException).IsAssignableFrom(typeof(IncompleteArchiveException))
|
||||
);
|
||||
|
||||
// Verify that ReaderCancelledException inherits from SharpCompressException
|
||||
Assert.True(
|
||||
typeof(SharpCompressException).IsAssignableFrom(typeof(ReaderCancelledException))
|
||||
);
|
||||
|
||||
// Verify that MultipartStreamRequiredException inherits from SharpCompressException (through ExtractionException)
|
||||
Assert.True(
|
||||
typeof(SharpCompressException).IsAssignableFrom(
|
||||
typeof(MultipartStreamRequiredException)
|
||||
)
|
||||
);
|
||||
|
||||
// Verify that MultiVolumeExtractionException inherits from SharpCompressException (through ExtractionException)
|
||||
Assert.True(
|
||||
typeof(SharpCompressException).IsAssignableFrom(typeof(MultiVolumeExtractionException))
|
||||
);
|
||||
|
||||
// Verify that ZlibException inherits from SharpCompressException
|
||||
Assert.True(typeof(SharpCompressException).IsAssignableFrom(typeof(ZlibException)));
|
||||
|
||||
// Verify that XZIndexMarkerReachedException inherits from SharpCompressException
|
||||
Assert.True(
|
||||
typeof(SharpCompressException).IsAssignableFrom(typeof(XZIndexMarkerReachedException))
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SharpCompressException_CanBeCaughtByBaseType()
|
||||
{
|
||||
// Test that a derived exception can be caught as SharpCompressException
|
||||
var exception = new InvalidFormatException("Test message");
|
||||
var caughtException = false;
|
||||
|
||||
try
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
catch (SharpCompressException ex)
|
||||
{
|
||||
caughtException = true;
|
||||
Assert.Same(exception, ex);
|
||||
}
|
||||
|
||||
Assert.True(caughtException, "Exception should have been caught as SharpCompressException");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InternalLzmaExceptions_InheritFromSharpCompressException()
|
||||
{
|
||||
// Use reflection to verify internal exception types
|
||||
var dataErrorExceptionType = Type.GetType(
|
||||
"SharpCompress.Compressors.LZMA.DataErrorException, SharpCompress"
|
||||
);
|
||||
Assert.NotNull(dataErrorExceptionType);
|
||||
Assert.True(typeof(SharpCompressException).IsAssignableFrom(dataErrorExceptionType));
|
||||
|
||||
var invalidParamExceptionType = Type.GetType(
|
||||
"SharpCompress.Compressors.LZMA.InvalidParamException, SharpCompress"
|
||||
);
|
||||
Assert.NotNull(invalidParamExceptionType);
|
||||
Assert.True(typeof(SharpCompressException).IsAssignableFrom(invalidParamExceptionType));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ExceptionConstructors_WorkCorrectly()
|
||||
{
|
||||
// Test parameterless constructor
|
||||
var ex1 = new SharpCompressException();
|
||||
Assert.NotNull(ex1);
|
||||
|
||||
// Test message constructor
|
||||
var ex2 = new SharpCompressException("Test message");
|
||||
Assert.Equal("Test message", ex2.Message);
|
||||
|
||||
// Test message and inner exception constructor
|
||||
var inner = new InvalidOperationException("Inner");
|
||||
var ex3 = new SharpCompressException("Test message", inner);
|
||||
Assert.Equal("Test message", ex3.Message);
|
||||
Assert.Same(inner, ex3.InnerException);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user