TestIcon.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. using System.Security.Permissions;
  35. namespace MonoTests.System.Drawing{
  36. [TestFixture]
  37. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  38. public class TestIcon {
  39. Icon icon;
  40. Icon newIcon;
  41. FileStream fs;
  42. FileStream fs1;
  43. [SetUp]
  44. public void SetUp ()
  45. {
  46. String path = TestBitmap.getInFile ("bitmaps/smiley.ico");
  47. icon = new Icon (path);
  48. fs1 = new FileStream (path, FileMode.Open);
  49. }
  50. [Test]
  51. public void TestConstructors ()
  52. {
  53. newIcon = new Icon (fs1, 48, 48);
  54. Assert.AreEqual (48, newIcon.Height, "C#1a");
  55. Assert.AreEqual (48, newIcon.Width, "C#1b");
  56. newIcon = new Icon (icon, 16, 16);
  57. Assert.AreEqual (16, newIcon.Height, "C#2a");
  58. Assert.AreEqual (16, newIcon.Width, "C#2b");
  59. }
  60. [Test]
  61. public void TestProperties ()
  62. {
  63. Assert.AreEqual (32, icon.Height, "P#1");
  64. Assert.AreEqual (32, icon.Width, "P#2");
  65. Assert.AreEqual (32, icon.Size.Width, "P#3");
  66. Assert.AreEqual (32, icon.Size.Height, "P#4");
  67. }
  68. [Test]
  69. public void TestMethods ()
  70. {
  71. /*
  72. TODO: This does not work on Win32
  73. newIcon = (Icon) icon.Clone ();
  74. Assert.AreEqual (32, newIcon.Height, "M#1a");
  75. Assert.AreEqual (32, newIcon.Width, "M#1b");
  76. Bitmap bmp = icon.ToBitmap();
  77. Assert.AreEqual (32, bmp.Height, "M#2a");
  78. Assert.AreEqual (32, bmp.Width, "M#2b");
  79. */
  80. fs = new FileStream ("newIcon.ico", FileMode.Create);
  81. icon.Save (fs);
  82. Assert.AreEqual (fs1.Length, fs.Length, "M#3");
  83. }
  84. [TearDown]
  85. public void TearDown ()
  86. {
  87. if (fs != null)
  88. fs.Close();
  89. if (fs1 != null)
  90. fs1.Close();
  91. if (File.Exists ("newIcon.ico"))
  92. File.Delete("newIcon.ico");
  93. }
  94. }
  95. }