2016-05-26 16:06:52 +03:00
|
|
|
// Copyright 2011-2013 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;
|
|
|
|
using Foundation;
|
|
|
|
using UIKit;
|
2017-06-10 04:39:40 +03:00
|
|
|
using CoreGraphics;
|
2016-05-26 16:06:52 +03:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace MonoTouchFixtures.UIKit {
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
public class TextFieldTest {
|
|
|
|
|
|
|
|
[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 (UITextField tf = new UITextField (frame)) {
|
|
|
|
Assert.That (tf.Frame, Is.EqualTo (frame), "Frame");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void InputAccessoryViewTest ()
|
|
|
|
{
|
|
|
|
using (var tf = new UITextField ()) {
|
|
|
|
Assert.That (tf.InputAccessoryView, Is.Null, "1");
|
|
|
|
tf.InputAccessoryView = new UIView ();
|
|
|
|
Assert.That (tf.InputAccessoryView, Is.Not.Null, "2");
|
|
|
|
tf.InputAccessoryView = null;
|
|
|
|
Assert.That (tf.InputAccessoryView, Is.Null, "3");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void EmptySelection ()
|
|
|
|
{
|
|
|
|
using (var tf = new UITextField ()) {
|
2017-06-10 04:39:40 +03:00
|
|
|
if (TestRuntime.CheckXcodeVersion (9, 0)) {
|
|
|
|
Assert.IsNotNull (tf.SelectedTextRange, "SelectedTextRange 1");
|
|
|
|
} else {
|
|
|
|
Assert.IsNull (tf.SelectedTextRange, "SelectedTextRange");
|
|
|
|
}
|
2019-06-14 12:15:16 +03:00
|
|
|
if (TestRuntime.CheckXcodeVersion (11, 0)) {
|
2020-03-04 19:24:02 +03:00
|
|
|
if (TestRuntime.CheckXcodeVersion (11, 4))
|
|
|
|
Assert.That (tf.TypingAttributes, Is.Not.Empty, "default"); // iOS 13.4 returns contents
|
|
|
|
else
|
|
|
|
Assert.That (tf.TypingAttributes, Is.Empty, "default");
|
2019-06-14 12:15:16 +03:00
|
|
|
} else {
|
|
|
|
Assert.IsNull (tf.TypingAttributes, "default");
|
|
|
|
}
|
2018-07-03 18:12:42 +03:00
|
|
|
// ^ calling TypingAttributes does not crash like UITextView does, it simply returns null
|
|
|
|
tf.TypingAttributes = new NSDictionary ();
|
2019-06-14 12:15:16 +03:00
|
|
|
if (TestRuntime.CheckXcodeVersion (11, 0)) {
|
2020-03-04 19:24:02 +03:00
|
|
|
if (TestRuntime.CheckXcodeVersion (11, 4))
|
|
|
|
Assert.That (tf.TypingAttributes, Is.Not.Empty, "not empty"); // iOS 13.4 returns contents
|
|
|
|
else
|
|
|
|
Assert.That (tf.TypingAttributes, Is.Empty, "empty");
|
2019-06-14 12:15:16 +03:00
|
|
|
} else {
|
|
|
|
Assert.IsNull (tf.TypingAttributes, "empty");
|
|
|
|
}
|
2018-07-03 18:12:42 +03:00
|
|
|
// and it stays null, even if assigned, since there's not selection
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void LeftRight ()
|
|
|
|
{
|
|
|
|
// https://bugzilla.xamarin.com/show_bug.cgi?id=15004
|
|
|
|
using (UITextField tf = new UITextField ()) {
|
|
|
|
Assert.IsNull (tf.LeftView, "LeftView");
|
|
|
|
tf.LeftView = null;
|
|
|
|
Assert.IsNull (tf.RightView, "RightView");
|
|
|
|
tf.RightView = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetCaretRectForPositiont_Null ()
|
|
|
|
{
|
|
|
|
// https://bugzilla.xamarin.com/show_bug.cgi?id=20572
|
|
|
|
using (UITextField tf = new UITextField ()) {
|
2017-11-07 22:48:16 +03:00
|
|
|
// most iOS versions returns `CGRect.Empty` but iOS [9-11.2[ did not
|
|
|
|
// so we're not checking the return value - just that the call works (original bug)
|
|
|
|
tf.GetCaretRectForPosition (null);
|
2016-05-26 16:06:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TextInputTraits ()
|
|
|
|
{
|
|
|
|
// UITextInputTraits members are not required but we marked them abstract
|
|
|
|
// that's even more confusing since they all fails for respondToSelector tests but works in real life
|
|
|
|
using (UITextField tf = new UITextField ()) {
|
|
|
|
// this is just to show we can get and set those values (even if respondToSelector returns NO)
|
|
|
|
tf.AutocapitalizationType = tf.AutocapitalizationType;
|
|
|
|
tf.AutocorrectionType = tf.AutocorrectionType;
|
|
|
|
tf.EnablesReturnKeyAutomatically = tf.EnablesReturnKeyAutomatically;
|
|
|
|
tf.KeyboardAppearance = tf.KeyboardAppearance;
|
|
|
|
tf.KeyboardType = tf.KeyboardType;
|
|
|
|
tf.ReturnKeyType = tf.ReturnKeyType;
|
|
|
|
tf.SecureTextEntry = tf.SecureTextEntry;
|
|
|
|
tf.SpellCheckingType = tf.SpellCheckingType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !__WATCHOS__
|