PaddingConverterTest.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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) 2006 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 PaddingConverterTest
  33. {
  34. [Test]
  35. public void CanConvertFrom ()
  36. {
  37. PaddingConverter c = new PaddingConverter ();
  38. Assert.IsTrue (c.CanConvertFrom (null, typeof (string)), "1");
  39. Assert.IsFalse (c.CanConvertFrom (null, typeof (int)), "2");
  40. Assert.IsFalse (c.CanConvertFrom (null, typeof (float)), "3");
  41. Assert.IsFalse (c.CanConvertFrom (null, typeof (object)), "4");
  42. }
  43. [Test]
  44. public void CanConvertTo ()
  45. {
  46. PaddingConverter c = new PaddingConverter ();
  47. Assert.IsTrue (c.CanConvertTo (null, typeof (string)), "1");
  48. Assert.IsFalse (c.CanConvertTo (null, typeof (int)), "2");
  49. Assert.IsFalse (c.CanConvertTo (null, typeof (float)), "3");
  50. Assert.IsFalse (c.CanConvertTo (null, typeof (object)), "4");
  51. }
  52. [Test]
  53. public void RoundTrip ()
  54. {
  55. Padding p1 = new Padding (1, 2, 3, 4);
  56. Padding p2 = new Padding (1);
  57. Padding p3 = new Padding ();
  58. Assert.AreEqual (p1, RoundTripPadding (p1), "B1");
  59. Assert.AreEqual (p2, RoundTripPadding (p2), "B2");
  60. Assert.AreEqual (p3, RoundTripPadding (p3), "B3");
  61. }
  62. [Test]
  63. public void ConvertFrom ()
  64. {
  65. string listSeparator = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
  66. PaddingConverter pc = new PaddingConverter ();
  67. Assert.AreEqual (new Padding (1, 2, 3, 4), pc.ConvertFrom (
  68. string.Format ("1{0} 2{0} 3{0} 4", listSeparator)), "A1");
  69. Assert.AreEqual (new Padding (1, 2, 3, 4), pc.ConvertFrom (
  70. string.Format ("1{0}2{0}3{0}4", listSeparator)), "A2");
  71. Assert.AreEqual (new Padding (1, 2, 3, 4), pc.ConvertFrom (
  72. string.Format ("1{0} 2{0} 3{0} 4", listSeparator)), "A3");
  73. Assert.AreEqual (new Padding (1), pc.ConvertFrom (string.Format (
  74. "1{0} 1{0} 1{0} 1", listSeparator)), "A4");
  75. Assert.AreEqual (new Padding (), pc.ConvertFrom (string.Format (
  76. "0{0} 0{0} 0{0} 0", listSeparator)), "A5");
  77. }
  78. [Test]
  79. public void ConvertTo ()
  80. {
  81. PaddingConverter pc = new PaddingConverter ();
  82. Assert.AreEqual (string.Format (CultureInfo.CurrentCulture,
  83. "1{0} 2{0} 3{0} 4", CultureInfo.CurrentCulture.TextInfo.ListSeparator),
  84. (string) pc.ConvertTo (new Padding (1, 2, 3, 4), typeof (string)), "A1");
  85. Assert.AreEqual (string.Format (CultureInfo.CurrentCulture,
  86. "1{0} 1{0} 1{0} 1", CultureInfo.CurrentCulture.TextInfo.ListSeparator),
  87. (string) pc.ConvertTo (new Padding (1), typeof (string)), "A2");
  88. Assert.AreEqual (string.Format (CultureInfo.CurrentCulture,
  89. "0{0} 0{0} 0{0} 0", CultureInfo.CurrentCulture.TextInfo.ListSeparator),
  90. (string) pc.ConvertTo (Padding.Empty, typeof (string)), "A3");
  91. }
  92. private Padding RoundTripPadding (Padding p)
  93. {
  94. PaddingConverter pc = new PaddingConverter ();
  95. string s = (string)pc.ConvertTo (p, typeof (string));
  96. return (Padding)pc.ConvertFrom (s);
  97. }
  98. [Test]
  99. public void CreateInstanceSupported ()
  100. {
  101. PaddingConverter pc = new PaddingConverter ();
  102. Assert.AreEqual (true, pc.GetCreateInstanceSupported (null), "A1");
  103. Assert.AreEqual (true, pc.GetPropertiesSupported (null), "A2");
  104. }
  105. }
  106. }
  107. #endif