From 42124b3691197c3c4f52f069775fa0390a8ff942 Mon Sep 17 00:00:00 2001 From: dmaclach Date: Fri, 7 Oct 2016 12:10:23 -0400 Subject: First cut at pruning things/updating things. Remove a bunch of code that Google stopped using/maintaining rather than trying to update it it. Some would be hard to update, some actually has system provided replacements; others are patterns that just don't seem as common now. Prune out the code related to macOS <= 10.5, start pruning some of the really old iOS support also. Get the projects mostly limping again with modern Xcodes so tests can be run. If someone ends up on this commit via history for something they still find as useful, feel free to do a pull request to bring the snippet of code back to life and update it for current SDKs. --- AppKit/GTMNSBezierPath+RoundRectTest.m | 63 ++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'AppKit/GTMNSBezierPath+RoundRectTest.m') 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 -#import #import "GTMNSBezierPath+RoundRect.h" -#import "GTMAppKit+UnitTesting.h" +#import "GTMSenTestCase.h" -@interface GTMNSBezierPath_RoundRectTest : GTMTestCase +@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 -- cgit v1.2.3