Improve the tests to properly load platform values

This commit is contained in:
Matthew Leibowitz 2018-07-21 03:18:19 +02:00
Родитель cdad437a90
Коммит 462d3a126d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 3650EBE4AA155AF9
4 изменённых файлов: 43 добавлений и 29 удалений

Просмотреть файл

@ -45,7 +45,7 @@ namespace SkiaSharp.Tests
{
var fonts = SKFontManager.Default;
var set = fonts.MatchFamily("Arial");
var set = fonts.MatchFamily(DefaultFontFamily);
Assert.NotNull(set);
Assert.True(set.Count > 0);
@ -56,7 +56,7 @@ namespace SkiaSharp.Tests
{
var fonts = SKFontManager.Default;
var tf = fonts.MatchFamily("Arial", SKFontStyle.Bold);
var tf = fonts.MatchFamily(DefaultFontFamily, SKFontStyle.Bold);
Assert.NotNull(tf);
Assert.Equal((int)SKFontStyleWeight.Bold, tf.FontWeight);
@ -70,7 +70,7 @@ namespace SkiaSharp.Tests
var fonts = SKFontManager.Default;
var normal = fonts.MatchFamily("Arial", SKFontStyle.Normal);
var normal = fonts.MatchFamily(DefaultFontFamily, SKFontStyle.Normal);
Assert.NotNull(normal);
Assert.Equal((int)SKFontStyleWeight.Normal, normal.FontWeight);

Просмотреть файл

@ -28,7 +28,7 @@ namespace SkiaSharp.Tests
{
var fonts = SKFontManager.Default;
var set = fonts.MatchFamily("Arial");
var set = fonts.MatchFamily(DefaultFontFamily);
Assert.NotNull(set);
Assert.True(set.Count > 0);
@ -38,7 +38,7 @@ namespace SkiaSharp.Tests
public void TestCanGetStyles()
{
var fonts = SKFontManager.Default;
var set = fonts.MatchFamily("Arial");
var set = fonts.MatchFamily(DefaultFontFamily);
for (var i = 0; i < set.Count; i++)
{
@ -53,7 +53,7 @@ namespace SkiaSharp.Tests
public void TestCanCreateBoldFromIndex()
{
var fonts = SKFontManager.Default;
var set = fonts.MatchFamily("Arial");
var set = fonts.MatchFamily(DefaultFontFamily);
int idx;
for (idx = 0; idx < set.Count; idx++)
@ -81,7 +81,7 @@ namespace SkiaSharp.Tests
public void TestCanCreateBold()
{
var fonts = SKFontManager.Default;
var set = fonts.MatchFamily("Arial");
var set = fonts.MatchFamily(DefaultFontFamily);
var typeface = set.CreateTypeface(SKFontStyle.Bold);

Просмотреть файл

@ -72,7 +72,7 @@ namespace SkiaSharp.Tests
{
using (var bitmap = new SKBitmap(new SKImageInfo(200, 200)))
using (var canvas = new SKCanvas(bitmap))
using (var tf = SKTypeface.FromFamilyName("Arial"))
using (var tf = SKTypeface.FromFamilyName(DefaultFontFamily))
using (var paint = new SKPaint { TextSize = 50, IsAntialias = true, Typeface = tf })
{
canvas.Clear(SKColors.White);
@ -86,7 +86,7 @@ namespace SkiaSharp.Tests
using (var bitmap = new SKBitmap(new SKImageInfo(200, 200)))
using (var canvas = new SKCanvas(bitmap))
using (var tf = SKTypeface.FromFamilyName("Arial"))
using (var tf = SKTypeface.FromFamilyName(DefaultFontFamily))
using (var paint = new SKPaint { TextSize = 50, Typeface = tf })
{
canvas.Clear(SKColors.White);

Просмотреть файл

@ -9,11 +9,28 @@ namespace SkiaSharp.Tests
{
public abstract class SKTest
{
#if !NET_STANDARD
protected const string Category = nameof(Category);
protected const string GpuCategory = "GPU";
protected static bool IsLinux;
protected static bool IsMac;
protected static bool IsUnix;
protected static bool IsWindows;
protected static readonly string DefaultFontFamily;
protected static readonly string PathToAssembly;
protected static readonly string PathToFonts;
protected static readonly string PathToImages;
static SKTest()
{
// some platforms run the tests from a temporary location
// the the base paths
PathToAssembly = Directory.GetCurrentDirectory();
PathToFonts = Path.Combine(PathToAssembly, "fonts");
PathToImages = Path.Combine(PathToAssembly, "images");
// some platforms run the tests from a temporary location, so copy the native files
#if !NET_STANDARD
var skiaRoot = Path.GetDirectoryName(typeof(SkiaSharp.SKImageInfo).Assembly.Location);
var harfRoot = Path.GetDirectoryName(typeof(HarfBuzzSharp.Buffer).Assembly.Location);
@ -33,15 +50,24 @@ namespace SkiaSharp.Tests
File.Copy(file, harfDest, true);
}
}
}
#endif
protected const string Category = nameof(Category);
protected const string GpuCategory = "GPU";
// set the OS fields
#if NET_STANDARD
IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
IsMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
IsUnix = IsLinux || IsMac;
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
IsMac = MacPlatformDetector.IsMac.Value;
IsUnix = Environment.OSVersion.Platform == PlatformID.Unix || IsMac;
IsLinux = IsUnix && !IsMac;
IsWindows = !IsUnix;
#endif
protected static readonly string PathToAssembly = Directory.GetCurrentDirectory();
protected static readonly string PathToFonts = Path.Combine(PathToAssembly, "fonts");
protected static readonly string PathToImages = Path.Combine(PathToAssembly, "images");
// set the test fields
DefaultFontFamily = IsLinux ? "DejaVu Sans" : "Arial";
}
protected static void SaveBitmap(SKBitmap bmp, string filename = "output.png")
{
@ -89,12 +115,6 @@ namespace SkiaSharp.Tests
return bmp;
}
#if NET_STANDARD
protected static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
protected static bool IsMac => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
protected static bool IsUnix => IsLinux || IsMac;
protected static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
#else
private static class MacPlatformDetector
{
internal static readonly Lazy<bool> IsMac = new Lazy<bool> (IsRunningOnMac);
@ -122,12 +142,6 @@ namespace SkiaSharp.Tests
}
}
protected static bool IsMac => MacPlatformDetector.IsMac.Value;
protected static bool IsUnix => Environment.OSVersion.Platform == PlatformID.Unix || IsMac;
protected static bool IsLinux => IsUnix && !IsMac;
protected static bool IsWindows => !IsUnix;
#endif
public static class MacDynamicLibraries
{
private const string SystemLibrary = "/usr/lib/libSystem.dylib";