* Test/System.Windows.Forms/TestHelper.cs: Inconsistent eol fixes and
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / TestImageIndexConverter.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) 2004 Novell, Inc.
21 //
22 // Authors:
23 //      Ravindra (rkumar@novell.com)
24 //
25 //
26
27 using NUnit.Framework;
28 using System;
29 using System.ComponentModel;
30 using System.Windows.Forms;
31 using System.Globalization;
32
33 namespace MonoTests.System.Windows.Forms
34 {
35         [TestFixture]   
36         [Ignore ("This test has to be completly reviewed")]     
37         public class ImageIndexConverterTest : TestHelper
38         {
39                 ToolBarButton button;
40                 PropertyDescriptorCollection pdc;
41                 ImageIndexConverter ic;
42
43                 public ImageIndexConverterTest ()
44                 {
45                         button = new ToolBarButton ();
46                         pdc = TypeDescriptor.GetProperties (button);
47                         ic = (ImageIndexConverter) pdc.Find ("ImageIndex", true).Converter;
48                 }
49
50                 [Test]
51                 public void TestCanConvertFrom ()
52                 {
53                         Assert.IsFalse (ic.CanConvertFrom (typeof (byte)), "CanConvertFromByte must be false.");
54                         Assert.IsFalse (ic.CanConvertFrom (typeof (char)), "CanConvertFromChar must be false.");
55                         Assert.IsFalse (ic.CanConvertFrom (typeof (int)), "CanConvertFromInt must be false.");
56                         Assert.IsFalse (ic.CanConvertFrom (typeof (float)), "CanConvertFromFloat must be false.");
57                         Assert.IsFalse (ic.CanConvertFrom (typeof (long)), "CanConvertFromLong must be false.");
58                         Assert.IsFalse (ic.CanConvertFrom (typeof (double)), "CanConvertFromDouble must be false.");
59                         Assert.IsTrue (ic.CanConvertFrom (typeof (string)), "CanConvertFromString must be true.");
60                         Assert.IsFalse (ic.CanConvertFrom (typeof (object)), "CanConvertFromObject must be false.");
61                 }
62
63                 [Test]
64                 public void TestCanConvertTo ()
65                 {
66                         Assert.IsTrue (ic.CanConvertTo (typeof (byte)), "CanConvertToByte must be true.");
67                         Assert.IsTrue (ic.CanConvertTo (typeof (char)), "CanConvertToChar must be true.");
68                         Assert.IsTrue (ic.CanConvertTo (typeof (int)), "CanConvertToInt must be true.");
69                         Assert.IsTrue (ic.CanConvertTo (typeof (float)), "CanConvertToFloat must be true.");
70                         Assert.IsTrue (ic.CanConvertTo (typeof (long)), "CanConvertToLong must be true.");
71                         Assert.IsTrue (ic.CanConvertTo (typeof (double)), "CanConvertToDouble must be true.");
72                         Assert.IsTrue (ic.CanConvertTo (typeof (string)), "CanConvertToString must be true.");
73                         Assert.IsFalse (ic.CanConvertTo (typeof (object)), "CanConvertToObject must be false.");
74                 }
75
76                 [Test]
77                 public void TestConvertFrom ()
78                 {
79                         Assert.AreEqual (-12, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "-12"), "ConvertFromStr -12");
80                         Assert.AreEqual (-1, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "-1"), "ConvertFromStr -1");
81                         Assert.AreEqual (1, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "1"), "ConvertFromStr 1");
82
83                         try {
84                                 ic.ConvertFrom (null, CultureInfo.InvariantCulture, 1.2f);
85                                 Assert.Fail ("ConvertFromFloat did not throw exception.");
86                         } catch (Exception e) {
87                                 Assert.IsTrue (e is NotSupportedException, "ConvertFromFloat did not throw NotSupportedException.");
88                         }
89
90                         try {
91                                 ic.ConvertFrom (null, CultureInfo.InvariantCulture, 1);
92                                 Assert.Fail ("ConvertFromInt did not throw exception.");
93                         } catch (Exception e) {
94                                 Assert.IsTrue (e is NotSupportedException, "ConvertFromInt did not throw NotSupportedException.");
95                         }
96                 }
97
98                 [Test]
99                 public void TestConvertTo ()
100                 {
101                         Assert.AreEqual ("(none)", ic.ConvertTo (null, CultureInfo.InvariantCulture, -1, typeof (string)), "ConvertInt_Minus1_ToStr");
102                         Assert.AreEqual ("0", ic.ConvertTo (null, CultureInfo.InvariantCulture, 0, typeof (string)), "ConvertInt_0_ToStr");
103                         Assert.AreEqual ("1", ic.ConvertTo (null, CultureInfo.InvariantCulture, 1, typeof (string)), "ConvertInt_1_ToStr");
104                         Assert.AreEqual (0, ic.ConvertTo (null, CultureInfo.InvariantCulture, 0, typeof (int)), "ConvertInt_0_ToInt");
105                         Assert.AreEqual ("(none)", ic.ConvertTo (null, CultureInfo.InvariantCulture, "(none)", typeof (string)), "ConvertStr_none_ToStr");
106                         Assert.AreEqual ("-1", ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1", typeof (string)), "ConvertStr_Minus1_ToStr");
107                         Assert.AreEqual (-1, ic.ConvertTo (null, CultureInfo.InvariantCulture, -1, typeof (int)), "ConvertInt_Minus1_ToInt");
108                         Assert.AreEqual (1, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1, typeof (int)), "ConvertInt_1_ToInt");
109                         Assert.AreEqual (-1, ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1", typeof (int)), "ConvertStr_Minus1_ToInt");
110                         Assert.AreEqual (0, ic.ConvertTo (null, CultureInfo.InvariantCulture, "0", typeof (int)), "ConvertStr_0_ToInt");
111                         Assert.AreEqual (1, ic.ConvertTo (null, CultureInfo.InvariantCulture, "1", typeof (int)), "ConvertStr_1_ToInt");
112
113                         Assert.AreEqual (2, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (int)), "ConvertFloat_1_5_ToInt must return 2.");
114
115                         try {
116                                 ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1.5f", typeof (int));
117                                 Assert.Fail("ConvertFloatStrToInt must throw exception.");
118                         } catch (Exception e) {
119                                 Assert.IsTrue (e is FormatException, "ConvertFloatStrToInt must throw FormatException.");
120                         }
121
122                         Assert.AreEqual (1.5, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (float)), "ConvertFloat_1_5_ToFloat");
123                 }
124
125                 [Test]
126                 public void TestGetCreateInstanceSupported ()
127                 {
128                         Assert.IsFalse (ic.GetCreateInstanceSupported (), "GetCreateInstance must return false.");
129                 }
130
131                 [Test]
132                 public void TestGetStandardValuesSupported ()
133                 {
134                         Assert.IsTrue (ic.GetStandardValuesSupported (), "GetStandardValuesSupported must return true.");
135                 }
136
137                 [Test]
138                 public void TestGetStandardValuesExclusive ()
139                 {
140                         Assert.IsFalse (ic.GetStandardValuesExclusive (), "GetStandardValuesExclusive must return false.");
141                 }
142
143                 [Test]
144                 public void TestGetStandardValues ()
145                 {
146                         TypeConverter.StandardValuesCollection stdVals = ic.GetStandardValues (null);
147                         Assert.AreEqual (1, stdVals.Count, "StandardValues count must be 1.");
148                         Assert.AreEqual (-1, stdVals [0], "Standard Value count must be -1.");
149                 }
150         }
151 }