GraphicsPathTest.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. //
  2. // System.Drawing.GraphicsPath unit tests
  3. //
  4. // Authors:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2006 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 SC = System.ComponentModel;
  30. using System.Drawing;
  31. using System.Drawing.Drawing2D;
  32. using System.Security.Permissions;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Drawing.Drawing2D {
  35. [TestFixture]
  36. [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
  37. public class GraphicsPathTest {
  38. private const float Pi4 = (float) (Math.PI / 4);
  39. // let's tolerate a few differences
  40. private const float Delta = 0.0003f;
  41. private void CheckEmpty (string prefix, GraphicsPath gp)
  42. {
  43. Assert.AreEqual (0, gp.PathData.Points.Length, "PathData.Points");
  44. Assert.AreEqual (0, gp.PathData.Types.Length, "PathData.Types");
  45. Assert.AreEqual (0, gp.PointCount, prefix + "PointCount");
  46. }
  47. [Test]
  48. public void Constructor_InvalidFillMode ()
  49. {
  50. GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MinValue);
  51. Assert.AreEqual (Int32.MinValue, (int) gp.FillMode, "FillMode");
  52. CheckEmpty ("InvalidFillMode.", gp);
  53. }
  54. [Test]
  55. [ExpectedException (typeof (ArgumentNullException))]
  56. public void Constructor_Point_Null_Byte ()
  57. {
  58. new GraphicsPath ((Point[]) null, new byte[1]);
  59. }
  60. [Test]
  61. [ExpectedException (typeof (NullReferenceException))]
  62. public void Constructor_Point_Byte_Null ()
  63. {
  64. new GraphicsPath (new Point[1], null);
  65. }
  66. [Test]
  67. [ExpectedException (typeof (ArgumentException))]
  68. public void Constructor_Point_Byte_LengthMismatch ()
  69. {
  70. new GraphicsPath (new Point[1], new byte [2]);
  71. }
  72. [Test]
  73. [ExpectedException (typeof (ArgumentNullException))]
  74. public void Constructor_PointF_Null_Byte ()
  75. {
  76. new GraphicsPath ((PointF[])null, new byte [1]);
  77. }
  78. [Test]
  79. [ExpectedException (typeof (NullReferenceException))]
  80. public void Constructor_PointF_Byte_Null ()
  81. {
  82. new GraphicsPath ( new PointF[1], null);
  83. }
  84. [Test]
  85. [ExpectedException (typeof (ArgumentException))]
  86. public void Constructor_PointF_Byte_LengthMismatch ()
  87. {
  88. new GraphicsPath (new PointF[2], new byte [1]);
  89. }
  90. [Test]
  91. public void GraphicsPath_Empty ()
  92. {
  93. GraphicsPath gp = new GraphicsPath ();
  94. Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode");
  95. CheckEmpty ("Empty.", gp);
  96. GraphicsPath clone = (GraphicsPath) gp.Clone ();
  97. Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode");
  98. CheckEmpty ("Clone.", gp);
  99. }
  100. [Test]
  101. [ExpectedException (typeof (ArgumentException))]
  102. public void GraphicsPath_Empty_PathPoints ()
  103. {
  104. Assert.IsNull (new GraphicsPath ().PathPoints);
  105. }
  106. [Test]
  107. [ExpectedException (typeof (ArgumentException))]
  108. public void GraphicsPath_Empty_PathTypes ()
  109. {
  110. Assert.IsNull (new GraphicsPath ().PathTypes);
  111. }
  112. [Test]
  113. [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
  114. public void FillMode_Invalid ()
  115. {
  116. // constructor accept an invalid FillMode
  117. GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
  118. Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
  119. // but you can't set the FillMode property to an invalid value ;-)
  120. gp.FillMode = (FillMode) Int32.MaxValue;
  121. }
  122. [Test]
  123. public void PathData_CannotChange ()
  124. {
  125. GraphicsPath gp = new GraphicsPath ();
  126. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  127. Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
  128. Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
  129. // now try to change the first point
  130. gp.PathData.Points[0] = new Point (0, 0);
  131. // the changes isn't reflected in the property
  132. Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
  133. Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
  134. }
  135. [Test]
  136. public void PathPoints_CannotChange ()
  137. {
  138. GraphicsPath gp = new GraphicsPath ();
  139. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  140. Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
  141. Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
  142. // now try to change the first point
  143. gp.PathPoints[0] = new Point (0, 0);
  144. // the changes isn't reflected in the property
  145. Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
  146. Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
  147. }
  148. [Test]
  149. public void PathTypes_CannotChange ()
  150. {
  151. GraphicsPath gp = new GraphicsPath ();
  152. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  153. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  154. // now try to change the first type
  155. gp.PathTypes[0] = 1;
  156. // the changes isn't reflected in the property
  157. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
  158. }
  159. private void CheckArc (GraphicsPath path)
  160. {
  161. Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
  162. Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
  163. Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
  164. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  165. RectangleF rect = path.GetBounds ();
  166. Assert.AreEqual (2.999624f, rect.X, "Bounds.X");
  167. Assert.AreEqual (2.013707f, rect.Y, "Bounds.Y");
  168. Assert.AreEqual (0f, rect.Width, Delta, "Bounds.Width");
  169. Assert.AreEqual (0.01370478f, rect.Height, "Bounds.Height");
  170. Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
  171. Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
  172. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  173. Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
  174. Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
  175. Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
  176. Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
  177. Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
  178. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  179. Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
  180. Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
  181. Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
  182. }
  183. [Test]
  184. public void AddArc_Rectangle ()
  185. {
  186. GraphicsPath gp = new GraphicsPath ();
  187. gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
  188. CheckArc (gp);
  189. }
  190. [Test]
  191. public void AddArc_RectangleF ()
  192. {
  193. GraphicsPath gp = new GraphicsPath ();
  194. gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
  195. CheckArc (gp);
  196. }
  197. [Test]
  198. public void AddArc_Int ()
  199. {
  200. GraphicsPath gp = new GraphicsPath ();
  201. gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
  202. CheckArc (gp);
  203. }
  204. [Test]
  205. public void AddArc_Float ()
  206. {
  207. GraphicsPath gp = new GraphicsPath ();
  208. gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
  209. CheckArc (gp);
  210. }
  211. private void CheckBezier (GraphicsPath path)
  212. {
  213. Assert.AreEqual (4, path.PointCount, "PointCount");
  214. Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
  215. Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
  216. Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
  217. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  218. RectangleF rect = path.GetBounds ();
  219. Assert.AreEqual (1f, rect.X, "Bounds.X");
  220. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  221. Assert.AreEqual (3f, rect.Width, "Bounds.Width");
  222. Assert.AreEqual (3f, rect.Height, "Bounds.Height");
  223. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  224. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  225. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  226. Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
  227. Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
  228. Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
  229. Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
  230. Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
  231. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  232. Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
  233. Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
  234. Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
  235. }
  236. [Test]
  237. public void AddBezier_Point ()
  238. {
  239. GraphicsPath gp = new GraphicsPath ();
  240. gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
  241. CheckBezier (gp);
  242. }
  243. [Test]
  244. public void AddBezier_PointF ()
  245. {
  246. GraphicsPath gp = new GraphicsPath ();
  247. gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
  248. CheckBezier (gp);
  249. }
  250. [Test]
  251. public void AddBezier_Int ()
  252. {
  253. GraphicsPath gp = new GraphicsPath ();
  254. gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
  255. CheckBezier (gp);
  256. }
  257. [Test]
  258. public void AddBezier_Float ()
  259. {
  260. GraphicsPath gp = new GraphicsPath ();
  261. gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
  262. CheckBezier (gp);
  263. }
  264. [Test]
  265. [ExpectedException (typeof (ArgumentNullException))]
  266. public void AddBeziers_Point_Null ()
  267. {
  268. new GraphicsPath ().AddBeziers ((Point[]) null);
  269. }
  270. [Test]
  271. [ExpectedException (typeof (ArgumentException))]
  272. public void AddBeziers_3_Points ()
  273. {
  274. GraphicsPath gp = new GraphicsPath ();
  275. gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  276. }
  277. [Test]
  278. public void AddBeziers_Point ()
  279. {
  280. GraphicsPath gp = new GraphicsPath ();
  281. gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
  282. CheckBezier (gp);
  283. }
  284. [Test]
  285. [ExpectedException (typeof (ArgumentNullException))]
  286. public void AddBeziers_PointF_Null ()
  287. {
  288. new GraphicsPath ().AddBeziers ((PointF[]) null);
  289. }
  290. [Test]
  291. [ExpectedException (typeof (ArgumentException))]
  292. public void AddBeziers_3_PointFs ()
  293. {
  294. GraphicsPath gp = new GraphicsPath ();
  295. gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
  296. }
  297. [Test]
  298. public void AddBeziers_PointF ()
  299. {
  300. GraphicsPath gp = new GraphicsPath ();
  301. gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
  302. CheckBezier (gp);
  303. }
  304. private void CheckEllipse (GraphicsPath path)
  305. {
  306. Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
  307. Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
  308. Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
  309. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  310. RectangleF rect = path.GetBounds ();
  311. Assert.AreEqual (1f, rect.X, "Bounds.X");
  312. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  313. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  314. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  315. Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
  316. for (int i = 1; i < 12; i++)
  317. Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
  318. Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
  319. }
  320. [Test]
  321. public void AddEllipse_Rectangle ()
  322. {
  323. GraphicsPath gp = new GraphicsPath ();
  324. gp.AddEllipse (new Rectangle (1, 1, 2, 2));
  325. CheckEllipse (gp);
  326. }
  327. [Test]
  328. public void AddEllipse_RectangleF ()
  329. {
  330. GraphicsPath gp = new GraphicsPath ();
  331. gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
  332. CheckEllipse (gp);
  333. }
  334. [Test]
  335. public void AddEllipse_Int ()
  336. {
  337. GraphicsPath gp = new GraphicsPath ();
  338. gp.AddEllipse (1, 1, 2, 2);
  339. CheckEllipse (gp);
  340. }
  341. [Test]
  342. public void AddEllipse_Float ()
  343. {
  344. GraphicsPath gp = new GraphicsPath ();
  345. gp.AddEllipse (1f, 1f, 2f, 2f);
  346. CheckEllipse (gp);
  347. }
  348. private void CheckLine (GraphicsPath path)
  349. {
  350. Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
  351. Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
  352. Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
  353. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  354. RectangleF rect = path.GetBounds ();
  355. Assert.AreEqual (1f, rect.X, "Bounds.X");
  356. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  357. Assert.AreEqual (1f, rect.Width, "Bounds.Width");
  358. Assert.AreEqual (1f, rect.Height, "Bounds.Height");
  359. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  360. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  361. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  362. Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
  363. Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
  364. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  365. }
  366. [Test]
  367. public void AddLine_Point ()
  368. {
  369. GraphicsPath gp = new GraphicsPath ();
  370. gp.AddLine (new Point (1, 1), new Point (2, 2));
  371. CheckLine (gp);
  372. }
  373. [Test]
  374. public void AddLine_PointF ()
  375. {
  376. GraphicsPath gp = new GraphicsPath ();
  377. gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
  378. CheckLine (gp);
  379. }
  380. [Test]
  381. public void AddLine_Int ()
  382. {
  383. GraphicsPath gp = new GraphicsPath ();
  384. gp.AddLine (1, 1, 2, 2);
  385. CheckLine (gp);
  386. }
  387. [Test]
  388. public void AddLine_Float ()
  389. {
  390. GraphicsPath gp = new GraphicsPath ();
  391. gp.AddLine (1f, 1f, 2f, 2f);
  392. CheckLine (gp);
  393. }
  394. [Test]
  395. public void AddLine_SamePoint ()
  396. {
  397. GraphicsPath gp = new GraphicsPath ();
  398. gp.AddLine (new Point (1, 1), new Point (1, 1));
  399. Assert.AreEqual (2, gp.PointCount, "PointCount");
  400. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  401. Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
  402. }
  403. [Test]
  404. [ExpectedException (typeof (ArgumentNullException))]
  405. public void AddLines_Point_Null ()
  406. {
  407. new GraphicsPath ().AddLines ((Point[])null);
  408. }
  409. [Test]
  410. [ExpectedException (typeof (ArgumentException))]
  411. public void AddLines_Point_0 ()
  412. {
  413. GraphicsPath gp = new GraphicsPath ();
  414. gp.AddLines (new Point[0]);
  415. CheckLine (gp);
  416. }
  417. [Test]
  418. [Category ("NotWorking")]
  419. public void AddLines_Point_1 ()
  420. {
  421. GraphicsPath gp = new GraphicsPath ();
  422. gp.AddLines (new Point[1] { new Point (1, 1) });
  423. // Special case - a line with a single point is valid
  424. Assert.AreEqual (1, gp.PointCount, "PointCount");
  425. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  426. }
  427. [Test]
  428. public void AddLines_Point ()
  429. {
  430. GraphicsPath gp = new GraphicsPath ();
  431. gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
  432. CheckLine (gp);
  433. }
  434. [Test]
  435. [ExpectedException (typeof (ArgumentNullException))]
  436. public void AddLines_PointF_Null ()
  437. {
  438. new GraphicsPath ().AddLines ((PointF[]) null);
  439. }
  440. [Test]
  441. [ExpectedException (typeof (ArgumentException))]
  442. public void AddLines_PointF_0 ()
  443. {
  444. GraphicsPath gp = new GraphicsPath ();
  445. gp.AddLines (new PointF[0]);
  446. CheckLine (gp);
  447. }
  448. [Test]
  449. [Category ("NotWorking")]
  450. public void AddLines_PointF_1 ()
  451. {
  452. GraphicsPath gp = new GraphicsPath ();
  453. gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
  454. // Special case - a line with a single point is valid
  455. Assert.AreEqual (1, gp.PointCount, "PointCount");
  456. Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
  457. }
  458. [Test]
  459. public void AddLines_PointF ()
  460. {
  461. GraphicsPath gp = new GraphicsPath ();
  462. gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  463. CheckLine (gp);
  464. }
  465. private void CheckPie (GraphicsPath path)
  466. {
  467. // the number of points generated for a Pie isn't the same between Mono and MS
  468. #if false
  469. Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
  470. Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
  471. Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
  472. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  473. RectangleF rect = path.GetBounds ();
  474. Assert.AreEqual (2f, rect.X, "Bounds.X");
  475. Assert.AreEqual (2f, rect.Y, "Bounds.Y");
  476. Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
  477. Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
  478. Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
  479. Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
  480. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  481. Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
  482. Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
  483. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  484. Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
  485. Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
  486. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  487. Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
  488. Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
  489. Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
  490. Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
  491. Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
  492. Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
  493. #endif
  494. }
  495. [Test]
  496. public void AddPie_Rect ()
  497. {
  498. GraphicsPath gp = new GraphicsPath ();
  499. gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
  500. CheckPie (gp);
  501. }
  502. [Test]
  503. public void AddPie_Int ()
  504. {
  505. GraphicsPath gp = new GraphicsPath ();
  506. gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
  507. CheckPie (gp);
  508. }
  509. [Test]
  510. public void AddPie_Float ()
  511. {
  512. GraphicsPath gp = new GraphicsPath ();
  513. gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
  514. CheckPie (gp);
  515. }
  516. private void CheckPolygon (GraphicsPath path)
  517. {
  518. // an extra point is generated by Mono (libgdiplus)
  519. #if false
  520. Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
  521. Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
  522. Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
  523. #endif
  524. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  525. RectangleF rect = path.GetBounds ();
  526. Assert.AreEqual (1f, rect.X, "Bounds.X");
  527. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  528. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  529. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  530. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  531. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  532. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  533. Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
  534. Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
  535. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  536. Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
  537. Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
  538. // the extra point change the type of the last point
  539. #if false
  540. Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
  541. #endif
  542. }
  543. [Test]
  544. [ExpectedException (typeof (ArgumentNullException))]
  545. public void AddPolygon_Point_Null ()
  546. {
  547. new GraphicsPath ().AddPolygon ((Point[]) null);
  548. }
  549. [Test]
  550. [ExpectedException (typeof (ArgumentException))]
  551. public void AddPolygon_Point_Empty ()
  552. {
  553. new GraphicsPath ().AddPolygon (new Point[0]);
  554. }
  555. [Test]
  556. [ExpectedException (typeof (ArgumentException))]
  557. public void AddPolygon_Point_1 ()
  558. {
  559. GraphicsPath gp = new GraphicsPath ();
  560. gp.AddPolygon (new Point[1] { new Point (1, 1) });
  561. }
  562. [Test]
  563. [ExpectedException (typeof (ArgumentException))]
  564. public void AddPolygon_Point_2 ()
  565. {
  566. GraphicsPath gp = new GraphicsPath ();
  567. gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
  568. }
  569. [Test]
  570. public void AddPolygon_Point_3 ()
  571. {
  572. GraphicsPath gp = new GraphicsPath ();
  573. gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  574. CheckPolygon (gp);
  575. }
  576. [Test]
  577. [ExpectedException (typeof (ArgumentNullException))]
  578. public void AddPolygon_PointF_Null ()
  579. {
  580. new GraphicsPath ().AddPolygon ((PointF[]) null);
  581. }
  582. [Test]
  583. [ExpectedException (typeof (ArgumentException))]
  584. public void AddPolygon_PointF_Empty ()
  585. {
  586. new GraphicsPath ().AddPolygon (new PointF[0]);
  587. }
  588. [Test]
  589. [ExpectedException (typeof (ArgumentException))]
  590. public void AddPolygon_PointF_1 ()
  591. {
  592. GraphicsPath gp = new GraphicsPath ();
  593. gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
  594. }
  595. [Test]
  596. [ExpectedException (typeof (ArgumentException))]
  597. public void AddPolygon_PointF_2 ()
  598. {
  599. GraphicsPath gp = new GraphicsPath ();
  600. gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  601. }
  602. [Test]
  603. public void AddPolygon_PointF_3 ()
  604. {
  605. GraphicsPath gp = new GraphicsPath ();
  606. gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
  607. CheckPolygon (gp);
  608. }
  609. private void CheckRectangle (GraphicsPath path, int count)
  610. {
  611. Assert.AreEqual (count, path.PathPoints.Length, "PathPoints");
  612. Assert.AreEqual (count, path.PathTypes.Length, "PathPoints");
  613. Assert.AreEqual (count, path.PathData.Points.Length, "PathData");
  614. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  615. RectangleF rect = path.GetBounds ();
  616. Assert.AreEqual (1f, rect.X, "Bounds.X");
  617. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  618. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  619. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  620. // check first four points (first rectangle)
  621. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  622. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  623. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  624. Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
  625. Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
  626. Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
  627. Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
  628. Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
  629. Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
  630. Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
  631. Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
  632. Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
  633. }
  634. [Test]
  635. public void AddRectangle_Int ()
  636. {
  637. GraphicsPath gp = new GraphicsPath ();
  638. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  639. CheckRectangle (gp, 4);
  640. }
  641. [Test]
  642. public void AddRectangle_Float ()
  643. {
  644. GraphicsPath gp = new GraphicsPath ();
  645. gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
  646. CheckRectangle (gp, 4);
  647. }
  648. [Test]
  649. [ExpectedException (typeof (ArgumentNullException))]
  650. public void AddRectangles_Int_Null ()
  651. {
  652. GraphicsPath gp = new GraphicsPath ();
  653. gp.AddRectangles ((Rectangle[]) null);
  654. }
  655. [Test]
  656. [ExpectedException (typeof (ArgumentException))]
  657. public void AddRectangles_Int_Empty ()
  658. {
  659. GraphicsPath gp = new GraphicsPath ();
  660. gp.AddRectangles (new Rectangle[0]);
  661. CheckRectangle (gp, 4);
  662. }
  663. [Test]
  664. public void AddRectangles_Int ()
  665. {
  666. GraphicsPath gp = new GraphicsPath ();
  667. gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
  668. CheckRectangle (gp, 4);
  669. }
  670. [Test]
  671. [ExpectedException (typeof (ArgumentNullException))]
  672. public void AddRectangles_Float_Null ()
  673. {
  674. GraphicsPath gp = new GraphicsPath ();
  675. gp.AddRectangles ((RectangleF[]) null);
  676. }
  677. [Test]
  678. [ExpectedException (typeof (ArgumentException))]
  679. public void AddRectangles_Float_Empty ()
  680. {
  681. GraphicsPath gp = new GraphicsPath ();
  682. gp.AddRectangles ( new RectangleF[0]);
  683. CheckRectangle (gp, 4);
  684. }
  685. [Test]
  686. public void AddRectangles_Float ()
  687. {
  688. GraphicsPath gp = new GraphicsPath ();
  689. gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
  690. CheckRectangle (gp, 4);
  691. }
  692. [Test]
  693. public void AddRectangles_Two ()
  694. {
  695. GraphicsPath gp = new GraphicsPath ();
  696. gp.AddRectangles (new RectangleF[2] {
  697. new RectangleF (1f, 1f, 2f, 2f),
  698. new RectangleF (2f, 2f, 1f, 1f) } );
  699. RectangleF rect = gp.GetBounds ();
  700. Assert.AreEqual (1f, rect.X, "Bounds.X");
  701. Assert.AreEqual (1f, rect.Y, "Bounds.Y");
  702. Assert.AreEqual (2f, rect.Width, "Bounds.Width");
  703. Assert.AreEqual (2f, rect.Height, "Bounds.Height");
  704. // second rectangle is completely within the first one
  705. CheckRectangle (gp, 8);
  706. }
  707. [Test]
  708. [ExpectedException (typeof (ArgumentNullException))]
  709. public void AddPath_Null ()
  710. {
  711. new GraphicsPath ().AddPath (null, false);
  712. }
  713. [Test]
  714. public void AddPath ()
  715. {
  716. GraphicsPath gpr = new GraphicsPath ();
  717. gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
  718. GraphicsPath gp = new GraphicsPath ();
  719. gp.AddPath (gpr, true);
  720. CheckRectangle (gp, 4);
  721. }
  722. private void CheckClosedCurve (GraphicsPath path)
  723. {
  724. Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
  725. Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
  726. Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
  727. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  728. RectangleF rect = path.GetBounds ();
  729. Assert.AreEqual (0.8333333f, rect.X, "Bounds.X");
  730. Assert.AreEqual (0.8333333f, rect.Y, "Bounds.Y");
  731. Assert.AreEqual (2.33333278f, rect.Width, "Bounds.Width");
  732. Assert.AreEqual (2.33333278f, rect.Height, "Bounds.Height");
  733. Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
  734. for (int i = 1; i < 9; i++)
  735. Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
  736. Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
  737. }
  738. [Test]
  739. [ExpectedException (typeof (ArgumentNullException))]
  740. public void AddClosedCurve_Point_Null ()
  741. {
  742. new GraphicsPath ().AddClosedCurve ((Point[])null);
  743. }
  744. [Test]
  745. [ExpectedException (typeof (ArgumentException))]
  746. public void AddClosedCurve_Point_0 ()
  747. {
  748. GraphicsPath gp = new GraphicsPath ();
  749. gp.AddClosedCurve (new Point [0]);
  750. }
  751. [Test]
  752. [ExpectedException (typeof (ArgumentException))]
  753. public void AddClosedCurve_Point_1 ()
  754. {
  755. GraphicsPath gp = new GraphicsPath ();
  756. gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
  757. }
  758. [Test]
  759. [ExpectedException (typeof (ArgumentException))]
  760. public void AddClosedCurve_Point_2 ()
  761. {
  762. GraphicsPath gp = new GraphicsPath ();
  763. gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
  764. }
  765. [Test]
  766. public void AddClosedCurve_Point_3 ()
  767. {
  768. GraphicsPath gp = new GraphicsPath ();
  769. gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  770. CheckClosedCurve (gp);
  771. }
  772. [Test]
  773. [ExpectedException (typeof (ArgumentNullException))]
  774. public void AddClosedCurve_PointF_Null ()
  775. {
  776. new GraphicsPath ().AddClosedCurve ((PointF[]) null);
  777. }
  778. [Test]
  779. [ExpectedException (typeof (ArgumentException))]
  780. public void AddClosedCurve_PointF_0 ()
  781. {
  782. GraphicsPath gp = new GraphicsPath ();
  783. gp.AddClosedCurve (new PointF[0]);
  784. }
  785. [Test]
  786. [ExpectedException (typeof (ArgumentException))]
  787. public void AddClosedCurve_PointF_1 ()
  788. {
  789. GraphicsPath gp = new GraphicsPath ();
  790. gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
  791. }
  792. [Test]
  793. [ExpectedException (typeof (ArgumentException))]
  794. public void AddClosedCurve_PointF_2 ()
  795. {
  796. GraphicsPath gp = new GraphicsPath ();
  797. gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  798. }
  799. [Test]
  800. public void AddClosedCurve_PointF_3 ()
  801. {
  802. GraphicsPath gp = new GraphicsPath ();
  803. gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
  804. CheckClosedCurve (gp);
  805. }
  806. private void CheckCurve (GraphicsPath path)
  807. {
  808. Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
  809. Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
  810. Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
  811. // GetBounds (well GdipGetPathWorldBounds) isn't implemented
  812. RectangleF rect = path.GetBounds ();
  813. Assert.AreEqual (1.0f, rect.X, "Bounds.X");
  814. Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
  815. Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
  816. Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
  817. Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
  818. Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
  819. Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
  820. // Mono has wrong? results
  821. #if false
  822. Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
  823. Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
  824. #endif
  825. Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
  826. // Mono has wrong? results
  827. #if false
  828. Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
  829. Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
  830. #endif
  831. Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
  832. Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
  833. Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
  834. Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
  835. }
  836. [Test]
  837. [ExpectedException (typeof (ArgumentNullException))]
  838. public void AddCurve_Point_Null ()
  839. {
  840. new GraphicsPath ().AddCurve ((Point[]) null);
  841. }
  842. [Test]
  843. [ExpectedException (typeof (ArgumentException))]
  844. public void AddCurve_Point_0 ()
  845. {
  846. GraphicsPath gp = new GraphicsPath ();
  847. gp.AddCurve (new Point[0]);
  848. }
  849. [Test]
  850. [ExpectedException (typeof (ArgumentException))]
  851. public void AddCurve_Point_1 ()
  852. {
  853. GraphicsPath gp = new GraphicsPath ();
  854. gp.AddCurve (new Point[1] { new Point (1, 1) });
  855. }
  856. [Test]
  857. public void AddCurve_Point_2 ()
  858. {
  859. GraphicsPath gp = new GraphicsPath ();
  860. gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
  861. CheckCurve (gp);
  862. }
  863. [Test]
  864. [ExpectedException (typeof (ArgumentNullException))]
  865. public void AddCurve_PointF_Null ()
  866. {
  867. new GraphicsPath ().AddCurve ((PointF[]) null);
  868. }
  869. [Test]
  870. [ExpectedException (typeof (ArgumentException))]
  871. public void AddCurve_PointF_0 ()
  872. {
  873. GraphicsPath gp = new GraphicsPath ();
  874. gp.AddCurve (new PointF[0]);
  875. }
  876. [Test]
  877. [ExpectedException (typeof (ArgumentException))]
  878. public void AddCurve_PointF_1 ()
  879. {
  880. GraphicsPath gp = new GraphicsPath ();
  881. gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
  882. }
  883. [Test]
  884. public void AddCurve_PointF_2 ()
  885. {
  886. GraphicsPath gp = new GraphicsPath ();
  887. gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
  888. CheckCurve (gp);
  889. }
  890. [Test]
  891. public void GetBounds_Empty_Empty ()
  892. {
  893. GraphicsPath gp = new GraphicsPath ();
  894. RectangleF rect = gp.GetBounds ();
  895. Assert.AreEqual (0.0f, rect.X, "Bounds.X");
  896. Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
  897. Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
  898. Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
  899. }
  900. private void CheckRectangleBounds (RectangleF rect)
  901. {
  902. Assert.AreEqual (1.0f, rect.X, "Bounds.X");
  903. Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
  904. Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
  905. Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
  906. }
  907. [Test]
  908. public void GetBounds_Empty_Rectangle ()
  909. {
  910. GraphicsPath gp = new GraphicsPath ();
  911. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  912. CheckRectangleBounds (gp.GetBounds ());
  913. }
  914. [Test]
  915. public void GetBounds_Null_Rectangle ()
  916. {
  917. GraphicsPath gp = new GraphicsPath ();
  918. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  919. CheckRectangleBounds (gp.GetBounds (null));
  920. }
  921. [Test]
  922. public void GetBounds_MatrixEmpty_Rectangle ()
  923. {
  924. GraphicsPath gp = new GraphicsPath ();
  925. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  926. CheckRectangleBounds (gp.GetBounds (new Matrix ()));
  927. }
  928. [Test]
  929. public void GetBounds_NullNull_Rectangle ()
  930. {
  931. GraphicsPath gp = new GraphicsPath ();
  932. gp.AddRectangle (new Rectangle (1, 1, 2, 2));
  933. CheckRectangleBounds (gp.GetBounds (null, null));
  934. }
  935. [Test]
  936. [Category ("NotWorking")] // bounds+pen support is missing in libgdiplus
  937. public void GetBounds_WithPen ()
  938. {
  939. Rectangle rect = new Rectangle (1, 1, 2, 2);
  940. Pen p = new Pen (Color.Aqua, 0);
  941. GraphicsPath gp = new GraphicsPath ();
  942. gp.AddRectangle (rect);
  943. RectangleF bounds = gp.GetBounds (null, p);
  944. Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
  945. Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
  946. Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
  947. Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
  948. Matrix m = new Matrix ();
  949. // an empty matrix is different than a null matrix
  950. bounds = gp.GetBounds (m, p);
  951. Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
  952. Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
  953. Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
  954. Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
  955. gp = new GraphicsPath ();
  956. gp.AddRectangle (rect);
  957. gp.Widen (p);
  958. bounds = gp.GetBounds (null);
  959. Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
  960. Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
  961. Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
  962. Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
  963. bounds = gp.GetBounds (m);
  964. Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
  965. Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
  966. Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
  967. Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
  968. }
  969. [Test]
  970. [ExpectedException (typeof (ArgumentNullException))]
  971. public void Transform_Null ()
  972. {
  973. new GraphicsPath ().Transform (null);
  974. }
  975. private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
  976. {
  977. Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
  978. for (int i = 0; i < expected.PointCount; i++) {
  979. Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
  980. Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
  981. }
  982. }
  983. private void CompareFlats (GraphicsPath flat, GraphicsPath original)
  984. {
  985. Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
  986. for (int i = 0; i < flat.PointCount; i++) {
  987. Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
  988. }
  989. }
  990. [Test]
  991. public void Flatten_Empty ()
  992. {
  993. GraphicsPath path = new GraphicsPath ();
  994. GraphicsPath clone = (GraphicsPath) path.Clone ();
  995. // this is a no-op as there's nothing in the path
  996. path.Flatten ();
  997. ComparePaths (path, clone);
  998. }
  999. [Test]
  1000. public void Flatten_Null ()
  1001. {
  1002. GraphicsPath path = new GraphicsPath ();
  1003. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1004. // this is a no-op as there's nothing in the path
  1005. // an no matrix to apply
  1006. path.Flatten (null);
  1007. ComparePaths (path, clone);
  1008. }
  1009. [Test]
  1010. public void Flatten_NullFloat ()
  1011. {
  1012. GraphicsPath path = new GraphicsPath ();
  1013. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1014. // this is a no-op as there's nothing in the path
  1015. // an no matrix to apply
  1016. path.Flatten (null, 1f);
  1017. ComparePaths (path, clone);
  1018. }
  1019. [Test]
  1020. public void Flatten_Arc ()
  1021. {
  1022. GraphicsPath path = new GraphicsPath ();
  1023. path.AddArc (0f, 0f, 100f, 100f, 30, 30);
  1024. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1025. path.Flatten ();
  1026. CompareFlats (path, clone);
  1027. }
  1028. [Test]
  1029. public void Flatten_Bezier ()
  1030. {
  1031. GraphicsPath path = new GraphicsPath ();
  1032. path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
  1033. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1034. path.Flatten ();
  1035. CompareFlats (path, clone);
  1036. }
  1037. [Test]
  1038. public void Flatten_ClosedCurve ()
  1039. {
  1040. GraphicsPath path = new GraphicsPath ();
  1041. path.AddClosedCurve (new Point[4] {
  1042. new Point (0, 0), new Point (40, 20),
  1043. new Point (20, 40), new Point (40, 40)
  1044. });
  1045. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1046. path.Flatten ();
  1047. CompareFlats (path, clone);
  1048. }
  1049. [Test]
  1050. public void Flatten_Curve ()
  1051. {
  1052. GraphicsPath path = new GraphicsPath ();
  1053. path.AddCurve (new Point[4] {
  1054. new Point (0, 0), new Point (40, 20),
  1055. new Point (20, 40), new Point (40, 40)
  1056. });
  1057. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1058. path.Flatten ();
  1059. CompareFlats (path, clone);
  1060. }
  1061. [Test]
  1062. public void Flatten_Ellipse ()
  1063. {
  1064. GraphicsPath path = new GraphicsPath ();
  1065. path.AddEllipse (10f, 10f, 100f, 100f);
  1066. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1067. path.Flatten ();
  1068. CompareFlats (path, clone);
  1069. }
  1070. [Test]
  1071. public void Flatten_Line ()
  1072. {
  1073. GraphicsPath path = new GraphicsPath ();
  1074. path.AddLine (10f, 10f, 100f, 100f);
  1075. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1076. path.Flatten ();
  1077. ComparePaths (path, clone);
  1078. }
  1079. [Test]
  1080. public void Flatten_Pie ()
  1081. {
  1082. GraphicsPath path = new GraphicsPath ();
  1083. path.AddPie (0, 0, 100, 100, 30, 30);
  1084. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1085. path.Flatten ();
  1086. CompareFlats (path, clone);
  1087. }
  1088. [Test]
  1089. public void Flatten_Polygon ()
  1090. {
  1091. GraphicsPath path = new GraphicsPath ();
  1092. path.AddPolygon (new Point[4] {
  1093. new Point (0, 0), new Point (10, 10),
  1094. new Point (20, 20), new Point (40, 40)
  1095. });
  1096. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1097. path.Flatten ();
  1098. ComparePaths (path, clone);
  1099. }
  1100. [Test]
  1101. public void Flatten_Rectangle ()
  1102. {
  1103. GraphicsPath path = new GraphicsPath ();
  1104. path.AddRectangle (new Rectangle (0, 0, 100, 100));
  1105. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1106. path.Flatten ();
  1107. ComparePaths (path, clone);
  1108. }
  1109. [Test]
  1110. [ExpectedException (typeof (ArgumentNullException))]
  1111. public void Warp_Null ()
  1112. {
  1113. new GraphicsPath ().Warp (null, new RectangleF ());
  1114. }
  1115. [Test]
  1116. public void SetMarkers_EmptyPath ()
  1117. {
  1118. new GraphicsPath ().SetMarkers ();
  1119. }
  1120. [Test]
  1121. public void ClearMarkers_EmptyPath ()
  1122. {
  1123. new GraphicsPath ().ClearMarkers ();
  1124. }
  1125. [Test]
  1126. public void CloseFigure_EmptyPath ()
  1127. {
  1128. new GraphicsPath ().CloseFigure ();
  1129. }
  1130. [Test]
  1131. public void CloseAllFigures_EmptyPath ()
  1132. {
  1133. new GraphicsPath ().CloseAllFigures ();
  1134. }
  1135. }
  1136. }