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

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

2016-05-26 16:06:52 +03:00
//
// Unit tests for CGContext
//
// Authors:
// Sebastien Pouliot <sebastien@xamarin.com>
//
// Copyright 2013 Xamarin Inc. All rights reserved.
//
using System;
using Foundation;
using CoreGraphics;
using ObjCRuntime;
2016-05-26 16:06:52 +03:00
using NUnit.Framework;
namespace MonoTouchFixtures.CoreGraphics {
[TestFixture]
[Preserve (AllMembers = true)]
public class ContextTest {
CGContext Create ()
{
using (CGColorSpace space = CGColorSpace.CreateDeviceRGB ()) {
return new CGBitmapContext (null, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast);
}
}
[Test]
public void SetLineDash ()
{
var lengths = new nfloat [] { 1.0f, 2.0f, 3.0f };
using (var c = Create ()) {
c.SetLineDash (1.0f, lengths);
c.SetLineDash (2.0f, null);
c.SetLineDash (3.0f, lengths, 2);
c.SetLineDash (4.0f, null, -1);
Assert.Throws<ArgumentException> (delegate { c.SetLineDash (5.0f, lengths, -1); }, "negative");
Assert.Throws<ArgumentException> (delegate { c.SetLineDash (6.0f, lengths, Int32.MaxValue); }, "max");
}
}
[CoreGraphics] Implement CoreGraphics bindings for Xcode 9. (#2812) * [ios11-b1] CoreGraphics bindings * Updated with feedback from Sebastien * Fix build, optimize checks * Add version information * Address comments * Tests * Remove Apply code, add special code for typo * [CoreGraphics] Add comma after last enum value. * [CoreGraphics] No need to bind CGColorSpaceGetName. * [CoreGraphics] Add new field in Xcode 9 beta 5. * [CoreGraphics] Move kCGPDFContextAccessPermissions to the correct dictionary container and implement the corresponding manual code. * [CoreGraphics] Adjust nullability acceptance based on new attributes for CGColorSpace.CreateCalibratedGray/RGB functions. * [CoreGraphics] Bind CGColorSpaceCreateLab, introduced in Xcode 9 beta 5. * [CoreGraphics] Adjust CGColorSpaceCreateWithICCData and CGColorSpaceCreateWithICCProfile bindings according to Xcode 9 beta 2. Apple introduced CGColorSpaceCreateWithICCData in b1, and made CGColorSpaceCreateWithICCProfile a typedef to CGColorSpaceCreateWithICCData. Apple reversed the typedef in b2 (probably because it creates broken executables when targetting earlier versions of macOS, since those executables would use CGColorSpaceCreateWithICCData, which would not exist), and instead made CGColorSpaceCreateWithICCProfile a normal deprecated method. So copy this logic in our bindings: deprecate CreateICCProfile, and introduce CreateICCProfile, with two overloads for NSData and CGDataProvider (since that's what's accepted according to the documentation). * [CoreGraphics] Add CGContextPDF constructors to make parity between different overloads. There are two types of CGContextPDF constructors: the first argument is either an NSUrl or a CGDataConsumer. Previously the NSUrl type had more overloads, and also allowed a null CGRect for the second argument. With the overloads are identical between the two types of CGContextPDF constructors. Existing constructors: CGContextPDF (NSUrl, CGRect, CGPDFInfo) CGContextPDF (NSUrl, CGRect) CGContextPDF (NSUrl, CGPDFInfo) CGContextPDF (NSUrl) CGContextPDF (CGDataConsumer, CGRect, CGPDFInfo) Added constructors: CGContextPDF (CGDataConsumer, CGRect) CGContextPDF (CGDataConsumer, CGPDFInfo) CGContextPDF (CGDataConsumer) Additionally the code has been fixed to not throw NullReferenceExceptions if null is passed for any of the values and instead pass on any null values to the native `CGPDFContextCreate` method (since `CGPDFContextCreate`'s arguments are all `__nullable`). * [tests] Add and improve existing tests for new and some existing CoreGraphics API. * Undo accidental whitespace noise. * [tests] Remove random characters in assert message. * [CoreGraphics] Improve argument exception messages in CGColorSpace according to review. * [CoreGraphics] Use 'Icc' instead of 'ICC' for new API, and also make the change for XAMCORE_4_0. * [CoreGraphics] Fix availability attribute for High Sierra. * [tests] Update monotouch-test after API changes.
2017-10-02 13:02:41 +03:00
[Test]
public void ResetClip ()
{
TestRuntime.AssertXcodeVersion (9, 0);
// Merely tests that the P/Invoke is correct
using (var c = Create ()) {
var original = c.GetClipBoundingBox ();
var rect = new CGRect (0, 0, 2, 2);
c.ClipToRect (rect);
Assert.That (rect, Is.EqualTo (c.GetClipBoundingBox ()));
c.ResetClip ();
Assert.That (original, Is.EqualTo (c.GetClipBoundingBox ()));
}
}
2016-05-26 16:06:52 +03:00
}
}