From 89eae4bf5df1bab1f45020e64f1cd5870718c562 Mon Sep 17 00:00:00 2001 From: Alan Rogers Date: Tue, 23 Apr 2013 11:51:14 +1000 Subject: [PATCH] Add assertions to check we have the blue border --- RebelTests/RBLResizableImageSpec.m | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/RebelTests/RBLResizableImageSpec.m b/RebelTests/RBLResizableImageSpec.m index 3998010..25f4aed 100644 --- a/RebelTests/RBLResizableImageSpec.m +++ b/RebelTests/RBLResizableImageSpec.m @@ -11,6 +11,7 @@ SpecBegin(RBLResizableImage) __block RBLResizableImage *testImage = nil; +__block void(^expectBlueBorder)(NSBitmapImageRep* imageRep, NSSize size) = nil; beforeEach(^{ NSURL *testImageURL = [[NSBundle bundleForClass:self.class] URLForResource:@"_testimage" withExtension:@"tiff"]; @@ -20,6 +21,35 @@ beforeEach(^{ testImage = [[RBLResizableImage alloc] initByReferencingURL:testImageURL]; expect(testImage).toNot.beNil(); + + expectBlueBorder = ^(NSBitmapImageRep *imageRep, NSSize size) { + NSUInteger topLeft[4], bottomRight[4]; + + // confirm we have the borders + [imageRep getPixel:&topLeft[0] atX:0 y:0]; + + NSUInteger red = topLeft[0]; + NSUInteger green = topLeft[1]; + NSUInteger blue = topLeft[2]; + NSUInteger alpha = topLeft[3]; + + expect(red).to.equal(0); + expect(green).to.equal(0); + expect(blue).to.equal(255); + expect(alpha).to.equal(255); + + [imageRep getPixel:&bottomRight[0] atX:(NSUInteger)(size.width - 1) y:(NSUInteger)(size.height - 1)]; + + red = bottomRight[0]; + green = bottomRight[1]; + blue = bottomRight[2]; + alpha = bottomRight[3]; + + expect(red).to.equal(0); + expect(green).to.equal(0); + expect(blue).to.equal(255); + expect(alpha).to.equal(255); + }; }); it(@"should use @1x asset in @1x context", ^{ @@ -49,6 +79,8 @@ it(@"should use @1x asset in @1x context", ^{ expect(green).to.equal(0); expect(blue).to.equal(0); expect(alpha).to.equal(255); + + expectBlueBorder(bitmapImageRep, targetSize); }); it(@"should use @2x asset in @2x context", ^{ @@ -78,6 +110,8 @@ it(@"should use @2x asset in @2x context", ^{ expect(green).to.equal(255); expect(blue).to.equal(0); expect(alpha).to.equal(255); + + expectBlueBorder(bitmapImageRep, targetSize); }); SpecEnd