Browse Source

[SL.Core] Merge pull request SixLabors/Core#16 from carbon/master

Improve CQ1
af/octree-no-pixelmap
James Jackson-South 8 years ago
committed by GitHub
parent
commit
dfbe335889
  1. 46
      src/SixLabors.Core/Helpers/DebugGuard.cs
  2. 120
      src/SixLabors.Core/Helpers/Guard.cs
  3. 43
      src/SixLabors.Core/Helpers/HashHelpers.cs
  4. 2
      src/SixLabors.Core/MathF.cs
  5. 4
      src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs
  6. 13
      src/SixLabors.Core/Primitives/Point.cs
  7. 21
      src/SixLabors.Core/Primitives/PointF.cs
  8. 55
      src/SixLabors.Core/Primitives/Rectangle.cs
  9. 54
      src/SixLabors.Core/Primitives/RectangleF.cs
  10. 22
      src/SixLabors.Core/Primitives/Size.cs
  11. 9
      src/SixLabors.Core/Primitives/SizeF.cs
  12. 31
      src/SixLabors.Core/Properties/AssemblyInfo.cs
  13. 36
      src/SixLabors.Core/SixLabors.Core.csproj
  14. 2
      tests/CodeCoverage/CodeCoverage.cmd
  15. 41
      tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs
  16. 158
      tests/SixLabors.Core.Tests/Helpers/GuardTests.cs
  17. 28
      tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs
  18. 1
      tests/SixLabors.Core.Tests/Helpers/MathFTests.cs
  19. 1
      tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs
  20. 12
      tests/SixLabors.Core.Tests/Primitives/PointFTests.cs
  21. 14
      tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj

46
src/SixLabors.Core/Helpers/DebugGuard.cs

@ -24,7 +24,7 @@ namespace SixLabors
public static void NotNull<T>(T target, string parameterName)
where T : class
{
if (target == null)
if (target is null)
{
throw new ArgumentNullException(parameterName);
}
@ -116,50 +116,6 @@ namespace SixLabors
}
}
/// <summary>
/// Verifies, that the method parameter with specified target value is true
/// and throws an exception if it is found to be so.
/// </summary>
/// <param name="target">
/// The target value, which cannot be false.
/// </param>
/// <param name="parameterName">
/// The name of the parameter that is to be checked.
/// </param>
/// <param name="message">
/// The error message, if any to add to the exception.
/// </param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is false
/// </exception>
[Conditional("DEBUG")]
public static void IsTrue(bool target, string parameterName, string message)
{
if (!target)
{
throw new ArgumentException(message, parameterName);
}
}
/// <summary>
/// Verifies, that the method parameter with specified target value is false
/// and throws an exception if it is found to be so.
/// </summary>
/// <param name="target">The target value, which cannot be true.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentException">
/// <paramref name="target"/> is true
/// </exception>
[Conditional("DEBUG")]
public static void IsFalse(bool target, string parameterName, string message)
{
if (target)
{
throw new ArgumentException(message, parameterName);
}
}
/// <summary>
/// Verifies, that the `target` array has declared the length or longer.
/// </summary>

120
src/SixLabors.Core/Helpers/Guard.cs

