PageRenderTime 35ms CodeModel.GetById 10ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/AppKit/GTMNSBezierPath+RoundRectTest.m

http://macfuse.googlecode.com/
Objective C | 112 lines | 75 code | 15 blank | 22 comment | 7 complexity | 274e5beae861428edbf2756d1d6eb7dd MD5 | raw file
  1//
  2//  GTMNSBezierPath+RoundRectTest.m
  3//
  4//  Copyright 2006-2008 Google Inc.
  5//
  6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7//  use this file except in compliance with the License.  You may obtain a copy
  8//  of the License at
  9// 
 10//  http://www.apache.org/licenses/LICENSE-2.0
 11// 
 12//  Unless required by applicable law or agreed to in writing, software
 13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 15//  License for the specific language governing permissions and limitations under
 16//  the License.
 17//
 18
 19#import <Cocoa/Cocoa.h>
 20
 21#import <SenTestingKit/SenTestingKit.h>
 22#import "GTMNSBezierPath+RoundRect.h"
 23#import "GTMAppKit+UnitTesting.h"
 24
 25@interface GTMNSBezierPath_RoundRectTest : GTMTestCase<GTMUnitTestViewDrawer>
 26@end
 27
 28@implementation GTMNSBezierPath_RoundRectTest
 29
 30- (void)testRoundRects {
 31  GTMAssertDrawingEqualToImageNamed(self, NSMakeSize(490, 500), 
 32                                    @"GTMNSBezierPath+RoundRectTest", nil, nil);
 33}
 34
 35// Draws all of our tests so that we can compare this to our stored TIFF file.
 36- (void)gtm_unitTestViewDrawRect:(NSRect)rect contextInfo:(void*)contextInfo{
 37  NSRect theRects[] = { 
 38    NSMakeRect(0.0, 10.0, 0.0, 0.0), //Empty Rect test
 39    NSMakeRect(50.0, 10.0, 30.0, 30.0), //Square Test
 40    NSMakeRect(100.0, 10.0, 1.0, 2.0), //Small Test
 41    NSMakeRect(120.0, 10.0, 15.0, 20.0), //Medium Test
 42    NSMakeRect(140.0, 10.0, 150.0, 30.0),  //Large Test
 43    NSMakeRect(300.0, 10.0, 150.0, 30.0)  //Large Test 2 (for different radius)
 44  };
 45  const NSUInteger theRectCount = sizeof(theRects) / sizeof(theRects[0]);
 46  
 47  // Line Width Tests
 48  CGFloat theLineWidths[] = { 0.5, 50.0, 2.0 };
 49  const NSUInteger theLineWidthCount = sizeof(theLineWidths) / sizeof(theLineWidths[0]);
 50  NSUInteger i,j;
 51  
 52  for (i = 0; i < theLineWidthCount; ++i) {
 53    for (j = 0; j < theRectCount; ++j) {
 54      CGFloat cornerRadius = ( (j < (theRectCount - 1)) ? 20.0 : 0.0 );
 55      NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] 
 56                                                             cornerRadius:cornerRadius];
 57      [roundRect setLineWidth: theLineWidths[i]];
 58      [roundRect stroke];
 59      CGFloat newWidth = 35.0;
 60      if (i < theLineWidthCount - 1) {
 61        newWidth += theLineWidths[i + 1] + theLineWidths[i];
 62      }
 63      theRects[j].origin.y += newWidth;
 64    }
 65  }
 66  
 67  // Fill test
 68  NSColor *theColors[] = { 
 69    [NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0], 
 70    [NSColor colorWithCalibratedRed:0.2 green:0.4 blue:0.6 alpha:0.4]
 71  };
 72  const NSUInteger theColorCount = sizeof(theColors)/sizeof(theColors[0]);
 73  
 74  for (i = 0; i < theColorCount; ++i) {
 75    for (j = 0; j < theRectCount; ++j) {
 76      CGFloat cornerRadius = ( (j < (theRectCount - 1)) ? 10.0 : 0.0 );
 77      NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] 
 78                                                             cornerRadius:cornerRadius];
 79      [theColors[i] setFill];
 80      [roundRect fill];
 81      theRects[j].origin.y += 35.0;
 82    }
 83  }
 84  
 85  // Flatness test
 86  CGFloat theFlatness[] = {0.0, 0.1, 1.0, 10.0};
 87  const NSUInteger theFlatnessCount = sizeof(theFlatness)/sizeof(theFlatness[0]);
 88  
 89  for (i = 0; i < theFlatnessCount; i++) {
 90    for (j = 0; j < theRectCount; ++j) {
 91      CGFloat cornerRadius = ( (j < (theRectCount - 1)) ? 6.0 : 0.0 );
 92      NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:theRects[j] 
 93                                                             cornerRadius:cornerRadius];
 94      [roundRect setFlatness:theFlatness[i]];
 95      [roundRect stroke];
 96      theRects[j].origin.y += 35.0;
 97    }
 98  }
 99  
100  // Different radii
101  NSRect bigRect = NSMakeRect(50, 440, 200, 40);
102  NSBezierPath *roundRect = [NSBezierPath gtm_bezierPathWithRoundRect:bigRect 
103                                                  topLeftCornerRadius:0.0
104                                                 topRightCornerRadius:5.0
105                                               bottomLeftCornerRadius:10.0
106                                              bottomRightCornerRadius:20.0];
107  [roundRect setLineWidth:5.0];
108  [roundRect stroke];
109}
110
111
112@end