2006-04-12 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / RichTextBoxTest.cs
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 //
9
10 using System;
11 using System.Windows.Forms;
12 using System.Drawing;
13 using System.Reflection;
14 using NUnit.Framework;
15
16 namespace MonoTests.System.Windows.Forms
17 {
18         [TestFixture]
19         public class RichTextBoxBaseTest
20         {
21 #if not
22                 [Test]
23                 public void RichTextBoxPropertyTest ()
24                 {
25                         RichTextBox rTBox = new RichTextBox ();
26                         
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");
34                         
35                         
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");
44                         
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");
51
52                         // D
53                         Assert.AreEqual (true, rTBox.DetectUrls, "#D1");
54
55                         // F 
56                         Assert.AreEqual (FontStyle.Regular, rTBox.Font.Style, "#F1");
57                         Assert.AreEqual ("WindowText", rTBox.ForeColor.Name, "#F2");
58
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");
64                         
65                         // R
66                         Assert.AreEqual ("", rTBox.RedoActionName, "#R1");
67                         Assert.AreEqual (0, rTBox.RightMargin, "#R2");
68                         
69                         // [MonoTODO ("Assert.AreEqual (false, rTBox.Rtf, "#R3");") ]
70                                                 
71                         // S
72         
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");")] 
91                         
92                         // T
93                         Assert.AreEqual ("sample TextBox", rTBox.Text, "#T1");
94                         Assert.AreEqual (14, rTBox.TextLength, "#T2");
95                         
96                         // UVW 
97                         Assert.AreEqual ("", rTBox.UndoActionName, "#U1");
98
99                         // XYZ
100                         Assert.AreEqual (1, rTBox.ZoomFactor, "#Z1");
101
102                 }
103
104                 [Test]
105                 public void CanPasteTest ()
106                 {
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");
112                 }
113 #endif
114                 
115                 [Test]
116                 public void FindCharTest ()
117                 {
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");
123                 }
124                 
125                 [Test]
126                 public void FindStringTest ()
127                 {
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");
140                 }
141
142                 [Test]
143                 public void FindTest() {
144                         RichTextBox t = new RichTextBox();
145
146                         t.Text = "Testtext and arglblah may not be what we're looking for\n, but blah Blah is";
147
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");
166
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
174                 }
175
176                 [Test]
177                 public void GetCharFromPositionTest ()
178                 {
179                         Form myForm = new Form ();
180                         RichTextBox rTextBox = new RichTextBox ();
181                         rTextBox.Text = "sample text for richtextbox";
182                         myForm.Controls.Add (rTextBox);
183                         Assert.AreEqual ('m', rTextBox.GetCharFromPosition (new Point (10, 10)), "#21");
184                 }
185                 //[MonoTODO("Add test for method Paste (Visual Test)")]
186         }
187 }