@ -14,78 +14,6 @@ namespace SixLabors
[DebuggerStepThrough]
internal static class Guard
{
/// <summary>
/// Verifies, that the method parameter with specified object value is not null
/// and throws an exception if it is found to be so.
/// </summary>
/// <param name="target">The target object, which cannot be null.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null</exception>
/// <typeparam name="T">The type of the object to verify</typeparam>
public static void NotNull<T>(T target, string parameterName, string message = "")
where T : class
{
if (target == null)
{
if (!string.IsNullOrWhiteSpace(message))
{
throw new ArgumentNullException(parameterName, message);
}
throw new ArgumentNullException(parameterName);
}
}
/// <summary>
/// Verifies, that the string method parameter with specified object value and message
/// is not null, not empty and does not contain only blanks and throws an exception
/// if the object is null.
/// </summary>
/// <param name="target">The target string, which should be checked against being null or empty.</param>
/// <param name="parameterName">Name of the parameter.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="target"/> is empty or contains only blanks.</exception>
public static void NotNullOrEmpty(string target, string parameterName, string message = "")
{
NotNull(target, parameterName, message);
if (string.IsNullOrWhiteSpace(target))
{
if (!string.IsNullOrWhiteSpace(message))
{
throw new ArgumentException(message, parameterName);
}
throw new ArgumentException("Value cannot be null, empty, or cannot contain only whitespace.", parameterName);
}
}
/// <summary>
/// Verifies, that the enumeration is not null and not empty.
/// </summary>
/// <typeparam name="T">The type of objects in the <paramref name="target"/></typeparam>
/// <param name="target">The target enumeration, which should be checked against being null or empty.</param>
/// <param name="parameterName">Name of the parameter.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentNullException"><paramref name="target"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="target"/> is empty.</exception>
public static void NotNullOrEmpty<T>(IEnumerable<T> target, string parameterName, string message = "")
{
NotNull(target, parameterName, message);
if (!target.Any())
{
if (!string.IsNullOrWhiteSpace(message))
{
throw new ArgumentException(message, parameterName);
}
throw new ArgumentException("Value cannot be empty.", parameterName);
}
}
/// <summary>
/// Verifies that the specified value is less than a maximum value
/// and throws an exception if it is not.
@ -98,7 +26,7 @@ namespace SixLabors
/// <paramref name="value"/> is greater than the maximum value.
/// </exception>
public static void MustBeLessThan<TValue>(TValue value, TValue max, string parameterName)
where TValue : IComparable<TValue>
where TValue : IComparable<TValue>
{
if (value.CompareTo(max) >= 0)
{
@ -118,7 +46,7 @@ namespace SixLabors
/// <paramref name="value"/> is greater than the maximum value.
/// </exception>
public static void MustBeLessThanOrEqualTo<TValue>(TValue value, TValue max, string parameterName)
where TValue : IComparable<TValue>
where TValue : IComparable<TValue>
{
if (value.CompareTo(max) > 0)
{
@ -187,48 +115,6 @@ namespace SixLabors
}
}
/// <summary>
/// Verifies, that the method parameter with specified target value is true
/// and throws an exception if it is found to be so.
/// </summary>
/// <param name="value">
/// The target value, which cannot be false.
/// </param>
/// <param name="parameterName">
/// The name of the parameter that is to be checked.
/// </param>
/// <param name="message">
/// The error message, if any to add to the exception.
/// </param>
/// <exception cref="ArgumentException">
/// <paramref name="value"/> is false
/// </exception>
public static void IsTrue(bool value, string parameterName, string message)
{
if (!value)
{
throw new ArgumentException(message, parameterName);
}
}
/// <summary>
/// Verifies, that the method parameter with specified target value is false
/// and throws an exception if it is found to be so.
/// </summary>
/// <param name="value">The target value, which cannot be true.</param>
/// <param name="parameterName">The name of the parameter that is to be checked.</param>
/// <param name="message">The error message, if any to add to the exception.</param>
/// <exception cref="ArgumentException">
/// <paramref name="value"/> is true
/// </exception>
public static void IsFalse(bool value, string parameterName, string message)
{
if (value)
{
throw new ArgumentException(message, parameterName);
}
}
/// <summary>
/// Verifies, that the `target` span has the length of 'minLength', or longer.
/// </summary>
@ -247,4 +133,4 @@ namespace SixLabors
}
}
}
}
}

43
src/SixLabors.Core/Helpers/HashHelpers.cs

@ -1,10 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors
{
/// <summary>
/// Lifted from coreFX repo
/// Provides a set of helpers for combining object hashes.
/// </summary>
internal static class HashHelpers
{
@ -13,9 +15,11 @@ namespace SixLabors
/// </summary>
/// <param name="h1">Hash code one</param>
/// <param name="h2">Hash code two</param>
/// <returns>Returns a hash code for the two specified has codes.</returns>
/// <returns>Returns a hash code for the provided hash codes.</returns>
public static int Combine(int h1, int h2)
{
// Lifted from coreFX repo
unchecked
{
// RyuJIT optimizes this to use the ROL instruction
@ -24,5 +28,38 @@ namespace SixLabors
return ((int)rol5 + h1) ^ h2;
}
}
/// <summary>
/// Combines the three specified hash codes.
/// </summary>
/// <param name="h1">The first </param>
/// <param name="h2">Hash code two</param>
/// <param name="h3">Hash code three</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
public static int Combine(int h1, int h2, int h3)
{
int hash = Combine(h1, h2);
hash = Combine(hash, h3);
return hash;
}
/// <summary>
/// Combines the four specified hash codes.
/// </summary>
/// <param name="h1">The first </param>
/// <param name="h2">Hash code two</param>
/// <param name="h3">Hash code three</param>
/// <param name="h4">Hash code four</param>
/// <returns>Returns a hash code for the provided hash codes.</returns>
public static int Combine(int h1, int h2, int h3, int h4)
{
int hash = Combine(h1, h2);
hash = Combine(hash, h3);
return Combine(hash, h4);
}
}
}
}

