GraphicsPathTest.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  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. [Test]
  976. public void Transform_Empty ()
  977. {
  978. // no points in path and no exception
  979. new GraphicsPath ().Transform (new Matrix ());
  980. }
  981. private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
  982. {
  983. Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
  984. for (int i = 0; i < expected.PointCount; i++) {
  985. Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
  986. Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
  987. }
  988. }
  989. private void CompareFlats (GraphicsPath flat, GraphicsPath original)
  990. {
  991. Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
  992. for (int i = 0; i < flat.PointCount; i++) {
  993. Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
  994. }
  995. }
  996. [Test]
  997. public void Flatten_Empty ()
  998. {
  999. GraphicsPath path = new GraphicsPath ();
  1000. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1001. // this is a no-op as there's nothing in the path
  1002. path.Flatten ();
  1003. ComparePaths (path, clone);
  1004. }
  1005. [Test]
  1006. public void Flatten_Null ()
  1007. {
  1008. GraphicsPath path = new GraphicsPath ();
  1009. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1010. // this is a no-op as there's nothing in the path
  1011. // an no matrix to apply
  1012. path.Flatten (null);
  1013. ComparePaths (path, clone);
  1014. }
  1015. [Test]
  1016. public void Flatten_NullFloat ()
  1017. {
  1018. GraphicsPath path = new GraphicsPath ();
  1019. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1020. // this is a no-op as there's nothing in the path
  1021. // an no matrix to apply
  1022. path.Flatten (null, 1f);
  1023. ComparePaths (path, clone);
  1024. }
  1025. [Test]
  1026. public void Flatten_Arc ()
  1027. {
  1028. GraphicsPath path = new GraphicsPath ();
  1029. path.AddArc (0f, 0f, 100f, 100f, 30, 30);
  1030. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1031. path.Flatten ();
  1032. CompareFlats (path, clone);
  1033. }
  1034. [Test]
  1035. public void Flatten_Bezier ()
  1036. {
  1037. GraphicsPath path = new GraphicsPath ();
  1038. path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
  1039. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1040. path.Flatten ();
  1041. CompareFlats (path, clone);
  1042. }
  1043. [Test]
  1044. public void Flatten_ClosedCurve ()
  1045. {
  1046. GraphicsPath path = new GraphicsPath ();
  1047. path.AddClosedCurve (new Point[4] {
  1048. new Point (0, 0), new Point (40, 20),
  1049. new Point (20, 40), new Point (40, 40)
  1050. });
  1051. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1052. path.Flatten ();
  1053. CompareFlats (path, clone);
  1054. }
  1055. [Test]
  1056. public void Flatten_Curve ()
  1057. {
  1058. GraphicsPath path = new GraphicsPath ();
  1059. path.AddCurve (new Point[4] {
  1060. new Point (0, 0), new Point (40, 20),
  1061. new Point (20, 40), new Point (40, 40)
  1062. });
  1063. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1064. path.Flatten ();
  1065. CompareFlats (path, clone);
  1066. }
  1067. [Test]
  1068. public void Flatten_Ellipse ()
  1069. {
  1070. GraphicsPath path = new GraphicsPath ();
  1071. path.AddEllipse (10f, 10f, 100f, 100f);
  1072. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1073. path.Flatten ();
  1074. CompareFlats (path, clone);
  1075. }
  1076. [Test]
  1077. public void Flatten_Line ()
  1078. {
  1079. GraphicsPath path = new GraphicsPath ();
  1080. path.AddLine (10f, 10f, 100f, 100f);
  1081. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1082. path.Flatten ();
  1083. ComparePaths (path, clone);
  1084. }
  1085. [Test]
  1086. public void Flatten_Pie ()
  1087. {
  1088. GraphicsPath path = new GraphicsPath ();
  1089. path.AddPie (0, 0, 100, 100, 30, 30);
  1090. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1091. path.Flatten ();
  1092. CompareFlats (path, clone);
  1093. }
  1094. [Test]
  1095. public void Flatten_Polygon ()
  1096. {
  1097. GraphicsPath path = new GraphicsPath ();
  1098. path.AddPolygon (new Point[4] {
  1099. new Point (0, 0), new Point (10, 10),
  1100. new Point (20, 20), new Point (40, 40)
  1101. });
  1102. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1103. path.Flatten ();
  1104. ComparePaths (path, clone);
  1105. }
  1106. [Test]
  1107. public void Flatten_Rectangle ()
  1108. {
  1109. GraphicsPath path = new GraphicsPath ();
  1110. path.AddRectangle (new Rectangle (0, 0, 100, 100));
  1111. GraphicsPath clone = (GraphicsPath) path.Clone ();
  1112. path.Flatten ();
  1113. ComparePaths (path, clone);
  1114. }
  1115. [Test]
  1116. [ExpectedException (typeof (ArgumentNullException))]
  1117. public void Warp_Null ()
  1118. {
  1119. new GraphicsPath ().Warp (null, new RectangleF ());
  1120. }
  1121. [Test]
  1122. public void SetMarkers_EmptyPath ()
  1123. {
  1124. new GraphicsPath ().SetMarkers ();
  1125. }
  1126. [Test]
  1127. public void ClearMarkers_EmptyPath ()
  1128. {
  1129. new GraphicsPath ().ClearMarkers ();
  1130. }
  1131. [Test]
  1132. public void CloseFigure_EmptyPath ()
  1133. {
  1134. new GraphicsPath ().CloseFigure ();
  1135. }
  1136. [Test]
  1137. public void CloseAllFigures_EmptyPath ()
  1138. {
  1139. new GraphicsPath ().CloseAllFigures ();
  1140. }
  1141. [Test]
  1142. public void StartClose_AddArc ()
  1143. {
  1144. GraphicsPath path = new GraphicsPath ();
  1145. path.AddLine (1, 1, 2, 2);
  1146. path.AddArc (10, 10, 100, 100, 90, 180);
  1147. path.AddLine (10, 10, 20, 20);
  1148. byte[] types = path.PathTypes;
  1149. // check first types
  1150. Assert.AreEqual (0, types[0], "start/Line");
  1151. Assert.AreEqual (1, types[2], "start/Arc");
  1152. // check last types
  1153. Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
  1154. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1155. }
  1156. [Test]
  1157. public void StartClose_AddBezier ()
  1158. {
  1159. GraphicsPath path = new GraphicsPath ();
  1160. path.AddLine (1, 1, 2, 2);
  1161. path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
  1162. path.AddLine (10, 10, 20, 20);
  1163. byte[] types = path.PathTypes;
  1164. // check first types
  1165. Assert.AreEqual (0, types[0], "start/Line");
  1166. Assert.AreEqual (1, types[2], "start/Bezier");
  1167. // check last types
  1168. Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
  1169. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1170. }
  1171. [Test]
  1172. public void StartClose_AddBeziers ()
  1173. {
  1174. GraphicsPath path = new GraphicsPath ();
  1175. path.AddLine (1, 1, 2, 2);
  1176. path.AddBeziers (new Point[7] { new Point (10, 10),
  1177. new Point (20, 10), new Point (20, 20), new Point (30, 20),
  1178. new Point (40, 40), new Point (50, 40), new Point (50, 50)
  1179. });
  1180. path.AddLine (10, 10, 20, 20);
  1181. byte[] types = path.PathTypes;
  1182. // check first types
  1183. Assert.AreEqual (0, types[0], "start/Line");
  1184. Assert.AreEqual (1, types[2], "start/Bezier");
  1185. // check last types
  1186. Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
  1187. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1188. }
  1189. [Test]
  1190. public void StartClose_AddClosedCurve ()
  1191. {
  1192. GraphicsPath path = new GraphicsPath ();
  1193. path.AddLine (1, 1, 2, 2);
  1194. path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1195. path.AddLine (10, 10, 20, 20);
  1196. byte[] types = path.PathTypes;
  1197. // check first types
  1198. Assert.AreEqual (0, types[0], "start/Line");
  1199. Assert.AreEqual (0, types[2], "start/ClosedCurve");
  1200. // check last types
  1201. Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
  1202. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
  1203. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
  1204. }
  1205. [Test]
  1206. public void StartClose_AddCurve ()
  1207. {
  1208. GraphicsPath path = new GraphicsPath ();
  1209. path.AddLine (1, 1, 2, 2);
  1210. path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1211. path.AddLine (10, 10, 20, 20);
  1212. byte[] types = path.PathTypes;
  1213. // check first types
  1214. Assert.AreEqual (0, types[0], "start/Line");
  1215. Assert.AreEqual (1, types[2], "start/Curve");
  1216. // check last types
  1217. Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
  1218. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1219. }
  1220. [Test]
  1221. public void StartClose_AddEllipse ()
  1222. {
  1223. GraphicsPath path = new GraphicsPath ();
  1224. path.AddLine (1, 1, 2, 2);
  1225. path.AddEllipse (10, 10, 100, 100);
  1226. path.AddLine (10, 10, 20, 20);
  1227. byte[] types = path.PathTypes;
  1228. // check first types
  1229. Assert.AreEqual (0, types[0], "start/Line");
  1230. Assert.AreEqual (0, types[2], "start/Ellipse");
  1231. // check last types
  1232. Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
  1233. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
  1234. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
  1235. }
  1236. [Test]
  1237. public void StartClose_AddLine ()
  1238. {
  1239. GraphicsPath path = new GraphicsPath ();
  1240. path.AddLine (1, 1, 2, 2);
  1241. path.AddLine (5, 5, 10, 10);
  1242. path.AddLine (10, 10, 20, 20);
  1243. byte[] types = path.PathTypes;
  1244. // check first types
  1245. Assert.AreEqual (0, types[0], "start/Line");
  1246. Assert.AreEqual (1, types[2], "start/Line2");
  1247. // check last types
  1248. Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
  1249. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1250. }
  1251. [Test]
  1252. public void StartClose_AddLines ()
  1253. {
  1254. GraphicsPath path = new GraphicsPath ();
  1255. path.AddLine (1, 1, 2, 2);
  1256. path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
  1257. path.AddLine (10, 10, 20, 20);
  1258. byte[] types = path.PathTypes;
  1259. // check first types
  1260. Assert.AreEqual (0, types[0], "start/Line");
  1261. Assert.AreEqual (1, types[2], "start/Lines");
  1262. // check last types
  1263. Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
  1264. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1265. }
  1266. [Test]
  1267. public void StartClose_AddPath_Connect ()
  1268. {
  1269. GraphicsPath inner = new GraphicsPath ();
  1270. inner.AddArc (10, 10, 100, 100, 90, 180);
  1271. GraphicsPath path = new GraphicsPath ();
  1272. path.AddLine (1, 1, 2, 2);
  1273. path.AddPath (inner, true);
  1274. path.AddLine (10, 10, 20, 20);
  1275. byte[] types = path.PathTypes;
  1276. // check first types
  1277. Assert.AreEqual (0, types[0], "start/Line");
  1278. Assert.AreEqual (1, types[2], "start/Path");
  1279. // check last types
  1280. Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
  1281. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1282. }
  1283. [Test]
  1284. public void StartClose_AddPath_NoConnect ()
  1285. {
  1286. GraphicsPath inner = new GraphicsPath ();
  1287. inner.AddArc (10, 10, 100, 100, 90, 180);
  1288. GraphicsPath path = new GraphicsPath ();
  1289. path.AddLine (1, 1, 2, 2);
  1290. path.AddPath (inner, false);
  1291. path.AddLine (10, 10, 20, 20);
  1292. byte[] types = path.PathTypes;
  1293. // check first types
  1294. Assert.AreEqual (0, types[0], "start/Line");
  1295. Assert.AreEqual (0, types[2], "start/Path");
  1296. // check last types
  1297. Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
  1298. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
  1299. }
  1300. [Test]
  1301. public void StartClose_AddPie ()
  1302. {
  1303. GraphicsPath path = new GraphicsPath ();
  1304. path.AddLine (1, 1, 2, 2);
  1305. path.AddPie (10, 10, 10, 10, 90, 180);
  1306. path.AddLine (10, 10, 20, 20);
  1307. byte[] types = path.PathTypes;
  1308. // check first types
  1309. Assert.AreEqual (0, types[0], "start/Line");
  1310. Assert.AreEqual (0, types[2], "start/Pie");
  1311. // check last types
  1312. // libgdiplus draws pie by ending with a line (not a curve) section
  1313. Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
  1314. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1315. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1316. }
  1317. [Test]
  1318. public void StartClose_AddPolygon ()
  1319. {
  1320. GraphicsPath path = new GraphicsPath ();
  1321. path.AddLine (1, 1, 2, 2);
  1322. path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
  1323. path.AddLine (10, 10, 20, 20);
  1324. byte[] types = path.PathTypes;
  1325. // check first types
  1326. Assert.AreEqual (0, types[0], "start/Line");
  1327. Assert.AreEqual (0, types[2], "start/Polygon");
  1328. // check last types
  1329. Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
  1330. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1331. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1332. }
  1333. [Test]
  1334. public void StartClose_AddRectangle ()
  1335. {
  1336. GraphicsPath path = new GraphicsPath ();
  1337. path.AddLine (1, 1, 2, 2);
  1338. path.AddRectangle (new RectangleF (10, 10, 20, 20));
  1339. path.AddLine (10, 10, 20, 20);
  1340. byte[] types = path.PathTypes;
  1341. // check first types
  1342. Assert.AreEqual (0, types[0], "start/Line");
  1343. Assert.AreEqual (0, types[2], "start/Rectangle");
  1344. // check last types
  1345. Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
  1346. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1347. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1348. }
  1349. [Test]
  1350. public void StartClose_AddRectangles ()
  1351. {
  1352. GraphicsPath path = new GraphicsPath ();
  1353. path.AddLine (1, 1, 2, 2);
  1354. path.AddRectangles (new RectangleF[2] {
  1355. new RectangleF (10, 10, 20, 20),
  1356. new RectangleF (20, 20, 10, 10) });
  1357. path.AddLine (10, 10, 20, 20);
  1358. byte[] types = path.PathTypes;
  1359. // check first types
  1360. Assert.AreEqual (0, types[0], "start/Line");
  1361. Assert.AreEqual (0, types[2], "start/Rectangles");
  1362. // check last types
  1363. Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
  1364. Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
  1365. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1366. }
  1367. [Test]
  1368. [Category ("NotWorking")]
  1369. public void StartClose_AddString ()
  1370. {
  1371. GraphicsPath path = new GraphicsPath ();
  1372. path.AddLine (1, 1, 2, 2);
  1373. path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
  1374. path.AddLine (10, 10, 20, 20);
  1375. byte[] types = path.PathTypes;
  1376. // check first types
  1377. Assert.AreEqual (0, types[0], "start/Line");
  1378. Assert.AreEqual (0, types[2], "start/String");
  1379. // check last types
  1380. Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
  1381. Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
  1382. Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
  1383. }
  1384. }
  1385. }