TextBoxTest.cs 5.4 KB

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