public void TestSetNewImage()
        {
            var imageSetter   = new ImageSetterManipulator();
            var originalImage = imageSetter.ManipulatedImage;

            var newImage = new CodedImage {
                Size = new Size(5, 5)
            };

            int[] newPixels, manipulatedPixels;
            using (newImage.LockPixels(out newPixels))
            {
                for (int i = 0; i < newPixels.Length; i++)
                {
                    newPixels[i] = i;
                }
            }

            imageSetter.SetNewImage(newImage);

            Assert.AreSame(originalImage, imageSetter.SourceImage, "Source image still should be same original object.");
            Assert.AreSame(originalImage, imageSetter.ManipulatedImage, "Manipulated image still should be same original object.");
            Assert.AreEqual(newImage.Size, imageSetter.ManipulatedImage.Size);

            using (newImage.LockPixels(out newPixels))
                using (imageSetter.ManipulatedImage.LockPixels(out manipulatedPixels))
                {
                    Assert.AreEqual(newPixels.Length, manipulatedPixels.Length);
                    for (int i = 0; i < newPixels.Length; i++)
                    {
                        Assert.AreEqual(newPixels[i], manipulatedPixels[i], string.Format("Pixels in position {0} should be same", i));
                    }
                }
        }
        public void TestOperationsCallsOnImageChanged()
        {
            var imageSetter      = new ImageSetterManipulator();
            var childManipulator = new ImageManipulatorTest.DummyManipulator(imageSetter);

            var newImage = new CodedImage {
                Size = new Size(5, 5)
            };

            AssertActionCallsOnImageChanged(childManipulator, () => imageSetter.SetNewImage(newImage));
        }
Exemple #3
0
        public override void TestRestoreManipulationsCore()
        {
            var srcImage = new CodedImage {
                Size = new Size(3, 2)
            };
            var imageSetter = new ImageSetterManipulator();

            imageSetter.SetNewImage(srcImage);

            var rotator = new ImageRotateManipulator(imageSetter);

            rotator.RotateCW();
            Assert.AreEqual(new Size(2, 3), rotator.ManipulatedImage.Size, "Manipulated image should be rotated.");

            srcImage.Size = new Size(5, 4);
            Assert.AreEqual(new Size(2, 3), rotator.ManipulatedImage.Size, "Manipulated image should not change.");

            imageSetter.SetNewImage(srcImage);
            Assert.AreEqual(new Size(5, 4), rotator.ManipulatedImage.Size, "Flip/Rotation manipulation should not be restored when called by parent manipulator.");

            rotator.RestoreManipulations("W");
            Assert.AreEqual(new Size(4, 5), rotator.ManipulatedImage.Size, "Flip/Rotation manipulation should restored when called manually.");
        }
        public override void TestRestoreManipulationsCore()
        {
            var imageSetter   = new ImageSetterManipulator();
            var originalImage = imageSetter.ManipulatedImage;

            var newImage = new CodedImage {
                Size = new Size(3, 2)
            };

            imageSetter.SetNewImage(newImage);
            Assert.AreSame(originalImage, imageSetter.ManipulatedImage, "Precondition: manipulated image should be same original object.");

            imageSetter.RestoreManipulations();
            Assert.AreSame(originalImage, imageSetter.ManipulatedImage, "Manipulated image still should be same original object.");

            imageSetter.Reset();
            Assert.AreSame(originalImage, imageSetter.ManipulatedImage, "Manipulated image still should be same original object.");
        }