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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
23 // Ravindra (rkumar@novell.com)
27 using NUnit.Framework;
29 using System.ComponentModel;
30 using System.Windows.Forms;
31 using System.Globalization;
33 namespace MonoTests.System.Windows.Forms
36 [Ignore ("This test has to be completly reviewed")]
37 public class ImageIndexConverterTest : TestHelper
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;
51 public void TestCanConvertFrom ()
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.");
64 public void TestCanConvertTo ()
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.");
77 public void TestConvertFrom ()
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");
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.");
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.");
99 public void TestConvertTo ()
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");
113 Assert.AreEqual (2, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (int)), "ConvertFloat_1_5_ToInt must return 2.");
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.");
122 Assert.AreEqual (1.5, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (float)), "ConvertFloat_1_5_ToFloat");
126 public void TestGetCreateInstanceSupported ()
128 Assert.IsFalse (ic.GetCreateInstanceSupported (), "GetCreateInstance must return false.");
132 public void TestGetStandardValuesSupported ()
134 Assert.IsTrue (ic.GetStandardValuesSupported (), "GetStandardValuesSupported must return true.");
138 public void TestGetStandardValuesExclusive ()
140 Assert.IsFalse (ic.GetStandardValuesExclusive (), "GetStandardValuesExclusive must return false.");
144 public void TestGetStandardValues ()
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.");