ImageKeyConverterTest.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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) 2007 Novell, Inc.
  21. //
  22. #if NET_2_0
  23. using System;
  24. using System.ComponentModel;
  25. using System.Globalization;
  26. using System.Windows.Forms;
  27. using System.Windows.Forms.Layout;
  28. using NUnit.Framework;
  29. namespace MonoTests.System.Windows.Forms
  30. {
  31. [TestFixture]
  32. public class ImageKeyConverterTest : TestHelper
  33. {
  34. [Test]
  35. public void PropertyIncludeNoneAsStandardValue ()
  36. {
  37. PublicImageKeyConverter c = new PublicImageKeyConverter ();
  38. Assert.AreEqual (true, c.PublicIncludeNoneAsStandardValue, "A1");
  39. }
  40. private class PublicImageKeyConverter : ImageKeyConverter
  41. {
  42. public bool PublicIncludeNoneAsStandardValue { get { return base.IncludeNoneAsStandardValue; } }
  43. }
  44. [Test]
  45. public void GetStandardValues ()
  46. {
  47. ImageKeyConverter c = new ImageKeyConverter ();
  48. Assert.AreEqual (1, c.GetStandardValues (null).Count, "B1");
  49. Assert.AreEqual (string.Empty, c.GetStandardValues (null)[0].ToString (), "B2");
  50. }
  51. [Test]
  52. public void GetStandardValuesExclusive ()
  53. {
  54. ImageKeyConverter c = new ImageKeyConverter ();
  55. Assert.AreEqual (true, c.GetStandardValuesExclusive (null), "C1");
  56. }
  57. [Test]
  58. public void GetStandardValuesSupported ()
  59. {
  60. ImageKeyConverter c = new ImageKeyConverter ();
  61. Assert.AreEqual (true, c.GetStandardValuesSupported (null), "D1");
  62. }
  63. [Test]
  64. public void CanConvertFrom ()
  65. {
  66. ImageKeyConverter c = new ImageKeyConverter ();
  67. Assert.IsTrue (c.CanConvertFrom (null, typeof (string)), "1");
  68. Assert.IsFalse (c.CanConvertFrom (null, typeof (int)), "2");
  69. Assert.IsFalse (c.CanConvertFrom (null, typeof (float)), "3");
  70. Assert.IsFalse (c.CanConvertFrom (null, typeof (object)), "4");
  71. }
  72. [Test]
  73. public void ConvertFrom ()
  74. {
  75. ImageKeyConverter ikc = new ImageKeyConverter ();
  76. Assert.AreEqual (string.Empty, ikc.ConvertFrom (null, null, string.Empty), "N1");
  77. Assert.AreEqual (string.Empty, ikc.ConvertFrom (null, null, null), "N2");
  78. Assert.AreEqual ("(none)", ikc.ConvertFrom (null, null, "(none)"), "N2-1");
  79. Assert.AreEqual ("bob", ikc.ConvertFrom (null, null, "bob"), "N3");
  80. Assert.AreEqual ("oSCar", ikc.ConvertFrom (null, null, "oSCar"), "N4");
  81. }
  82. [Test]
  83. public void ConvertTo ()
  84. {
  85. ImageKeyConverter ikc = new ImageKeyConverter ();
  86. Assert.AreEqual ("(none)", ikc.ConvertTo (null, null, string.Empty, typeof (string)), "N1");
  87. Assert.AreEqual ("(none)", ikc.ConvertTo (null, null, null, typeof (string)), "N2");
  88. Assert.AreEqual ("(none)", ikc.ConvertTo (null, null, "(none)", typeof (string)), "N2-1");
  89. Assert.AreEqual ("bob", ikc.ConvertTo (null, null, "bob", typeof (string)), "N3");
  90. Assert.AreEqual ("oSCar", ikc.ConvertTo (null, null, "oSCar", typeof (string)), "N4");
  91. }
  92. }
  93. }
  94. #endif