2016-05-26 16:06:52 +03:00
|
|
|
|
//
|
2016-08-12 14:45:09 +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;
|
2016-08-12 14:45:09 +03:00
|
|
|
|
using Foundation;
|
2016-05-26 16:06:52 +03:00
|
|
|
|
using ObjCRuntime;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
2016-08-12 14:45:09 +03:00
|
|
|
|
namespace MonoTouchFixtures.CoreGraphics {
|
|
|
|
|
|
2016-05-26 16:06:52 +03:00
|
|
|
|
[TestFixture]
|
2016-08-12 14:45:09 +03:00
|
|
|
|
public class ColorConversionInfoTest {
|
|
|
|
|
|
2016-05-26 16:06:52 +03:00
|
|
|
|
[Test]
|
|
|
|
|
public void CreateNone ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (8,0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
2016-08-12 14:45:09 +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 ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (8, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
2016-08-12 14:45:09 +03:00
|
|
|
|
var triple = new GColorConversionInfoTriple () {
|
2016-05-26 16:06:52 +03:00
|
|
|
|
Space = CGColorSpace.CreateGenericRgb (),
|
|
|
|
|
Intent = CGColorRenderingIntent.Default,
|
2016-08-12 14:45:09 +03:00
|
|
|
|
Transform = CGColorConversionInfoTransformType.ApplySpace
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var options = new CGColorConversionOptions () {
|
|
|
|
|
BlackPointCompensation = false
|
2016-05-26 16:06:52 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-12 14:45:09 +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 ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (8, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
2016-08-12 14:45:09 +03:00
|
|
|
|
var triple = new GColorConversionInfoTriple () {
|
2016-05-26 16:06:52 +03:00
|
|
|
|
Space = CGColorSpace.CreateGenericRgb (),
|
|
|
|
|
Intent = CGColorRenderingIntent.Default,
|
2016-08-12 14:45:09 +03:00
|
|
|
|
Transform = CGColorConversionInfoTransformType.ApplySpace
|
2016-05-26 16:06:52 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-12 14:45:09 +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 ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (8, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
2016-08-12 14:45:09 +03:00
|
|
|
|
var first = new GColorConversionInfoTriple () {
|
2016-05-26 16:06:52 +03:00
|
|
|
|
Space = CGColorSpace.CreateGenericRgb (),
|
|
|
|
|
Intent = CGColorRenderingIntent.Default,
|
2016-08-12 14:45:09 +03:00
|
|
|
|
Transform = CGColorConversionInfoTransformType.ApplySpace
|
2016-05-26 16:06:52 +03:00
|
|
|
|
};
|
2016-08-12 14:45:09 +03:00
|
|
|
|
var second = new GColorConversionInfoTriple () {
|
2016-05-26 16:06:52 +03:00
|
|
|
|
Space = CGColorSpace.CreateGenericGray (),
|
|
|
|
|
Intent = CGColorRenderingIntent.Perceptual,
|
2016-08-12 14:45:09 +03:00
|
|
|
|
Transform = CGColorConversionInfoTransformType.FromSpace
|
2016-05-26 16:06:52 +03:00
|
|
|
|
};
|
2016-08-12 14:45:09 +03:00
|
|
|
|
var third = new GColorConversionInfoTriple () {
|
2016-05-26 16:06:52 +03:00
|
|
|
|
Space = CGColorSpace.CreateGenericXyz (),
|
|
|
|
|
Intent = CGColorRenderingIntent.Saturation,
|
2016-08-12 14:45:09 +03:00
|
|
|
|
Transform = CGColorConversionInfoTransformType.ToSpace
|
2016-05-26 16:06:52 +03:00
|
|
|
|
};
|
|
|
|
|
|
2016-08-12 14:45:09 +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 ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
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 ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (8, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
|
|
using (var from = CGColorSpace.CreateGenericGray ())
|
|
|
|
|
using (var to = CGColorSpace.CreateGenericRgb ())
|
2016-08-12 14:45:09 +03:00
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-12 14:45:09 +03:00
|
|
|
|
[DllImport (Constants.CoreGraphicsLibrary)]
|
|
|
|
|
extern static IntPtr CGColorConversionInfoCreate (IntPtr src, IntPtr dst);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CreateSimple_GetINativeObject ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
TestRuntime.AssertXcodeVersion (8, 0);
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
|
|
using (var from = CGColorSpace.CreateGenericGray ())
|
|
|
|
|
using (var to = CGColorSpace.CreateGenericRgb ()) {
|
2016-08-12 14:45:09 +03:00
|
|
|
|
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 ()
|
|
|
|
|
{
|
2016-08-12 14:45:09 +03:00
|
|
|
|
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 ()) {
|
2016-08-12 14:45:09 +03:00
|
|
|
|
Assert.Throws<Exception> (() => new CGColorConversionInfo (from, to));
|
2016-05-26 16:06:52 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-19 03:59:08 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|