ListViewCollectionsTest.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Author:
  23. // Jordi Mas i Hernandez <[email protected]>
  24. //
  25. //
  26. using System;
  27. using System.Windows.Forms;
  28. using System.Drawing;
  29. using System.Reflection;
  30. using System.Collections;
  31. using NUnit.Framework;
  32. namespace MonoTests.System.Windows.Forms
  33. {
  34. [TestFixture]
  35. public class ListViewCollectionsTest
  36. {
  37. /*
  38. ColumnHeaderCollection
  39. */
  40. [Test]
  41. public void ColumnHeaderCollectionTest_PropertiesTest ()
  42. {
  43. ListView listview = new ListView ();
  44. // Properties
  45. Assert.AreEqual (false, listview.Columns.IsReadOnly, "ColumnHeaderCollectionTest_PropertiesTest#1");
  46. Assert.AreEqual (true, ((ICollection)listview.Columns).IsSynchronized, "ColumnHeaderCollectionTest_PropertiesTest#2");
  47. Assert.AreEqual (listview.Columns, ((ICollection)listview.Columns).SyncRoot, "ColumnHeaderCollectionTest_PropertiesTest#3");
  48. Assert.AreEqual (false, ((IList)listview.Columns).IsFixedSize, "ColumnHeaderCollectionTest_PropertiesTest#4");
  49. Assert.AreEqual (0, listview.Columns.Count, "ColumnHeaderCollectionTest_PropertiesTest#5");
  50. }
  51. [Test]
  52. public void ColumnHeaderCollectionTest_AddTest ()
  53. {
  54. ListView listview = new ListView ();
  55. // Duplicated elements with same text added
  56. listview.Columns.Add (new ColumnHeader ());
  57. listview.Columns.Add (new ColumnHeader ());
  58. Assert.AreEqual (2, listview.Columns.Count, "ColumnHeaderCollectionTest_AddTest#1");
  59. Assert.AreEqual ("ColumnHeader", listview.Columns[0].Text, "ColumnHeaderCollectionTest_AddTest#2");
  60. }
  61. [Test]
  62. public void ColumnHeaderCollectionTest_ClearTest ()
  63. {
  64. ListView listview = new ListView ();
  65. // Duplicated elements with same text added
  66. listview.Columns.Add (new ColumnHeader ());
  67. listview.Columns.Clear ();
  68. Assert.AreEqual (0, listview.Columns.Count, "ColumnHeaderCollectionTest_ClearTest#1");
  69. }
  70. // Exceptions
  71. [Test, ExpectedException (typeof (ArgumentOutOfRangeException))]
  72. public void ColumnHeaderCollectionTest_GetItem_ExceptionTest ()
  73. {
  74. // Duplicated elements not added
  75. ListView listview = new ListView ();
  76. ColumnHeader item = listview.Columns[5];
  77. }
  78. /*
  79. CheckedIndexCollection
  80. */
  81. [Test]
  82. public void CheckedIndexCollectionTest_PropertiesTest ()
  83. {
  84. ListView listview = new ListView ();
  85. // Properties
  86. Assert.AreEqual (true, listview.CheckedIndices.IsReadOnly, "CheckedIndexCollectionTest_PropertiesTest#1");
  87. Assert.AreEqual (false, ((ICollection)listview.CheckedIndices).IsSynchronized, "CheckedIndexCollectionTest_PropertiesTest#2");
  88. Assert.AreEqual (listview.CheckedIndices, ((ICollection)listview.CheckedIndices).SyncRoot, "CheckedIndexCollectionTest_PropertiesTest#3");
  89. Assert.AreEqual (true, ((IList)listview.CheckedIndices).IsFixedSize, "CheckedIndexCollectionTest_PropertiesTest#4");
  90. Assert.AreEqual (0, listview.CheckedIndices.Count, "CheckedIndexCollectionTest_PropertiesTest#5");
  91. }
  92. // Exceptions
  93. [Test, ExpectedException (typeof (NotSupportedException))]
  94. public void CheckedIndexCollectionTest_Add_ExceptionTest ()
  95. {
  96. ListView listview = new ListView ();
  97. ((IList)listview.CheckedIndices).Add (5);
  98. }
  99. [Test, ExpectedException (typeof (NotSupportedException))]
  100. public void CheckedIndexCollectionTest_Remove_ExceptionTest ()
  101. {
  102. ListView listview = new ListView ();
  103. ((IList)listview.CheckedIndices).Remove (5);
  104. }
  105. [Test, ExpectedException (typeof (NotSupportedException))]
  106. public void CheckedIndexCollectionTest_RemoveAt_ExceptionTest ()
  107. {
  108. ListView listview = new ListView ();
  109. ((IList)listview.CheckedIndices).RemoveAt (5);
  110. }
  111. /*
  112. CheckedItemCollection
  113. */
  114. [Test]
  115. public void CheckedItemCollectionTest_PropertiesTest ()
  116. {
  117. ListView listview = new ListView ();
  118. // Properties
  119. Assert.AreEqual (true, listview.CheckedItems.IsReadOnly, "CheckedItemCollectionTest_PropertiesTest#1");
  120. Assert.AreEqual (false, ((ICollection)listview.CheckedItems).IsSynchronized, "CheckedItemCollectionTest_PropertiesTest#2");
  121. Assert.AreEqual (listview.CheckedItems, ((ICollection)listview.CheckedItems).SyncRoot, "CheckedItemCollectionTest_PropertiesTest#3");
  122. Assert.AreEqual (true, ((IList)listview.CheckedItems).IsFixedSize, "CheckedItemCollectionTest_PropertiesTest#4");
  123. Assert.AreEqual (0, listview.CheckedItems.Count, "CheckedItemCollectionTest_PropertiesTest#5");
  124. }
  125. // Exceptions
  126. [Test, ExpectedException (typeof (NotSupportedException))]
  127. public void CheckedItemCollectionTest_PropertiesTest_Add_ExceptionTest ()
  128. {
  129. ListView listview = new ListView ();
  130. ((IList)listview.CheckedItems).Add (5);
  131. }
  132. [Test, ExpectedException (typeof (NotSupportedException))]
  133. public void CheckedItemCollectionTest_PropertiesTest_Remove_ExceptionTest ()
  134. {
  135. ListView listview = new ListView ();
  136. ((IList)listview.CheckedItems).Remove (5);
  137. }
  138. [Test, ExpectedException (typeof (NotSupportedException))]
  139. public void CheckedItemCollectionTest_PropertiesTest_RemoveAt_ExceptionTest ()
  140. {
  141. ListView listview = new ListView ();
  142. ((IList)listview.CheckedItems).RemoveAt (5);
  143. }
  144. /*
  145. SelectedIndexCollection
  146. */
  147. [Test]
  148. public void SelectedIndexCollectionTest_PropertiesTest ()
  149. {
  150. ListView listview = new ListView ();
  151. // Properties
  152. Assert.AreEqual (true, listview.SelectedIndices.IsReadOnly, "SelectedIndexCollectionTest_PropertiesTest#1");
  153. Assert.AreEqual (false, ((ICollection)listview.SelectedIndices).IsSynchronized, "SelectedIndexCollectionTest_PropertiesTest#2");
  154. Assert.AreEqual (listview.SelectedIndices, ((ICollection)listview.SelectedIndices).SyncRoot, "SelectedIndexCollectionTest_PropertiesTest#3");
  155. Assert.AreEqual (true, ((IList)listview.SelectedIndices).IsFixedSize, "SelectedIndexCollectionTest_PropertiesTest#4");
  156. Assert.AreEqual (0, listview.SelectedIndices.Count, "SelectedIndexCollectionTest_PropertiesTest#5");
  157. }
  158. // Exceptions
  159. [Test, ExpectedException (typeof (NotSupportedException))]
  160. public void SelectedIndexCollectionTest_Add_ExceptionTest ()
  161. {
  162. ListView listview = new ListView ();
  163. ((IList)listview.SelectedIndices).Add (5);
  164. }
  165. [Test, ExpectedException (typeof (NotSupportedException))]
  166. public void SelectedIndexCollectionTest_Remove_ExceptionTest ()
  167. {
  168. ListView listview = new ListView ();
  169. ((IList)listview.SelectedIndices).Remove (5);
  170. }
  171. [Test, ExpectedException (typeof (NotSupportedException))]
  172. public void SelectedIndexCollectionTest_RemoveAt_ExceptionTest ()
  173. {
  174. ListView listview = new ListView ();
  175. ((IList)listview.SelectedIndices).RemoveAt (5);
  176. }
  177. /*
  178. SelectedItemCollection
  179. */
  180. [Test]
  181. public void SelectedItemCollectionTest_PropertiesTest ()
  182. {
  183. ListView listview = new ListView ();
  184. // Properties
  185. Assert.AreEqual (true, listview.SelectedItems.IsReadOnly, "SelectedItemCollectionTest_PropertiesTest#1");
  186. Assert.AreEqual (false, ((ICollection)listview.SelectedItems).IsSynchronized, "SelectedItemCollectionTest_PropertiesTest#2");
  187. Assert.AreEqual (listview.SelectedItems, ((ICollection)listview.SelectedItems).SyncRoot, "SelectedItemCollectionTest_PropertiesTest#3");
  188. Assert.AreEqual (true, ((IList)listview.SelectedItems).IsFixedSize, "SelectedItemCollectionTest_PropertiesTest#4");
  189. Assert.AreEqual (0, listview.SelectedItems.Count, "SelectedItemCollectionTest_PropertiesTest#5");
  190. }
  191. // Exceptions
  192. [Test, ExpectedException (typeof (NotSupportedException))]
  193. public void SelectedItemCollectionTest_PropertiesTest_Add_ExceptionTest ()
  194. {
  195. ListView listview = new ListView ();
  196. ((IList)listview.SelectedItems).Add (5);
  197. }
  198. [Test, ExpectedException (typeof (NotSupportedException))]
  199. public void SelectedItemCollectionTest_PropertiesTest_Remove_ExceptionTest ()
  200. {
  201. ListView listview = new ListView ();
  202. ((IList)listview.SelectedItems).Remove (5);
  203. }
  204. [Test, ExpectedException (typeof (NotSupportedException))]
  205. public void SelectedItemCollectionTest_PropertiesTest_RemoveAt_ExceptionTest ()
  206. {
  207. ListView listview = new ListView ();
  208. ((IList)listview.SelectedItems).RemoveAt (5);
  209. }
  210. }
  211. }