| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- // Tests for System.Drawing.SystemPens.cs
- //
- // Author:
- // Ravindra ([email protected])
- //
- //
- // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using NUnit.Framework;
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- namespace MonoTests.System.Drawing
- {
- [TestFixture]
- public class SystemPensTest : Assertion
- {
- [TearDown]
- public void TearDown () {}
- [SetUp]
- public void SetUp () {}
- [Test]
- public void TestActiveCaptionText ()
- {
- Pen pen;
- pen = SystemPens.ActiveCaptionText;
- CheckProperties (pen, "P1", SystemColors.ActiveCaptionText);
- CheckMethods (pen, "M1");
- }
- [Test]
- public void TestControl ()
- {
- Pen pen;
- pen = SystemPens.Control;
- CheckProperties (pen, "P2", SystemColors.Control);
- CheckMethods (pen, "M2");
- }
- [Test]
- public void TestControlDark ()
- {
- Pen pen;
- pen = SystemPens.ControlDark;
- CheckProperties (pen, "P3", SystemColors.ControlDark);
- CheckMethods (pen, "M3");
- }
- [Test]
- public void TestControlDarkDark ()
- {
- Pen pen;
- pen = SystemPens.ControlDarkDark;
- CheckProperties (pen, "P4", SystemColors.ControlDarkDark);
- CheckMethods (pen, "M4");
- }
- [Test]
- public void TestControlLight ()
- {
- Pen pen;
- pen = SystemPens.ControlLight;
- CheckProperties (pen, "P5", SystemColors.ControlLight);
- CheckMethods (pen, "M5");
- }
- [Test]
- public void TestControlLightLight ()
- {
- Pen pen;
- pen = SystemPens.ControlLightLight;
- CheckProperties (pen, "P6", SystemColors.ControlLightLight);
- CheckMethods (pen, "M6");
- }
- [Test]
- public void TestControlText ()
- {
- Pen pen;
- pen = SystemPens.ControlText;
- CheckProperties (pen, "P7", SystemColors.ControlText);
- CheckMethods (pen, "M7");
- }
- [Test]
- public void TestGrayText ()
- {
- Pen pen;
- pen = SystemPens.GrayText;
- CheckProperties (pen, "P8", SystemColors.GrayText);
- CheckMethods (pen, "M8");
- }
- [Test]
- public void TestHighlight ()
- {
- Pen pen;
- pen = SystemPens.Highlight;
- CheckProperties (pen, "P9", SystemColors.Highlight);
- CheckMethods (pen, "M9");
- }
- [Test]
- public void TestHighlightText ()
- {
- Pen pen;
- pen = SystemPens.HighlightText;
- CheckProperties (pen, "P10", SystemColors.HighlightText);
- CheckMethods (pen, "M10");
- }
- [Test]
- public void TestInactiveCaptionText ()
- {
- Pen pen;
- pen = SystemPens.InactiveCaptionText;
- CheckProperties (pen, "P11", SystemColors.InactiveCaptionText);
- CheckMethods (pen, "M11");
- }
- [Test]
- public void TestInfoText ()
- {
- Pen pen;
- pen = SystemPens.InfoText;
- CheckProperties (pen, "P12", SystemColors.InfoText);
- CheckMethods (pen, "M12");
- }
- [Test]
- public void TestMenuText ()
- {
- Pen pen;
- pen = SystemPens.MenuText;
- CheckProperties (pen, "P13", SystemColors.MenuText);
- CheckMethods (pen, "M13");
- }
- [Test]
- public void TestWindowFrame ()
- {
- Pen pen;
- pen = SystemPens.WindowFrame;
- CheckProperties (pen, "P14", SystemColors.WindowFrame);
- CheckMethods (pen, "M14");
- }
- [Test]
- public void TestWindowText ()
- {
- Pen pen;
- pen = SystemPens.WindowText;
- CheckProperties (pen, "P15", SystemColors.WindowText);
- CheckMethods (pen, "M15");
- }
- [Test]
- public void TestFromSystemColor ()
- {
- Pen pen;
- pen = SystemPens.FromSystemColor (SystemColors.MenuText);
- CheckProperties (pen, "P16", SystemColors.MenuText);
- CheckMethods (pen, "M16");
- try {
- pen = SystemPens.FromSystemColor (Color.Red);
- Fail ("M17: must throw ArgumentException");
- } catch (Exception e) {
- Assert ("M17", e is ArgumentException);
- }
- }
- // helper test functions
- void CheckProperties (Pen pen, String tag, Color sysColor)
- {
- // Try modifying properties of a SystemPen.
- // ArgumentException must be thrown.
- Assert (tag + "#1", pen.Color.IsSystemColor);
- AssertEquals (tag + "#1", sysColor, pen.Color);
- try {
- pen.Alignment = PenAlignment.Center;
- Fail (tag + "#2: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#2", e is ArgumentException);
- }
- try {
- pen.Brush = new SolidBrush(Color.Red);
- Fail (tag + "#3: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#3", e is ArgumentException);
- }
- try {
- pen.Color = Color.Red;
- Fail (tag + "#4: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#4", e is ArgumentException);
- }
- try {
- pen.Color = sysColor;
- Fail (tag + "#5" + ": must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#5", e is ArgumentException);
- }
- /*
- try {
- // NotImplemented
- pen.CompoundArray = new float[2];
- Fail (tag + "#6: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#6", e is ArgumentException);
- }
- try {
- // NotImplemented
- pen.CustomEndCap = null;
- Fail (tag + "#7: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#7", e is ArgumentException);
- }
- try {
- // NotImplemented
- pen.CustomStartCap = null;
- Fail (tag + "#8: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#8", e is ArgumentException);
- }
- try {
- // NotImplemented
- pen.DashCap = DashCap.Flat;
- Fail (tag + "#9: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#9", e is ArgumentException);
- }
- */
- try {
- pen.DashOffset = 5.5F;
- Fail (tag + "#10: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#10", e is ArgumentException);
- }
- try {
- pen.DashPattern = null;
- Fail (tag + "#11: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#11", e is ArgumentException);
- }
- try {
- pen.DashStyle = DashStyle.Dot; // hangs!prob
- Fail (tag + "#12: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#12", e is ArgumentException);
- }
- /*
- try {
- // NotImplemented
- pen.EndCap = LineCap.Round;
- Fail (tag + "#13: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#13", e is ArgumentException);
- }
- */
- try {
- pen.LineJoin = LineJoin.Round;
- Fail (tag + "#14: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#14", e is ArgumentException);
- }
- try {
- pen.MiterLimit = 0.1f;
- Fail (tag + "#15: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#15", e is ArgumentException);
- }
- /*
- try {
- // NotImplemented
- pen.StartCap = LineCap.Square;
- Fail (tag + "#16: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#16", e is ArgumentException);
- }
- */
- try {
- pen.Transform = new Matrix (); //Matrix hangs!problem
- Fail (tag + "#17: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#17", e is ArgumentException);
- }
- try {
- pen.Width = 0.5F;
- Fail (tag + "#18: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#18", e is ArgumentException);
- }
- }
- void CheckMethods (Pen pen, String tag)
- {
- // Try modifying a SystemPen by calling methods.
- // ArgumentException must be thrown in some cases.
- /*
- try {
- // NotImplemented
- pen.SetLineCap (LineCap.Flat, LineCap.Round, DashCap.Triangle);
- Fail (tag + "#1: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#1", e is ArgumentException);
- }
- */
- try {
- pen.ResetTransform ();
- } catch {
- Fail (tag + "#2: unexpected Exception");
- }
- try {
- pen.RotateTransform (90);
- } catch {
- Fail (tag + "#3: unexpected Exception");
- }
- try {
- pen.ScaleTransform (2, 1);
- } catch {
- Fail (tag + "#4: unexpected Exception");
- }
- try {
- pen.TranslateTransform (10, 20);
- } catch {
- Fail (tag + "#5: unexpected Exception");
- }
- try {
- pen.MultiplyTransform (new Matrix ());
- } catch {
- Fail (tag + "#6: unexpected Exception");
- }
- try {
- pen.Clone ();
- } catch {
- Fail (tag + "#7: unexpected Exception");
- }
- try {
- pen.Dispose ();
- Fail (tag + "#8: must throw ArgumentException");
- } catch (Exception e) {
- Assert (tag + "#8", e is ArgumentException);
- }
- }
- }
- }
|