xamarin-macios/tests/monotouch-test/CoreGraphics/ColorConversionInfoTest.cs

187 строки
5.8 KiB
C#
Исходник Обычный вид История

2016-05-26 16:06:52 +03:00
//
// Unit tests for CGColorConversionInfo
2016-05-26 16:06:52 +03:00
//
// Authors:
// Vincent Dondain <vincent@xamarin.com>
//
// Copyright 2016 Xamarin Inc. All rights reserved.
//
using System;
using System.IO;
using System.Runtime.InteropServices;
using CoreGraphics;
using Foundation;
2016-05-26 16:06:52 +03:00
using ObjCRuntime;
using NUnit.Framework;
namespace MonoTouchFixtures.CoreGraphics {
2016-05-26 16:06:52 +03:00
[TestFixture]
[Preserve (AllMembers = true)]
public class ColorConversionInfoTest {
2016-05-26 16:06:52 +03:00
[Test]
public void CreateNone ()
{
TestRuntime.AssertXcodeVersion (8,0);
2016-05-26 16:06:52 +03:00
Assert.Throws<ArgumentNullException> (() => new CGColorConversionInfo (null, (CGColorSpace)null), "null");
Assert.Throws<ArgumentNullException> (() => new CGColorConversionInfo ((NSDictionary) null, (GColorConversionInfoTriple [])null), "null-2");
Assert.Throws<ArgumentNullException> (() => new CGColorConversionInfo ((NSDictionary) null, new GColorConversionInfoTriple [0]), "empty");
2016-05-26 16:06:52 +03:00
}
[Test]
public void CreateSingle ()
{
TestRuntime.AssertXcodeVersion (8, 0);
2016-05-26 16:06:52 +03:00
var triple = new GColorConversionInfoTriple () {
2016-05-26 16:06:52 +03:00
Space = CGColorSpace.CreateGenericRgb (),
Intent = CGColorRenderingIntent.Default,
Transform = CGColorConversionInfoTransformType.ApplySpace
};
var options = new CGColorConversionOptions () {
BlackPointCompensation = false
2016-05-26 16:06:52 +03:00
};
using (var converter = new CGColorConversionInfo (options, triple)) {
2016-05-26 16:06:52 +03:00
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
}
}
[Test]
public void CreateDual ()
{
TestRuntime.AssertXcodeVersion (8, 0);
2016-05-26 16:06:52 +03:00
var triple = new GColorConversionInfoTriple () {
2016-05-26 16:06:52 +03:00
Space = CGColorSpace.CreateGenericRgb (),
Intent = CGColorRenderingIntent.Default,
Transform = CGColorConversionInfoTransformType.ApplySpace
2016-05-26 16:06:52 +03:00
};
var options = new CGColorConversionOptions () {
BlackPointCompensation = true
};
using (var converter = new CGColorConversionInfo ((CGColorConversionOptions) null, triple, triple)) {
2016-05-26 16:06:52 +03:00
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
}
}
[Test]
public void CreateMax ()
{
TestRuntime.AssertXcodeVersion (8, 0);
2016-05-26 16:06:52 +03:00
var first = new GColorConversionInfoTriple () {
2016-05-26 16:06:52 +03:00
Space = CGColorSpace.CreateGenericRgb (),
Intent = CGColorRenderingIntent.Default,
Transform = CGColorConversionInfoTransformType.ApplySpace
2016-05-26 16:06:52 +03:00
};
var second = new GColorConversionInfoTriple () {
2016-05-26 16:06:52 +03:00
Space = CGColorSpace.CreateGenericGray (),
Intent = CGColorRenderingIntent.Perceptual,
Transform = CGColorConversionInfoTransformType.FromSpace
2016-05-26 16:06:52 +03:00
};
var third = new GColorConversionInfoTriple () {
2016-05-26 16:06:52 +03:00
Space = CGColorSpace.CreateGenericXyz (),
Intent = CGColorRenderingIntent.Saturation,
Transform = CGColorConversionInfoTransformType.ToSpace
2016-05-26 16:06:52 +03:00
};
using (var converter = new CGColorConversionInfo ((NSDictionary) null, first, first, first)) {
2016-05-26 16:06:52 +03:00
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
}
}
[Test]
public void CreateTooMany ()
{
TestRuntime.AssertXcodeVersion (8, 0);
Assert.Throws<ArgumentException> (() => new CGColorConversionInfo ((CGColorConversionOptions) null, new GColorConversionInfoTriple [4]));
2016-05-26 16:06:52 +03:00
}
[Test]
public void CreateSimple ()
{
TestRuntime.AssertXcodeVersion (8, 0);
2016-05-26 16:06:52 +03:00
using (var from = CGColorSpace.CreateGenericGray ())
using (var to = CGColorSpace.CreateGenericRgb ())
using (var converter = new CGColorConversionInfo (from, to)) {
2016-05-26 16:06:52 +03:00
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
}
}
[DllImport (Constants.CoreGraphicsLibrary)]
extern static IntPtr CGColorConversionInfoCreate (IntPtr src, IntPtr dst);
2016-05-26 16:06:52 +03:00
[Test]
public void CreateSimple_GetINativeObject ()
{
TestRuntime.AssertXcodeVersion (8, 0);
2016-05-26 16:06:52 +03:00
using (var from = CGColorSpace.CreateGenericGray ())
using (var to = CGColorSpace.CreateGenericRgb ()) {
var handle = CGColorConversionInfoCreate (from == null ? IntPtr.Zero : from.Handle,
to == null ? IntPtr.Zero : to.Handle);
using (var o = Runtime.GetINativeObject<CGColorConversionInfo> (handle, false)) {
2016-05-26 16:06:52 +03:00
Assert.That (o.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
}
}
}
[Test]
public void CreateSimple_DeviceColorSpace ()
{
TestRuntime.AssertXcodeVersion (8, 0);
2016-05-26 16:06:52 +03:00
// Requirements: CG color spaces must be calibrated
// (no Device{Gray,RGB,CMYK}, Indexed or DeviceN).
// This test lets us know if Apple changes that behavior.
using (var from = CGColorSpace.CreateDeviceGray ())
using (var to = CGColorSpace.CreateDeviceRGB ()) {
Assert.Throws<Exception> (() => new CGColorConversionInfo (from, to));
2016-05-26 16:06:52 +03:00
}
}
[Test]
public void CGColorSpace_CGColorSpace_NSDictionary ()
{
TestRuntime.AssertXcodeVersion (11, 0);
using (var from = CGColorSpace.CreateGenericGray ())
using (var to = CGColorSpace.CreateGenericRgb ()) {
using (var converter = new CGColorConversionInfo (from, to, (NSDictionary)null)) {
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle - null");
}
using (var d = new NSDictionary ())
using (var converter = new CGColorConversionInfo (from, to, d)) {
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
}
}
}
[Test]
public void CGColorSpace_CGColorSpace_CGColorConversionOptions ()
{
TestRuntime.AssertXcodeVersion (11, 0);
using (var from = CGColorSpace.CreateGenericGray ())
using (var to = CGColorSpace.CreateGenericRgb ()) {
using (var converter = new CGColorConversionInfo (from, to, (CGColorConversionOptions)null)) {
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle-null");
}
var o = new CGColorConversionOptions ();
o.BlackPointCompensation = true;
using (var converter = new CGColorConversionInfo (from, to, o)) {
Assert.That (converter.Handle, Is.Not.EqualTo (IntPtr.Zero), "Handle");
}
}
}
2016-05-26 16:06:52 +03:00
}
}