mirror of https://github.com/SixLabors/ImageSharp
8 changed files with 118 additions and 147 deletions
@ -1,48 +0,0 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using System; |
|
||||
using System.Runtime.CompilerServices; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Memory |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Utility methods for <see cref="Span{T}"/>
|
|
||||
/// </summary>
|
|
||||
internal static class SpanHelper |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Copy all elements of 'source' into 'destination'.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="T">The element type.</typeparam>
|
|
||||
/// <param name="source">The <see cref="Span{T}"/> to copy elements from.</param>
|
|
||||
/// <param name="destination">The destination <see cref="Span{T}"/>.</param>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public static void Copy<T>(ReadOnlySpan<T> source, Span<T> destination) |
|
||||
where T : struct |
|
||||
{ |
|
||||
source.Slice(0, Math.Min(source.Length, destination.Length)).CopyTo(destination); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the size of `count` elements in bytes.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="T">The element type.</typeparam>
|
|
||||
/// <param name="count">The count of the elements</param>
|
|
||||
/// <returns>The size in bytes as int</returns>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public static int SizeOf<T>(int count) |
|
||||
where T : struct => Unsafe.SizeOf<T>() * count; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets the size of `count` elements in bytes as UInt32
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="T">The element type.</typeparam>
|
|
||||
/// <param name="count">The count of the elements</param>
|
|
||||
/// <returns>The size in bytes as UInt32</returns>
|
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
||||
public static uint USizeOf<T>(int count) |
|
||||
where T : struct |
|
||||
=> (uint)SizeOf<T>(count); |
|
||||
} |
|
||||
} |
|
||||
@ -1,95 +1,95 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
// Copyright (c) Six Labors and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
using System; |
using System; |
||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.IO; |
using System.IO; |
||||
using System.Linq; |
using System.Linq; |
||||
using SixLabors.ImageSharp.Formats; |
using SixLabors.ImageSharp.Formats; |
||||
using SixLabors.ImageSharp.IO; |
using SixLabors.ImageSharp.IO; |
||||
using SixLabors.ImageSharp.PixelFormats; |
using SixLabors.ImageSharp.PixelFormats; |
||||
using Moq; |
using Moq; |
||||
using Xunit; |
using Xunit; |
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests |
namespace SixLabors.ImageSharp.Tests |
||||
{ |
{ |
||||
/// <summary>
|
/// <summary>
|
||||
/// Tests the configuration class.
|
/// Tests the configuration class.
|
||||
/// </summary>
|
/// </summary>
|
||||
public class ConfigurationTests |
public class ConfigurationTests |
||||
{ |
{ |
||||
public Configuration ConfigurationEmpty { get; private set; } |
public Configuration ConfigurationEmpty { get; private set; } |
||||
public Configuration DefaultConfiguration { get; private set; } |
public Configuration DefaultConfiguration { get; private set; } |
||||
|
|
||||
public ConfigurationTests() |
public ConfigurationTests() |
||||
{ |
{ |
||||
// the shallow copy of configuration should behave exactly like the default configuration,
|
// the shallow copy of configuration should behave exactly like the default configuration,
|
||||
// so by using the copy, we test both the default and the copy.
|
// so by using the copy, we test both the default and the copy.
|
||||
this.DefaultConfiguration = Configuration.CreateDefaultInstance().ShallowCopy(); |
this.DefaultConfiguration = Configuration.CreateDefaultInstance().ShallowCopy(); |
||||
this.ConfigurationEmpty = new Configuration(); |
this.ConfigurationEmpty = new Configuration(); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void DefaultsToLocalFileSystem() |
public void DefaultsToLocalFileSystem() |
||||
{ |
{ |
||||
Assert.IsType<LocalFileSystem>(this.DefaultConfiguration.FileSystem); |
Assert.IsType<LocalFileSystem>(this.DefaultConfiguration.FileSystem); |
||||
Assert.IsType<LocalFileSystem>(this.ConfigurationEmpty.FileSystem); |
Assert.IsType<LocalFileSystem>(this.ConfigurationEmpty.FileSystem); |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Test that the default configuration is not null.
|
/// Test that the default configuration is not null.
|
||||
/// </summary>
|
/// </summary>
|
||||
[Fact] |
[Fact] |
||||
public void TestDefultConfigurationIsNotNull() |
public void TestDefaultConfigurationIsNotNull() |
||||
{ |
{ |
||||
Assert.True(Configuration.Default != null); |
Assert.True(Configuration.Default != null); |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Test that the default configuration parallel options is not null.
|
/// Test that the default configuration parallel options is not null.
|
||||
/// </summary>
|
/// </summary>
|
||||
[Fact] |
[Fact] |
||||
public void TestDefultConfigurationParallelOptionsIsNotNull() |
public void TestDefaultConfigurationParallelOptionsIsNotNull() |
||||
{ |
{ |
||||
Assert.True(Configuration.Default.ParallelOptions != null); |
Assert.True(Configuration.Default.ParallelOptions != null); |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Test that the default configuration read origin options is set to begin.
|
/// Test that the default configuration read origin options is set to begin.
|
||||
/// </summary>
|
/// </summary>
|
||||
[Fact] |
[Fact] |
||||
public void TestDefultConfigurationReadOriginIsCurrent() |
public void TestDefaultConfigurationReadOriginIsCurrent() |
||||
{ |
{ |
||||
Assert.True(Configuration.Default.ReadOrigin == ReadOrigin.Current); |
Assert.True(Configuration.Default.ReadOrigin == ReadOrigin.Current); |
||||
} |
} |
||||
|
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Test that the default configuration parallel options max degrees of parallelism matches the
|
/// Test that the default configuration parallel options max degrees of parallelism matches the
|
||||
/// environment processor count.
|
/// environment processor count.
|
||||
/// </summary>
|
/// </summary>
|
||||
[Fact] |
[Fact] |
||||
public void TestDefultConfigurationMaxDegreeOfParallelism() |
public void TestDefaultConfigurationMaxDegreeOfParallelism() |
||||
{ |
{ |
||||
Assert.True(Configuration.Default.ParallelOptions.MaxDegreeOfParallelism == Environment.ProcessorCount); |
Assert.True(Configuration.Default.ParallelOptions.MaxDegreeOfParallelism == Environment.ProcessorCount); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ConstructorCallConfigureOnFormatProvider() |
public void ConstructorCallConfigureOnFormatProvider() |
||||
{ |
{ |
||||
var provider = new Mock<IConfigurationModule>(); |
var provider = new Mock<IConfigurationModule>(); |
||||
var config = new Configuration(provider.Object); |
var config = new Configuration(provider.Object); |
||||
|
|
||||
provider.Verify(x => x.Configure(config)); |
provider.Verify(x => x.Configure(config)); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void AddFormatCallsConfig() |
public void AddFormatCallsConfig() |
||||
{ |
{ |
||||
var provider = new Mock<IConfigurationModule>(); |
var provider = new Mock<IConfigurationModule>(); |
||||
var config = new Configuration(); |
var config = new Configuration(); |
||||
config.Configure(provider.Object); |
config.Configure(provider.Object); |
||||
|
|
||||
provider.Verify(x => x.Configure(config)); |
provider.Verify(x => x.Configure(config)); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
version https://git-lfs.github.com/spec/v1 |
||||
|
oid sha256:3fe23e56bf22a220efdc75cb98e7c9a7a5e29ca960be5e5dc5ca3a0a33d8cd2c |
||||
|
size 7751 |
||||
Loading…
Reference in new issue