2007-01-10 Chris Toshok <toshok@ximian.com>
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / TestImageIndexConverter.cs
blob679dcef4ea27ac1e1edba4331dcba9a1ce4a4198
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.
20 // Copyright (c) 2004 Novell, Inc.
22 // Authors:
23 // Ravindra (rkumar@novell.com)
27 using NUnit.Framework;
28 using System;
29 using System.ComponentModel;
30 using System.Windows.Forms;
31 using System.Globalization;
33 namespace MonoTests.System.Windows.Forms
35 [TestFixture]
36 [Ignore ("This test has to be completly reviewed")]
37 public class ImageIndexConverterTest
39 ToolBarButton button;
40 PropertyDescriptorCollection pdc;
41 ImageIndexConverter ic;
43 public ImageIndexConverterTest ()
45 button = new ToolBarButton ();
46 pdc = TypeDescriptor.GetProperties (button);
47 ic = (ImageIndexConverter) pdc.Find ("ImageIndex", true).Converter;
50 [TearDown]
51 public void TearDown () { }
53 [SetUp]
54 public void SetUp () { }
56 [Test]
57 public void TestCanConvertFrom ()
59 Assert.IsFalse (ic.CanConvertFrom (typeof (byte)), "CanConvertFromByte must be false.");
60 Assert.IsFalse (ic.CanConvertFrom (typeof (char)), "CanConvertFromChar must be false.");
61 Assert.IsFalse (ic.CanConvertFrom (typeof (int)), "CanConvertFromInt must be false.");
62 Assert.IsFalse (ic.CanConvertFrom (typeof (float)), "CanConvertFromFloat must be false.");
63 Assert.IsFalse (ic.CanConvertFrom (typeof (long)), "CanConvertFromLong must be false.");
64 Assert.IsFalse (ic.CanConvertFrom (typeof (double)), "CanConvertFromDouble must be false.");
65 Assert.IsTrue (ic.CanConvertFrom (typeof (string)), "CanConvertFromString must be true.");
66 Assert.IsFalse (ic.CanConvertFrom (typeof (object)), "CanConvertFromObject must be false.");
69 [Test]
70 public void TestCanConvertTo ()
72 Assert.IsTrue (ic.CanConvertTo (typeof (byte)), "CanConvertToByte must be true.");
73 Assert.IsTrue (ic.CanConvertTo (typeof (char)), "CanConvertToChar must be true.");
74 Assert.IsTrue (ic.CanConvertTo (typeof (int)), "CanConvertToInt must be true.");
75 Assert.IsTrue (ic.CanConvertTo (typeof (float)), "CanConvertToFloat must be true.");
76 Assert.IsTrue (ic.CanConvertTo (typeof (long)), "CanConvertToLong must be true.");
77 Assert.IsTrue (ic.CanConvertTo (typeof (double)), "CanConvertToDouble must be true.");
78 Assert.IsTrue (ic.CanConvertTo (typeof (string)), "CanConvertToString must be true.");
79 Assert.IsFalse (ic.CanConvertTo (typeof (object)), "CanConvertToObject must be false.");
82 [Test]
83 public void TestConvertFrom ()
85 Assert.AreEqual (-12, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "-12"), "ConvertFromStr -12");
86 Assert.AreEqual (-1, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "-1"), "ConvertFromStr -1");
87 Assert.AreEqual (1, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "1"), "ConvertFromStr 1");
89 try {
90 ic.ConvertFrom (null, CultureInfo.InvariantCulture, 1.2f);
91 Assert.Fail ("ConvertFromFloat did not throw exception.");
92 } catch (Exception e) {
93 Assert.IsTrue (e is NotSupportedException, "ConvertFromFloat did not throw NotSupportedException.");
96 try {
97 ic.ConvertFrom (null, CultureInfo.InvariantCulture, 1);
98 Assert.Fail ("ConvertFromInt did not throw exception.");
99 } catch (Exception e) {
100 Assert.IsTrue (e is NotSupportedException, "ConvertFromInt did not throw NotSupportedException.");
104 [Test]
105 public void TestConvertTo ()
107 Assert.AreEqual ("(none)", ic.ConvertTo (null, CultureInfo.InvariantCulture, -1, typeof (string)), "ConvertInt_Minus1_ToStr");
108 Assert.AreEqual ("0", ic.ConvertTo (null, CultureInfo.InvariantCulture, 0, typeof (string)), "ConvertInt_0_ToStr");
109 Assert.AreEqual ("1", ic.ConvertTo (null, CultureInfo.InvariantCulture, 1, typeof (string)), "ConvertInt_1_ToStr");
110 Assert.AreEqual (0, ic.ConvertTo (null, CultureInfo.InvariantCulture, 0, typeof (int)), "ConvertInt_0_ToInt");
111 Assert.AreEqual ("(none)", ic.ConvertTo (null, CultureInfo.InvariantCulture, "(none)", typeof (string)), "ConvertStr_none_ToStr");
112 Assert.AreEqual ("-1", ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1", typeof (string)), "ConvertStr_Minus1_ToStr");
113 Assert.AreEqual (-1, ic.ConvertTo (null, CultureInfo.InvariantCulture, -1, typeof (int)), "ConvertInt_Minus1_ToInt");
114 Assert.AreEqual (1, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1, typeof (int)), "ConvertInt_1_ToInt");
115 Assert.AreEqual (-1, ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1", typeof (int)), "ConvertStr_Minus1_ToInt");
116 Assert.AreEqual (0, ic.ConvertTo (null, CultureInfo.InvariantCulture, "0", typeof (int)), "ConvertStr_0_ToInt");
117 Assert.AreEqual (1, ic.ConvertTo (null, CultureInfo.InvariantCulture, "1", typeof (int)), "ConvertStr_1_ToInt");
119 Assert.AreEqual (2, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (int)), "ConvertFloat_1_5_ToInt must return 2.");
121 try {
122 ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1.5f", typeof (int));
123 Assert.Fail("ConvertFloatStrToInt must throw exception.");
124 } catch (Exception e) {
125 Assert.IsTrue (e is FormatException, "ConvertFloatStrToInt must throw FormatException.");
128 Assert.AreEqual (1.5, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (float)), "ConvertFloat_1_5_ToFloat");
131 [Test]
132 public void TestGetCreateInstanceSupported ()
134 Assert.IsFalse (ic.GetCreateInstanceSupported (), "GetCreateInstance must return false.");
137 [Test]
138 public void TestGetStandardValuesSupported ()
140 Assert.IsTrue (ic.GetStandardValuesSupported (), "GetStandardValuesSupported must return true.");
143 [Test]
144 public void TestGetStandardValuesExclusive ()
146 Assert.IsFalse (ic.GetStandardValuesExclusive (), "GetStandardValuesExclusive must return false.");
149 [Test]
150 public void TestGetStandardValues ()
152 TypeConverter.StandardValuesCollection stdVals = ic.GetStandardValues (null);
153 Assert.AreEqual (1, stdVals.Count, "StandardValues count must be 1.");
154 Assert.AreEqual (-1, stdVals [0], "Standard Value count must be -1.");