merge -r 58784:58785
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / TextBoxTest.cs
1 //
2 // Copyright (c) 2005 Novell, Inc.
3 //
4 // Authors:
5 //      Ritvik Mayank (mritvik@novell.com)
6 //
7
8 using System;
9 using System.Windows.Forms;
10 using System.Drawing;
11 using System.Reflection;
12 using NUnit.Framework;
13
14 namespace MonoTests.System.Windows.Forms
15 {
16         [TestFixture]
17         public class TextBoxBaseTest
18         {
19                 [Test]
20                 public void TextBoxBasePropertyTest ()
21                 {
22                         TextBox tb = new TextBox ();
23                         Assert.AreEqual (false, tb.AcceptsTab, "#1a");
24                         tb.Multiline = true;
25                         tb.AcceptsTab = true;
26                         SendKeys.SendWait ("^%");
27                         Assert.AreEqual (true, tb.AcceptsTab, "#1b");
28                         Assert.AreEqual (true, tb.AutoSize, "#2");
29                         Assert.AreEqual ("Window", tb.BackColor.Name, "#3a");
30                         tb.BackColor = Color.White;
31                         Assert.AreEqual ("White", tb.BackColor.Name, "#3b");
32                         Assert.AreEqual (null, tb.BackgroundImage, "#4a");
33                         string gif = "M.gif";
34                         tb.BackgroundImage = Image.FromFile (gif);
35                         // comparing image objects fails on MS .Net so using Size property
36                         Assert.AreEqual (Image.FromFile(gif, true).Size, tb.BackgroundImage.Size, "#4b");
37                         
38                         Assert.AreEqual (BorderStyle.Fixed3D, tb.BorderStyle, "#5");
39                         Assert.AreEqual (false, tb.CanUndo, "#6a");
40                         tb.Paste ();
41                         Assert.AreEqual (true, tb.CanUndo, "#6b");
42                         tb.ClearUndo ();
43                         Assert.AreEqual (false, tb.CanUndo, "#6c");
44                         Assert.AreEqual ("WindowText", tb.ForeColor.Name, "#7");
45                         Assert.AreEqual (true, tb.HideSelection, "#8");
46                         Assert.AreEqual (1, tb.Lines.Length, "#9");
47                         Assert.AreEqual (32767, tb.MaxLength, "#10");
48                         Assert.AreEqual (true, tb.Modified, "#11");
49                         Assert.AreEqual (true, tb.Multiline, "#12a");
50                         tb.WordWrap = false;
51                         Assert.AreEqual (true, tb.Multiline, "#12b");
52                         tb.AcceptsReturn = true;
53                         Assert.AreEqual (true, tb.Multiline, "#12c");
54                         Assert.AreEqual (20, tb.PreferredHeight, "#13");
55                         Assert.AreEqual (false, tb.ReadOnly, "#14");
56                         Assert.AreEqual ("", tb.SelectedText, "#15");
57                         tb.Text = "sample TextBox";
58                         Assert.AreEqual (0, tb.SelectionLength, "#16b");
59                         Assert.AreEqual (0, tb.SelectionStart, "#17");
60                         tb.WordWrap = false;
61                         tb.AcceptsReturn = true;
62                         Assert.AreEqual ("sample TextBox", tb.Text, "#18");
63                         Assert.AreEqual (14, tb.TextLength, "#19");
64                         Assert.AreEqual (false, tb.WordWrap, "#20");
65                 }
66
67                 [Test]
68                 public void TextBoxPropertyTest ()
69                 {
70                         TextBox tb = new TextBox ();
71                         Assert.AreEqual (false, tb.AcceptsReturn, "#21");
72                         Assert.AreEqual (CharacterCasing.Normal, tb.CharacterCasing, "#22");
73                         Assert.AreEqual ('\0', tb.PasswordChar, "#23");
74                         tb.PasswordChar = '*';
75                         Assert.AreEqual ('*', tb.PasswordChar, "#23b");
76                         Assert.AreEqual (ScrollBars.None, tb.ScrollBars, "#24");
77                         Assert.AreEqual (-1, tb.SelectionLength, "#25");
78                         Assert.AreEqual (HorizontalAlignment.Left , tb.TextAlign, "#26");
79                 }
80
81                 [Test]
82                 public void AppendTextTest ()
83                 {   
84                         Form f = new Form (); 
85                         f.Visible = true;
86                         TextBox tb1 = new TextBox ();
87                         tb1.Visible = true;
88                         tb1.Text = "TextBox1";
89                         TextBox tb2 = new TextBox ();
90                         tb2.Visible = true;
91                         f.Controls.Add (tb1);
92                         f.Controls.Add (tb2);
93                         tb2.AppendText (tb1.Text);
94                         Assert.AreEqual ("TextBox1", tb2.Text, "#27");
95                 }
96
97                 [Test]
98                 public void ClearTest ()
99                 {
100                         TextBox tb1 = new TextBox ();
101                         tb1.Text = "TextBox1";
102                         Assert.AreEqual ("TextBox1", tb1.Text, "#28a" );
103                         tb1.Clear ();
104                         Assert.AreEqual ("", tb1.Text, "#28b");
105                 }
106
107                 [Test]
108                 public void ClearUndoTest ()
109                 {
110                         TextBox tb1 = new TextBox ();
111                         tb1.Text = "TextBox1";
112                         tb1.SelectionLength = 4;
113                         tb1.Copy ();
114                         Assert.AreEqual ("Text", tb1.SelectedText, "#29a");
115                         tb1.Paste ();
116                         Assert.AreEqual (true, tb1.CanUndo, "#29b");
117                         tb1.ClearUndo ();
118                         Assert.AreEqual (false, tb1.CanUndo, "#29c");
119                 }
120
121                 [Test]
122                 public void CopyTest ()
123                 {
124                         TextBox tb1 = new TextBox ();
125                         tb1.Text = "ABCDE";
126                         tb1.SelectionLength = 4;
127                         tb1.Copy ();
128                         Assert.AreEqual ("ABCD", tb1.SelectedText, "#30");
129                 }
130
131                 [Test]
132                 public void CutTest ()
133                 {
134                         TextBox tb1 = new TextBox ();
135                         tb1.Text = "ABCDE";
136                         tb1.SelectionLength = 4;
137                         tb1.Cut ();
138                         Assert.AreEqual ("E", tb1.Text, "#31");
139                 }
140
141                 [Test]
142                 public void PasteTest ()
143                 {
144                         TextBox tb1 = new TextBox ();
145                         tb1.Text = "ABCDE";
146                         tb1.SelectionLength = 4;
147                         tb1.SelectionStart = tb1.SelectionStart + tb1.SelectionLength;
148                         tb1.Paste ();
149                         Assert.AreEqual ("ABCDABCD", tb1.Text, "#32");
150                 }
151
152                 [Test]
153                 public void SelectTest ()
154                 {
155                         TextBox tb1 = new TextBox ();
156                         tb1.Text = "This is a sample test.";
157                         tb1.Select (0, 4);
158                         Assert.AreEqual ("This", tb1.SelectedText, "#33");
159                 }
160
161                 [Test]
162                 public void SelectAllTest ()
163                 {
164                         TextBox tb1 = new TextBox ();
165                         tb1.Text = "This is a sample test.";
166                         tb1.SelectAll ();
167                         Assert.AreEqual ("This is a sample test.", tb1.SelectedText, "#34");
168                 }
169
170                 [Test]
171                 public void ToStringTest ()
172                 {
173                         TextBox tb1 = new TextBox ();
174                         Assert.AreEqual ("System.Windows.Forms.TextBox, Text: ", tb1.ToString(), "#35");
175                 }
176
177                 [Test]
178                 public void UndoTest1 ()
179                 {
180                         TextBox tb1 = new TextBox ();
181                         tb1.Text = "ABCDE";
182                         tb1.SelectionLength = 4;
183                         tb1.Copy ();
184                         tb1.SelectionStart = tb1.SelectionStart + tb1.SelectionLength;
185                         tb1.Paste ();
186                         tb1.Undo ();
187                         Assert.AreEqual ("ABCDE", tb1.Text, "#36");
188                 }
189
190         }
191 }