public unsafe void TestImageDiffsSucessCalculation()
        {
            Mock <IImageDiffView>    diffViewMock         = new Mock <IImageDiffView>();
            Mock <IProgressControls> progressControlsMock = new Mock <IProgressControls>();

            byte[] leftBitmap  = new byte[0];
            byte[] rightBitmap = new byte[0];

            fixed(byte *leftPointer = leftBitmap)
            fixed(byte *rightPointer = rightBitmap)
            {
                ImageDiffOperations.CalculateImageDiff(
                    diffViewMock.Object, progressControlsMock.Object,
                    leftPointer, rightPointer, 0, 0);
            }

            progressControlsMock.Verify(
                progress => progress.ShowProgress(),
                Times.Once(),
                "Progress should be displayed");

            progressControlsMock.Verify(
                progress => progress.HideProgress(),
                Times.Once(),
                "Progress should be hidden");

            diffViewMock.Verify(
                diffView => diffView.SetDiffImageBytes(It.IsAny <byte[]>()),
                Times.Once(),
                "SetDiffImageBytes should be called.");
        }
예제 #2
0
        unsafe void BrowseButton_Activated(object sender, EventArgs e)
        {
            NSOpenPanel panel = new NSOpenPanel();

            panel.CanChooseFiles          = true;
            panel.CanChooseDirectories    = false;
            panel.AllowsMultipleSelection = true;
            panel.CanCreateDirectories    = true;

            using (panel)
            {
                nint result = panel.RunModal();
                if (result != 1)
                {
                    return;
                }

                NSUrl[] urls = panel.Urls;
                if (urls.Length == 0)
                {
                    return;
                }

                NSUrl leftImagePath  = urls[1];
                NSUrl rightImagePath = urls[0];

                mLeftImage  = new NSImage(leftImagePath.Path, false);
                mRightImage = new NSImage(rightImagePath.Path, false);

                NSBitmapImageRep leftImageRep =
                    ImageDiffUtils.GetBitmapRepresentation(mLeftImage);

                NSBitmapImageRep rightImageRep =
                    ImageDiffUtils.GetBitmapRepresentation(mRightImage);

                nint leftLen  = leftImageRep.BytesPerRow * leftImageRep.PixelsHigh;
                nint rightLen = rightImageRep.BytesPerRow * rightImageRep.PixelsHigh;

                byte *leftBitmapData  = (byte *)leftImageRep.BitmapData;
                byte *rightBitmapData = (byte *)rightImageRep.BitmapData;

                ImageDiffOperations.CalculateImageDiff(
                    this, this, leftBitmapData, rightBitmapData,
                    (int)leftLen, (int)rightLen);
            }
        }
        public unsafe void TestImageDiffDifferentSizes()
        {
            Mock <IImageDiffView>    diffViewMock         = new Mock <IImageDiffView>();
            Mock <IProgressControls> progressControlsMock = new Mock <IProgressControls>();

            ImageDiffOperations.CalculateImageDiff(
                diffViewMock.Object, progressControlsMock.Object,
                null, null, 256, 512);

            progressControlsMock.Verify(
                progress => progress.ShowInformation(ImageDiffOperations.DIFF_SIZE_INFO_MESSSAGE),
                Times.Once(),
                "Info message about diff image sizes should be notified.");

            diffViewMock.Verify(
                diffView => diffView.SetDiffImageBytes(It.IsAny <byte[]>()),
                Times.Never(),
                "SetDiffImageBytes should not be called.");
        }