2
src/SixLabors.Core/MathF.cs

@ -3,7 +3,7 @@
using System.Runtime.CompilerServices;
#if NETCOREAPP2_0
#if SUPPORTS_MATHF
[assembly: TypeForwardedTo(typeof(System.MathF))]
#else
namespace System

4
src/SixLabors.Core/Memory/ArrayPoolMemoryAllocator.Buffer{T}.cs

@ -51,7 +51,7 @@ namespace SixLabors.Memory
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (!disposing || this.Data == null || this.sourcePoolReference == null)
if (!disposing || this.Data is null || this.sourcePoolReference is null)
{
return;
}
@ -71,7 +71,7 @@ namespace SixLabors.Memory
/// <summary>
/// The <see cref="IManagedByteBuffer"/> implementation of <see cref="ArrayPoolMemoryAllocator"/>.
/// </summary>
private class ManagedByteBuffer : Buffer<byte>, IManagedByteBuffer
private sealed class ManagedByteBuffer : Buffer<byte>, IManagedByteBuffer
{
public ManagedByteBuffer(byte[] data, int length, ArrayPool<byte> sourcePool)
: base(data, length, sourcePool)

13
src/SixLabors.Core/Primitives/Point.cs

@ -258,25 +258,20 @@ namespace SixLabors.Primitives
public void Offset(Point point) => this.Offset(point.X, point.Y);
/// <inheritdoc/>
public override int GetHashCode() => this.GetHashCode(this);
public override int GetHashCode() => HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
/// <inheritdoc/>
public override string ToString()
{
return $"Point [ X={this.X}, Y={this.Y} ]";
}
public override string ToString() => $"Point [ X={this.X}, Y={this.Y} ]";
/// <inheritdoc/>
public override bool Equals(object obj) => obj is Point && this.Equals((Point)obj);
public override bool Equals(object obj) => obj is Point other && this.Equals(other);
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Point other) => this.X == other.X && this.Y == other.Y;
public bool Equals(Point other) => this.X.Equals(other.X) && this.Y.Equals(other.Y);
private static short HighInt16(int n) => unchecked((short)((n >> 16) & 0xffff));
private static short LowInt16(int n) => unchecked((short)(n & 0xffff));
private int GetHashCode(Point point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode());
}
}

21
src/SixLabors.Core/Primitives/PointF.cs

@ -267,30 +267,19 @@ namespace SixLabors.Primitives
public void Offset(PointF point) => this.Offset(point.X, point.Y);
/// <inheritdoc/>
public override int GetHashCode() => this.GetHashCode(this);
/// <inheritdoc/>
public override string ToString()
public override int GetHashCode()
{
return $"PointF [ X={this.X}, Y={this.Y} ]";
return HashHelpers.Combine(this.X.GetHashCode(), this.Y.GetHashCode());
}
/// <inheritdoc/>
public override string ToString() => $"PointF [ X={this.X}, Y={this.Y} ]";
/// <inheritdoc/>
public override bool Equals(object obj) => obj is PointF && this.Equals((PointF)obj);
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(PointF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y);
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <param name="point">
/// The instance of <see cref="PointF"/> to return the hash code for.
/// </param>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
private int GetHashCode(PointF point) => HashHelpers.Combine(point.X.GetHashCode(), point.Y.GetHashCode());
}
}

55
src/SixLabors.Core/Primitives/Rectangle.cs

