diff options
Diffstat (limited to 'AppKit/GTMNSBezierPath+RoundRectTest.m')
-rw-r--r-- | AppKit/GTMNSBezierPath+RoundRectTest.m | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/AppKit/GTMNSBezierPath+RoundRectTest.m b/AppKit/GTMNSBezierPath+RoundRectTest.m index 69a0621..02cd87b 100644 --- a/AppKit/GTMNSBezierPath+RoundRectTest.m +++ b/AppKit/GTMNSBezierPath+RoundRectTest.m @@ -6,9 +6,9 @@ // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -18,23 +18,33 @@ #import <Cocoa/Cocoa.h> -#import <SenTestingKit/SenTestingKit.h> #import "GTMNSBezierPath+RoundRect.h" -#import "GTMAppKit+UnitTesting.h" +#import "GTMSenTestCase.h" -@interface GTMNSBezierPath_RoundRectTest : GTMTestCase<GTMUnitTestViewDrawer> +@interface GTMNSBezierPath_RoundRectTest : GTMTestCase @end @implementation GTMNSBezierPath_RoundRectTest - (void)testRoundRects { - GTMAssertDrawingEqualToImageNamed(self, NSMakeSize(490, 500), - @"GTMNSBezierPath+RoundRectTest", nil, nil); -} + NSBitmapImageRep *offscreenRep = [[[NSBitmapImageRep alloc] + initWithBitmapDataPlanes:NULL + pixelsWide:100 + pixelsHigh:100 + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bitmapFormat:NSAlphaFirstBitmapFormat + bytesPerRow:0 + bitsPerPixel:0] autorelease]; -// Draws all of our tests so that we can compare this to our stored TIFF file. -- (void)gtm_unitTestViewDrawRect:(NSRect)rect contextInfo:(void*)contextInfo{ - NSRect theRects[] = { + // set offscreen context + NSGraphicsContext *nsContext = + [NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep]; + [NSGraphicsContext setCurrentContext:nsContext]; + NSRect theRects[] = { NSMakeRect(0.0, 10.0, 0.0, 0.0), //Empty Rect test NSMakeRect(50.0, 10.0, 30.0, 30.0), //Square Test NSMakeRect(100.0, 10.0, 1.0, 2.0), //Small Test @@ -43,16 +53,17 @@ NSMakeRect(300.0, 10.0, 150.0, 30.0) //Large Test 2 (for different radius) }; const NSUInteger theRectCount = sizeof(theRects) / sizeof(theRects[0]); - + // Line Width Tests CGFloat theLineWidths[] = { 0.5, 50.0, 2.0 }; - const NSUInteger theLineWidthCount = sizeof(theLineWidths) / sizeof(theLineWidths[0]); - NSUInteger i,j; - + const NSUInteger theLineWidthCount = + sizeof(theLineWidths) / sizeof(theLineWidths[0]); + NSUInteger i, j; + for (i = 0; i < theLineWidthCount; ++i) { for (j = 0; j < theRectCount; ++j) { CGFloat cornerRadius = ( (j < (theRectCount - 1)) ? 20.0 : 0.0 ); - NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] + NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] cornerRadius:cornerRadius]; [roundRect setLineWidth: theLineWidths[i]]; [roundRect stroke]; @@ -63,43 +74,43 @@ theRects[j].origin.y += newWidth; } } - + // Fill test - NSColor *theColors[] = { - [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0], + NSColor *theColors[] = { + [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0], [NSColor colorWithCalibratedRed:0.2 green:0.4 blue:0.6 alpha:0.4] }; const NSUInteger theColorCount = sizeof(theColors)/sizeof(theColors[0]); - + for (i = 0; i < theColorCount; ++i) { for (j = 0; j < theRectCount; ++j) { CGFloat cornerRadius = ( (j < (theRectCount - 1)) ? 10.0 : 0.0 ); - NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] + NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] cornerRadius:cornerRadius]; [theColors[i] setFill]; [roundRect fill]; theRects[j].origin.y += 35.0; } } - + // Flatness test CGFloat theFlatness[] = {0.0, 0.1, 1.0, 10.0}; const NSUInteger theFlatnessCount = sizeof(theFlatness)/sizeof(theFlatness[0]); - + for (i = 0; i < theFlatnessCount; i++) { for (j = 0; j < theRectCount; ++j) { CGFloat cornerRadius = ( (j < (theRectCount - 1)) ? 6.0 : 0.0 ); - NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] + NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] cornerRadius:cornerRadius]; [roundRect setFlatness:theFlatness[i]]; [roundRect stroke]; theRects[j].origin.y += 35.0; } } - + // Different radii NSRect bigRect = NSMakeRect(50, 440, 200, 40); - NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:bigRect + NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:bigRect topLeftCornerRadius:0.0 topRightCornerRadius:5.0 bottomLeftCornerRadius:10.0 |