TestSystemPens.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. // Tests for System.Drawing.SystemPens.cs
  2. //
  3. // Author:
  4. // Ravindra ([email protected])
  5. //
  6. //
  7. // Copyright (C) 2004 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 NUnit.Framework;
  29. using System;
  30. using System.Drawing;
  31. using System.Drawing.Drawing2D;
  32. namespace MonoTests.System.Drawing
  33. {
  34. [TestFixture]
  35. public class SystemPensTest : Assertion
  36. {
  37. [TearDown]
  38. public void TearDown () {}
  39. [SetUp]
  40. public void SetUp () {}
  41. [Test]
  42. public void TestActiveCaptionText ()
  43. {
  44. Pen pen;
  45. pen = SystemPens.ActiveCaptionText;
  46. CheckProperties (pen, "P1", SystemColors.ActiveCaptionText);
  47. CheckMethods (pen, "M1");
  48. }
  49. [Test]
  50. public void TestControl ()
  51. {
  52. Pen pen;
  53. pen = SystemPens.Control;
  54. CheckProperties (pen, "P2", SystemColors.Control);
  55. CheckMethods (pen, "M2");
  56. }
  57. [Test]
  58. public void TestControlDark ()
  59. {
  60. Pen pen;
  61. pen = SystemPens.ControlDark;
  62. CheckProperties (pen, "P3", SystemColors.ControlDark);
  63. CheckMethods (pen, "M3");
  64. }
  65. [Test]
  66. public void TestControlDarkDark ()
  67. {
  68. Pen pen;
  69. pen = SystemPens.ControlDarkDark;
  70. CheckProperties (pen, "P4", SystemColors.ControlDarkDark);
  71. CheckMethods (pen, "M4");
  72. }
  73. [Test]
  74. public void TestControlLight ()
  75. {
  76. Pen pen;
  77. pen = SystemPens.ControlLight;
  78. CheckProperties (pen, "P5", SystemColors.ControlLight);
  79. CheckMethods (pen, "M5");
  80. }
  81. [Test]
  82. public void TestControlLightLight ()
  83. {
  84. Pen pen;
  85. pen = SystemPens.ControlLightLight;
  86. CheckProperties (pen, "P6", SystemColors.ControlLightLight);
  87. CheckMethods (pen, "M6");
  88. }
  89. [Test]
  90. public void TestControlText ()
  91. {
  92. Pen pen;
  93. pen = SystemPens.ControlText;
  94. CheckProperties (pen, "P7", SystemColors.ControlText);
  95. CheckMethods (pen, "M7");
  96. }
  97. [Test]
  98. public void TestGrayText ()
  99. {
  100. Pen pen;
  101. pen = SystemPens.GrayText;
  102. CheckProperties (pen, "P8", SystemColors.GrayText);
  103. CheckMethods (pen, "M8");
  104. }
  105. [Test]
  106. public void TestHighlight ()
  107. {
  108. Pen pen;
  109. pen = SystemPens.Highlight;
  110. CheckProperties (pen, "P9", SystemColors.Highlight);
  111. CheckMethods (pen, "M9");
  112. }
  113. [Test]
  114. public void TestHighlightText ()
  115. {
  116. Pen pen;
  117. pen = SystemPens.HighlightText;
  118. CheckProperties (pen, "P10", SystemColors.HighlightText);
  119. CheckMethods (pen, "M10");
  120. }
  121. [Test]
  122. public void TestInactiveCaptionText ()
  123. {
  124. Pen pen;
  125. pen = SystemPens.InactiveCaptionText;
  126. CheckProperties (pen, "P11", SystemColors.InactiveCaptionText);
  127. CheckMethods (pen, "M11");
  128. }
  129. [Test]
  130. public void TestInfoText ()
  131. {
  132. Pen pen;
  133. pen = SystemPens.InfoText;
  134. CheckProperties (pen, "P12", SystemColors.InfoText);
  135. CheckMethods (pen, "M12");
  136. }
  137. [Test]
  138. public void TestMenuText ()
  139. {
  140. Pen pen;
  141. pen = SystemPens.MenuText;
  142. CheckProperties (pen, "P13", SystemColors.MenuText);
  143. CheckMethods (pen, "M13");
  144. }
  145. [Test]
  146. public void TestWindowFrame ()
  147. {
  148. Pen pen;
  149. pen = SystemPens.WindowFrame;
  150. CheckProperties (pen, "P14", SystemColors.WindowFrame);
  151. CheckMethods (pen, "M14");
  152. }
  153. [Test]
  154. public void TestWindowText ()
  155. {
  156. Pen pen;
  157. pen = SystemPens.WindowText;
  158. CheckProperties (pen, "P15", SystemColors.WindowText);
  159. CheckMethods (pen, "M15");
  160. }
  161. [Test]
  162. public void TestFromSystemColor ()
  163. {
  164. Pen pen;
  165. pen = SystemPens.FromSystemColor (SystemColors.MenuText);
  166. CheckProperties (pen, "P16", SystemColors.MenuText);
  167. CheckMethods (pen, "M16");
  168. try {
  169. pen = SystemPens.FromSystemColor (Color.Red);
  170. Fail ("M17: must throw ArgumentException");
  171. } catch (Exception e) {
  172. Assert ("M17", e is ArgumentException);
  173. }
  174. }
  175. // helper test functions
  176. void CheckProperties (Pen pen, String tag, Color sysColor)
  177. {
  178. // Try modifying properties of a SystemPen.
  179. // ArgumentException must be thrown.
  180. Assert (tag + "#1", pen.Color.IsSystemColor);
  181. AssertEquals (tag + "#1", sysColor, pen.Color);
  182. try {
  183. pen.Alignment = PenAlignment.Center;
  184. Fail (tag + "#2: must throw ArgumentException");
  185. } catch (Exception e) {
  186. Assert (tag + "#2", e is ArgumentException);
  187. }
  188. try {
  189. pen.Brush = new SolidBrush(Color.Red);
  190. Fail (tag + "#3: must throw ArgumentException");
  191. } catch (Exception e) {
  192. Assert (tag + "#3", e is ArgumentException);
  193. }
  194. try {
  195. pen.Color = Color.Red;
  196. Fail (tag + "#4: must throw ArgumentException");
  197. } catch (Exception e) {
  198. Assert (tag + "#4", e is ArgumentException);
  199. }
  200. try {
  201. pen.Color = sysColor;
  202. Fail (tag + "#5" + ": must throw ArgumentException");
  203. } catch (Exception e) {
  204. Assert (tag + "#5", e is ArgumentException);
  205. }
  206. /*
  207. try {
  208. // NotImplemented
  209. pen.CompoundArray = new float[2];
  210. Fail (tag + "#6: must throw ArgumentException");
  211. } catch (Exception e) {
  212. Assert (tag + "#6", e is ArgumentException);
  213. }
  214. try {
  215. // NotImplemented
  216. pen.CustomEndCap = null;
  217. Fail (tag + "#7: must throw ArgumentException");
  218. } catch (Exception e) {
  219. Assert (tag + "#7", e is ArgumentException);
  220. }
  221. try {
  222. // NotImplemented
  223. pen.CustomStartCap = null;
  224. Fail (tag + "#8: must throw ArgumentException");
  225. } catch (Exception e) {
  226. Assert (tag + "#8", e is ArgumentException);
  227. }
  228. try {
  229. // NotImplemented
  230. pen.DashCap = DashCap.Flat;
  231. Fail (tag + "#9: must throw ArgumentException");
  232. } catch (Exception e) {
  233. Assert (tag + "#9", e is ArgumentException);
  234. }
  235. */
  236. try {
  237. pen.DashOffset = 5.5F;
  238. Fail (tag + "#10: must throw ArgumentException");
  239. } catch (Exception e) {
  240. Assert (tag + "#10", e is ArgumentException);
  241. }
  242. try {
  243. pen.DashPattern = null;
  244. Fail (tag + "#11: must throw ArgumentException");
  245. } catch (Exception e) {
  246. Assert (tag + "#11", e is ArgumentException);
  247. }
  248. try {
  249. pen.DashStyle = DashStyle.Dot; // hangs!prob
  250. Fail (tag + "#12: must throw ArgumentException");
  251. } catch (Exception e) {
  252. Assert (tag + "#12", e is ArgumentException);
  253. }
  254. /*
  255. try {
  256. // NotImplemented
  257. pen.EndCap = LineCap.Round;
  258. Fail (tag + "#13: must throw ArgumentException");
  259. } catch (Exception e) {
  260. Assert (tag + "#13", e is ArgumentException);
  261. }
  262. */
  263. try {
  264. pen.LineJoin = LineJoin.Round;
  265. Fail (tag + "#14: must throw ArgumentException");
  266. } catch (Exception e) {
  267. Assert (tag + "#14", e is ArgumentException);
  268. }
  269. try {
  270. pen.MiterLimit = 0.1f;
  271. Fail (tag + "#15: must throw ArgumentException");
  272. } catch (Exception e) {
  273. Assert (tag + "#15", e is ArgumentException);
  274. }
  275. /*
  276. try {
  277. // NotImplemented
  278. pen.StartCap = LineCap.Square;
  279. Fail (tag + "#16: must throw ArgumentException");
  280. } catch (Exception e) {
  281. Assert (tag + "#16", e is ArgumentException);
  282. }
  283. */
  284. try {
  285. pen.Transform = new Matrix (); //Matrix hangs!problem
  286. Fail (tag + "#17: must throw ArgumentException");
  287. } catch (Exception e) {
  288. Assert (tag + "#17", e is ArgumentException);
  289. }
  290. try {
  291. pen.Width = 0.5F;
  292. Fail (tag + "#18: must throw ArgumentException");
  293. } catch (Exception e) {
  294. Assert (tag + "#18", e is ArgumentException);
  295. }
  296. }
  297. void CheckMethods (Pen pen, String tag)
  298. {
  299. // Try modifying a SystemPen by calling methods.
  300. // ArgumentException must be thrown in some cases.
  301. /*
  302. try {
  303. // NotImplemented
  304. pen.SetLineCap (LineCap.Flat, LineCap.Round, DashCap.Triangle);
  305. Fail (tag + "#1: must throw ArgumentException");
  306. } catch (Exception e) {
  307. Assert (tag + "#1", e is ArgumentException);
  308. }
  309. */
  310. try {
  311. pen.ResetTransform ();
  312. } catch {
  313. Fail (tag + "#2: unexpected Exception");
  314. }
  315. try {
  316. pen.RotateTransform (90);
  317. } catch {
  318. Fail (tag + "#3: unexpected Exception");
  319. }
  320. try {
  321. pen.ScaleTransform (2, 1);
  322. } catch {
  323. Fail (tag + "#4: unexpected Exception");
  324. }
  325. try {
  326. pen.TranslateTransform (10, 20);
  327. } catch {
  328. Fail (tag + "#5: unexpected Exception");
  329. }
  330. try {
  331. pen.MultiplyTransform (new Matrix ());
  332. } catch {
  333. Fail (tag + "#6: unexpected Exception");
  334. }
  335. try {
  336. pen.Clone ();
  337. } catch {
  338. Fail (tag + "#7: unexpected Exception");
  339. }
  340. try {
  341. pen.Dispose ();
  342. Fail (tag + "#8: must throw ArgumentException");
  343. } catch (Exception e) {
  344. Assert (tag + "#8", e is ArgumentException);
  345. }
  346. }
  347. }
  348. }