xamarin-macios/tests/monotouch-test/CoreText/StringAttributes.cs

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

2016-05-26 16:06:52 +03:00
//
// Unit tests for CTStringAttributes
//
// Authors:
// Marek Safar (marek.safar@gmail.com)
//
// Copyright 2012 Xamarin Inc. All rights reserved.
//
using System;
using Foundation;
#if MONOMAC
using AppKit;
using UIColor = AppKit.NSColor;
#else
2016-05-26 16:06:52 +03:00
using UIKit;
#endif
2016-05-26 16:06:52 +03:00
using CoreGraphics;
using CoreText;
using NUnit.Framework;
using System.Drawing;
namespace MonoTouchFixtures.CoreText
{
[TestFixture]
[Preserve (AllMembers = true)]
public class StringAttributesTests
{
#if !MONOMAC // No UIGraphics on mac
2016-05-26 16:06:52 +03:00
[Test]
public void SimpleValuesSet ()
{
var sa = new CTStringAttributes ();
sa.ForegroundColor = UIColor.Blue.CGColor;
sa.Font = new CTFont ("Georgia-BoldItalic", 24);
sa.UnderlineStyle = CTUnderlineStyle.Double; // It does not seem to do anything
sa.UnderlineColor = UIColor.Blue.CGColor;
sa.UnderlineStyleModifiers = CTUnderlineStyleModifiers.PatternDashDotDot;
Assert.IsNull (sa.BaselineClass, "#0");
sa.BaselineClass = CTBaselineClass.IdeographicHigh;
Assert.AreEqual (CTBaselineClass.IdeographicHigh, sa.BaselineClass, "#1");
2016-05-26 16:06:52 +03:00
sa.SetBaselineInfo (CTBaselineClass.Roman, 13);
sa.SetBaselineInfo (CTBaselineClass.IdeographicHigh, 3);
sa.SetWritingDirection (CTWritingDirection.LeftToRight);
2016-05-26 16:06:52 +03:00
if (TestRuntime.CheckXcodeVersion (11, 0))
sa.TrackingAdjustment = 1.0f;
var size = new CGSize (300, 300);
2016-05-26 16:06:52 +03:00
UIGraphics.BeginImageContext (size);
var gctx = UIGraphics.GetCurrentContext ();
gctx.SetFillColor (UIColor.Green.CGColor);
var attributedString = new NSAttributedString ("Test_ME~`", sa);
using (var textLine = new CTLine (attributedString)) {
textLine.Draw (gctx);
}
UIGraphics.EndImageContext ();
}
#endif
[Test]
public void BackgroundColor ()
{
var sa = new CTStringAttributes ();
Assert.DoesNotThrow (() => { sa.BackgroundColor = TestRuntime.GetCGColor (UIColor.Blue); }, "#0");
Assert.DoesNotThrow (() => { var x = sa.BackgroundColor; }, "#1");
}
[Test]
public void HorizontalInVerticalForms ()
{
var sa = new CTStringAttributes ();
Assert.DoesNotThrow (() => { sa.HorizontalInVerticalForms = 1; }, "#0");
Assert.DoesNotThrow (() => { var x = sa.HorizontalInVerticalForms; }, "#1");
}
2016-05-26 16:06:52 +03:00
}
}