Test to make sure that setting focus activates the focused
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / RichTextBoxTest.cs
blobdd4f301dc5d1dffe69c818d1f819bf8ffe617c84
1 //
2 // RichTextBoxTest.cs: Test cases for RichTextBox.
3 //
4 // Author:
5 // Ritvik Mayank (mritvik@novell.com)
6 //
7 // (C) 2005 Novell, Inc. (http://www.novell.com)
8 //
10 using System;
11 using System.Windows.Forms;
12 using System.Drawing;
13 using System.Reflection;
14 using NUnit.Framework;
16 namespace MonoTests.System.Windows.Forms
18 [TestFixture]
19 public class RichTextBoxBaseTest
21 #if not
22 [Test]
23 public void RichTextBoxPropertyTest ()
25 RichTextBox rTBox = new RichTextBox ();
27 // A
28 Assert.AreEqual (false, rTBox.AllowDrop, "#A1");
29 rTBox.Multiline = true;
30 rTBox.AcceptsTab = true;
31 SendKeys.SendWait ("^%");
32 Assert.AreEqual (false, rTBox.AutoSize, "#A2");
33 Assert.AreEqual (false, rTBox.AutoWordSelection, "#A3");
36 // B
37 rTBox.BackColor = Color.White;
38 Assert.AreEqual (null, rTBox.BackgroundImage, "#B1");
39 string gif = "M.gif";
40 rTBox.BackgroundImage = Image.FromFile (gif);
41 // comparing image objects fails on MS .Net so using Size property
42 Assert.AreEqual (Image.FromFile(gif, true).Size, rTBox.BackgroundImage.Size, "#B2");
43 Assert.AreEqual (0, rTBox.BulletIndent, "#B3");
45 // C
46 Assert.AreEqual (false, rTBox.CanRedo, "#C1");
47 rTBox.Paste ();
48 Assert.AreEqual (false, rTBox.CanRedo, "#C2");
49 rTBox.ClearUndo ();
50 Assert.AreEqual (false, rTBox.CanRedo, "#C3");
52 // D
53 Assert.AreEqual (true, rTBox.DetectUrls, "#D1");
55 // F
56 Assert.AreEqual (FontStyle.Regular, rTBox.Font.Style, "#F1");
57 Assert.AreEqual ("WindowText", rTBox.ForeColor.Name, "#F2");
59 //M
60 Assert.AreEqual (2147483647, rTBox.MaxLength, "#M1");
61 Assert.AreEqual (true, rTBox.Multiline, "#M2");
62 rTBox.WordWrap = false;
63 Assert.AreEqual (true, rTBox.Multiline, "#M3");
65 // R
66 Assert.AreEqual ("", rTBox.RedoActionName, "#R1");
67 Assert.AreEqual (0, rTBox.RightMargin, "#R2");
69 // [MonoTODO ("Assert.AreEqual (false, rTBox.Rtf, "#R3");") ]
71 // S
73 // [MonoTODO ("Assert.AreEqual (ScrollBars.Both, rTBox.ScrollBars, "#S1");")]
74 Assert.AreEqual (RichTextBoxScrollBars.Both, rTBox.ScrollBars, "#S1");
75 Assert.AreEqual ("", rTBox.SelectedText, "#S3");
76 rTBox.Text = "sample TextBox";
77 Assert.AreEqual (HorizontalAlignment.Left, rTBox.SelectionAlignment, "#S5");
78 Assert.AreEqual (false, rTBox.SelectionBullet, "#S6");
79 Assert.AreEqual (0, rTBox.SelectionCharOffset, "#S7");
80 //Assert.AreEqual (Color.Black, rTBox.SelectionColor, "#S8"); // Random color
81 Assert.AreEqual ("Courier New", rTBox.SelectionFont.Name, "#S9a");
82 Assert.AreEqual (FontStyle.Regular, rTBox.SelectionFont.Style, "#S9b");
83 Assert.AreEqual (0, rTBox.SelectionHangingIndent, "#S10");
84 Assert.AreEqual (0, rTBox.SelectionIndent, "#S11");
85 Assert.AreEqual (0, rTBox.SelectionLength, "#S12");
86 Assert.AreEqual (false, rTBox.SelectionProtected, "#S13");
87 Assert.AreEqual (0, rTBox.SelectionRightIndent, "#S14");
88 Assert.AreEqual (false, rTBox.ShowSelectionMargin, "#S15");
89 // [MonoTODO ("Assert.AreEqual (, rTBox.SelectionTabs, "#S16");")]
90 // [MonoTODO("Assert.AreEqual (TypeCode.Empty, rTBox.SelectionType, "#S17");")]
92 // T
93 Assert.AreEqual ("sample TextBox", rTBox.Text, "#T1");
94 Assert.AreEqual (14, rTBox.TextLength, "#T2");
96 // UVW
97 Assert.AreEqual ("", rTBox.UndoActionName, "#U1");
99 // XYZ
100 Assert.AreEqual (1, rTBox.ZoomFactor, "#Z1");
104 [Test]
105 public void CanPasteTest ()
107 RichTextBox rTextBox = new RichTextBox ();
108 Bitmap myBitmap = new Bitmap ("M.gif");
109 Clipboard.SetDataObject (myBitmap);
110 DataFormats.Format myFormat = DataFormats.GetFormat (DataFormats.Bitmap);
111 Assert.AreEqual (true, rTextBox.CanPaste (myFormat), "#Mtd1");
113 #endif
115 [Test]
116 public void FindCharTest ()
118 RichTextBox rTextBox = new RichTextBox ();
119 rTextBox.Text = "something";
120 Assert.AreEqual (2, rTextBox.Find (new char [] {'m'}), "#Mtd3");
121 Assert.AreEqual (-1, rTextBox.Find (new char [] {'t'},5), "#Mtd3a");
122 Assert.AreEqual (4, rTextBox.Find (new char [] {'t'},4,5), "#Mtd3b");
125 [Test]
126 public void FindStringTest ()
128 RichTextBox rTextBox = new RichTextBox ();
129 rTextBox.Text = "sample text for richtextbox";
130 int indexToText1 = rTextBox.Find ("for");
131 Assert.AreEqual (12, indexToText1, "#Mtd4");
132 int indexToText2 = rTextBox.Find ("for", 0, 14, RichTextBoxFinds.MatchCase);
133 Assert.AreEqual (-1, indexToText2, "#Mtd5");
134 int indexToText3 = rTextBox.Find ("for", 0, 15, RichTextBoxFinds.MatchCase);
135 Assert.AreEqual (12, indexToText3, "#Mtd6");
136 int indexToText4 = rTextBox.Find ("richtextbox", 0, RichTextBoxFinds.MatchCase);
137 Assert.AreEqual (16, indexToText4, "#Mtd7");
138 int indexToText5 = rTextBox.Find ("text", RichTextBoxFinds.MatchCase);
139 Assert.AreEqual (7, indexToText5, "#Mtd8");
142 [Test]
143 public void FindTest() {
144 RichTextBox t = new RichTextBox();
146 t.Text = "Testtext and arglblah may not be what we're looking for\n, but blah Blah is";
148 Assert.AreEqual(t.Find(new char[] {'b', 'l', 'a', 'h'}), 9, "Find1");
149 Assert.AreEqual(t.Find(new char[] {'b', 'l', 'a', 'h'}, 20), 20, "Find2");
150 Assert.AreEqual(t.Find(new char[] {'b', 'l', 'a', 'h'}, 25, 30), -1, "Find3");
151 Assert.AreEqual(t.Find("blah"), 17, "Find4");
152 Assert.AreEqual(t.Find("blah", 10, 30, RichTextBoxFinds.None), 17, "Find5");
153 Assert.AreEqual(t.Find("blah", 10, 30, RichTextBoxFinds.WholeWord), -1, "Find6");
154 Assert.AreEqual(t.Find("blah", 10, 30, RichTextBoxFinds.MatchCase), 17, "Find7");
155 Assert.AreEqual(t.Find("blah", 10, 70, RichTextBoxFinds.Reverse), 62, "Find8");
156 Assert.AreEqual(t.Find("blah", 10, 73, RichTextBoxFinds.Reverse), 67, "Find9");
157 Assert.AreEqual(t.Find("blah", 10, 73, RichTextBoxFinds.Reverse | RichTextBoxFinds.MatchCase), 62, "Find10");
158 Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.None), 17, "Find11");
159 Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.WholeWord), 62, "Find12");
160 Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.MatchCase), 17, "Find13");
161 Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.Reverse), 67, "Find14");
162 Assert.AreEqual(t.Find("blah", 10, RichTextBoxFinds.Reverse | RichTextBoxFinds.MatchCase), 62, "Find15");
163 Assert.AreEqual(t.Find("blah", RichTextBoxFinds.Reverse), 67, "Find16");
164 Assert.AreEqual(t.Find("blah", RichTextBoxFinds.MatchCase), 17, "Find17");
165 Assert.AreEqual(t.Find("blah", RichTextBoxFinds.WholeWord), 62, "Find18");
167 // Special cases
168 Assert.AreEqual(t.Find("blah", 10, 11, RichTextBoxFinds.None), -1, "Find19"); // Range to short to ever match
169 Assert.AreEqual(t.Find("blah", 17, 18, RichTextBoxFinds.None), -1, "Find20"); // Range to short to ever match, but starts matching
170 Assert.AreEqual(t.Find("is", RichTextBoxFinds.WholeWord), 72, "Find21"); // Last word in document
171 Assert.AreEqual(t.Find("for", RichTextBoxFinds.WholeWord), 52, "Find22"); // word followed by \n
172 Assert.AreEqual(t.Find("Testtext", RichTextBoxFinds.WholeWord), 0, "Find23"); // First word in document
173 Assert.AreEqual(t.Find("Testtext", RichTextBoxFinds.WholeWord | RichTextBoxFinds.Reverse), 0, "Find24"); // First word in document, searched in reverse
176 [Test]
177 [Ignore ("this test depends on system default font")]
178 public void GetCharFromPositionTest ()
180 Form myForm = new Form ();
181 RichTextBox rTextBox = new RichTextBox ();
182 rTextBox.Text = "sample text for richtextbox";
183 myForm.Controls.Add (rTextBox);
184 Assert.AreEqual ('m', rTextBox.GetCharFromPosition (new Point (10, 10)), "#21");
186 //[MonoTODO("Add test for method Paste (Visual Test)")]