2016-05-26 16:06:52 +03:00
|
|
|
// Copyright 2011 Xamarin Inc. All rights reserved
|
|
|
|
|
2017-10-31 19:09:21 +03:00
|
|
|
#if !__WATCHOS__ && !MONOMAC
|
2016-05-26 16:06:52 +03:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Drawing;
|
2020-12-15 15:16:07 +03:00
|
|
|
using System.IO;
|
2020-05-28 17:35:09 +03:00
|
|
|
using CoreGraphics;
|
2016-05-26 16:06:52 +03:00
|
|
|
using Foundation;
|
|
|
|
using UIKit;
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.UIKit {
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
public class SegmentedControlTest {
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void InitWithFrame ()
|
|
|
|
{
|
2020-05-28 17:35:09 +03:00
|
|
|
var frame = new CGRect (10, 10, 100, 100);
|
2016-05-26 16:06:52 +03:00
|
|
|
using (UISegmentedControl sc = new UISegmentedControl (frame)) {
|
|
|
|
Assert.That (sc.Frame, Is.EqualTo (frame), "Frame");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void BackgroundImage ()
|
|
|
|
{
|
|
|
|
using (UISegmentedControl sc = new UISegmentedControl ()) {
|
|
|
|
Assert.Null (sc.GetBackgroundImage (UIControlState.Application, UIBarMetrics.Default), "Get");
|
|
|
|
sc.SetBackgroundImage (null, UIControlState.Application, UIBarMetrics.Default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Appearance_7 ()
|
|
|
|
{
|
|
|
|
// iOS 7 beta 3 throws "-setTintColor: is not allowed for use with the appearance proxy."
|
|
|
|
// ref: https://bugzilla.xamarin.com/show_bug.cgi?id=13286
|
|
|
|
UISegmentedControl.Appearance.TintColor = UIColor.Blue;
|
|
|
|
}
|
2017-01-12 05:17:51 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorObjects ()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((object []) null), "null");
|
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((object []) new [] { String.Empty, null }), "null element");
|
|
|
|
Assert.Throws<ArgumentException> (() => new UISegmentedControl ((object []) new [] { NSZone.Default }), "invalid type");
|
|
|
|
|
|
|
|
using (var ns = new NSString ("NSString"))
|
2020-12-15 15:16:07 +03:00
|
|
|
using (var img = UIImage.FromFile (Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png")))
|
2017-01-12 05:17:51 +03:00
|
|
|
using (UISegmentedControl sc = new UISegmentedControl ("string", ns, img)) {
|
2020-07-17 09:48:09 +03:00
|
|
|
Assert.That (sc.NumberOfSegments, Is.EqualTo ((nint) 3), "NumberOfSegments");
|
2017-01-12 05:17:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorNSArray ()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((NSArray) null), "null");
|
|
|
|
|
|
|
|
using (UISegmentedControl sc = new UISegmentedControl (new NSArray ())) {
|
2020-07-17 09:48:09 +03:00
|
|
|
Assert.That(sc.NumberOfSegments, Is.EqualTo ((nint) 0), "Empty");
|
2017-01-12 05:17:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
using (var ns = new NSString ("NSString"))
|
2020-12-15 15:16:07 +03:00
|
|
|
using (var img = UIImage.FromFile (Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png")))
|
2017-01-12 05:17:51 +03:00
|
|
|
using (var a = NSArray.FromObjects ("string", ns, img))
|
|
|
|
using (UISegmentedControl sc = new UISegmentedControl (a)) {
|
2020-07-17 09:48:09 +03:00
|
|
|
Assert.That (sc.NumberOfSegments, Is.EqualTo ((nint) 3), "NumberOfSegments");
|
2017-01-12 05:17:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorNSString ()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((NSString) null), "null");
|
2017-01-12 23:33:13 +03:00
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((NSString[]) null), "null array");
|
2017-01-12 05:17:51 +03:00
|
|
|
|
|
|
|
using (var ns = new NSString ("NSString"))
|
|
|
|
using (UISegmentedControl sc = new UISegmentedControl (ns)) {
|
2020-07-17 09:48:09 +03:00
|
|
|
Assert.That (sc.NumberOfSegments, Is.EqualTo ((nint) 1), "NumberOfSegments");
|
2017-01-12 05:17:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorString ()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((string) null), "null");
|
2017-01-12 23:33:13 +03:00
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((string[]) null), "null array");
|
2017-01-12 05:17:51 +03:00
|
|
|
|
|
|
|
using (UISegmentedControl sc = new UISegmentedControl ("one", "two")) {
|
2020-07-17 09:48:09 +03:00
|
|
|
Assert.That (sc.NumberOfSegments, Is.EqualTo ((nint) 2), "NumberOfSegments");
|
2017-01-12 05:17:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void CtorUIImage ()
|
|
|
|
{
|
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((UIImage) null), "null");
|
2017-01-12 23:33:13 +03:00
|
|
|
Assert.Throws<ArgumentNullException> (() => new UISegmentedControl ((UIImage[]) null), "null array");
|
2017-01-12 05:17:51 +03:00
|
|
|
|
2020-12-15 15:16:07 +03:00
|
|
|
using (var img = UIImage.FromFile (Path.Combine (NSBundle.MainBundle.ResourcePath, "basn3p08.png")))
|
2017-01-12 05:17:51 +03:00
|
|
|
using (UISegmentedControl sc = new UISegmentedControl (img)) {
|
2020-07-17 09:48:09 +03:00
|
|
|
Assert.That (sc.NumberOfSegments, Is.EqualTo ((nint) 1), "NumberOfSegments");
|
2017-01-12 05:17:51 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !__WATCHOS__
|