1 //
2 // ToolStripContentPanelTests.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2007 Jonathan Pobst
24 //
25 // Authors:
26 //	Jonathan Pobst (monkey@jpobst.com)
27 //
28 using System;
29 using System.Collections.Generic;
30 using System.Text;
31 using NUnit.Framework;
32 using System.Drawing;
33 using System.Windows.Forms;
34 
35 namespace MonoTests.System.Windows.Forms
36 {
37 	[TestFixture]
38 	public class ToolStripContentPanelTests : TestHelper
39 	{
40 		[Test]
Constructor()41 		public void Constructor ()
42 		{
43 			ToolStripContentPanel tsp = new ToolStripContentPanel ();
44 
45 			Assert.AreEqual (SystemColors.Control, tsp.BackColor, "A1");
46 			Assert.AreEqual ("System.Windows.Forms.ToolStripSystemRenderer", tsp.Renderer.ToString (), "A2");
47 			Assert.AreEqual (ToolStripRenderMode.System, tsp.RenderMode, "A3");
48 		}
49 
50 		[Test]
PropertyBackColor()51 		public void PropertyBackColor ()
52 		{
53 			ToolStripContentPanel tsp = new ToolStripContentPanel ();
54 			EventWatcher ew = new EventWatcher (tsp);
55 
56 			tsp.BackColor = Color.Green;
57 			Assert.AreEqual (Color.Green, tsp.BackColor, "B1");
58 			Assert.AreEqual (string.Empty, ew.ToString (), "B2");
59 
60 			ew.Clear ();
61 			tsp.BackColor = Color.Green;
62 			Assert.AreEqual (string.Empty, ew.ToString (), "B3");
63 		}
64 
65 		[Test]
PropertyRenderer()66 		public void PropertyRenderer ()
67 		{
68 			ToolStripContentPanel tsp = new ToolStripContentPanel ();
69 			EventWatcher ew = new EventWatcher (tsp);
70 
71 			ToolStripProfessionalRenderer pr = new ToolStripProfessionalRenderer ();
72 
73 			tsp.Renderer = pr;
74 			Assert.AreSame (pr, tsp.Renderer, "B1");
75 			Assert.AreEqual (ToolStripRenderMode.Custom, tsp.RenderMode, "B1-2");
76 			// I refuse to call the event twice like .Net does.
77 			//Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
78 
79 			ew.Clear ();
80 			tsp.Renderer = pr;
81 			//Assert.AreEqual (string.Empty, ew.ToString (), "B3");
82 		}
83 
84 		[Test]
PropertyRenderMode()85 		public void PropertyRenderMode ()
86 		{
87 			ToolStripContentPanel tsp = new ToolStripContentPanel ();
88 			EventWatcher ew = new EventWatcher (tsp);
89 
90 			tsp.RenderMode = ToolStripRenderMode.ManagerRenderMode;
91 			Assert.AreEqual (ToolStripRenderMode.ManagerRenderMode, tsp.RenderMode, "B1");
92 			// I refuse to call the event twice like .Net does.
93 			//Assert.AreEqual ("RendererChanged;RendererChanged", ew.ToString (), "B2");
94 
95 			ew.Clear ();
96 			tsp.RenderMode = ToolStripRenderMode.ManagerRenderMode;
97 			Assert.AreEqual (string.Empty, ew.ToString (), "B3");
98 		}
99 
100 		private class EventWatcher
101 		{
102 			private string events = string.Empty;
103 
EventWatcher(ToolStripContentPanel tsp)104 			public EventWatcher (ToolStripContentPanel tsp)
105 			{
106 				tsp.Load += new EventHandler (delegate (Object obj, EventArgs e) { events += ("Load;"); });
107 				tsp.RendererChanged += new EventHandler (delegate (Object obj, EventArgs e) { events += ("RendererChanged;"); });
108 			}
109 
ToString()110 			public override string ToString ()
111 			{
112 				return events.TrimEnd (';');
113 			}
114 
Clear()115 			public void Clear ()
116 			{
117 				events = string.Empty;
118 			}
119 		}
120 	}
121 }
122