static NativeMethods() { IntPtr library = FunctionLoader.LoadNativeLibrary( new string[] { "libzma.dll", "lzma.dll" }, new string[] { "liblzma.so.5", "liblzma.so" }, new string[] { "liblzma.dylib" }); if (library == IntPtr.Zero) { throw new FileLoadException("Could not load liblzma. On Linux, make sure you've installed liblzma or an equivalent package."); } lzma_stream_decoder_ptr = FunctionLoader.LoadFunctionDelegate <lzma_stream_decoder_delegate>(library, nameof(lzma_stream_decoder)); lzma_auto_decoder_ptr = FunctionLoader.LoadFunctionDelegate <lzma_auto_decoder_delegate>(library, nameof(lzma_auto_decoder)); lzma_alone_decoder_ptr = FunctionLoader.LoadFunctionDelegate <lzma_alone_decoder_delegate>(library, nameof(lzma_alone_decoder)); lzma_code_ptr = FunctionLoader.LoadFunctionDelegate <lzma_code_delegate>(library, nameof(lzma_code)); lzma_stream_footer_decode_ptr = FunctionLoader.LoadFunctionDelegate <lzma_stream_footer_decode_delegate>(library, nameof(lzma_stream_footer_decode)); lzma_index_uncompressed_size_ptr = FunctionLoader.LoadFunctionDelegate <lzma_index_uncompressed_size_delegate>(library, nameof(lzma_index_uncompressed_size)); lzma_index_buffer_decode_ptr = FunctionLoader.LoadFunctionDelegate <lzma_index_buffer_decode_delegate>(library, nameof(lzma_index_buffer_decode)); lzma_index_end_ptr = FunctionLoader.LoadFunctionDelegate <lzma_index_end_delegate>(library, nameof(lzma_index_end)); lzma_end_ptr = FunctionLoader.LoadFunctionDelegate <lzma_end_delegate>(library, nameof(lzma_end)); lzma_easy_encoder_ptr = FunctionLoader.LoadFunctionDelegate <lzma_easy_encoder_delegate>(library, nameof(lzma_easy_encoder)); lzma_stream_encoder_mt_ptr = FunctionLoader.LoadFunctionDelegate <lzma_stream_encoder_mt_delegate>(library, nameof(lzma_stream_encoder_mt), throwOnError: false); lzma_stream_buffer_bound_ptr = FunctionLoader.LoadFunctionDelegate <lzma_stream_buffer_bound_delegate>(library, nameof(lzma_stream_buffer_bound)); lzma_easy_buffer_encode_ptr = FunctionLoader.LoadFunctionDelegate <lzma_easy_buffer_encode_delegate>(library, nameof(lzma_easy_buffer_encode)); }
public void LoadFunctionDelegate_ReturnsNullOnError() { IntPtr library = FunctionLoader.LoadNativeLibrary( new string[] { "libzma.dll", "lzma.dll" }, new string[] { "liblzma.so.5", "liblzma.so" }, new string[] { "liblzma.dylib" }); Assert.Null(FunctionLoader.LoadFunctionDelegate <Action>(library, string.Empty, false)); }
public void LoadFunctionDelegate_ThrowsOnError() { IntPtr library = FunctionLoader.LoadNativeLibrary( new string[] { "libzma.dll", "lzma.dll" }, new string[] { "liblzma.so.5", "liblzma.so" }, new string[] { "liblzma.dylib" }); Assert.Throws <EntryPointNotFoundException>(() => FunctionLoader.LoadFunctionDelegate <Action>(library, string.Empty, true)); }