@ -117,14 +117,7 @@ namespace SixLabors.Primitives
/// <summary>
/// Gets the y-coordinate of the top edge of this <see cref="Rectangle"/>.
/// </summary>
public int Top
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.Y;
}
}
public int Top => this.Y;
/// <summary>
/// Gets the x-coordinate of the right edge of this <see cref="Rectangle"/>.
@ -132,10 +125,7 @@ namespace SixLabors.Primitives
public int Right
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return unchecked(this.X + this.Width);
}
get => unchecked(this.X + this.Width);
}
/// <summary>
@ -144,23 +134,14 @@ namespace SixLabors.Primitives
public int Bottom
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return unchecked(this.Y + this.Height);
}
get => unchecked(this.Y + this.Height);
}
/// <summary>
/// Gets the x-coordinate of the left edge of this <see cref="Rectangle"/>.
/// </summary>
public int Left
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.X;
}
}
public int Left => this.X;
/// <summary>
/// Creates a <see cref="RectangleF"/> with the coordinates of the specified <see cref="Rectangle"/>.
@ -443,7 +424,14 @@ namespace SixLabors.Primitives
}
/// <inheritdoc/>
public override int GetHashCode() => this.GetHashCode(this);
public override int GetHashCode()
{
return HashHelpers.Combine(
this.X.GetHashCode(),
this.Y.GetHashCode(),
this.Width.GetHashCode(),
this.Height.GetHashCode());
}
/// <inheritdoc/>
public override string ToString()
@ -452,19 +440,14 @@ namespace SixLabors.Primitives
}
/// <inheritdoc/>
public override bool Equals(object obj) => obj is Rectangle && this.Equals((Rectangle)obj);
public override bool Equals(object obj) => obj is Rectangle other && this.Equals(other);
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Rectangle other) => this.X == other.X && this.Y == other.Y && this.Width == other.Width && this.Height == other.Height;
private int GetHashCode(Rectangle rectangle)
{
int hashCode = rectangle.X.GetHashCode();
hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode());
return hashCode;
}
public bool Equals(Rectangle other) =>
this.X.Equals(other.X) &&
this.Y.Equals(other.Y) &&
this.Width.Equals(other.Width) &&
this.Height.Equals(other.Height);
}
}

54
src/SixLabors.Core/Primitives/RectangleF.cs

@ -117,14 +117,7 @@ namespace SixLabors.Primitives
/// <summary>
/// Gets the y-coordinate of the top edge of this <see cref="RectangleF"/>.
/// </summary>
public float Top
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.Y;
}
}
public float Top => this.Y;
/// <summary>
/// Gets the x-coordinate of the right edge of this <see cref="RectangleF"/>.
@ -132,10 +125,7 @@ namespace SixLabors.Primitives
public float Right
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.X + this.Width;
}
get => this.X + this.Width;
}
/// <summary>
@ -144,23 +134,13 @@ namespace SixLabors.Primitives
public float Bottom
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.Y + this.Height;
}
get => this.Y + this.Height;
}
/// <summary>
/// Gets the x-coordinate of the left edge of this <see cref="RectangleF"/>.
/// </summary>
public float Left
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return this.X;
}
}
public float Left => this.X;
/// <summary>
/// Creates a <see cref="Rectangle"/> with the coordinates of the specified <see cref="RectangleF"/> by truncating each coordinate.
@ -376,7 +356,14 @@ namespace SixLabors.Primitives
}
/// <inheritdoc/>
public override int GetHashCode() => this.GetHashCode(this);
public override int GetHashCode()
{
return HashHelpers.Combine(
this.X.GetHashCode(),
this.Y.GetHashCode(),
this.Width.GetHashCode(),
this.Height.GetHashCode());
}
/// <inheritdoc/>
public override string ToString()
@ -385,19 +372,14 @@ namespace SixLabors.Primitives
}
/// <inheritdoc/>
public override bool Equals(object obj) => obj is RectangleF && this.Equals((RectangleF)obj);
public override bool Equals(object obj) => obj is RectangleF other && this.Equals(other);
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(RectangleF other) => this.X.Equals(other.X) && this.Y.Equals(other.Y) && this.Width.Equals(other.Width) && this.Height.Equals(other.Height);
private int GetHashCode(RectangleF rectangle)
{
int hashCode = rectangle.X.GetHashCode();
hashCode = HashHelpers.Combine(hashCode, rectangle.Y.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Width.GetHashCode());
hashCode = HashHelpers.Combine(hashCode, rectangle.Height.GetHashCode());
return hashCode;
}
public bool Equals(RectangleF other) =>
this.X.Equals(other.X) &&
this.Y.Equals(other.Y) &&
this.Width.Equals(other.Width) &&
this.Height.Equals(other.Height);
}
}

22
src/SixLabors.Core/Primitives/Size.cs

