Imported Upstream version 5.10.0.47

Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-24 17:04:36 +00:00
parent 88ff76fe28
commit e46a49ecf1
5927 changed files with 226314 additions and 129848 deletions

View File

@@ -1,18 +1,104 @@
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
using System.Drawing.Printing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Xunit;
using Xunit.Sdk;
namespace System.Drawing.Tests
namespace System.Drawing
{
public static class Helpers
{
public const string GdiplusIsAvailable = nameof(Helpers) + "." + nameof(GetGdiplusIsAvailable);
public const string RecentGdiplusIsAvailable = nameof(Helpers) + "." + nameof(GetRecentGdiPlusIsAvailable);
public const string RecentGdiplusIsAvailable2 = nameof(Helpers) + "." + nameof(GetRecentGdiPlusIsAvailable2);
public const string GdiPlusIsAvailableNotRedhat73 = nameof(Helpers) + "." + nameof(GetGdiPlusIsAvailableNotRedhat73);
public const string GdiPlusIsAvailableNotWindows7 = nameof(Helpers) + "." + nameof(GetGdiPlusIsAvailableNotWindows7);
public const string AnyInstalledPrinters = nameof(Helpers) + "." + nameof(IsAnyInstalledPrinters);
public static bool GetGdiplusIsAvailable()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return PlatformDetection.IsNotWindowsNanoServer && PlatformDetection.IsNotWindowsServerCore;
}
else
{
IntPtr nativeLib;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
nativeLib = dlopen("libgdiplus.dylib", RTLD_NOW);
}
else
{
nativeLib = dlopen("libgdiplus.so", RTLD_NOW);
if (nativeLib == IntPtr.Zero)
{
nativeLib = dlopen("libgdiplus.so.0", RTLD_NOW);
}
}
return nativeLib != IntPtr.Zero;
}
}
public static bool GetRecentGdiPlusIsAvailable2()
{
// CentOS 7, RHEL 7 and Ubuntu 14.04, as well as Fedora 25 and OpenSUSE 4.22 are running outdated versions of libgdiplus
if (PlatformDetection.IsCentos7 || PlatformDetection.IsRedHat || PlatformDetection.IsUbuntu1404 || PlatformDetection.IsFedora || PlatformDetection.IsOpenSUSE)
{
return false;
}
return GetGdiplusIsAvailable();
}
public static bool GetGdiPlusIsAvailableNotRedhat73()
{
if (PlatformDetection.IsRedHat)
{
return false;
}
return GetGdiplusIsAvailable();
}
public static bool GetGdiPlusIsAvailableNotWindows7()
{
if (PlatformDetection.IsWindows7)
{
return false;
}
return GetGdiplusIsAvailable();
}
public static bool GetRecentGdiPlusIsAvailable()
{
// CentOS 7, RHEL 7 and Ubuntu 14.04 are running outdated versions of libgdiplus
if (PlatformDetection.IsCentos7 || PlatformDetection.IsRedHat || PlatformDetection.IsUbuntu1404)
{
return false;
}
return GetGdiplusIsAvailable();
}
public static bool IsAnyInstalledPrinters()
{
return PrinterSettings.InstalledPrinters.Count > 0;
}
[DllImport("libdl")]
private static extern IntPtr dlopen(string libName, int flags);
public const int RTLD_NOW = 0x002;
public static string GetTestBitmapPath(string fileName) => GetTestPath("bitmaps", fileName);
public static string GetTestFontPath(string fileName) => GetTestPath("fonts", fileName);
public static string GetTestColorProfilePath(string fileName) => GetTestPath("colorProfiles", fileName);
private static string GetTestPath(string directoryName, string fileName) => Path.Combine(AppContext.BaseDirectory, directoryName, fileName);
@@ -142,5 +228,23 @@ namespace System.Drawing.Tests
public int Right;
public int Bottom;
}
public static void VerifyBitmapNotBlank(Bitmap bmp)
{
Color emptyColor = Color.FromArgb(0);
for (int y = 0; y < bmp.Height; y++)
{
for (int x = 0; x < bmp.Width; x++)
{
Color pixel = bmp.GetPixel(x, y);
if (!pixel.Equals(emptyColor))
{
return;
}
}
}
throw new XunitException("The entire image was blank.");
}
}
}