2009-01-16 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / ToolStripOverflowButtonTest.cs
1 //\r
2 // ToolStripOverflowButtonTest.cs\r
3 //\r
4 // Permission is hereby granted, free of charge, to any person obtaining\r
5 // a copy of this software and associated documentation files (the\r
6 // "Software"), to deal in the Software without restriction, including\r
7 // without limitation the rights to use, copy, modify, merge, publish,\r
8 // distribute, sublicense, and/or sell copies of the Software, and to\r
9 // permit persons to whom the Software is furnished to do so, subject to\r
10 // the following conditions:\r
11 // \r
12 // The above copyright notice and this permission notice shall be\r
13 // included in all copies or substantial portions of the Software.\r
14 // \r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22 //\r
23 // Copyright (c) 2006 Jonathan Pobst\r
24 //\r
25 // Authors:\r
26 //      Jonathan Pobst (monkey@jpobst.com)\r
27 //\r
28 #if NET_2_0\r
29 using System;\r
30 using System.Collections.Generic;\r
31 using System.Text;\r
32 using NUnit.Framework;\r
33 using System.Drawing;\r
34 using System.Windows.Forms;\r
35 \r
36 namespace MonoTests.System.Windows.Forms\r
37 {\r
38         [TestFixture]\r
39         public class ToolStripOverflowButtonTests : TestHelper\r
40         {\r
41                 [Test]\r
42                 public void Constructor ()\r
43                 {\r
44                 }\r
45 \r
46                 [Test]\r
47                 public void ProtectedProperties ()\r
48                 {\r
49                         ExposeProtectedProperties epp = new ExposeProtectedProperties ();\r
50 \r
51                         Assert.AreEqual (new Padding (0, 1, 0, 2), epp.DefaultMargin, "C1");\r
52                 }\r
53 \r
54                 [Test]\r
55                 [Category ("NotWorking")]\r
56                 public void Size2 ()\r
57                 {\r
58                         Form f = new Form ();\r
59                         f.ShowInTaskbar = false;\r
60                         f.Show ();\r
61 \r
62                         ToolStrip ts = new ToolStrip ();\r
63                         f.Controls.Add (ts);\r
64                         ToolStripOverflowButton tsi = ts.OverflowButton;\r
65 \r
66                         Assert.AreEqual (new Size (16, 25), tsi.Size, "B1");\r
67                         Assert.AreEqual (false, tsi.Visible, "B3");\r
68                         ToolStripItem test = ts.Items.Add ("test");\r
69                         test.Overflow = ToolStripItemOverflow.Always;\r
70                         ts.PerformLayout ();\r
71 \r
72                         Assert.AreEqual (Size.Empty, tsi.Size, "B2");\r
73                         f.Hide ();\r
74                 }\r
75 \r
76                 [Test]\r
77                 [Category ("NotWorking")]\r
78                 public void MethodGetPreferredSize ()\r
79                 {\r
80                         Form f = new Form ();\r
81                         f.ShowInTaskbar = false;\r
82                         f.Show ();\r
83 \r
84                         ToolStrip ts = new ToolStrip ();\r
85                         f.Controls.Add (ts);\r
86                         ToolStripOverflowButton tsi = ts.OverflowButton;\r
87 \r
88                         Assert.AreEqual (Size.Empty, tsi.GetPreferredSize (Size.Empty), "B1");\r
89                         Assert.AreEqual (false, tsi.Visible, "B2");\r
90                         \r
91                         ToolStripItem test = ts.Items.Add ("test");\r
92                         test.Overflow = ToolStripItemOverflow.Always;\r
93                         ts.PerformLayout ();\r
94 \r
95                         Assert.AreEqual (new Size (16, 25), tsi.GetPreferredSize (new Size (100, 100)), "B3");\r
96                         Assert.AreEqual (false, tsi.Visible, "B4");\r
97                         f.Hide ();\r
98                 }\r
99                 \r
100                 [Test]\r
101                 [Category ("NotWorking")]\r
102                 public void BehaviorItemsOnOverflow ()\r
103                 {\r
104                         Form f = new Form ();\r
105                         f.ShowInTaskbar = false;\r
106                         MyToolStrip ts = new MyToolStrip ();\r
107                         f.Controls.Add (ts);\r
108                         f.Show ();\r
109                         \r
110                         Assert.AreEqual (0, ts.Items.Count, "A1");\r
111                         Assert.AreEqual (1, ts.PublicDisplayedItems.Count, "A2");\r
112                         Assert.AreEqual (false, ts.OverflowButton.Visible, "A3");\r
113                         Assert.AreEqual (0, ts.OverflowButton.DropDown.Items.Count, "A3");\r
114 \r
115                         ToolStripItem tsi = ts.Items.Add ("test");\r
116 \r
117                         Assert.AreEqual (1, ts.Items.Count, "A4");\r
118                         Assert.AreEqual (2, ts.PublicDisplayedItems.Count, "A5");\r
119                         Assert.AreEqual (false, ts.OverflowButton.Visible, "A3");\r
120                         Assert.AreEqual (0, ts.OverflowButton.DropDown.Items.Count, "A6");\r
121 \r
122                         tsi.Overflow = ToolStripItemOverflow.Always;\r
123 \r
124                         Assert.AreEqual (1, ts.Items.Count, "A7");\r
125                         Assert.AreEqual (2, ts.PublicDisplayedItems.Count, "A8");\r
126                         Assert.AreEqual (true, ts.OverflowButton.Visible, "A3");\r
127                         Assert.AreEqual (0, ts.OverflowButton.DropDown.Items.Count, "A9");\r
128                         Console.WriteLine (ts.PublicDisplayedItems[1].GetType().ToString());\r
129                         f.Dispose ();\r
130                 }\r
131                 \r
132                 private class ExposeProtectedProperties : ToolStripButton\r
133                 {\r
134                         public new Padding DefaultMargin { get { return base.DefaultMargin; } }\r
135                 }\r
136                 \r
137                 private class MyToolStrip : ToolStrip\r
138                 {\r
139                         public ToolStripItemCollection PublicDisplayedItems {\r
140                                 get { return base.DisplayedItems; }\r
141                         }\r
142                 }\r
143         }\r
144 }\r
145 #endif