FontNamesConverterTest.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // Tests for System.Web.UI.WebControls.Style.cs
  3. //
  4. // Author:
  5. // Peter Dennis Bartok ([email protected])
  6. //
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.Drawing;
  33. using System.IO;
  34. using System.Globalization;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.UI.WebControls;
  38. namespace MonoTests.System.Web.UI.WebControls
  39. {
  40. [TestFixture]
  41. public class FontNamesConverterTest {
  42. [Test]
  43. public void Basic ()
  44. {
  45. FontNamesConverter conv;
  46. string[] name_array;
  47. string name_list;
  48. conv = new FontNamesConverter();
  49. name_array = new string[] { "Arial", "Courier" };
  50. name_list = "Arial,Courier";
  51. Assert.AreEqual (true, conv.CanConvertFrom(null, typeof(string)), "B1");
  52. Assert.AreEqual (true, conv.CanConvertTo(null, typeof(string)), "B2");
  53. Assert.AreEqual (false, conv.CanConvertFrom(null, typeof(string[])), "B3");
  54. Assert.AreEqual (false, conv.CanConvertTo(null, typeof(string[])), "B4");
  55. Assert.AreEqual (false, conv.CanConvertFrom(null, typeof(int)), "B5");
  56. Assert.AreEqual (false, conv.CanConvertTo(null, typeof(int)), "B6");
  57. // ASP.NET in a Nutshell 2nd Edition (O'Reilly), pg855:
  58. // FontNamesConverter converts between a font name array and a string that contains a
  59. // list of font names separated by comma.
  60. // Why does the CanConvertFrom() and CanConvertTo() then indicate that it cannot handle string[]???
  61. // It obviously works:
  62. Assert.AreEqual (name_array, conv.ConvertFrom(null, null, name_list), "B7");
  63. Assert.AreEqual (name_list, conv.ConvertTo(null, null, name_array, typeof(string)), "B8");
  64. // Special cases
  65. Assert.AreEqual ("", conv.ConvertTo(null, null, new string[0], typeof(string)), "B9");
  66. Assert.AreEqual ("", conv.ConvertTo(null, null, null, typeof(string)), "B10");
  67. Assert.AreEqual (new string[0], conv.ConvertFrom(null, null, ""), "B11");
  68. // Roundtrip
  69. Assert.AreEqual (name_list, conv.ConvertTo(null, null, conv.ConvertFrom(null, null, name_list), typeof(string)), "B12");
  70. // Whitespace (leading and trailing)
  71. Assert.AreEqual (name_array, conv.ConvertFrom(null, null, "Arial, Courier"), "B13");
  72. Assert.AreEqual (new string[] { "Arial\nCourier" }, conv.ConvertFrom(null, null, "Arial\nCourier\n"), "B14");
  73. Assert.AreEqual (name_array, conv.ConvertFrom(null, null, "Arial,\nCourier\r\n"), "B15");
  74. Assert.AreEqual (new string[] { "Arial", "Courier" }, conv.ConvertFrom(null, null, "Arial\n,\nCourier\n"), "B16");
  75. // This is stupid behaviour and prevents roundtripping; why trim in ConvertFrom and not in ConvertTo?
  76. Assert.AreEqual ("Arial\n,Courier\n", conv.ConvertTo(null, null, new string[] { "Arial\n", "Courier\n" }, typeof(string)), "B17");
  77. Assert.AreEqual ("Arial,\n,Courier\n", conv.ConvertTo(null, null, new string[] { "Arial,\n", "Courier\n" }, typeof(string)), "B18");
  78. }
  79. }
  80. }