TestIcon.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // Icon class testing unit
  3. //
  4. // Author:
  5. //
  6. // Sanjay Gupta <[email protected]>
  7. //
  8. //
  9. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Drawing;
  32. using NUnit.Framework;
  33. using System.IO;
  34. namespace MonoTests.System.Drawing{
  35. [TestFixture]
  36. public class TestIcon {
  37. Icon icon;
  38. Icon newIcon;
  39. FileStream fs;
  40. FileStream fs1;
  41. [SetUp]
  42. public void SetUp ()
  43. {
  44. String path = TestBitmap.getInFile ("bitmaps/smiley.ico");
  45. icon = new Icon (path);
  46. fs1 = new FileStream (path, FileMode.Open);
  47. }
  48. [Test]
  49. public void TestConstructors ()
  50. {
  51. newIcon = new Icon (fs1, 48, 48);
  52. Assert.AreEqual (48, newIcon.Height, "C#1a");
  53. Assert.AreEqual (48, newIcon.Width, "C#1b");
  54. newIcon = new Icon (icon, 16, 16);
  55. Assert.AreEqual (16, newIcon.Height, "C#2a");
  56. Assert.AreEqual (16, newIcon.Width, "C#2b");
  57. }
  58. [Test]
  59. public void TestProperties ()
  60. {
  61. Assert.AreEqual (32, icon.Height, "P#1");
  62. Assert.AreEqual (32, icon.Width, "P#2");
  63. Assert.AreEqual (32, icon.Size.Width, "P#3");
  64. Assert.AreEqual (32, icon.Size.Height, "P#4");
  65. }
  66. [Test]
  67. public void TestMethods ()
  68. {
  69. /*
  70. TODO: This does not work on Win32
  71. newIcon = (Icon) icon.Clone ();
  72. Assert.AreEqual (32, newIcon.Height, "M#1a");
  73. Assert.AreEqual (32, newIcon.Width, "M#1b");
  74. Bitmap bmp = icon.ToBitmap();
  75. Assert.AreEqual (32, bmp.Height, "M#2a");
  76. Assert.AreEqual (32, bmp.Width, "M#2b");
  77. */
  78. fs = new FileStream ("newIcon.ico", FileMode.Create);
  79. icon.Save (fs);
  80. Assert.AreEqual (fs1.Length, fs.Length, "M#3");
  81. }
  82. [TearDown]
  83. public void TearDown ()
  84. {
  85. if (fs != null)
  86. fs.Close();
  87. if (fs1 != null)
  88. fs1.Close();
  89. if (File.Exists ("newIcon.ico"))
  90. File.Delete("newIcon.ico");
  91. }
  92. }
  93. }