@ -252,20 +252,17 @@ namespace SixLabors.Primitives
public static Size Truncate(SizeF size) => new Size(unchecked((int)size.Width), unchecked((int)size.Height));
/// <inheritdoc/>
public override int GetHashCode() => this.GetHashCode(this);
public override int GetHashCode() => HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode());
/// <inheritdoc/>
public override string ToString()
{
return $"Size [ Width={this.Width}, Height={this.Height} ]";
}
public override string ToString() => $"Size [ Width={this.Width}, Height={this.Height} ]";
/// <inheritdoc/>
public override bool Equals(object obj) => obj is Size && this.Equals((Size)obj);
public override bool Equals(object obj) => obj is Size other && this.Equals(other);
/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Size other) => this.Width == other.Width && this.Height == other.Height;
public bool Equals(Size other) => this.Width.Equals(other.Width) && this.Height.Equals(other.Height);
/// <summary>
/// Multiplies <see cref="Size"/> by an <see cref="int"/> producing <see cref="Size"/>.
@ -284,16 +281,5 @@ namespace SixLabors.Primitives
/// <returns>Product of type SizeF.</returns>
private static SizeF Multiply(Size size, float multiplier) =>
new SizeF(size.Width * multiplier, size.Height * multiplier);
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <param name="size">
/// The instance of <see cref="Size"/> to return the hash code for.
/// </param>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
private int GetHashCode(Size size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode());
}
}

9
src/SixLabors.Core/Primitives/SizeF.cs

@ -200,14 +200,11 @@ namespace SixLabors.Primitives
/// <inheritdoc/>
public override int GetHashCode()
{
return this.GetHashCode(this);
return HashHelpers.Combine(this.Width.GetHashCode(), this.Height.GetHashCode());
}
/// <inheritdoc/>
public override string ToString()
{
return $"SizeF [ Width={this.Width}, Height={this.Height} ]";
}
public override string ToString() => $"SizeF [ Width={this.Width}, Height={this.Height} ]";
/// <inheritdoc/>
public override bool Equals(object obj) => obj is SizeF && this.Equals((SizeF)obj);
@ -224,7 +221,5 @@ namespace SixLabors.Primitives
/// <returns>Product of type SizeF.</returns>
private static SizeF Multiply(SizeF size, float multiplier) =>
new SizeF(size.Width * multiplier, size.Height * multiplier);
private int GetHashCode(SizeF size) => HashHelpers.Combine(size.Width.GetHashCode(), size.Height.GetHashCode());
}
}

31
src/SixLabors.Core/Properties/AssemblyInfo.cs

