GraphicsPathIteratorTest.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // System.Drawing.Drawing2D.GraphicPathIterator unit tests
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Drawing;
  30. using System.Drawing.Drawing2D;
  31. using System.Security.Permissions;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Drawing.Drawing2D {
  34. [TestFixture]
  35. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  36. public class GraphicsPathIteratorTest {
  37. private PointF [] pts_2f = new PointF [2] { new PointF (1, 2), new PointF (20, 30) };
  38. [Test]
  39. public void Ctor_Null ()
  40. {
  41. using (GraphicsPathIterator gpi = new GraphicsPathIterator (null)) {
  42. Assert.AreEqual (0, gpi.Count, "Count");
  43. }
  44. }
  45. [Test]
  46. public void NextMarker_Null ()
  47. {
  48. using (GraphicsPath gp = new GraphicsPath ()) {
  49. gp.AddLines (pts_2f);
  50. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  51. Assert.AreEqual (0, gpi.NextMarker (null));
  52. }
  53. }
  54. }
  55. [Test]
  56. public void NextSubpath_Null ()
  57. {
  58. using (GraphicsPath gp = new GraphicsPath ()) {
  59. gp.AddLines (pts_2f);
  60. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  61. bool closed;
  62. Assert.AreEqual (0, gpi.NextSubpath (null, out closed));
  63. Assert.IsTrue (closed, "Closed");
  64. }
  65. }
  66. }
  67. [Test]
  68. [ExpectedException (typeof (NullReferenceException))]
  69. public void CopyData_NullPoints ()
  70. {
  71. using (GraphicsPath gp = new GraphicsPath ()) {
  72. gp.AddLines (pts_2f);
  73. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  74. PointF [] points = null;
  75. byte [] types = new byte [1];
  76. Assert.AreEqual (0, gpi.CopyData (ref points, ref types, 0, 1));
  77. }
  78. }
  79. }
  80. [Test]
  81. [ExpectedException (typeof (NullReferenceException))]
  82. public void CopyData_NullTypes ()
  83. {
  84. using (GraphicsPath gp = new GraphicsPath ()) {
  85. gp.AddLines (pts_2f);
  86. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  87. PointF [] points = new PointF [1];
  88. byte [] types = null;
  89. Assert.AreEqual (0, gpi.CopyData (ref points, ref types, 0, 1));
  90. }
  91. }
  92. }
  93. [Test]
  94. [ExpectedException (typeof (ArgumentException))]
  95. public void CopyData_DifferentSize ()
  96. {
  97. using (GraphicsPath gp = new GraphicsPath ()) {
  98. gp.AddLines (pts_2f);
  99. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  100. PointF [] points = new PointF [1];
  101. byte [] types = new byte [2];
  102. Assert.AreEqual (0, gpi.CopyData (ref points, ref types, 0, 1));
  103. }
  104. }
  105. }
  106. [Test]
  107. [ExpectedException (typeof (NullReferenceException))]
  108. public void Enumerate_NullPoints ()
  109. {
  110. using (GraphicsPath gp = new GraphicsPath ()) {
  111. gp.AddLines (pts_2f);
  112. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  113. PointF [] points = null;
  114. byte [] types = new byte [2];
  115. Assert.AreEqual (0, gpi.Enumerate (ref points, ref types));
  116. }
  117. }
  118. }
  119. [Test]
  120. [ExpectedException (typeof (NullReferenceException))]
  121. public void Enumerate_NullTypes ()
  122. {
  123. using (GraphicsPath gp = new GraphicsPath ()) {
  124. gp.AddLines (pts_2f);
  125. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  126. PointF [] points = new PointF [1];
  127. byte [] types = null;
  128. Assert.AreEqual (0, gpi.Enumerate (ref points, ref types));
  129. }
  130. }
  131. }
  132. [Test]
  133. [ExpectedException (typeof (ArgumentException))]
  134. public void Enumerate_DifferentSize ()
  135. {
  136. using (GraphicsPath gp = new GraphicsPath ()) {
  137. gp.AddLines (pts_2f);
  138. using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
  139. PointF [] points = new PointF [1];
  140. byte [] types = new byte [2];
  141. Assert.AreEqual (0, gpi.Enumerate (ref points, ref types));
  142. }
  143. }
  144. }
  145. }
  146. }