public void TestSourceOverTransparentOperation() { Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver }; operation.StartOpertaion(); operation.MoveTo(5, 5); operation.DrawTo(10, 10); operation.DrawTo(15, 17); operation.DrawTo(20, 25); operation.DrawTo(25, 37); operation.DrawTo(5, 5); operation.FinishOperation(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0x7D, 0xBB, 0x8A, 0xAE, 0x0, 0x75, 0x55, 0x54, 0x67, 0xE1, 0x35, 0x90, 0xE2, 0x77, 0xD3, 0xF1, 0xE4, 0xAD, 0xE2, 0xD6, 0xB, 0xDA, 0xCA, 0xB9, 0xDD, 0x64, 0x99, 0x70, 0xFF, 0x69, 0x6D, 0x52 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_SourceOverTransparentPaint"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation must match the good hash stored"); }
public void TestSourceOverAlphaAccumulationOffTransparentOperation() { Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver }; operation.StartOpertaion(false); operation.MoveTo(5, 5); operation.DrawTo(10, 10); operation.DrawTo(15, 17); operation.DrawTo(20, 25); operation.DrawTo(25, 37); operation.DrawTo(5, 5); operation.FinishOperation(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0x7E, 0xCD, 0xAB, 0x2D, 0xB, 0x48, 0x83, 0x2B, 0x1E, 0xCA, 0xA, 0x98, 0x68, 0x58, 0x86, 0x66, 0x67, 0x15, 0x62, 0xDA, 0xC4, 0xB5, 0xE2, 0x8, 0x12, 0xBD, 0x3C, 0x7A, 0xF2, 0x92, 0x80, 0x9 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_SourceOverTransparentPaint_AccumulateAlphaOff"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation must match the good hash stored"); }
public void TestImagePersistence() { // Setup the test Bitmap bitmap1 = FrameGenerator.GenerateRandomBitmap(48, 37, 0); Bitmap bitmap2 = FrameGenerator.GenerateRandomBitmap(12, 45, 0); Stream stream = new MemoryStream(); // Test the methods PersistenceHelper.SaveImageToStream(bitmap1, stream); PersistenceHelper.SaveImageToStream(bitmap2, stream); // Reset stream stream.Position = 0; // Load the bitmaps back up again one at a time Bitmap loadedBitmap1 = PersistenceHelper.LoadImageFromStream(stream); Bitmap loadedBitmap2 = PersistenceHelper.LoadImageFromStream(stream); // Compare images Assert.IsTrue(ImageUtilities.ImagesAreIdentical(bitmap1, loadedBitmap1), "An image loaded from a stream must match completely the image that was saved"); Assert.IsTrue(ImageUtilities.ImagesAreIdentical(bitmap2, loadedBitmap2), "An image loaded from a stream must match completely the image that was saved"); // Try to edit the loaded bitmaps to verify editability loadedBitmap1.SetPixel(0, 0, Color.Black); loadedBitmap2.SetPixel(0, 0, Color.Black); }
public void TestSourceCopyTransparentOperation() { Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); PencilPaintOperation operation = new PencilPaintOperation(target, true) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceCopy }; operation.StartOpertaion(); operation.MoveTo(5, 5); operation.DrawTo(10, 10); operation.DrawTo(15, 17); operation.DrawTo(20, 25); operation.DrawTo(25, 37); operation.FinishOperation(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0x7C, 0xB0, 0xE9, 0x83, 0x12, 0xC3, 0x13, 0x74, 0x20, 0xCA, 0x40, 0x8E, 0x27, 0x11, 0x8B, 0xF5, 0xE9, 0x5F, 0x33, 0x41, 0xCE, 0x7D, 0x8D, 0x74, 0x76, 0x5C, 0xA6, 0xD1, 0xAB, 0x90, 0x1C, 0x34 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_SourceCopyTransparentPaint"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation does not match the good hash stored. Verify the output image for an analysis of what went wrong"); }
public void TestLayerIndexing() { Frame frame = FrameGenerator.GenerateRandomFrame(64, 64, 5, 1); frame.AddLayer(FrameGenerator.GenerateRandomBitmap(64, 64, 2)); IFrameLayer layer = frame.CreateLayer(); Assert.AreEqual(0, frame.GetLayerAt(0).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(1, frame.GetLayerAt(1).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(2, frame.GetLayerAt(2).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(2, layer.Index, "Layers returned by calls to AddLayer() and CreateLayer() must have an index that match the 'index' parameter passed"); }
public void TestImagesAreIdentical() { // Generate the bitmaps Bitmap bitmap1 = FrameGenerator.GenerateRandomBitmap(64, 64, 10); Bitmap bitmap2 = FrameGenerator.GenerateRandomBitmap(64, 64, 10); // Test the equality Assert.IsTrue(ImageUtilities.ImagesAreIdentical(bitmap1, bitmap2), "ImagesAreIdentical should return true for images that are equal down to each pixel"); // Generate a different random bitmap bitmap2 = FrameGenerator.GenerateRandomBitmap(64, 64, 11); Assert.IsFalse(ImageUtilities.ImagesAreIdentical(bitmap1, bitmap2), "ImagesAreIdentical should return false for images that are not equal down to each pixel"); }
public void TestLayerBitmapUpdating() { // Create a frame Frame frame = new Frame(null, 64, 64); Bitmap layer1 = FrameGenerator.GenerateRandomBitmap(64, 64, 10); frame.CreateLayer(); // Swap the layers frame.SetLayerBitmap(1, layer1); // Test layer swapping by comparing the bitmaps Assert.IsTrue(ImageUtilities.ImagesAreIdentical(layer1, frame.GetLayerAt(1).LayerBitmap), "The layer bitmap has not been updated correctly"); }
public void TestFrameLayerInsertion() { Frame frame = new Frame(null, 64, 64); Bitmap layer1 = FrameGenerator.GenerateRandomBitmap(64, 64, 10); Bitmap layer2 = FrameGenerator.GenerateRandomBitmap(64, 64, 9); frame.AddLayer(layer1); frame.AddLayer(layer2, 1); Assert.AreEqual(frame, frame.GetLayerAt(0).Frame, "The Frame reference of the layer must match the frame that it was added to"); Assert.AreEqual(3, frame.LayerCount, "The layer count must go up for each new layer added"); Assert.AreEqual(1, frame.GetLayerAt(1).Index, "A layer's index must reflect its current position on the owning frame's layer list"); Assert.IsTrue(ImageUtilities.ImagesAreIdentical(layer2, frame.GetLayerAt(1).LayerBitmap), "The layer bitmaps insertion must obey the index provided on AddLayer"); }
public void TestFrameEquals() { Frame fr1 = new Frame(null, 64, 64); Frame fr2 = fr1.Clone(); Assert.AreEqual(fr1, fr2, "The frames after a Clone() operation must be equal"); // Fill both frames with randomly generated images Bitmap bit = FrameGenerator.GenerateRandomBitmap(64, 64, 0); fr1.SetFrameBitmap(bit); fr2.SetFrameBitmap(bit); Assert.AreEqual(fr1, fr2, "Frames with equal images must return true to .Equals()"); fr2.SetFrameBitmap(FrameGenerator.GenerateRandomBitmap(64, 64, 1)); Assert.AreNotEqual(fr1, fr2, "Frames with different images must return false to .Equals()"); }
public void TestFrameLayerCreation() { // TODO: Find out why this test fails under Release mode but succeeds under Debug mode Frame frame = FrameGenerator.GenerateRandomFrame(64, 64, 1, 1); frame.AddLayer(FrameGenerator.GenerateRandomBitmap(64, 64, 2)); frame.AddLayer(FrameGenerator.GenerateRandomBitmap(64, 64, 3)); Bitmap target = frame.GetComposedBitmap(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0xBF, 0x8F, 0x9B, 0x56, 0xBE, 0x8D, 0xF5, 0xD2, 0x99, 0x1C, 0x9B, 0xEC, 0x56, 0xB8, 0x6D, 0xA9, 0x41, 0xBB, 0x31, 0x66, 0xD, 0xB2, 0xDC, 0x66, 0xF3, 0x5C, 0x9A, 0xDE, 0x59, 0xC2, 0xC2, 0x52 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "FrameLayering"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the composed frame does not match the good hash stored. Verify the output image for an analysis of what went wrong"); }
public void TestLayerRemoval() { // Create a frame Frame frame = new Frame(null, 64, 64); Bitmap bitmap = FrameGenerator.GenerateRandomBitmap(64, 64, 10); frame.CreateLayer(); // Swap the layers frame.SetLayerBitmap(1, bitmap); IFrameLayer layer = frame.GetLayerAt(0); frame.RemoveLayerAt(0); // Test layer swapping by comparing the bitmaps Assert.AreEqual(null, layer.Frame, "After removing a layer from a frame, its Frame reference must be null"); Assert.IsTrue(ImageUtilities.ImagesAreIdentical(bitmap, frame.GetLayerAt(0).LayerBitmap), "The layer does not appear to have been correctly removed"); }
public void TestRedoOperation_SizedSourceOverAlpha() { // Create the objects Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); // Create the test subjects PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil"); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver, Size = 5, Notifier = generator }; operation.StartOpertaion(); operation.MoveTo(5, 5); operation.DrawTo(10, 10); operation.DrawTo(15, 17); operation.DrawTo(20, 25); operation.DrawTo(25, 37); operation.DrawTo(5, 5); operation.FinishOperation(); byte[] originalHash = GetHashForBitmap(target); // Undo and redo the task back generator.UndoTask.Undo(); generator.UndoTask.Redo(); byte[] afterRedoHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_AfterRedo_SizedSourceOverAlpha"); Assert.IsTrue(originalHash.SequenceEqual(afterRedoHash), "After redoing a paint operation's task, its pixels must return to their original state after the operation was applied"); }
public void TestUndoOperation_SourceOverAlphaFailing() { // Create the objects Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); byte[] originalHash = GetHashForBitmap(target); // Create the test subjects PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil", keepReplacedUndos: false); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver, Notifier = generator }; operation.StartOpertaion(); operation.MoveTo(5, 5); operation.DrawTo(10, 10); operation.DrawTo(15, 17); operation.DrawTo(20, 25); operation.DrawTo(25, 37); operation.DrawTo(5, 5); operation.FinishOperation(); // Undo the task generator.UndoTask.Undo(); byte[] afterUndoHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_AfterUndo_SourceOverAlpha_Failed"); Assert.IsFalse(originalHash.SequenceEqual(afterUndoHash), "Plotting the same pixel repeatedly with an undo generator that has keepReplacedOriginals should fail, since the redrawn pixels have their undo color replaced"); }
public void TestLayerSwapping() { // Create a frame Bitmap layer0 = FrameGenerator.GenerateRandomBitmap(64, 64, 11); Frame frame = new Frame(null, 64, 64); frame.SetFrameBitmap(layer0); Bitmap layer1 = FrameGenerator.GenerateRandomBitmap(64, 64, 10); Bitmap layer2 = FrameGenerator.GenerateRandomBitmap(64, 64, 9); frame.AddLayer(layer1); frame.AddLayer(layer2); // Swap the layers frame.SwapLayers(0, 2); // Test layer swapping by comparing the bitmaps Assert.AreEqual(0, frame.GetLayerAt(0).Index, "A layer's index must reflect its current position on the owning frame's layer list"); Assert.AreEqual(2, frame.GetLayerAt(2).Index, "A layer's index must reflect its current position on the owning frame's layer list"); Assert.IsTrue(ImageUtilities.ImagesAreIdentical(layer2, frame.GetLayerAt(0).LayerBitmap), "The layers have not been swapped correctly"); Assert.IsTrue(ImageUtilities.ImagesAreIdentical(layer0, frame.GetLayerAt(2).LayerBitmap), "The layers have not been swapped correctly"); }