@ -1,37 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SixLabors.Core")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Six Labors")]
[assembly: AssemblyProduct("SixLabors.Core")]
[assembly: AssemblyCopyright("Copyright (c) Six Labors and contributors.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: AssemblyInformationalVersion("0.1.0-alpha02")]
// Ensure the internals can be tested.
[assembly: InternalsVisibleTo("SixLabors.Core.Tests")]
@ -41,4 +12,4 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("SixLabors.ImageSharp")]
[assembly: InternalsVisibleTo("SixLabors.ImageSharp.Drawing")]
[assembly: InternalsVisibleTo("SixLabors.Shapes")]
[assembly: InternalsVisibleTo("SixLabors.Shapes.Text")]
[assembly: InternalsVisibleTo("SixLabors.Shapes.Text")]

36
src/SixLabors.Core/SixLabors.Core.csproj

@ -5,7 +5,7 @@
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix>
<VersionPrefix Condition="$(packageversion) == ''">0.1.0-alpha2</VersionPrefix>
<Authors>Six Labors</Authors>
<TargetFrameworks>netstandard1.1;netcoreapp2.0;</TargetFrameworks>
<TargetFrameworks>netstandard1.1;netcoreapp2.0;netcoreapp2.1;</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>SixLabors.Core</AssemblyName>
@ -16,16 +16,7 @@
<PackageLicenseUrl>http://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/SixLabors/Core</RepositoryUrl>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<Copyright>Copyright (c) Six Labors and contributors.</Copyright>
<DebugType Condition="$(codecov) == 'true'">full</DebugType>
<RootNamespace>SixLabors</RootNamespace>
</PropertyGroup>
@ -34,19 +25,28 @@
<CodeAnalysisRuleSet>..\SixLabors.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp2')) ">
<DefineConstants>$(DefineConstants);SUPPORTS_MATHF</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<AdditionalFiles Include="..\..\stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp2.1' ">
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.5.1" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1'">
<PackageReference Include="System.Numerics.Vectors" Version="4.4.0" />
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
</Project>

2
tests/CodeCoverage/CodeCoverage.cmd

@ -10,7 +10,7 @@ cd ..
dotnet restore SixLabors.Core.sln
dotnet build SixLabors.Core.sln --no-incremental -c release /p:codecov=true
tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\SixLabors.Core.Tests\SixLabors.Core.Tests.csproj --no-build -c release" -searchdirs:"tests\SixLabors.Core.Tests\bin\Release\netcoreapp1.1" -register:user -output:.\SixLabors.Core.Coverage.xml -hideskipped:All -returntargetcode -oldStyle -filter:"+[SixLabors.*]*"
tests\CodeCoverage\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test tests\SixLabors.Core.Tests\SixLabors.Core.Tests.csproj --no-build -c release" -searchdirs:"tests\SixLabors.Core.Tests\bin\Release\netcoreapp2.1" -register:user -output:.\SixLabors.Core.Coverage.xml -hideskipped:All -returntargetcode -oldStyle -filter:"+[SixLabors.*]*"
if %errorlevel% neq 0 exit /b %errorlevel%

41
tests/SixLabors.Core.Tests/Helpers/DebugGuardTests.cs

@ -5,7 +5,6 @@
#define DEBUG
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
@ -100,7 +99,7 @@ namespace SixLabors.Helpers.Tests
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains($"Value must be greater than {min}."));
Assert.Contains($"Value must be greater than {min}.", exception.Message);
}
[Theory]
@ -120,43 +119,7 @@ namespace SixLabors.Helpers.Tests
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains($"Value must be greater than or equal to 2."));
}
[Fact]
public void IsTrue_IsTrue_ThrowsNoException()
{
DebugGuard.IsTrue(true, "myParamName", "myTestMessage");
}
[Fact]
public void IsTrue_IsFalse_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
DebugGuard.IsTrue(false, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact]
public void IsFalse_IsFalse_ThrowsNoException()
{
DebugGuard.IsFalse(false, "myParamName", "myTestMessage");
}
[Fact]
public void IsFalse_IsTrue_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
DebugGuard.IsFalse(true, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
Assert.Contains($"Value must be greater than or equal to 2.", exception.Message);
}
[Theory]

158
tests/SixLabors.Core.Tests/Helpers/GuardTests.cs

