2008-11-24 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / DataGridViewCellStyleTest.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 //      Pedro Martínez Juliá <pedromj@gmail.com>
24 //
25
26
27 #if NET_2_0
28
29 using NUnit.Framework;
30 using System;
31 using System.Drawing;
32 using System.Windows.Forms;
33 using System.ComponentModel;
34 using System.Collections;
35 using System.Globalization;
36 using System.Threading;
37
38 namespace MonoTests.System.Windows.Forms {
39
40         [TestFixture]
41         public class DataGridViewCellStyleTest  : TestHelper {
42
43                 DataGridViewCellStyle style;
44                 
45                 [SetUp]
46                 protected override void SetUp () {
47                         style = new DataGridViewCellStyle();
48                         base.SetUp ();
49                 }
50
51                 [Test]
52                 public void TestDefaultValues () {
53                         Assert.AreEqual (DataGridViewContentAlignment.NotSet, style.Alignment, "#A1");
54                         Assert.AreEqual (Color.Empty, style.BackColor, "#A2");
55                         Assert.AreEqual (null, style.Font, "#A3");
56                         Assert.AreEqual (Color.Empty, style.ForeColor, "#A4");
57                         Assert.AreEqual (String.Empty, style.Format, "#A5");
58                         Assert.AreEqual (true, style.IsNullValueDefault, "#A8");
59                         Assert.AreEqual (string.Empty, style.NullValue, "#A9");
60                         Assert.AreEqual (Color.Empty, style.SelectionBackColor, "#A10");
61                         Assert.AreEqual (Color.Empty, style.SelectionForeColor, "#A11");
62                         Assert.AreEqual (null, style.Tag, "#A12");
63                         Assert.AreEqual (DataGridViewTriState.NotSet, style.WrapMode, "#A13");
64                 }
65
66                 [Test]
67                 public void TestApplyStyle () {
68                         DataGridViewCellStyle style_aux = new DataGridViewCellStyle();
69                         style.ApplyStyle(style_aux);
70                         Assert.AreEqual (style_aux, style, "#B1");
71                 }
72
73                 [Test]
74                 public void TestClone () {
75                         DataGridViewCellStyle style_aux = (DataGridViewCellStyle) style.Clone();
76                         Assert.AreEqual (style_aux, style, "#C1");
77                 }
78
79                 [Test]
80                 public void TestEquals () {
81                         DataGridViewCellStyle style_aux = (DataGridViewCellStyle) style.Clone();
82                         Assert.AreEqual (true, (style_aux.Equals(style)), "#D1");
83                 }
84
85                 [Test]
86                 [ExpectedException(typeof(InvalidEnumArgumentException))]
87                 public void TestAlignmentInvalidEnumArgumentException () {
88                         style.Alignment = DataGridViewContentAlignment.BottomCenter | DataGridViewContentAlignment.BottomRight;
89                 }
90
91                 [Test]
92                 [ExpectedException(typeof(InvalidEnumArgumentException))]
93                 public void TestWrapModeInvalidEnumArgumentException () {
94                         style.WrapMode = (DataGridViewTriState) 3;
95                 }
96
97                 [Test]
98                 public void FormatProvider ()
99                 {
100                         CultureInfo orignalCulture = CultureInfo.CurrentCulture;
101                         CultureInfo orignalUICulture = CultureInfo.CurrentUICulture;
102
103                         try {
104                                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
105                                 Thread.CurrentThread.CurrentUICulture = new CultureInfo ("ja-JP");
106                                 Assert.AreSame (CultureInfo.CurrentCulture, style.FormatProvider, "#1");
107                                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("fr-FR");
108                                 Assert.AreSame (CultureInfo.CurrentCulture, style.FormatProvider, "#2");
109                                 style.FormatProvider = CultureInfo.CurrentCulture;
110                                 Assert.AreSame (CultureInfo.CurrentCulture, style.FormatProvider, "#3");
111                                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
112                                 Assert.AreEqual (new CultureInfo ("fr-FR"), style.FormatProvider, "#4");
113                                 style.FormatProvider = null;
114                                 Assert.AreSame (CultureInfo.CurrentCulture, style.FormatProvider, "#5");
115                         } finally {
116                                 Thread.CurrentThread.CurrentCulture = orignalCulture;
117                                 Thread.CurrentThread.CurrentUICulture = orignalUICulture;
118                         }
119                 }
120
121                 [Test]
122                 public void IsFormatProviderDefault ()
123                 {
124                         CultureInfo orignalCulture = CultureInfo.CurrentCulture;
125
126                         try {
127                                 Assert.IsTrue (style.IsFormatProviderDefault, "#1");
128                                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE");
129                                 Assert.IsTrue (style.IsFormatProviderDefault, "#2");
130                                 Thread.CurrentThread.CurrentCulture = new CultureInfo ("fr-FR");
131                                 Assert.IsTrue (style.IsFormatProviderDefault, "#3");
132                                 style.FormatProvider = CultureInfo.CurrentCulture;
133                                 Assert.IsFalse (style.IsFormatProviderDefault, "#4");
134                                 style.FormatProvider = new CultureInfo ("en-US");
135                                 Assert.IsFalse (style.IsFormatProviderDefault, "#5");
136                                 style.FormatProvider = null;
137                                 Assert.IsTrue (style.IsFormatProviderDefault, "#6");
138                         } finally {
139                                 Thread.CurrentThread.CurrentCulture = orignalCulture;
140                         }
141                 }
142         }
143 }
144
145 #endif