|
|
@ -1,12 +1,13 @@ |
|
|
namespace ImageSharp.Tests |
|
|
namespace ImageSharp.Tests |
|
|
{ |
|
|
{ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Reflection; |
|
|
using System.Reflection; |
|
|
using System.Security; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using ImageSharp.Formats; |
|
|
|
|
|
using ImageSharp.Tests.TestUtilities.ReferenceCodecs; |
|
|
|
|
|
|
|
|
public static class TestEnvironment |
|
|
public static class TestEnvironment |
|
|
{ |
|
|
{ |
|
|
private const string ImageSharpSolutionFileName = "ImageSharp.sln"; |
|
|
private const string ImageSharpSolutionFileName = "ImageSharp.sln"; |
|
|
@ -26,6 +27,8 @@ namespace ImageSharp.Tests |
|
|
return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi; |
|
|
return bool.TryParse(Environment.GetEnvironmentVariable("CI"), out isCi) && isCi; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
private static Lazy<Configuration> configuration = new Lazy<Configuration>(CreateDefaultConfiguration); |
|
|
|
|
|
|
|
|
// ReSharper disable once InconsistentNaming
|
|
|
// ReSharper disable once InconsistentNaming
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets a value indicating whether test execution runs on CI.
|
|
|
/// Gets a value indicating whether test execution runs on CI.
|
|
|
@ -34,6 +37,24 @@ namespace ImageSharp.Tests |
|
|
|
|
|
|
|
|
internal static string SolutionDirectoryFullPath => solutionDirectoryFullPath.Value; |
|
|
internal static string SolutionDirectoryFullPath => solutionDirectoryFullPath.Value; |
|
|
|
|
|
|
|
|
|
|
|
internal static Configuration Configuration => configuration.Value; |
|
|
|
|
|
|
|
|
|
|
|
private static Configuration CreateDefaultConfiguration() |
|
|
|
|
|
{ |
|
|
|
|
|
var configuration = new Configuration( |
|
|
|
|
|
new PngConfigurationModule(), |
|
|
|
|
|
new JpegConfigurationModule(), |
|
|
|
|
|
new GifConfigurationModule(), |
|
|
|
|
|
new BmpConfigurationModule() |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
configuration.SetDecoder(ImageFormats.Png, SystemDrawingReferenceDecoder.Instance); |
|
|
|
|
|
configuration.SetEncoder(ImageFormats.Png, SystemDrawingReferenceEncoder.Png); |
|
|
|
|
|
configuration.AddImageFormatDetector(new PngImageFormatDetector()); |
|
|
|
|
|
|
|
|
|
|
|
return configuration; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private static string GetSolutionDirectoryFullPathImpl() |
|
|
private static string GetSolutionDirectoryFullPathImpl() |
|
|
{ |
|
|
{ |
|
|
string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; |
|
|
string assemblyLocation = typeof(TestFile).GetTypeInfo().Assembly.Location; |
|
|
@ -62,23 +83,48 @@ namespace ImageSharp.Tests |
|
|
|
|
|
|
|
|
return directory.FullName; |
|
|
return directory.FullName; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the correct full path to the Input Images directory.
|
|
|
/// Gets the correct full path to the Input Images directory.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
internal static string InputImagesDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, InputImagesRelativePath); |
|
|
internal static string InputImagesDirectoryFullPath => |
|
|
|
|
|
Path.Combine(SolutionDirectoryFullPath, InputImagesRelativePath); |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.)
|
|
|
/// Gets the correct full path to the Actual Output directory. (To be written to by the test cases.)
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
internal static string ActualOutputDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, ActualOutputDirectoryRelativePath); |
|
|
internal static string ActualOutputDirectoryFullPath => Path.Combine( |
|
|
|
|
|
SolutionDirectoryFullPath, |
|
|
|
|
|
ActualOutputDirectoryRelativePath); |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets the correct full path to the Expected Output directory. (To compare the test results to.)
|
|
|
/// Gets the correct full path to the Expected Output directory. (To compare the test results to.)
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
internal static string ReferenceOutputDirectoryFullPath => Path.Combine(SolutionDirectoryFullPath, ReferenceOutputDirectoryRelativePath); |
|
|
internal static string ReferenceOutputDirectoryFullPath => Path.Combine( |
|
|
|
|
|
SolutionDirectoryFullPath, |
|
|
|
|
|
ReferenceOutputDirectoryRelativePath); |
|
|
|
|
|
|
|
|
internal static string GetReferenceOutputFileName(string actualOutputFileName) => |
|
|
internal static string GetReferenceOutputFileName(string actualOutputFileName) => |
|
|
actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput"); |
|
|
actualOutputFileName.Replace("ActualOutput", @"External\ReferenceOutput"); |
|
|
|
|
|
|
|
|
|
|
|
internal static IImageDecoder GetReferenceDecoder(string filePath) |
|
|
|
|
|
{ |
|
|
|
|
|
IImageFormat format = GetImageFormat(filePath); |
|
|
|
|
|
return Configuration.FindDecoder(format); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static IImageEncoder GetReferenceEncoder(string filePath) |
|
|
|
|
|
{ |
|
|
|
|
|
IImageFormat format = GetImageFormat(filePath); |
|
|
|
|
|
return Configuration.FindEncoder(format); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static IImageFormat GetImageFormat(string filePath) |
|
|
|
|
|
{ |
|
|
|
|
|
string extension = Path.GetExtension(filePath).ToLower(); |
|
|
|
|
|
if (extension[0] == '.') extension = extension.Substring(1); |
|
|
|
|
|
IImageFormat format = Configuration.FindFormatByFileExtension(extension); |
|
|
|
|
|
return format; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |