2 // Copyright (c) 2005 Novell, Inc.
5 // Ritvik Mayank (mritvik@novell.com)
9 using System
.Windows
.Forms
;
11 using System
.Reflection
;
12 using NUnit
.Framework
;
14 namespace MonoTests
.System
.Windows
.Forms
17 public class TextBoxTest
24 textBox
= new TextBox();
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");
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");
49 Assert
.AreEqual (true, textBox
.CanUndo
, "#6b");
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");
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");
90 public void UseSystemPasswordCharDefault()
92 Assert
.IsFalse(textBox
.UseSystemPasswordChar
);
96 public void UseSystemPasswordCharOverridesPasswordChar()
98 textBox
.PasswordChar
= '!';
99 textBox
.UseSystemPasswordChar
= true;
100 Assert
.AreEqual('*', textBox
.PasswordChar
);
105 public void AppendTextTest ()
107 Form f
= new Form ();
108 f
.ShowInTaskbar
= false;
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");
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");
134 [Category ("NotWorking")] // bug #79799
135 public void AppendText_Multiline_CRLF ()
137 TextBox textBox
= new TextBox ();
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;
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");
164 [Category ("NotWorking")] // bug #79799
165 public void AppendText_Multiline_LF ()
167 TextBox textBox
= new TextBox ();
168 textBox
.Multiline
= true;
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;
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");
195 public void ClearTest ()
197 textBox
.Text
= "TextBox1";
198 Assert
.AreEqual ("TextBox1", textBox
.Text
, "#28a" );
200 Assert
.AreEqual ("", textBox
.Text
, "#28b");
204 public void ClearUndoTest ()
206 textBox
.Text
= "TextBox1";
207 textBox
.SelectionLength
= 4;
209 Assert
.AreEqual ("Text", textBox
.SelectedText
, "#29a");
211 Assert
.AreEqual (true, textBox
.CanUndo
, "#29b");
212 textBox
.ClearUndo ();
213 Assert
.AreEqual (false, textBox
.CanUndo
, "#29c");
217 public void CopyTest ()
219 textBox
.Text
= "ABCDE";
220 textBox
.SelectionLength
= 4;
222 Assert
.AreEqual ("ABCD", textBox
.SelectedText
, "#30");
226 public void CutTest ()
228 textBox
.Text
= "ABCDE";
229 textBox
.SelectionLength
= 4;
231 Assert
.AreEqual ("E", textBox
.Text
, "#31");
235 public void PasteTest ()
237 textBox
.Text
= "ABCDE";
238 textBox
.SelectionLength
= 4;
240 textBox
.SelectionStart
= textBox
.SelectionStart
+ textBox
.SelectionLength
;
242 Assert
.AreEqual ("ABCDABCD", textBox
.Text
, "#32");
246 public void SelectTest ()
248 textBox
.Text
= "This is a sample test.";
249 textBox
.Select (0, 4);
250 Assert
.AreEqual ("This", textBox
.SelectedText
, "#33");
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");
262 public void ToStringTest ()
264 Assert
.AreEqual ("System.Windows.Forms.TextBox, Text: ", textBox
.ToString(), "#35");
268 public void UndoTest1 ()
270 textBox
.Text
= "ABCDE";
271 textBox
.SelectionLength
= 4;
273 textBox
.SelectionStart
= textBox
.SelectionStart
+ textBox
.SelectionLength
;
275 Console
.WriteLine ("pre paste text: {0}", textBox
.Text
);
277 Assert
.AreEqual ("ABCDE", textBox
.Text
, "#36");
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);
290 Form form
= new Form ();
291 form
.Controls
.Add (textBox
);
292 form
.ShowInTaskbar
= false;
295 Assert
.AreEqual (text
, textBox
.Text
);
299 public void MultilineText ()
301 string text
= "line1\n\nline2\nline3\r\nline4";
303 textBox
.Multiline
= true;
304 textBox
.Size
= new Size (300, 168);
307 Form form
= new Form ();
308 form
.Controls
.Add (textBox
);
309 form
.ShowInTaskbar
= false;
312 Assert
.AreEqual (text
, textBox
.Text
, "#1");
314 text
= "line1\n\nline2\nline3\r\nline4\rline5\r\n\nline6\n\n\nline7";
318 form
.Visible
= false;
321 Assert
.AreEqual (text
, textBox
.Text
, "#2");