2006-12-19 Daniel Nauck <dna@mono-project.de>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ListViewItemTest.cs
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 <jordi@ximian.com>
24 //
25 //
26
27 using System;
28 using System.Windows.Forms;
29 using System.Drawing;
30 using System.Reflection;
31 using NUnit.Framework;
32
33 namespace MonoTests.System.Windows.Forms
34 {
35         [TestFixture]
36         public class ListViewItemTest
37         {
38                 [Test]
39                 public void ListViewItemConstructors ()
40                 {
41                         Font fnt = new Font ("Arial", 12);
42                         ListViewItem item1 = new ListViewItem ("Hello folks");
43                         Assert.AreEqual ("Hello folks", item1.Text, "Constructor#1");
44
45                         ListViewItem item2 = new ListViewItem (new string [] {"Element1", "Element2"},
46                                 -1, Color.Blue, Color.Red, fnt);
47
48                         Assert.AreEqual (item2.ForeColor, Color.Blue, "Constructor#2");
49                         Assert.AreEqual (item2.BackColor, Color.Red, "Constructor#3");
50
51                         Assert.AreEqual (2, item2.SubItems.Count,"Constructor#4");
52                         Assert.AreEqual (Color.Blue, item2.SubItems[0].ForeColor,"Constructor#5");
53                         Assert.AreEqual (Color.Red, item2.SubItems[0].BackColor, "Constructor#6");
54                         Assert.AreEqual (fnt, item2.SubItems[0].Font, "Constructor#7");
55                         Assert.AreEqual ("Element1", item2.SubItems[0].Text, "Constructor#8");
56                         Assert.AreEqual ("Element2", item2.SubItems[1].Text, "Constructor#12");
57                 }
58
59                 [Test]
60                 public void ListViewItemDefaultValues ()
61                 {
62                         ListViewItem item = new ListViewItem ();
63
64                         Assert.AreEqual (false, item.Focused, "DefaultValues#3");
65                         Assert.AreEqual (false, item.Checked, "DefaultValues#4");
66                         Assert.AreEqual (string.Empty, item.Text, "DefaultValues#5");
67                         Assert.AreEqual (true, item.UseItemStyleForSubItems, "DefaultValues#6");
68 #if NET_2_0
69                         Assert.AreEqual (String.Empty, item.Name, "DefaultValues#7");
70 #endif
71                 }
72
73                 [Test]
74                 public void ListViewItemTestClone ()
75                 {
76                         ListViewItem item1 = new ListViewItem ("Hello");
77                         item1.ForeColor = Color.Blue;
78                         item1.BackColor = Color.Red;
79                         item1.Font = new Font ("Arial", 14);
80                         item1.SubItems.Add ("Element2");
81
82                         ListViewItem item2 =  (ListViewItem) item1.Clone ();
83                         Assert.AreEqual (item2.ForeColor, Color.Blue, "Clone#1");
84                         Assert.AreEqual (item2.BackColor, Color.Red, "Clone#2");
85                         Assert.AreEqual (item2.Text, "Hello", "Clone#3");
86                         Assert.AreEqual (item2.Font, item1.Font, "Clone#4");
87                         Assert.AreEqual (2, item2.SubItems.Count, "Clone#5");
88                         Assert.AreEqual (item2.SubItems[1].Text, "Element2", "Clone#6");
89                 }
90         }
91
92         [TestFixture]
93         public class ListViewSubItemTest
94         {
95                 [Test]
96                 public void ListViewSubItemPropertiesTest ()
97                 {
98                         ListViewItem.ListViewSubItem subItem1 = new ListViewItem.ListViewSubItem ();
99                         Assert.AreEqual (string.Empty, subItem1.Text, "#A1");
100                         
101                         subItem1.Text = null;
102                         Assert.AreEqual (string.Empty, subItem1.Text, "#B1");
103                         subItem1.Text = "test";
104                         Assert.AreEqual ("test", subItem1.Text, "#B2");
105                 }
106         }
107 }