@ -2,128 +2,12 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
namespace SixLabors.Helpers.Tests
{
public class GuardTests
{
[Fact]
public void NotNull_TargetNotNull_ThrowsNoException()
{
Guard.NotNull("test", "myParamName");
}
[Fact]
public void NotNull_TargetNull_ThrowsException()
{
Assert.Throws<ArgumentNullException>(() =>
{
Guard.NotNull((object)null, "myParamName");
});
}
[Fact]
public void NotNull_TargetNullWithMessage_ThrowsException()
{
var exception = Assert.Throws<ArgumentNullException>(() =>
{
Guard.NotNull((object)null, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact]
public void NotNullOrEmpty_TargetNotNullOrEmpty_ThrowsNoException()
{
Guard.NotNullOrEmpty("test", "myParamName");
}
[Fact]
public void NotNullOrEmpty_TargetNull_ThrowsException()
{
Assert.Throws<ArgumentNullException>(() =>
{
Guard.NotNullOrEmpty(null, "myParamName");
});
}
[Fact]
public void NotNullOrEmpty_TargetWhitespace_ThrowsException()
{
Assert.Throws<ArgumentException>(() =>
{
Guard.NotNullOrEmpty("\n\n", "myParamName");
});
}
[Fact]
public void NotNullOrEmpty_TargetEmpty_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.NotNullOrEmpty(string.Empty, "myParamName");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("Value cannot be null, empty, or cannot contain only whitespace."));
}
[Fact]
public void NotNullOrEmpty_TargetEmptyWithMessage_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.NotNullOrEmpty(string.Empty, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact]
public void NotNullOrEmptyIEnumerable_TargetNotNullOrEmpty_ThrowsNoException()
{
Guard.NotNullOrEmpty(new string[] { "test" }, "myParamName");
}
[Fact]
public void NotNullOrEmptyIEnumerable_TargetNull_ThrowsException()
{
Assert.Throws<ArgumentNullException>(() =>
{
Guard.NotNullOrEmpty((IEnumerable<string>)null, "myParamName");
});
}
[Fact]
public void NotNullOrEmptyIEnumerable_TargetEmpty_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.NotNullOrEmpty(new string[] { }, "myParamName");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("Value cannot be empty."));
}
[Fact]
public void NotNullOrEmptyIEnumerable_TargetEmptyWithMessage_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.NotNullOrEmpty(new string[] { }, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact]
public void MustBeLessThan_IsLess_ThrowsNoException()
{
@ -181,7 +65,7 @@ namespace SixLabors.Helpers.Tests
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains($"Value must be greater than {min}."));
Assert.Contains($"Value must be greater than {min}.", exception.Message);
}
[Theory]
@ -224,43 +108,7 @@ namespace SixLabors.Helpers.Tests
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains($"Value must be greater than or equal to {min} and less than or equal to {max}."));
}
[Fact]
public void IsTrue_IsTrue_ThrowsNoException()
{
Guard.IsTrue(true, "myParamName", "myTestMessage");
}
[Fact]
public void IsTrue_IsFalse_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.IsTrue(false, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
}
[Fact]
public void IsFalse_IsFalse_ThrowsNoException()
{
Guard.IsFalse(false, "myParamName", "myTestMessage");
}
[Fact]
public void IsFalse_IsTrue_ThrowsException()
{
var exception = Assert.Throws<ArgumentException>(() =>
{
Guard.IsFalse(true, "myParamName", "myTestMessage");
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains("myTestMessage"));
Assert.Contains($"Value must be greater than or equal to {min} and less than or equal to {max}.", exception.Message);
}
[Theory]
@ -280,7 +128,7 @@ namespace SixLabors.Helpers.Tests
});
Assert.Equal("myParamName", exception.ParamName);
Assert.True(exception.Message.Contains($"The size must be at least 3."));
Assert.Contains("The size must be at least 3.", exception.Message);
}
}
}

28
tests/SixLabors.Core.Tests/Helpers/HashHelpersTests.cs

@ -0,0 +1,28 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using Xunit;
namespace SixLabors.Tests.Helpers
{
public class HashHelpersTests
{
[Fact]
public void CanCombineTwoValues()
{
Assert.Equal(35, HashHelpers.Combine(1, 2));
}
[Fact]
public void CanCombineThreeValues()
{
Assert.Equal(1152, HashHelpers.Combine(1, 2, 3));
}
[Fact]
public void CanCombineFourValues()
{
Assert.Equal(38020, HashHelpers.Combine(1, 2, 3, 4));
}
}
}

1
tests/SixLabors.Core.Tests/Helpers/MathFTests.cs

@ -6,6 +6,7 @@ using Xunit;
namespace SixLabors.Tests.Helpers
{
public class MathFTests
{
[Fact]

1
tests/SixLabors.Core.Tests/Memory/ArrayPoolMemoryManagerTests.cs

@ -80,7 +80,6 @@ namespace SixLabors.Memory.Tests
Assert.True(this.CheckIsRentingPooledBuffer<byte>(size));
}
[Theory]
[InlineData(128 * 1024 * 1024)]
[InlineData(MaxPooledBufferSizeInBytes + 1)]

12
tests/SixLabors.Core.Tests/Primitives/PointFTests.cs

@ -5,12 +5,24 @@ using System;
using System.Globalization;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using Xunit;
namespace SixLabors.Primitives.Tests
{
public class PointFTests
{
[Fact]
public void CanReinterpretCastFromVector2()
{
var vector = new Vector2(1, 2);
PointF point = Unsafe.As<Vector2, PointF>(ref vector);
Assert.Equal(vector.X, point.X);
Assert.Equal(vector.Y, point.Y);
}
[Fact]
public void DefaultConstructorTest()
{

14
tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<VersionPrefix>0.0.0</VersionPrefix>
<TargetFrameworks>netcoreapp1.1;netcoreapp2.0;</TargetFrameworks>
<TargetFrameworks>netcoreapp1.1;netcoreapp2.1;</TargetFrameworks>
<AssemblyName>SixLabors.Core.Tests</AssemblyName>
<PackageId>SixLabors.Shapes.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
@ -28,18 +28,14 @@
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Moq" Version="4.7.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="Moq" Version="4.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SixLabors.Core\SixLabors.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

Loading…
Cancel
Save