(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / TestImageIndexConverter.cs
blob6ec68d48a0e162efe598c0cedd6a7d1174354ce6
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)
25 // $Revision: 1.1 $
26 // $Modtime: $
27 // $Log: TestImageIndexConverter.cs,v $
28 // Revision 1.1 2004/08/27 22:17:37 ravindra
29 // Adding test for ImageIndexConverter.cs
34 using NUnit.Framework;
35 using System;
36 using System.ComponentModel;
37 using System.Windows.Forms;
38 using System.Globalization;
40 namespace MonoTests.System.Windows.Forms
42 [TestFixture]
43 public class ImageIndexConverterTest
45 ToolBarButton button;
46 PropertyDescriptorCollection pdc;
47 ImageIndexConverter ic;
49 public ImageIndexConverterTest ()
51 button = new ToolBarButton ();
52 pdc = TypeDescriptor.GetProperties (button);
53 ic = (ImageIndexConverter) pdc.Find ("ImageIndex", true).Converter;
56 [TearDown]
57 public void TearDown () { }
59 [SetUp]
60 public void SetUp () { }
62 [Test]
63 public void TestCanConvertFrom ()
65 Assert.IsFalse (ic.CanConvertFrom (typeof (byte)), "CanConvertFromByte must be false.");
66 Assert.IsFalse (ic.CanConvertFrom (typeof (char)), "CanConvertFromChar must be false.");
67 Assert.IsFalse (ic.CanConvertFrom (typeof (int)), "CanConvertFromInt must be false.");
68 Assert.IsFalse (ic.CanConvertFrom (typeof (float)), "CanConvertFromFloat must be false.");
69 Assert.IsFalse (ic.CanConvertFrom (typeof (long)), "CanConvertFromLong must be false.");
70 Assert.IsFalse (ic.CanConvertFrom (typeof (double)), "CanConvertFromDouble must be false.");
71 Assert.IsTrue (ic.CanConvertFrom (typeof (string)), "CanConvertFromString must be true.");
72 Assert.IsFalse (ic.CanConvertFrom (typeof (object)), "CanConvertFromObject must be false.");
75 [Test]
76 public void TestCanConvertTo ()
78 Assert.IsTrue (ic.CanConvertTo (typeof (byte)), "CanConvertToByte must be true.");
79 Assert.IsTrue (ic.CanConvertTo (typeof (char)), "CanConvertToChar must be true.");
80 Assert.IsTrue (ic.CanConvertTo (typeof (int)), "CanConvertToInt must be true.");
81 Assert.IsTrue (ic.CanConvertTo (typeof (float)), "CanConvertToFloat must be true.");
82 Assert.IsTrue (ic.CanConvertTo (typeof (long)), "CanConvertToLong must be true.");
83 Assert.IsTrue (ic.CanConvertTo (typeof (double)), "CanConvertToDouble must be true.");
84 Assert.IsTrue (ic.CanConvertTo (typeof (string)), "CanConvertToString must be true.");
85 Assert.IsFalse (ic.CanConvertTo (typeof (object)), "CanConvertToObject must be false.");
88 [Test]
89 public void TestConvertFrom ()
91 Assert.AreEqual (-12, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "-12"), "ConvertFromStr -12");
92 Assert.AreEqual (-1, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "-1"), "ConvertFromStr -1");
93 Assert.AreEqual (1, (int) ic.ConvertFrom (null, CultureInfo.InvariantCulture, "1"), "ConvertFromStr 1");
95 try {
96 ic.ConvertFrom (null, CultureInfo.InvariantCulture, 1.2f);
97 Assert.Fail ("ConvertFromFloat did not throw exception.");
98 } catch (Exception e) {
99 Assert.IsTrue (e is NotSupportedException, "ConvertFromFloat did not throw NotSupportedException.");
102 try {
103 ic.ConvertFrom (null, CultureInfo.InvariantCulture, 1);
104 Assert.Fail ("ConvertFromInt did not throw exception.");
105 } catch (Exception e) {
106 Assert.IsTrue (e is NotSupportedException, "ConvertFromInt did not throw NotSupportedException.");
110 [Test]
111 public void TestConvertTo ()
113 Assert.AreEqual ("(none)", ic.ConvertTo (null, CultureInfo.InvariantCulture, -1, typeof (string)), "ConvertInt_Minus1_ToStr");
114 Assert.AreEqual ("0", ic.ConvertTo (null, CultureInfo.InvariantCulture, 0, typeof (string)), "ConvertInt_0_ToStr");
115 Assert.AreEqual ("1", ic.ConvertTo (null, CultureInfo.InvariantCulture, 1, typeof (string)), "ConvertInt_1_ToStr");
116 Assert.AreEqual (0, ic.ConvertTo (null, CultureInfo.InvariantCulture, 0, typeof (int)), "ConvertInt_0_ToInt");
117 Assert.AreEqual ("(none)", ic.ConvertTo (null, CultureInfo.InvariantCulture, "(none)", typeof (string)), "ConvertStr_none_ToStr");
118 Assert.AreEqual ("-1", ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1", typeof (string)), "ConvertStr_Minus1_ToStr");
119 Assert.AreEqual (-1, ic.ConvertTo (null, CultureInfo.InvariantCulture, -1, typeof (int)), "ConvertInt_Minus1_ToInt");
120 Assert.AreEqual (1, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1, typeof (int)), "ConvertInt_1_ToInt");
121 Assert.AreEqual (-1, ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1", typeof (int)), "ConvertStr_Minus1_ToInt");
122 Assert.AreEqual (0, ic.ConvertTo (null, CultureInfo.InvariantCulture, "0", typeof (int)), "ConvertStr_0_ToInt");
123 Assert.AreEqual (1, ic.ConvertTo (null, CultureInfo.InvariantCulture, "1", typeof (int)), "ConvertStr_1_ToInt");
125 Assert.AreEqual (2, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (int)), "ConvertFloat_1_5_ToInt must return 2.");
127 try {
128 ic.ConvertTo (null, CultureInfo.InvariantCulture, "-1.5f", typeof (int));
129 Assert.Fail("ConvertFloatStrToInt must throw exception.");
130 } catch (Exception e) {
131 Assert.IsTrue (e is FormatException, "ConvertFloatStrToInt must throw FormatException.");
134 Assert.AreEqual (1.5, ic.ConvertTo (null, CultureInfo.InvariantCulture, 1.5f, typeof (float)), "ConvertFloat_1_5_ToFloat");
137 [Test]
138 public void TestGetCreateInstanceSupported ()
140 Assert.IsFalse (ic.GetCreateInstanceSupported (), "GetCreateInstance must return false.");
143 [Test]
144 public void TestGetStandardValuesSupported ()
146 Assert.IsTrue (ic.GetStandardValuesSupported (), "GetStandardValuesSupported must return true.");
149 [Test]
150 public void TestGetStandardValuesExclusive ()
152 Assert.IsFalse (ic.GetStandardValuesExclusive (), "GetStandardValuesExclusive must return false.");
155 [Test]
156 public void TestGetStandardValues ()
158 TypeConverter.StandardValuesCollection stdVals = ic.GetStandardValues (null);
159 Assert.AreEqual (1, stdVals.Count, "StandardValues count must be 1.");
160 Assert.AreEqual (-1, stdVals [0], "Standard Value count must be -1.");