1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
|
//
// System.Drawing.Drawing2D.PathGradientBrush unit tests
//
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2006 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 System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Security.Permissions;
using NUnit.Framework;
namespace MonoTests.System.Drawing.Drawing2D {
[TestFixture]
public class PathGradientBrushTest {
private Point[] pts_2i;
private PointF[] pts_2f;
private Matrix empty_matrix;
private void CheckDefaultRectangle (string message, RectangleF rect)
{
Assert.AreEqual (1f, rect.X, message + ".Rectangle.X");
Assert.AreEqual (2f, rect.Y, message + ".Rectangle.Y");
Assert.AreEqual (19f, rect.Width, message + ".Rectangle.Width");
Assert.AreEqual (28f, rect.Height, message + ".Rectangle.Height");
}
private void CheckDefaults (PathGradientBrush pgb)
{
Assert.AreEqual (1, pgb.Blend.Factors.Length, "Blend.Factors.Length");
Assert.AreEqual (1f, pgb.Blend.Factors[0], "Blend.Factors[0]");
Assert.AreEqual (1, pgb.Blend.Positions.Length, "Blend.Positions.Length");
Assert.AreEqual (0f, pgb.Blend.Positions[0], 1e-30, "Blend.Positions[0]");
Assert.AreEqual (10.5f, pgb.CenterPoint.X, "CenterPoint.X");
Assert.AreEqual (16f, pgb.CenterPoint.Y, "CenterPoint.Y");
Assert.IsTrue (pgb.FocusScales.IsEmpty, "FocusScales");
Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "InterpolationColors.Colors.Length");
Assert.AreEqual (0, pgb.InterpolationColors.Colors[0].ToArgb (), "InterpolationColors.Colors[0]");
Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "InterpolationColors.Positions.Length");
Assert.AreEqual (0f, pgb.InterpolationColors.Positions[0], 1e-38, "InterpolationColors.Positions[0]");
CheckDefaultRectangle (String.Empty, pgb.Rectangle);
Assert.AreEqual (1, pgb.SurroundColors.Length, "SurroundColors.Length");
Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors[0]");
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform");
}
private void CheckPointsDefaults (PathGradientBrush pgb)
{
CheckDefaults (pgb);
Assert.AreEqual (-16777216, pgb.CenterColor.ToArgb (), "CenterColor");
}
private void CheckPathDefaults (PathGradientBrush pgb)
{
CheckDefaults (pgb);
Assert.AreEqual (-1, pgb.CenterColor.ToArgb (), "CenterColor");
}
[TestFixtureSetUp]
public void FixtureSetUp ()
{
pts_2i = new Point[2] { new Point (1, 2), new Point (20, 30) };
pts_2f = new PointF[2] { new PointF (1, 2), new PointF (20, 30) };
empty_matrix = new Matrix ();
}
[Test]
public void Constructor_GraphicsPath_Null ()
{
GraphicsPath gp = null;
Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (gp));
}
[Test]
public void Constructor_GraphicsPath_Empty ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (gp));
}
}
[Test]
public void Constructor_GraphicsPath_SinglePoint ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
gp.AddLines (new Point[1] { new Point (1, 1) });
// Special case - a line with a single point is valid
Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (gp));
}
}
[Test]
public void Constructor_GraphicsPath_Line ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
gp.AddLines (pts_2f);
using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
CheckPathDefaults (pgb);
Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
}
}
}
[Test]
public void Constructor_Point_Null ()
{
Point[] pts = null;
Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts));
}
[Test]
public void Constructor_Point_Empty ()
{
Point[] pts = new Point [0];
Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
}
[Test]
public void Constructor_Point_One ()
{
Point[] pts = new Point[1] { new Point (1, 1) };
Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
}
[Test]
public void Constructor_Point_Two ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2i)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_Point_WrapMode_Clamp ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Clamp)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_Point_WrapMode_Tile ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Tile)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_Point_WrapMode_TileFlipX ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipX)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_Point_WrapMode_TileFlipY ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipY)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_Point_WrapMode_TileFlipXY ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipXY)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_PointF_Null ()
{
PointF[] pts = null;
Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts));
}
[Test]
public void Constructor_PointF_Empty ()
{
PointF[] pts = new PointF[0];
Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
}
[Test]
public void Constructor_PointF_One ()
{
PointF[] pts = new PointF[1] { new PointF (1, 1) };
Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
}
[Test]
public void Constructor_PointF_Two ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_PointF_WrapMode_Invalid ()
{
Assert.Throws<InvalidEnumArgumentException> (() => new PathGradientBrush (pts_2f, (WrapMode)Int32.MinValue));
}
[Test]
public void Constructor_PointF_WrapMode_Clamp ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_PointF_WrapMode_Tile ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Tile)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_PointF_WrapMode_TileFlipX ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipX)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_PointF_WrapMode_TileFlipY ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipY)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Constructor_PointF_WrapMode_TileFlipXY ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
CheckPointsDefaults (pgb);
Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
}
}
[Test]
public void Blend ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
// change not accepted - but no exception is thrown
pgb.Blend.Factors = new float[0];
Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-0");
pgb.Blend.Factors = new float[2];
Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-1");
// change not accepted - but no exception is thrown
pgb.Blend.Positions = new float[0];
Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-0");
pgb.Blend.Positions = new float[2];
Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-1");
}
}
[Test]
public void FocusScales ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
PointF fs = new PointF (Single.MaxValue, Single.MinValue);
pgb.FocusScales = fs;
Assert.AreEqual (Single.MaxValue, pgb.FocusScales.X, "MaxValue");
Assert.AreEqual (Single.MinValue, pgb.FocusScales.Y, "MinValue");
fs.X = Single.NaN;
fs.Y = Single.NegativeInfinity;
pgb.FocusScales = fs;
Assert.AreEqual (Single.NaN, pgb.FocusScales.X, "NaN");
Assert.AreEqual (Single.NegativeInfinity, pgb.FocusScales.Y, "NegativeInfinity");
}
}
[Test]
public void CenterColor ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
pgb.CenterColor = Color.Black;
Assert.AreEqual (Color.Black.ToArgb (), pgb.CenterColor.ToArgb (), "Black");
pgb.CenterColor = Color.Transparent;
Assert.AreEqual (Color.Transparent.ToArgb (), pgb.CenterColor.ToArgb (), "Transparent");
}
}
[Test]
public void CenterPoint ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
PointF cp = new PointF (Single.MaxValue, Single.MinValue);
pgb.CenterPoint = cp;
Assert.AreEqual (Single.MaxValue, pgb.CenterPoint.X, "MaxValue");
Assert.AreEqual (Single.MinValue, pgb.CenterPoint.Y, "MinValue");
cp.X = Single.NaN;
cp.Y = Single.NegativeInfinity;
pgb.CenterPoint = cp;
Assert.AreEqual (Single.NaN, pgb.CenterPoint.X, "NaN");
Assert.AreEqual (Single.NegativeInfinity, pgb.CenterPoint.Y, "NegativeInfinity");
}
}
[Test]
public void InterpolationColors ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
// change not accepted - but no exception is thrown
pgb.InterpolationColors.Colors = new Color[0];
Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-0");
pgb.InterpolationColors.Colors = new Color[2];
Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-1");
// change not accepted - but no exception is thrown
pgb.InterpolationColors.Positions = new float[0];
Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-0");
pgb.InterpolationColors.Positions = new float[2];
Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-1");
}
}
[Test]
public void Rectangle ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
CheckDefaultRectangle ("Original", pgb.Rectangle);
pgb.MultiplyTransform (new Matrix (2, 0, 0, 2, 2, 2));
CheckDefaultRectangle ("Multiply", pgb.Rectangle);
pgb.ResetTransform ();
CheckDefaultRectangle ("Reset", pgb.Rectangle);
pgb.RotateTransform (90);
CheckDefaultRectangle ("Rotate", pgb.Rectangle);
pgb.ScaleTransform (4, 0.25f);
CheckDefaultRectangle ("Scale", pgb.Rectangle);
pgb.TranslateTransform (-10, -20);
CheckDefaultRectangle ("Translate", pgb.Rectangle);
pgb.SetBlendTriangularShape (0.5f);
CheckDefaultRectangle ("SetBlendTriangularShape", pgb.Rectangle);
pgb.SetSigmaBellShape (0.5f);
CheckDefaultRectangle ("SetSigmaBellShape", pgb.Rectangle);
}
}
[Test]
public void SurroundColors_Empty ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
Assert.Throws<ArgumentException> (() => pgb.SurroundColors = new Color[0]);
}
}
[Test]
public void SurroundColors_2PointF ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
// default values
Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-0");
Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-0");
// default can't be changed
pgb.SurroundColors[0] = Color.Gold;
Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
// 2 empty color isn't valid, change isn't accepted
pgb.SurroundColors = new Color[2];
Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
pgb.SurroundColors = new Color[2] { Color.Black, Color.White };
Assert.AreEqual (2, pgb.SurroundColors.Length, "Length-2");
Assert.AreEqual (-16777216, pgb.SurroundColors[0].ToArgb (), "SurroundColors-2");
Assert.AreEqual (-1, pgb.SurroundColors[1].ToArgb (), "SurroundColors-3");
}
}
[Test]
public void SurroundColors_3PointsF ()
{
PointF[] points = new PointF[3] { new PointF (5, 50), new PointF (10, 100), new PointF (20, 75) };
using (PathGradientBrush pgb = new PathGradientBrush (points)) {
// 3 empty color isn't valid, change isn't accepted
pgb.SurroundColors = new Color[3] { Color.Empty, Color.Empty, Color.Empty };
Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
pgb.SurroundColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
// change not accepted - but no exception is thrown
Assert.AreEqual (3, pgb.SurroundColors.Length, "Length-1");
Assert.AreEqual (-65536, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
Assert.AreEqual (-16744448, pgb.SurroundColors[1].ToArgb (), "SurroundColors-2");
Assert.AreEqual (-16776961, pgb.SurroundColors[2].ToArgb (), "SurroundColors-3");
}
}
[Test]
public void Transform_Null ()
{
Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts_2f, WrapMode.Clamp).Transform = null);
}
[Test]
public void Transform_Empty ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.Transform = new Matrix ();
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
}
}
[Test]
public void Transform_NonInvertible ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.Transform = new Matrix (123, 24, 82, 16, 47, 30));
}
}
[Test]
public void WrapMode_All ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
foreach (WrapMode wm in Enum.GetValues (typeof (WrapMode))) {
pgb.WrapMode = wm;
Assert.AreEqual (wm, pgb.WrapMode, wm.ToString ());
}
}
}
[Test]
public void WrapMode_Invalid ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<InvalidEnumArgumentException> (() => pgb.WrapMode = (WrapMode) Int32.MinValue);
}
}
[Test]
public void Clone ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
gp.AddLines (pts_2f);
using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
using (PathGradientBrush clone = (PathGradientBrush) pgb.Clone ()) {
CheckPathDefaults (clone);
Assert.AreEqual (WrapMode.Clamp, clone.WrapMode, "WrapMode");
}
}
}
}
[Test]
public void MultiplyTransform1_Null ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentNullException> (() => pgb.MultiplyTransform (null));
}
}
[Test]
public void MultiplyTransform2_Null ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentNullException> (() => pgb.MultiplyTransform (null, MatrixOrder.Append));
}
}
[Test]
public void MultiplyTransform2_Invalid ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
}
}
[Test]
public void MultiplyTransform_NonInvertible ()
{
using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.MultiplyTransform (noninvertible));
}
}
}
[Test]
public void ResetTransform ()
{
using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.Transform = m;
Assert.IsFalse (pgb.Transform.IsIdentity, "Transform.IsIdentity");
pgb.ResetTransform ();
Assert.IsTrue (pgb.Transform.IsIdentity, "Reset.IsIdentity");
}
}
}
[Test]
public void RotateTransform ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.RotateTransform (90);
float[] elements = pgb.Transform.Elements;
Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
pgb.RotateTransform (270);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
}
}
[Test]
[NUnit.Framework.Category ("NotWorking")]
public void RotateTransform_Max ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.RotateTransform (Single.MaxValue);
float[] elements = pgb.Transform.Elements;
Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
}
}
[Test]
[NUnit.Framework.Category ("NotWorking")]
public void RotateTransform_Min ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.RotateTransform (Single.MinValue);
float[] elements = pgb.Transform.Elements;
Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
}
}
[Test]
public void RotateTransform_InvalidOrder ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.RotateTransform (720, (MatrixOrder) Int32.MinValue));
}
}
[Test]
public void ScaleTransform ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.ScaleTransform (2, 4);
float[] elements = pgb.Transform.Elements;
Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
pgb.ScaleTransform (0.5f, 0.25f);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
}
}
[Test]
public void ScaleTransform_MaxMin ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.ScaleTransform (Single.MaxValue, Single.MinValue);
float[] elements = pgb.Transform.Elements;
Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
}
}
[Test]
public void ScaleTransform_InvalidOrder ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue));
}
}
[Test]
public void SetBlendTriangularShape_Focus ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
// max valid
pgb.SetBlendTriangularShape (1);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// min valid
pgb.SetBlendTriangularShape (0);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// middle
pgb.SetBlendTriangularShape (0.5f);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// no impact on matrix
}
}
[Test]
public void SetBlendTriangularShape_Scale ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
// max valid
pgb.SetBlendTriangularShape (0, 1);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// min valid
pgb.SetBlendTriangularShape (1, 0);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// middle
pgb.SetBlendTriangularShape (0.5f, 0.5f);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// no impact on matrix
}
}
[Test]
public void SetBlendTriangularShape_FocusTooSmall ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (-1));
}
}
[Test]
public void SetBlendTriangularShape_FocusTooBig ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1.01f));
}
}
[Test]
public void SetBlendTriangularShape_ScaleTooSmall ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1, -1));
}
}
[Test]
public void SetBlendTriangularShape_ScaleTooBig ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1, 1.01f));
}
}
[Test]
public void SetSigmaBellShape_Focus ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
// max valid
pgb.SetSigmaBellShape (1);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// min valid
pgb.SetSigmaBellShape (0);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// middle
pgb.SetSigmaBellShape (0.5f);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// no impact on matrix
}
}
[Test]
public void SetSigmaBellShape_Scale ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
// max valid
pgb.SetSigmaBellShape (0, 1);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
// min valid
pgb.SetSigmaBellShape (1, 0);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-2");
// middle
pgb.SetSigmaBellShape (0.5f, 0.5f);
Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-3");
// no impact on matrix
}
}
[Test]
public void SetSigmaBellShape_FocusTooSmall ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (-1));
}
}
[Test]
public void SetSigmaBellShape_FocusTooBig ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1.01f));
}
}
[Test]
public void SetSigmaBellShape_ScaleTooSmall ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1, -1));
}
}
[Test]
public void SetSigmaBellShape_ScaleTooBig ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1, 1.01f));
}
}
[Test]
public void TranslateTransform ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
pgb.TranslateTransform (1, 1);
float[] elements = pgb.Transform.Elements;
Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
pgb.TranslateTransform (-1, -1);
// strangely lgb.Transform.IsIdentity is false
elements = pgb.Transform.Elements;
Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
}
}
[Test]
public void TranslateTransform_InvalidOrder ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Assert.Throws<ArgumentException> (() => pgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue));
}
}
[Test]
public void Transform_Operations ()
{
using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
Matrix clone = pgb.Transform.Clone ();
Matrix mul = clone.Clone ();
clone.Multiply (mul, MatrixOrder.Append);
pgb.MultiplyTransform (mul, MatrixOrder.Append);
Assert.AreEqual (pgb.Transform, clone, "Multiply/Append");
clone.Multiply (mul, MatrixOrder.Prepend);
pgb.MultiplyTransform (mul, MatrixOrder.Prepend);
Assert.AreEqual (pgb.Transform, clone, "Multiply/Prepend");
clone.Rotate (45, MatrixOrder.Append);
pgb.RotateTransform (45, MatrixOrder.Append);
Assert.AreEqual (pgb.Transform, clone, "Rotate/Append");
clone.Rotate (45, MatrixOrder.Prepend);
pgb.RotateTransform (45, MatrixOrder.Prepend);
Assert.AreEqual (pgb.Transform, clone, "Rotate/Prepend");
clone.Scale (0.25f, 2, MatrixOrder.Append);
pgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
Assert.AreEqual (pgb.Transform, clone, "Scale/Append");
clone.Scale (0.25f, 2, MatrixOrder.Prepend);
pgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
Assert.AreEqual (pgb.Transform, clone, "Scale/Prepend");
clone.Translate (10, 20, MatrixOrder.Append);
pgb.TranslateTransform (10, 20, MatrixOrder.Append);
Assert.AreEqual (pgb.Transform, clone, "Translate/Append");
clone.Translate (30, 40, MatrixOrder.Prepend);
pgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
Assert.AreEqual (pgb.Transform, clone, "Translate/Prepend");
clone.Reset ();
pgb.ResetTransform ();
Assert.AreEqual (pgb.Transform, clone, "Reset");
}
}
[Test]
public void Blend_Null ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
gp.AddLines (pts_2f);
using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
Assert.Throws<NullReferenceException> (() => pgb.Blend = null);
}
}
}
[Test]
public void InterpolationColors_Null ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
gp.AddLines (pts_2f);
using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
Assert.Throws<NullReferenceException> (() => pgb.InterpolationColors = null);
}
}
}
[Test]
public void SurroundColors_Null ()
{
using (GraphicsPath gp = new GraphicsPath ()) {
gp.AddLines (pts_2f);
using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
Assert.Throws<NullReferenceException> (() => pgb.SurroundColors = null);
}
}
}
}
}
|