This one is fixed too.
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / TextBoxTest.cs
blob5bf3969b7905173191abc107ed231392ea27731e
1 //
2 // Copyright (c) 2005 Novell, Inc.
3 //
4 // Authors:
5 // Ritvik Mayank (mritvik@novell.com)
6 //
8 using System;
9 using System.Windows.Forms;
10 using System.Drawing;
11 using System.Reflection;
12 using NUnit.Framework;
14 namespace MonoTests.System.Windows.Forms
16 [TestFixture]
17 public class TextBoxTest
19 TextBox textBox;
21 [SetUp]
22 public void SetUp()
24 textBox = new TextBox();
27 [Test]
28 [Category ("NotWorking")]
29 public void TextBoxBasePropertyTest ()
31 Assert.AreEqual (false, textBox.AcceptsTab, "#1a");
32 textBox.Multiline = true;
33 textBox.AcceptsTab = true;
34 SendKeys.SendWait ("^%");
35 Assert.AreEqual (true, textBox.AcceptsTab, "#1b");
36 Assert.AreEqual (true, textBox.AutoSize, "#2");
37 Assert.AreEqual ("Window", textBox.BackColor.Name, "#3a");
38 textBox.BackColor = Color.White;
39 Assert.AreEqual ("White", textBox.BackColor.Name, "#3b");
40 Assert.AreEqual (null, textBox.BackgroundImage, "#4a");
41 string gif = "M.gif";
42 textBox.BackgroundImage = Image.FromFile (gif);
43 // comparing image objects fails on MS .Net so using Size property
44 Assert.AreEqual (Image.FromFile(gif, true).Size, textBox.BackgroundImage.Size, "#4b");
46 Assert.AreEqual (BorderStyle.Fixed3D, textBox.BorderStyle, "#5");
47 Assert.AreEqual (false, textBox.CanUndo, "#6a");
48 textBox.Paste ();
49 Assert.AreEqual (true, textBox.CanUndo, "#6b");
50 textBox.ClearUndo ();
51 Assert.AreEqual (false, textBox.CanUndo, "#6c");
52 Assert.AreEqual ("WindowText", textBox.ForeColor.Name, "#7");
53 Assert.AreEqual (true, textBox.HideSelection, "#8");
54 Assert.AreEqual (1, textBox.Lines.Length, "#9");
55 Assert.AreEqual (32767, textBox.MaxLength, "#10");
56 Assert.AreEqual (true, textBox.Modified, "#11");
57 Assert.AreEqual (true, textBox.Multiline, "#12a");
58 textBox.WordWrap = false;
59 Assert.AreEqual (true, textBox.Multiline, "#12b");
60 textBox.AcceptsReturn = true;
61 Assert.AreEqual (true, textBox.Multiline, "#12c");
62 Assert.AreEqual (20, textBox.PreferredHeight, "#13");
63 Assert.AreEqual (false, textBox.ReadOnly, "#14");
64 Assert.AreEqual ("", textBox.SelectedText, "#15");
65 textBox.Text = "sample TextBox";
66 Assert.AreEqual (0, textBox.SelectionLength, "#16b");
67 Assert.AreEqual (0, textBox.SelectionStart, "#17");
68 textBox.WordWrap = false;
69 textBox.AcceptsReturn = true;
70 Assert.AreEqual ("sample TextBox", textBox.Text, "#18");
71 Assert.AreEqual (14, textBox.TextLength, "#19");
72 Assert.AreEqual (false, textBox.WordWrap, "#20");
75 [Test]
76 public void TextBoxPropertyTest ()
78 Assert.AreEqual (false, textBox.AcceptsReturn, "#21");
79 Assert.AreEqual (CharacterCasing.Normal, textBox.CharacterCasing, "#22");
80 Assert.AreEqual ('\0', textBox.PasswordChar, "#23");
81 textBox.PasswordChar = '*';
82 Assert.AreEqual ('*', textBox.PasswordChar, "#23b");
83 Assert.AreEqual (ScrollBars.None, textBox.ScrollBars, "#24");
84 Assert.AreEqual (-1, textBox.SelectionLength, "#25");
85 Assert.AreEqual (HorizontalAlignment.Left , textBox.TextAlign, "#26");
88 #if NET_2_0
89 [Test]
90 public void UseSystemPasswordCharDefault()
92 Assert.IsFalse(textBox.UseSystemPasswordChar);
95 [Test]
96 public void UseSystemPasswordCharOverridesPasswordChar()
98 textBox.PasswordChar = '!';
99 textBox.UseSystemPasswordChar = true;
100 Assert.AreEqual('*', textBox.PasswordChar);
102 #endif
104 [Test]
105 public void AppendTextTest ()
107 Form f = new Form ();
108 f.ShowInTaskbar = false;
109 f.Visible = true;
110 textBox.Visible = true;
111 textBox.Text = "TextBox1";
112 TextBox textBox2 = new TextBox ();
113 textBox2.Visible = true;
114 f.Controls.Add (textBox);
115 f.Controls.Add (textBox2);
116 textBox2.AppendText (textBox.Text);
117 Assert.AreEqual ("TextBox1", textBox2.Text, "#27");
118 f.Dispose ();
121 [Test]
122 public void AppendTextTest2 ()
124 TextBox textBox2 = new TextBox ();
125 textBox2.AppendText ("hi");
126 textBox2.AppendText ("ho");
127 Assert.AreEqual ("hiho", textBox2.Text, "#1");
128 Assert.IsNotNull (textBox2.Lines, "#2");
129 Assert.AreEqual (1, textBox2.Lines.Length, "#3");
130 Assert.AreEqual ("hiho", textBox2.Lines [0], "#4");
133 [Test]
134 [Category ("NotWorking")] // bug #79799
135 public void AppendText_Multiline_CRLF ()
137 TextBox textBox = new TextBox ();
138 textBox.Text = "ha";
139 textBox.AppendText ("hi\r\n\r\n");
140 textBox.AppendText ("ho\r\n");
141 Assert.AreEqual ("hahi\r\n\r\nho\r\n", textBox.Text, "#A1");
142 Assert.IsNotNull (textBox.Lines, "#A2");
143 Assert.AreEqual (4, textBox.Lines.Length, "#A3");
144 Assert.AreEqual ("hahi", textBox.Lines [0], "#A4");
145 Assert.AreEqual (string.Empty, textBox.Lines [1], "#A5");
146 Assert.AreEqual ("ho", textBox.Lines [2], "#A6");
147 Assert.AreEqual (string.Empty, textBox.Lines [3], "#A7");
149 textBox.Multiline = true;
151 textBox.Text = "ha";
152 textBox.AppendText ("hi\r\n\r\n");
153 textBox.AppendText ("ho\r\n");
154 Assert.AreEqual ("hahi\r\n\r\nho\r\n", textBox.Text, "#B1");
155 Assert.IsNotNull (textBox.Lines, "#B2");
156 Assert.AreEqual (4, textBox.Lines.Length, "#B3");
157 Assert.AreEqual ("hahi", textBox.Lines [0], "#B4");
158 Assert.AreEqual (string.Empty, textBox.Lines [1], "#B5");
159 Assert.AreEqual ("ho", textBox.Lines [2], "#B6");
160 Assert.AreEqual (string.Empty, textBox.Lines [3], "#B7");
163 [Test]
164 [Category ("NotWorking")] // bug #79799
165 public void AppendText_Multiline_LF ()
167 TextBox textBox = new TextBox ();
168 textBox.Multiline = true;
169 textBox.Text = "ha";
170 textBox.AppendText ("hi\n\n");
171 textBox.AppendText ("ho\n");
172 Assert.AreEqual ("hahi\n\nho\n", textBox.Text, "#A1");
173 Assert.IsNotNull (textBox.Lines, "#A2");
174 Assert.AreEqual (4, textBox.Lines.Length, "#A3");
175 Assert.AreEqual ("hahi", textBox.Lines [0], "#A4");
176 Assert.AreEqual (string.Empty, textBox.Lines [1], "#A5");
177 Assert.AreEqual ("ho", textBox.Lines [2], "#A6");
178 Assert.AreEqual (string.Empty, textBox.Lines [3], "#A7");
180 textBox.Multiline = true;
182 textBox.Text = "ha";
183 textBox.AppendText ("hi\n\n");
184 textBox.AppendText ("ho\n");
185 Assert.AreEqual ("hahi\n\nho\n", textBox.Text, "#B1");
186 Assert.IsNotNull (textBox.Lines, "#B2");
187 Assert.AreEqual (4, textBox.Lines.Length, "#B3");
188 Assert.AreEqual ("hahi", textBox.Lines [0], "#B4");
189 Assert.AreEqual (string.Empty, textBox.Lines [1], "#B5");
190 Assert.AreEqual ("ho", textBox.Lines [2], "#B6");
191 Assert.AreEqual (string.Empty, textBox.Lines [3], "#B7");
194 [Test]
195 public void ClearTest ()
197 textBox.Text = "TextBox1";
198 Assert.AreEqual ("TextBox1", textBox.Text, "#28a" );
199 textBox.Clear ();
200 Assert.AreEqual ("", textBox.Text, "#28b");
203 [Test]
204 public void ClearUndoTest ()
206 textBox.Text = "TextBox1";
207 textBox.SelectionLength = 4;
208 textBox.Copy ();
209 Assert.AreEqual ("Text", textBox.SelectedText, "#29a");
210 textBox.Paste ();
211 Assert.AreEqual (true, textBox.CanUndo, "#29b");
212 textBox.ClearUndo ();
213 Assert.AreEqual (false, textBox.CanUndo, "#29c");
216 [Test]
217 public void CopyTest ()
219 textBox.Text = "ABCDE";
220 textBox.SelectionLength = 4;
221 textBox.Copy ();
222 Assert.AreEqual ("ABCD", textBox.SelectedText, "#30");
225 [Test]
226 public void CutTest ()
228 textBox.Text = "ABCDE";
229 textBox.SelectionLength = 4;
230 textBox.Cut ();
231 Assert.AreEqual ("E", textBox.Text, "#31");
234 [Test]
235 public void PasteTest ()
237 textBox.Text = "ABCDE";
238 textBox.SelectionLength = 4;
239 textBox.Copy ();
240 textBox.SelectionStart = textBox.SelectionStart + textBox.SelectionLength;
241 textBox.Paste ();
242 Assert.AreEqual ("ABCDABCD", textBox.Text, "#32");
245 [Test]
246 public void SelectTest ()
248 textBox.Text = "This is a sample test.";
249 textBox.Select (0, 4);
250 Assert.AreEqual ("This", textBox.SelectedText, "#33");
253 [Test]
254 public void SelectAllTest ()
256 textBox.Text = "This is a sample test.";
257 textBox.SelectAll ();
258 Assert.AreEqual ("This is a sample test.", textBox.SelectedText, "#34");
261 [Test]
262 public void ToStringTest ()
264 Assert.AreEqual ("System.Windows.Forms.TextBox, Text: ", textBox.ToString(), "#35");
267 [Test]
268 public void UndoTest1 ()
270 textBox.Text = "ABCDE";
271 textBox.SelectionLength = 4;
272 textBox.Copy ();
273 textBox.SelectionStart = textBox.SelectionStart + textBox.SelectionLength;
274 textBox.Paste ();
275 Console.WriteLine ("pre paste text: {0}", textBox.Text);
276 textBox.Undo ();
277 Assert.AreEqual ("ABCDE", textBox.Text, "#36");
280 [Test] // bug #79851
281 public void WrappedText ()
283 string text = "blabla blablabalbalbalbalbalbal blabla blablabl bal " +
284 "bal bla bal balajkdhfk dskfk ersd dsfjksdhf sdkfjshd f";
286 textBox.Multiline = true;
287 textBox.Size = new Size (30, 168);
288 textBox.Text = text;
290 Form form = new Form ();
291 form.Controls.Add (textBox);
292 form.ShowInTaskbar = false;
293 form.Show ();
295 Assert.AreEqual (text, textBox.Text);
298 [Test] // bug #79909
299 public void MultilineText ()
301 string text = "line1\n\nline2\nline3\r\nline4";
303 textBox.Multiline = true;
304 textBox.Size = new Size (300, 168);
305 textBox.Text = text;
307 Form form = new Form ();
308 form.Controls.Add (textBox);
309 form.ShowInTaskbar = false;
310 form.Show ();
312 Assert.AreEqual (text, textBox.Text, "#1");
314 text = "line1\n\nline2\nline3\r\nline4\rline5\r\n\nline6\n\n\nline7";
316 textBox.Text = text;
318 form.Visible = false;
319 form.Show ();
321 Assert.AreEqual (text, textBox.Text, "#2");