* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.HtmlControls / HtmlImageTest.cs
1 //
2 // HtmlImageTest.cs
3 //      - Unit tests for System.Web.UI.HtmlControls.HtmlImage
4 //
5 // Author:
6 //      Dick Porter  <dick@ximian.com>
7 //
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.IO;
32 using System.Web.UI;
33 using System.Web.UI.HtmlControls;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Web.UI.HtmlControls {
38
39         public class TestHtmlImage : HtmlImage {
40
41                 public HtmlTextWriter GetWriter ()
42                 {
43                         StringWriter text = new StringWriter ();
44                         HtmlTextWriter writer = new HtmlTextWriter (text);
45                         base.RenderAttributes (writer);
46                         return writer;
47                 }
48         }
49
50         [TestFixture]
51         public class HtmlImageTest {
52
53                 [Test]
54                 public void DefaultProperties ()
55                 {
56                         HtmlImage img = new HtmlImage ();
57                         Assert.AreEqual (0, img.Attributes.Count, "Attributes.Count");
58
59                         Assert.AreEqual (String.Empty, img.Align, "Align");
60                         Assert.AreEqual (String.Empty, img.Alt, "Alt");
61                         Assert.AreEqual (-1, img.Border, "Border");
62                         Assert.AreEqual (-1, img.Height, "Height");
63                         Assert.AreEqual (String.Empty, img.Src, "Src");
64                         Assert.AreEqual (-1, img.Width, "Width");
65
66                         Assert.AreEqual ("img", img.TagName, "TagName");
67                 }
68
69                 [Test]
70                 public void NullProperties ()
71                 {
72                         HtmlImage img = new HtmlImage ();
73
74                         img.Align = null;
75                         Assert.AreEqual (String.Empty, img.Align, "Align");
76                         img.Alt = null;
77                         Assert.AreEqual (String.Empty, img.Alt, "Alt");
78                         img.Border = -1;
79                         Assert.AreEqual (-1, img.Border, "Border");
80                         img.Height = -1;
81                         Assert.AreEqual (-1, img.Height, "Height");
82                         img.Src = null;
83                         Assert.AreEqual (String.Empty, img.Src, "Src");
84                         img.Width = -1;
85                         Assert.AreEqual (-1, img.Width, "Width");
86
87                         Assert.AreEqual (0, img.Attributes.Count, "Attributes.Count");
88                 }
89
90                 [Test]
91                 public void Negative ()
92                 {
93                         HtmlImage img = new HtmlImage ();
94
95                         img.Border = 10;
96                         img.Height = 20;
97                         img.Width = 30;
98
99                         Assert.AreEqual (3, img.Attributes.Count, "First Attributes Count");
100
101                         img.Border = -10;
102                         img.Height = -20;
103                         img.Width = -30;
104
105                         Assert.AreEqual (-10, img.Border, "Border");
106                         Assert.AreEqual (-20, img.Height, "Height");
107                         Assert.AreEqual (-30, img.Width, "Width");
108
109                         Assert.AreEqual (3, img.Attributes.Count, "Second Attributes Count");
110                 }
111
112                 [Test]
113                 public void RenderAttributes ()
114                 {
115                         TestHtmlImage img = new TestHtmlImage ();
116
117                         img.Align = "*1*";
118                         img.Alt = "*2*";
119                         img.Border = 3;
120                         img.Height = 4;
121                         img.Src = "*5*";
122                         img.Width = 6;
123                         
124                         Assert.AreEqual (6, img.Attributes.Count, "Attributes.Count");
125
126                         HtmlTextWriter writer = img.GetWriter ();
127                         Assert.AreEqual (" src=\"*5*\" align=\"*1*\" alt=\"*2*\" border=\"3\" height=\"4\" width=\"6\" /", writer.InnerWriter.ToString ());
128                 }
129         }
130 }