Mark tests as not working under TARGET_JVM
[mono.git] / mcs / class / System.Web / Test / System.Web.UI.WebControls / StyleTest.cs
1 //
2 // Tests for System.Web.UI.WebControls.Style.cs 
3 //
4 // Author:
5 //      Peter Dennis Bartok (pbartok@novell.com)
6 //
7
8 //
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using NUnit.Framework;
32 using System;
33 using System.Collections;
34 using System.Drawing;
35 using System.IO;
36 using System.Globalization;
37 using refl = System.Reflection;
38 using System.Web;
39 using System.Web.UI;
40 using System.Web.UI.WebControls;
41 using MonoTests.SystemWeb.Framework;
42 using MonoTests.stand_alone.WebHarness;
43
44 namespace MonoTests.System.Web.UI.WebControls
45 {
46         public class StyleTestClass : Style {
47
48                 public StyleTestClass ()
49                         : base ()
50                 {
51                 }
52
53                 public StyleTestClass (StateBag bag)
54                         : base (bag)
55                 {
56                 }
57
58                 public StateBag StateBag {
59                         get { return base.ViewState; }
60                 }
61
62                 public bool Empty {
63                         get { return base.IsEmpty; }
64                 }
65
66                 public bool IsTracking {
67                         get { return base.IsTrackingViewState; }
68                 }
69 #if NET_2_0
70                 public void SetCssClass(string name) {
71                         Type style = typeof (Style);
72                         if (style != null) {    
73                                 refl.MethodInfo methodInfo = style.GetMethod("SetRegisteredCssClass",refl.BindingFlags.NonPublic | refl.BindingFlags.Instance);
74                                 if (methodInfo != null) {
75                                         object[] parameters =  new object[] {name};
76                                         methodInfo.Invoke(this, parameters);
77                                 }
78                         }
79                 }
80
81                 public override void AddAttributesToRender (HtmlTextWriter writer, WebControl owner) {
82                         base.AddAttributesToRender (writer, owner);
83                 }
84
85                 protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver) {
86                         base.FillStyleAttributes (attributes, urlResolver);
87                         attributes.Add ("FillStyleAttributes", "FillStyleAttributes");
88                 }
89 #endif
90
91                 public string[] KeyValuePairs() {
92                         IEnumerator     e;
93                         string[]        result;
94                         int             item;
95
96                         e = ViewState.GetEnumerator();
97                         result = new string[ViewState.Keys.Count];
98                         item = 0;
99
100                         while (e.MoveNext()) {
101                                 DictionaryEntry d;
102                                 StateItem       si;
103
104                                 d = (DictionaryEntry)e.Current;
105                                 si = (StateItem)d.Value;
106
107                                 if (si.Value is String[]) {
108                                         string[] values;
109
110                                         values = (string[]) si.Value;
111                                         result[item] = d.Key.ToString() + "=";
112                                         if (values.Length > 0) {
113                                                 result[item] += values[0];
114
115                                                 for (int i = 1; i < values.Length; i++) {
116                                                         result[item] += ", " + values[i];
117                                                 }
118                                         }
119                                 } else {
120                                         result[item] =  d.Key.ToString() + "=" + si.Value;
121                                 }
122                                 item++;
123                         }
124
125                         return result;
126                 }
127
128                 public bool SetBitCalledFlag = false;
129                 public int SetBitCalledValue = 0;
130                 protected override void SetBit (int bit) {
131                         SetBitCalledFlag = true;
132                         SetBitCalledValue = bit;
133                         base.SetBit (bit);
134                 }
135         }
136
137         [TestFixture]   
138         public class StyleTest {
139
140                 [TestFixtureTearDown]
141                 public void TearDown ()
142                 {
143                         WebTest.Unload ();
144                 }
145
146                 private static HtmlTextWriter GetWriter () {
147                         StringWriter sw = new StringWriter ();
148                         sw.NewLine = "\n";
149                         return new HtmlTextWriter (sw);
150                 }
151
152                 private void SetSomeValues(Style s) {
153                         s.BackColor = Color.Red;
154                         s.ForeColor = Color.Green;
155                         s.Width = new Unit(10);
156                         s.Font.Bold = true;
157                 }
158
159                 private void SetAllValues(Style s) {
160                         s.BackColor = Color.Red;
161                         s.BorderColor = Color.Green;
162                         s.BorderStyle = BorderStyle.None;
163                         s.BorderWidth = new Unit(1);
164                         s.CssClass = "Boing";
165                         s.Font.Bold = true;
166                         s.Font.Italic = true;
167                         s.Font.Names = new string[2] {"namelist1", "namelist2"};
168                         //s.Font.Name = string.Empty;
169                         //s.Font.Names = new string[0];
170                         //Console.WriteLine("Font name after setting name: {0}", s.Font.ToString());
171                         s.Font.Overline = true;
172                         s.Font.Size = new FontUnit(1);
173                         //Console.WriteLine("Font name after setting size: {0}", s.Font.ToString());
174                         s.Font.Strikeout = true;
175                         s.Font.Underline = true;
176                         s.ForeColor = Color.Blue;
177                         s.Height = new Unit(2);
178                         s.Width = new Unit(3);
179                 }
180
181                 private bool IsEqual(object[] a1, object[] a2, string assertion) {
182                         int     matches;
183                         bool[]  notfound;       
184
185                         if (a1.Length != a2.Length) {
186                                 if (assertion != null) {
187                                         Assert.Fail(assertion + "( different length )");
188                                 }
189                                 return false;
190                         }
191
192                         matches = 0;
193                         notfound = new bool[a1.Length];
194
195                         for (int i = 0; i < a1.Length; i++) {
196                                 for (int j = 0; j < a2.Length; j++) {
197                                         if (a1[i].Equals(a2[j])) {
198                                                 matches++;
199                                                 break;
200                                         }
201                                 }
202                                 if ((assertion != null) && (matches != i+1)) {
203                                         Assert.Fail(assertion + "( missing " + a1[i].ToString() + " )");
204                                 }
205                         }
206
207                         return matches == a1.Length;
208                 }
209
210                 [Test]
211                 public void Style_Defaults ()
212                 {
213                         Style s = new Style ();
214
215                         Assert.AreEqual (s.BackColor, Color.Empty, "Default1");
216                         Assert.AreEqual (s.BorderColor, Color.Empty, "Default22");
217                         Assert.AreEqual (s.BorderStyle, BorderStyle.NotSet, "Default3");
218                         Assert.AreEqual (s.BorderWidth, Unit.Empty, "Default4");
219                         Assert.AreEqual (s.CssClass, string.Empty, "Default5");
220                         Assert.AreEqual (s.ForeColor, Color.Empty, "Default6");
221                         Assert.AreEqual (s.Height, Unit.Empty, "Default7");
222                         Assert.AreEqual (s.Width, Unit.Empty, "Default8");
223                 }
224
225                 [Test]
226                 public void Style_ViewState () {
227                         Style s = new Style ();
228                         ((IStateManager) s).TrackViewState ();
229                         SetSomeValues (s);
230                         object state = ((IStateManager) s).SaveViewState ();
231
232                         Style copy = new Style ();
233                         ((IStateManager) copy).LoadViewState (state);
234
235                         Assert.AreEqual (Color.Red, copy.BackColor, "ViewState1");
236                         Assert.AreEqual (Color.Green, copy.ForeColor, "ViewState2");
237                         Assert.AreEqual (new Unit (10), copy.Width, "ViewState3");
238                         Assert.AreEqual (true, copy.Font.Bold, "ViewState4");
239                 }
240
241                 [Test]
242                 public void Style_ViewState2 () {
243                         Style s = new Style (null);
244                         ((IStateManager) s).TrackViewState ();
245                         SetSomeValues (s);
246                         object state = ((IStateManager) s).SaveViewState ();
247
248                         Assert.AreEqual (null, state, "ViewState2");
249                 }
250
251                 [Test]
252                 public void Style_ViewState3 () {
253                         Style s = new Style (new StateBag());
254                         ((IStateManager) s).TrackViewState ();
255                         SetSomeValues (s);
256                         object state = ((IStateManager) s).SaveViewState ();
257
258                         Assert.AreEqual (null, state, "ViewState3");
259                 }
260
261                 [Test]
262                 public void Style_State () {
263                         string[]        keyvalues;
264                         string[]        expect1 = {
265                                                 "BorderStyle=None",
266                                                 "Font_Bold=True",
267                                                 "Font_Italic=True",
268                                                 "Height=2px",
269                                                 "CssClass=Boing",
270                                                 "BorderWidth=1px",
271                                                 "ForeColor=Color [Blue]",
272                                                 "Font_Size=1pt",
273                                                 "Font_Overline=True",
274                                                 "Width=3px",
275                                                 "BorderColor=Color [Green]",
276                                                 "Font_Names=namelist1, namelist2",
277                                                 "Font_Underline=True",
278                                                 "BackColor=Color [Red]",
279                                                 "Font_Strikeout=True" };
280                         string[]        expect2 = {
281                                                 "BorderStyle=None",
282                                                 "Font_Bold=True",
283                                                 "Font_Italic=True",
284                                                 "Height=2px",
285                                                 "CssClass=Boing",
286                                                 "BorderWidth=1px",
287                                                 "ForeColor=Color [Blue]",
288                                                 "Font_Size=1pt",
289                                                 "Font_Overline=True",
290                                                 "Width=3px",
291                                                 "BorderColor=Color [Green]",
292                                                 "Font_Underline=True",
293                                                 "BackColor=Color [Red]",
294                                                 "Font_Strikeout=True" };
295                         string[]        expect3 = {
296                                                 "BorderStyle=None",
297                                                 "Font_Bold=True",
298                                                 "Font_Italic=True",
299                                                 "Height=2px",
300                                                 "CssClass=Boing",
301                                                 "BorderWidth=1px",
302                                                 "ForeColor=Color [Blue]",
303                                                 "Font_Size=1pt",
304                                                 "Font_Overline=True",
305                                                 "Width=3px",
306                                                 "BorderColor=Color [Green]",
307                                                 "Font_Names=",
308                                                 "Font_Underline=True",
309                                                 "BackColor=Color [Red]",
310                                                 "Font_Strikeout=True" };
311                         StyleTestClass  s;
312                         StyleTestClass  copy;
313
314                         s = new StyleTestClass();
315                         SetAllValues(s);
316                         keyvalues = s.KeyValuePairs();
317                         
318                         Assert.AreEqual (15, keyvalues.Length, "State1");
319                         IsEqual(keyvalues, expect1, "State2");
320
321                         s.Font.Name = string.Empty;
322                         keyvalues = s.KeyValuePairs();
323                         Assert.AreEqual (expect2.Length, keyvalues.Length, "State3");
324                         IsEqual(keyvalues, expect2, "State4");
325
326                         s.Font.Names = null;
327                         keyvalues = s.KeyValuePairs();
328                         Assert.AreEqual (expect2.Length, keyvalues.Length, "State5");
329                         IsEqual(keyvalues, expect2, "State6");
330
331                         copy = new StyleTestClass();
332                         copy.CopyFrom(s);
333                         keyvalues = copy.KeyValuePairs();
334                         Assert.AreEqual (expect3.Length, keyvalues.Length, "State7");
335                         IsEqual(keyvalues, expect3, "State8");
336
337                         Assert.AreEqual (false, copy.IsTracking, "State9");
338
339                 }
340
341                 [Test]
342                 public void Style_Merge ()
343                 {
344                         Style s = new Style ();
345                         Style copy = new Style ();
346
347                         SetSomeValues(s);
348                         copy.ForeColor = Color.Blue;
349
350                         copy.MergeWith(s);
351                         Assert.AreEqual (Color.Red, copy.BackColor, "Merge1");
352                         Assert.AreEqual (Color.Blue, copy.ForeColor, "Merge2");
353
354                         // Don't fail here
355                         copy.MergeWith(null);
356                 }
357
358                 [Test]
359                 public void Style_Copy ()
360                 {
361                         Style s = new Style ();
362                         Style copy = new Style ();
363
364                         SetSomeValues(s);
365
366                         copy.CopyFrom (s);
367                         Assert.AreEqual (Color.Red, s.BackColor, "Copy1");
368                 }
369
370 #if NET_2_0
371                 [Test]
372                 public void Style_CssClass ()
373                 {
374                         StyleTestClass s = new StyleTestClass ();
375
376                         Assert.AreEqual (String.Empty, s.RegisteredCssClass, "Css1");
377
378                         s.SetCssClass ("blah");
379                         Assert.AreEqual ("blah", s.RegisteredCssClass, "Css2");
380
381                         s.BackColor = Color.AliceBlue;
382                         Assert.AreEqual ("blah", s.RegisteredCssClass, "Css3");
383                 }
384
385                 [Test]
386                 [Category ("NunitWeb")]
387                 public void Style_AddRegisteredCssClassAttribute () {
388                         new WebTest (PageInvoker.CreateOnLoad (Style_AddRegisteredCssClassAttribute_Load)).Run ();
389                 }
390                 
391                 public static void Style_AddRegisteredCssClassAttribute_Load (Page p) {
392                         StringWriter sw = new StringWriter ();
393                         HtmlTextWriter tw = new HtmlTextWriter (sw);
394                         Style s = new Style ();
395                         s.CssClass = "MyClass";
396                         s.BackColor = Color.AliceBlue;
397                         s.AddAttributesToRender (tw);
398                         tw.RenderBeginTag ("span");
399                         tw.RenderEndTag ();
400                         Assert.AreEqual (true, sw.ToString ().Contains ("class=\"MyClass\""), "AddRegisteredCssClassAttribute#1");
401                         Assert.AreEqual (true, sw.ToString ().Contains ("style"), "AddRegisteredCssClassAttribute#2");
402                         
403                         sw = new StringWriter ();
404                         tw = new HtmlTextWriter (sw);
405                         s = new Style ();
406                         s.BackColor = Color.AliceBlue;
407                         p.Header.StyleSheet.RegisterStyle (s, p);
408                         s.AddAttributesToRender (tw);
409                         tw.RenderBeginTag ("span");
410                         tw.RenderEndTag ();
411                         Assert.AreEqual (true, sw.ToString ().Contains ("class"), "AddRegisteredCssClassAttribute#3");
412                         Assert.AreEqual (false, sw.ToString ().Contains ("style"), "AddRegisteredCssClassAttribute#4");
413                         
414                         sw = new StringWriter ();
415                         tw = new HtmlTextWriter (sw);
416                         s = new Style ();
417                         s.BackColor = Color.AliceBlue;
418                         s.CssClass = "MyClass";
419                         p.Header.StyleSheet.RegisterStyle (s, p);
420                         s.AddAttributesToRender (tw);
421                         tw.RenderBeginTag ("span");
422                         tw.RenderEndTag ();
423                         Assert.AreEqual (sw.ToString ().LastIndexOf ("class"), sw.ToString ().IndexOf ("class"), "AddRegisteredCssClassAttribute#5");
424                         Assert.AreEqual (false, sw.ToString ().Contains ("style"), "AddRegisteredCssClassAttribute#6");
425                         Assert.AreEqual (true, sw.ToString ().Contains ("class=\"MyClass "), "AddRegisteredCssClassAttribute#7");
426
427                         s = new Style ();
428                         p.Header.StyleSheet.RegisterStyle (s, p);
429                         Assert.AreEqual (false, s.IsEmpty, "AddRegisteredCssClassAttribute#8");
430                 }
431
432                 [Test]
433                 public void Style_AddAttributesToRender_use_FillStyleAttributes () {
434                         StringWriter sw = new StringWriter ();
435                         HtmlTextWriter tw = new HtmlTextWriter (sw);
436                         StyleTestClass s = new StyleTestClass ();
437                         s.AddAttributesToRender (tw);
438                         tw.RenderBeginTag ("span");
439                         tw.RenderEndTag ();
440                         HtmlDiff.AssertAreEqual ("<span style=\"FillStyleAttributes:FillStyleAttributes;\" />", sw.ToString (), "AddAttributesToRender_use_FillStyleAttributes#2");
441                 }
442
443                 [Test]
444                 public void Style_GetStyleAttributes () {
445                         Style s;
446                         CssStyleCollection css;
447
448                         s = new Style ();
449                         css = s.GetStyleAttributes (null);
450                         Assert.AreEqual (0, css.Count, "GetStyleAttributes#1");
451
452                         s.Font.Bold = true;
453                         s.Font.Italic = true;
454                         s.Font.Size = 10;
455                         s.Font.Names = new string [] { "Arial", "Veranda" };
456                         s.Font.Overline = true;
457                         s.Font.Strikeout = true;
458                         s.Font.Underline = true;
459                         css = s.GetStyleAttributes (null);
460                         Assert.AreEqual ("bold", css ["font-weight"], "GetStyleAttributes#2");
461                         Assert.AreEqual ("italic", css ["font-style"], "GetStyleAttributes#3");
462                         Assert.AreEqual ("10pt", css ["font-size"], "GetStyleAttributes#4");
463                         Assert.AreEqual ("Arial,Veranda", css ["font-family"], "GetStyleAttributes#5");
464                         Assert.AreEqual (true, css ["text-decoration"].Contains ("overline"), "GetStyleAttributes#6");
465                         Assert.AreEqual (true, css ["text-decoration"].Contains ("line-through"), "GetStyleAttributes#7");
466                         Assert.AreEqual (true, css ["text-decoration"].Contains ("underline"), "GetStyleAttributes#8");
467
468                         s.Font.Names = null;
469                         css = s.GetStyleAttributes (null);
470                         Assert.AreEqual (null, css ["font-family"], "GetStyleAttributes#9");
471
472                         s.Font.Name = "Arial, Veranda";
473                         css = s.GetStyleAttributes (null);
474                         Assert.AreEqual ("Arial, Veranda", css ["font-family"], "GetStyleAttributes#10");
475
476                         s.Font.Name = "";
477                         css = s.GetStyleAttributes (null);
478                         Assert.AreEqual (null, css ["font-family"], "GetStyleAttributes#11");
479
480                         s.Font.Bold = false;
481                         s.Font.Italic = false;
482                         s.Font.Size = FontUnit.Empty;
483                         s.Font.Overline = false;
484                         s.Font.Strikeout = false;
485                         s.Font.Underline = false;
486                         css = s.GetStyleAttributes (null);
487                         Assert.AreEqual ("normal", css ["font-weight"], "GetStyleAttributes#12");
488                         Assert.AreEqual ("normal", css ["font-style"], "GetStyleAttributes#13");
489                         Assert.AreEqual (null, css ["font-size"], "GetStyleAttributes#14");
490                         Assert.AreEqual ("none", css ["text-decoration"], "GetStyleAttributes#15");
491
492                         s.Reset ();
493                         css = s.GetStyleAttributes (null);
494                         Assert.AreEqual (0, css.Count, "GetStyleAttributes#16");
495
496                         s.Reset ();
497                         s.Font.Underline = false;
498                         css = s.GetStyleAttributes (null);
499                         Assert.AreEqual ("none", css ["text-decoration"], "GetStyleAttributes#17");
500
501                         s.Reset ();
502                         s.BorderWidth = 1;
503                         s.BorderStyle = BorderStyle.Dashed;
504                         css = s.GetStyleAttributes (null);
505                         Assert.AreEqual ("Dashed", css ["border-style"], "GetStyleAttributes#18");
506                         Assert.AreEqual ("1px", css ["border-width"], "GetStyleAttributes#19");
507
508                         s.BorderStyle = BorderStyle.NotSet;
509                         css = s.GetStyleAttributes (null);
510                         Assert.AreEqual ("solid", css ["border-style"], "GetStyleAttributes#20");
511                         Assert.AreEqual ("1px", css ["border-width"], "GetStyleAttributes#21");
512
513                         s.BorderWidth = 0;
514                         css = s.GetStyleAttributes (null);
515                         Assert.AreEqual (null, css ["border-style"], "GetStyleAttributes#22");
516                         Assert.AreEqual ("0px", css ["border-width"], "GetStyleAttributes#23");
517                 }
518 #endif
519
520                 [Test]
521                 public void StyleFonts () {
522                         Style s = new Style ();
523
524                         Assert.AreEqual(new string[0], s.Font.Names, "F1");
525
526                         s.Font.Name = string.Empty;
527                         Assert.AreEqual(new string[0], s.Font.Names, "F2");
528
529                         s.Font.Names = null;
530                         Assert.AreEqual(new string[0], s.Font.Names, "F3");
531                 }
532
533                 [Test]
534                 [ExpectedException(typeof(ArgumentNullException))]
535                 public void NullException1 ()
536                 {
537                         Style s = new Style ();
538
539                         s.Font.Name = null;
540                 }
541
542                 private Style GetStyle ()
543                 {
544                         Style s = new Style ();
545                         s.BackColor = Color.Aqua;
546                         s.BorderWidth = Unit.Pixel (1);
547                         return s;
548                 }
549
550                 private void CheckStyle (Style s)
551                 {
552                         Assert.AreEqual (Color.Aqua, s.BackColor, "BackColor");
553                         Assert.AreEqual (Unit.Pixel (1), s.BorderWidth, "BorderWidth");
554                 }
555
556
557                 [Test]
558                 public void CopyFrom_Null ()
559                 {
560                         Style s = GetStyle ();
561                         s.CopyFrom (null);
562                         CheckStyle (s);
563                 }
564
565                 [Test]
566                 public void CopyFrom_Self ()
567                 {
568                         Style s = GetStyle ();
569                         s.CopyFrom (s);
570                         CheckStyle (s);
571                 }
572
573                 [Test]
574                 public void CopyFrom_Empty ()
575                 {
576                         StyleTestClass s = new StyleTestClass ();
577                         s.CopyFrom (new Style ());
578                         Assert.IsTrue (s.Empty, "Empty");
579                 }
580
581                 [Test]
582                 public void CopyFrom ()
583                 {
584                         Style c = GetStyle ();
585                         Style s = GetStyle ();
586
587                         c.BorderColor = Color.Azure;
588                         c.BorderWidth = Unit.Empty;
589
590                         c.CopyFrom (s);
591                         CheckStyle (c);
592
593                         Assert.AreEqual (Color.Azure, c.BorderColor, "BorderColor");
594                         // CopyFrom doesn't do a Reset
595                 }
596
597                 [Test]
598                 public void CopyFrom_IsEmpty ()
599                 {
600                         StyleTestClass c = new StyleTestClass ();
601                         Style s = GetStyle ();
602
603                         s.BorderColor = Color.Azure;
604                         s.BorderWidth = Unit.Empty;
605
606                         c.CopyFrom (s);
607
608                         Assert.IsFalse (c.Empty, "IsEmpty");
609                 }
610
611                 [Test]
612                 public void Constructor_StateBag_Null ()
613                 {
614                         StyleTestClass s = new StyleTestClass (null);
615                         Assert.IsNotNull (s.StateBag, "StateBag");
616                         s.CssClass = "mono";
617                         Assert.AreEqual ("mono", s.CssClass, "CssClass");
618                 }
619
620                 [Test]
621                 public void Empty ()
622                 {
623                         StyleTestClass s = new StyleTestClass ();
624                         Assert.IsTrue (s.Empty, "Empty");
625                         Assert.AreEqual (0, s.StateBag.Count, "Count");
626                         s.StateBag["Mono"] = "go!";
627                         Assert.IsTrue (s.Empty, "Still Empty");
628                         Assert.AreEqual (1, s.StateBag.Count, "Count");
629                 }
630
631                 [Test]
632                 public void FontInfo_Empty ()
633                 {
634                         FontInfo f;
635                         StyleTestClass s = new StyleTestClass ();
636                         f = s.Font;
637                         Assert.IsTrue (s.Empty, "Empty after getter");
638                         s.Font.Name = "Arial";
639                         Assert.IsFalse (s.Empty, "No longer empty");
640                 }
641                 
642                 [Test]
643                 public void SetBitCalledWhenSetProperty () {
644                         StyleTestClass s = new StyleTestClass ();
645
646                         s.SetBitCalledFlag = false;
647                         s.BackColor = Color.Aqua;
648                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : BackColor");
649                         Assert.AreEqual (0x08, s.SetBitCalledValue, "SetBit() was called with wrong argument : BackColor");
650
651                         s.SetBitCalledFlag = false;
652                         s.BorderColor = Color.Blue;
653                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : BorderColor");
654                         Assert.AreEqual (0x10, s.SetBitCalledValue, "SetBit() was called with wrong argument : BorderColor");
655
656                         s.SetBitCalledFlag = false;
657                         s.BorderStyle = BorderStyle.Dashed;
658                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : BorderStyle");
659                         Assert.AreEqual (0x40, s.SetBitCalledValue, "SetBit() was called with wrong argument : BorderStyle");
660
661                         s.SetBitCalledFlag = false;
662                         s.BorderWidth = 1;
663                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : BorderWidth");
664                         Assert.AreEqual (0x20, s.SetBitCalledValue, "SetBit() was called with wrong argument : BorderWidth");
665
666                         s.SetBitCalledFlag = false;
667                         s.CssClass = "class";
668                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : CssClass");
669                         Assert.AreEqual (0x02, s.SetBitCalledValue, "SetBit() was called with wrong argument : CssClass");
670
671                         s.SetBitCalledFlag = false;
672                         s.ForeColor = Color.Red;
673                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : ForeColor");
674                         Assert.AreEqual (0x04, s.SetBitCalledValue, "SetBit() was called with wrong argument : ForeColor");
675
676                         s.SetBitCalledFlag = false;
677                         s.Height = 1;
678                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Height");
679                         Assert.AreEqual (0x80, s.SetBitCalledValue, "SetBit() was called with wrong argument : Height");
680
681                         s.SetBitCalledFlag = false;
682                         s.Width = 1;
683                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Width");
684                         Assert.AreEqual (0x100, s.SetBitCalledValue, "SetBit() was called with wrong argument : Width");
685                         
686                         s.SetBitCalledFlag = false;
687                         s.Font.Bold = true;
688                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Font.Bold");
689                         Assert.AreEqual (0x800, s.SetBitCalledValue, "SetBit() was called with wrong argument : Font.Bold");
690
691                         s.SetBitCalledFlag = false;
692                         s.Font.Italic = true;
693                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Font.Italic");
694                         Assert.AreEqual (0x1000, s.SetBitCalledValue, "SetBit() was called with wrong argument : Font.Italic");
695
696                         s.SetBitCalledFlag = false;
697                         s.Font.Overline = true;
698                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Font.Overline");
699                         Assert.AreEqual (0x4000, s.SetBitCalledValue, "SetBit() was called with wrong argument : Font.Overline");
700
701                         s.SetBitCalledFlag = false;
702                         s.Font.Underline = true;
703                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Font.Underline");
704                         Assert.AreEqual (0x2000, s.SetBitCalledValue, "SetBit() was called with wrong argument : Font.Underline");
705
706                         s.SetBitCalledFlag = false;
707                         s.Font.Strikeout = true;
708                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Font.Strikeout");
709                         Assert.AreEqual (0x8000, s.SetBitCalledValue, "SetBit() was called with wrong argument : Font.Strikeout");
710
711                         s.SetBitCalledFlag = false;
712                         s.Font.Names = new string [] { "Arial" };
713                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Font.Names");
714                         Assert.AreEqual (0x200, s.SetBitCalledValue, "SetBit() was called with wrong argument : Font.Strikeout");
715
716                         s.SetBitCalledFlag = false;
717                         s.Font.Size = new FontUnit (10);
718                         Assert.IsTrue (s.SetBitCalledFlag, "SetBit() was not called : Font.Size");
719                         Assert.AreEqual (0x400, s.SetBitCalledValue, "SetBit() was called with wrong argument : Font.Size");
720                 }
721
722                 public void Render ()
723                 {
724                         HtmlTextWriter  writer;
725                         StyleTestClass  s;
726
727                         writer = StyleTest.GetWriter();
728                         s  = new StyleTestClass ();
729
730                         s.BorderColor = Color.BlueViolet;
731                         s.AddAttributesToRender(writer);
732                         // Figure out an order-independent way to verify rendered results
733                 }
734 #if NET_2_0
735                 class PokerStyle : Style
736                 {
737                         public IUrlResolutionService UrlResolver;
738
739                         protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
740                         {
741                                 UrlResolver = urlResolver;
742                                 base.FillStyleAttributes (attributes, urlResolver);
743                         }
744                 }
745                 
746                 class PokerWebControl : WebControl
747                 {
748                         protected override Style CreateControlStyle ()
749                         {
750                                 return new PokerStyle ();
751                         }
752                 }
753
754                 [Test]
755                 public void FillStyleAttributes_UrlResolver ()
756                 {
757                         PokerWebControl c = new PokerWebControl ();
758                         c.BackColor = Color.AliceBlue;
759                         c.RenderControl (new HtmlTextWriter (new StringWriter ()));
760
761                         Assert.AreEqual (c, ((PokerStyle) c.ControlStyle).UrlResolver);
762                 }
763
764 #endif
765         }
766 }