LinearGradientBrushTest.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. //
  2. // System.Drawing.Drawing2D.LinearGradientBrush 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 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 LinearGradientBrushTest {
  38. private Point pt1;
  39. private Point pt2;
  40. private Color c1;
  41. private Color c2;
  42. private LinearGradientBrush default_brush;
  43. private Matrix empty_matrix;
  44. private RectangleF rect;
  45. [TestFixtureSetUp]
  46. public void FixtureSetUp ()
  47. {
  48. pt1 = new Point (0, 0);
  49. pt2 = new Point (32, 32);
  50. c1 = Color.Blue;
  51. c2 = Color.Red;
  52. default_brush = new LinearGradientBrush (pt1, pt2, c1, c2);
  53. empty_matrix = new Matrix ();
  54. rect = new RectangleF (0, 0, 32, 32);
  55. }
  56. private void CheckDefaultRectangle (string msg, RectangleF rect)
  57. {
  58. Assert.AreEqual (pt1.X, rect.X, msg + ".Rectangle.X");
  59. Assert.AreEqual (pt1.Y, rect.Y, msg + ".Rectangle.Y");
  60. Assert.AreEqual (pt2.X, rect.Width, msg + ".Rectangle.Width");
  61. Assert.AreEqual (pt2.Y, rect.Height, msg + ".Rectangle.Height");
  62. }
  63. private void CheckDefaultMatrix (Matrix matrix)
  64. {
  65. float[] elements = matrix.Elements;
  66. Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
  67. Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
  68. Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
  69. Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
  70. Assert.AreEqual (16, elements[4], "matrix.4");
  71. Assert.AreEqual (-16, elements[5], "matrix.5");
  72. }
  73. private void CheckBrushAt45 (LinearGradientBrush lgb)
  74. {
  75. CheckDefaultRectangle ("4", lgb.Rectangle);
  76. Assert.AreEqual (1, lgb.Blend.Factors.Length, "Blend.Factors");
  77. Assert.AreEqual (1, lgb.Blend.Factors[0], "Blend.Factors [0]");
  78. Assert.AreEqual (1, lgb.Blend.Positions.Length, "Blend.Positions");
  79. // lgb.Blend.Positions [0] is always small (e-39) but never quite the same
  80. Assert.IsFalse (lgb.GammaCorrection, "GammaCorrection");
  81. Assert.AreEqual (2, lgb.LinearColors.Length, "LinearColors");
  82. Assert.IsNotNull (lgb.Transform, "Transform");
  83. CheckDefaultMatrix (lgb.Transform);
  84. }
  85. [Test]
  86. [NUnit.Framework.Category ("NotWorking")]
  87. public void Constructor_Point_Point_Color_Color ()
  88. {
  89. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  90. CheckBrushAt45 (lgb);
  91. Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
  92. lgb.WrapMode = WrapMode.TileFlipX;
  93. Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
  94. lgb.WrapMode = WrapMode.TileFlipY;
  95. Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
  96. lgb.WrapMode = WrapMode.TileFlipXY;
  97. Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
  98. // can't set WrapMode.Clamp
  99. }
  100. [Test]
  101. public void Constructor_RectangleF_Color_Color_Single_0 ()
  102. {
  103. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  104. Assert.AreEqual (1, lgb.Blend.Factors.Length, "Blend.Factors");
  105. Assert.AreEqual (1, lgb.Blend.Factors[0], "Blend.Factors[0]");
  106. Assert.AreEqual (1, lgb.Blend.Positions.Length, "Blend.Positions");
  107. // lgb.Blend.Positions [0] is always small (e-39) but never quite the same
  108. Assert.IsFalse (lgb.GammaCorrection, "GammaCorrection");
  109. Assert.AreEqual (c1.ToArgb (), lgb.LinearColors[0].ToArgb (), "LinearColors[0]");
  110. Assert.AreEqual (c2.ToArgb (), lgb.LinearColors[1].ToArgb (), "LinearColors[1]");
  111. Assert.AreEqual (rect, lgb.Rectangle, "Rectangle");
  112. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
  113. Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode");
  114. Matrix matrix = new Matrix (2, -1, 1, 2, 10, 10);
  115. lgb.Transform = matrix;
  116. Assert.AreEqual (matrix, lgb.Transform, "Transform");
  117. }
  118. [Test]
  119. [NUnit.Framework.Category ("NotWorking")]
  120. public void Constructor_RectangleF_Color_Color_Single_22_5 ()
  121. {
  122. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 22.5f);
  123. float[] elements = lgb.Transform.Elements;
  124. Assert.AreEqual (1.207107, elements[0], 0.0001, "matrix.0");
  125. Assert.AreEqual (0.5, elements[1], 0.0001, "matrix.1");
  126. Assert.AreEqual (-0.5, elements[2], 0.0001, "matrix.2");
  127. Assert.AreEqual (1.207107, elements[3], 0.0001, "matrix.3");
  128. Assert.AreEqual (4.686291, elements[4], 0.0001, "matrix.4");
  129. Assert.AreEqual (-11.313709, elements[5], 0.0001, "matrix.5");
  130. }
  131. [Test]
  132. [NUnit.Framework.Category ("NotWorking")]
  133. public void Constructor_RectangleF_Color_Color_Single_45 ()
  134. {
  135. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 45f);
  136. CheckBrushAt45 (lgb);
  137. }
  138. [Test]
  139. [NUnit.Framework.Category ("NotWorking")]
  140. public void Constructor_RectangleF_Color_Color_Single_90 ()
  141. {
  142. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 90f);
  143. float[] elements = lgb.Transform.Elements;
  144. Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
  145. Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
  146. Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
  147. Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
  148. Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
  149. Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
  150. }
  151. [Test]
  152. [NUnit.Framework.Category ("NotWorking")]
  153. public void Constructor_RectangleF_Color_Color_Single_135 ()
  154. {
  155. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 135f);
  156. float[] elements = lgb.Transform.Elements;
  157. Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
  158. Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
  159. Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
  160. Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
  161. Assert.AreEqual (48, elements[4], 0.0001, "matrix.4");
  162. Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
  163. }
  164. [Test]
  165. [NUnit.Framework.Category ("NotWorking")]
  166. public void Constructor_RectangleF_Color_Color_Single_180 ()
  167. {
  168. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 180f);
  169. float[] elements = lgb.Transform.Elements;
  170. Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
  171. Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
  172. Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
  173. Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
  174. Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
  175. Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
  176. }
  177. [Test]
  178. [NUnit.Framework.Category ("NotWorking")]
  179. public void Constructor_RectangleF_Color_Color_Single_270 ()
  180. {
  181. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 270f);
  182. float[] elements = lgb.Transform.Elements;
  183. Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
  184. Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
  185. Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
  186. Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
  187. Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
  188. Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
  189. }
  190. [Test]
  191. [NUnit.Framework.Category ("NotWorking")]
  192. public void Constructor_RectangleF_Color_Color_Single_315 ()
  193. {
  194. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 315f);
  195. float[] elements = lgb.Transform.Elements;
  196. Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
  197. Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
  198. Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
  199. Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
  200. Assert.AreEqual (-16, elements[4], 0.0001, "matrix.4");
  201. Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
  202. }
  203. [Test]
  204. public void Constructor_RectangleF_Color_Color_Single_360()
  205. {
  206. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 360f);
  207. float[] elements = lgb.Transform.Elements;
  208. // just like 0'
  209. Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
  210. Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
  211. Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
  212. Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
  213. Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
  214. Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
  215. }
  216. [Test]
  217. [NUnit.Framework.Category ("NotWorking")]
  218. public void Constructor_RectangleF_Color_Color_Single_540 ()
  219. {
  220. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 540f);
  221. float[] elements = lgb.Transform.Elements;
  222. // just like 180'
  223. Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
  224. Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
  225. Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
  226. Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
  227. Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
  228. Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
  229. }
  230. [Test]
  231. [ExpectedException (typeof (ArgumentException))]
  232. public void InterpolationColors_Colors_InvalidBlend ()
  233. {
  234. // default Blend doesn't allow getting this property
  235. Assert.IsNotNull (default_brush.InterpolationColors.Colors);
  236. }
  237. [Test]
  238. [ExpectedException (typeof (ArgumentException))]
  239. public void InterpolationColors_Positions_InvalidBlend ()
  240. {
  241. // default Blend doesn't allow getting this property
  242. Assert.IsNotNull (default_brush.InterpolationColors.Positions);
  243. }
  244. [Test]
  245. [ExpectedException (typeof (IndexOutOfRangeException))]
  246. public void LinearColors_Empty ()
  247. {
  248. default_brush.LinearColors = new Color[0];
  249. }
  250. [Test]
  251. [ExpectedException (typeof (IndexOutOfRangeException))]
  252. public void LinearColors_One ()
  253. {
  254. default_brush.LinearColors = new Color[1];
  255. }
  256. [Test]
  257. public void LinearColors_Two ()
  258. {
  259. Assert.AreEqual (Color.FromArgb (255, 0, 0, 255), default_brush.LinearColors[0], "0");
  260. Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), default_brush.LinearColors[1], "1");
  261. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  262. lgb.LinearColors = new Color[2] { Color.Black, Color.White };
  263. // not the same, the alpha is changed to 255 so they can't compare
  264. Assert.AreEqual (Color.FromArgb (255, 0, 0, 0), lgb.LinearColors[0], "0");
  265. Assert.AreEqual (Color.FromArgb (255, 255, 255, 255), lgb.LinearColors[1], "1");
  266. }
  267. [Test]
  268. public void LinearColors_Three ()
  269. {
  270. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  271. lgb.LinearColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
  272. // not the same, the alpha is changed to 255 so they can't compare
  273. Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), lgb.LinearColors[0], "0");
  274. Assert.AreEqual (Color.FromArgb (255, 0, 128, 0), lgb.LinearColors[1], "1");
  275. }
  276. [Test]
  277. [ExpectedException (typeof (ArgumentNullException))]
  278. public void Transform_Null ()
  279. {
  280. default_brush.Transform = null;
  281. }
  282. [Test]
  283. public void Transform_Empty ()
  284. {
  285. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  286. lgb.Transform = new Matrix ();
  287. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
  288. }
  289. [Test]
  290. [ExpectedException (typeof (ArgumentException))]
  291. public void Transform_NonInvertible ()
  292. {
  293. default_brush.Transform = new Matrix (123, 24, 82, 16, 47, 30);
  294. }
  295. [Test]
  296. public void WrapMode_AllValid ()
  297. {
  298. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  299. lgb.WrapMode = WrapMode.Tile;
  300. Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
  301. lgb.WrapMode = WrapMode.TileFlipX;
  302. Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
  303. lgb.WrapMode = WrapMode.TileFlipY;
  304. Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
  305. lgb.WrapMode = WrapMode.TileFlipXY;
  306. Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
  307. }
  308. [Test]
  309. [ExpectedException (typeof (ArgumentException))]
  310. public void WrapMode_Clamp ()
  311. {
  312. default_brush.WrapMode = WrapMode.Clamp;
  313. }
  314. [Test]
  315. [ExpectedException (typeof (InvalidEnumArgumentException))]
  316. public void WrapMode_Invalid ()
  317. {
  318. default_brush.WrapMode = (WrapMode) Int32.MinValue;
  319. }
  320. [Test]
  321. public void Clone ()
  322. {
  323. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  324. LinearGradientBrush clone = (LinearGradientBrush) lgb.Clone ();
  325. Assert.AreEqual (lgb.Blend.Factors.Length, clone.Blend.Factors.Length, "Blend.Factors.Length");
  326. Assert.AreEqual (lgb.Blend.Positions.Length, clone.Blend.Positions.Length, "Blend.Positions.Length");
  327. Assert.AreEqual (lgb.GammaCorrection, clone.GammaCorrection, "GammaCorrection");
  328. Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
  329. Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
  330. Assert.AreEqual (lgb.Rectangle, clone.Rectangle, "Rectangle");
  331. Assert.AreEqual (lgb.Transform, clone.Transform, "Transform");
  332. Assert.AreEqual (lgb.WrapMode, clone.WrapMode, "WrapMode");
  333. }
  334. [Test]
  335. [ExpectedException (typeof (ArgumentNullException))]
  336. public void MultiplyTransform1_Null ()
  337. {
  338. default_brush.MultiplyTransform (null);
  339. }
  340. [Test]
  341. [ExpectedException (typeof (ArgumentNullException))]
  342. public void MultiplyTransform2_Null ()
  343. {
  344. default_brush.MultiplyTransform (null, MatrixOrder.Append);
  345. }
  346. [Test]
  347. public void MultiplyTransform2_Invalid ()
  348. {
  349. default_brush.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
  350. }
  351. [Test]
  352. [NUnit.Framework.Category ("NotWorking")]
  353. public void ResetTransform ()
  354. {
  355. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  356. Assert.IsFalse (lgb.Transform.IsIdentity, "Transform.IsIdentity");
  357. lgb.ResetTransform ();
  358. Assert.IsTrue (lgb.Transform.IsIdentity, "Reset.IsIdentity");
  359. }
  360. [Test]
  361. [NUnit.Framework.Category ("NotWorking")]
  362. public void RotateTransform ()
  363. {
  364. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  365. lgb.RotateTransform (90);
  366. float[] elements = lgb.Transform.Elements;
  367. Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
  368. Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
  369. Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
  370. Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
  371. Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
  372. Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
  373. lgb.RotateTransform (270);
  374. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
  375. }
  376. [Test]
  377. [NUnit.Framework.Category ("NotWorking")]
  378. public void RotateTransform_Max ()
  379. {
  380. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  381. lgb.RotateTransform (Single.MaxValue);
  382. float[] elements = lgb.Transform.Elements;
  383. Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
  384. Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
  385. Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
  386. Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
  387. Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
  388. Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
  389. }
  390. [Test]
  391. [NUnit.Framework.Category ("NotWorking")]
  392. public void RotateTransform_Min ()
  393. {
  394. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  395. lgb.RotateTransform (Single.MinValue);
  396. float[] elements = lgb.Transform.Elements;
  397. Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
  398. Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
  399. Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
  400. Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
  401. Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
  402. Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
  403. }
  404. [Test]
  405. [ExpectedException (typeof (ArgumentException))]
  406. public void RotateTransform_InvalidOrder ()
  407. {
  408. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  409. lgb.RotateTransform (720, (MatrixOrder) Int32.MinValue);
  410. }
  411. [Test]
  412. public void ScaleTransform ()
  413. {
  414. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  415. lgb.ScaleTransform (2, 4);
  416. float[] elements = lgb.Transform.Elements;
  417. Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
  418. Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
  419. Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
  420. Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
  421. Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
  422. Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
  423. lgb.ScaleTransform (0.5f, 0.25f);
  424. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
  425. }
  426. [Test]
  427. public void ScaleTransform_MaxMin ()
  428. {
  429. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  430. lgb.ScaleTransform (Single.MaxValue, Single.MinValue);
  431. float[] elements = lgb.Transform.Elements;
  432. Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
  433. Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
  434. Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
  435. Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
  436. Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
  437. Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
  438. }
  439. [Test]
  440. [ExpectedException (typeof (ArgumentException))]
  441. public void ScaleTransform_InvalidOrder ()
  442. {
  443. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  444. lgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
  445. }
  446. [Test]
  447. public void SetBlendTriangularShape_Focus ()
  448. {
  449. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  450. // max valid
  451. lgb.SetBlendTriangularShape (1);
  452. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  453. // min valid
  454. lgb.SetBlendTriangularShape (0);
  455. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  456. // middle
  457. lgb.SetBlendTriangularShape (0.5f);
  458. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  459. // no impact on matrix
  460. }
  461. [Test]
  462. public void SetBlendTriangularShape_Scale ()
  463. {
  464. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  465. // max valid
  466. lgb.SetBlendTriangularShape (0, 1);
  467. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  468. // min valid
  469. lgb.SetBlendTriangularShape (1, 0);
  470. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  471. // middle
  472. lgb.SetBlendTriangularShape (0.5f, 0.5f);
  473. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  474. // no impact on matrix
  475. }
  476. [Test]
  477. [ExpectedException (typeof (ArgumentException))]
  478. public void SetBlendTriangularShape_FocusTooSmall ()
  479. {
  480. default_brush.SetBlendTriangularShape (-1);
  481. }
  482. [Test]
  483. [ExpectedException (typeof (ArgumentException))]
  484. public void SetBlendTriangularShape_FocusTooBig ()
  485. {
  486. default_brush.SetBlendTriangularShape (1.01f);
  487. }
  488. [Test]
  489. [ExpectedException (typeof (ArgumentException))]
  490. public void SetBlendTriangularShape_ScaleTooSmall ()
  491. {
  492. default_brush.SetBlendTriangularShape (1, -1);
  493. }
  494. [Test]
  495. [ExpectedException (typeof (ArgumentException))]
  496. public void SetBlendTriangularShape_ScaleTooBig ()
  497. {
  498. default_brush.SetBlendTriangularShape (1, 1.01f);
  499. }
  500. [Test]
  501. public void SetSigmaBellShape_Focus ()
  502. {
  503. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  504. // max valid
  505. lgb.SetSigmaBellShape (1);
  506. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  507. // min valid
  508. lgb.SetSigmaBellShape (0);
  509. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  510. // middle
  511. lgb.SetSigmaBellShape (0.5f);
  512. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  513. // no impact on matrix
  514. }
  515. [Test]
  516. public void SetSigmaBellShape_Scale ()
  517. {
  518. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  519. // max valid
  520. lgb.SetSigmaBellShape (0, 1);
  521. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
  522. // min valid
  523. lgb.SetSigmaBellShape (1, 0);
  524. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-2");
  525. // middle
  526. lgb.SetSigmaBellShape (0.5f, 0.5f);
  527. Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-3");
  528. // no impact on matrix
  529. }
  530. [Test]
  531. [ExpectedException (typeof (ArgumentException))]
  532. public void SetSigmaBellShape_FocusTooSmall ()
  533. {
  534. default_brush.SetSigmaBellShape (-1);
  535. }
  536. [Test]
  537. [ExpectedException (typeof (ArgumentException))]
  538. public void SetSigmaBellShape_FocusTooBig ()
  539. {
  540. default_brush.SetSigmaBellShape (1.01f);
  541. }
  542. [Test]
  543. [ExpectedException (typeof (ArgumentException))]
  544. public void SetSigmaBellShape_ScaleTooSmall ()
  545. {
  546. default_brush.SetSigmaBellShape (1, -1);
  547. }
  548. [Test]
  549. [ExpectedException (typeof (ArgumentException))]
  550. public void SetSigmaBellShape_ScaleTooBig ()
  551. {
  552. default_brush.SetSigmaBellShape (1, 1.01f);
  553. }
  554. [Test]
  555. public void TranslateTransform ()
  556. {
  557. LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
  558. lgb.TranslateTransform (1, 1);
  559. float[] elements = lgb.Transform.Elements;
  560. Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
  561. Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
  562. Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
  563. Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
  564. Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
  565. Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
  566. lgb.TranslateTransform (-1, -1);
  567. // strangely lgb.Transform.IsIdentity is false
  568. elements = lgb.Transform.Elements;
  569. Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
  570. Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
  571. Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
  572. Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
  573. Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
  574. Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
  575. }
  576. [Test]
  577. [ExpectedException (typeof (ArgumentException))]
  578. public void TranslateTransform_InvalidOrder ()
  579. {
  580. LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
  581. lgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
  582. }
  583. }
  584. }