PageRenderTime 44ms CodeModel.GetById 24ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://macfuse.googlecode.com/
Objective C | 75 lines | 41 code | 13 blank | 21 comment | 2 complexity | 1c63c5bfe03a0dbb095d6a8616b20df6 MD5 | raw file
 1//
 2//  GTMNSBezierPath+CGPathTest.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+CGPath.h"
23#import "GTMAppKit+UnitTesting.h"
24#import "GTMSenTestCase.h"
25
26@interface GTMNSBezierPath_CGPathTest : GTMTestCase<GTMUnitTestViewDrawer>
27@end
28
29@implementation GTMNSBezierPath_CGPathTest
30
31- (void)testCGPath {
32  GTMAssertDrawingEqualToImageNamed(self, 
33                                    NSMakeSize(100, 100), 
34                                    @"GTMNSBezierPath+CGPathTest", 
35                                    nil, nil);
36}
37
38
39// Draws all of our tests so that we can compare this to our stored image file.
40- (void)gtm_unitTestViewDrawRect:(NSRect)rect contextInfo:(void*)contextInfo{
41  NSBezierPath *thePath = [NSBezierPath bezierPath];
42  NSPoint theStart = NSMakePoint(20.0, 20.0);
43  
44  // Test moveto/lineto
45  [thePath moveToPoint: theStart];
46  for (NSUInteger i = 0; i < 10; ++i) {
47    NSPoint theNewPoint = NSMakePoint(i * 5, i * 10);
48    [thePath lineToPoint: theNewPoint];
49    theNewPoint = NSMakePoint(i * 2, i * 6);
50    [thePath moveToPoint: theNewPoint];
51  }
52  
53  // Test moveto/curveto
54  for (NSUInteger i = 0; i < 10;  ++i) {
55    NSPoint startPoint = NSMakePoint(5.0, 50.0);
56    NSPoint endPoint = NSMakePoint(55.0, 50.0);
57    NSPoint controlPoint1 = NSMakePoint(17.5, 50.0 + 5.0 * i);
58    NSPoint controlPoint2 = NSMakePoint(42.5, 50.0 - 5.0 * i);
59    [thePath moveToPoint:startPoint];
60    [thePath curveToPoint:endPoint controlPoint1:controlPoint1 controlPoint2:controlPoint2];
61  }
62  // test close
63  [thePath closePath];
64  
65  CGPathRef cgPath = [thePath gtm_CGPath];
66  STAssertNotNULL(cgPath, @"Nil CGPath");
67
68  CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];
69  STAssertNotNULL(cgContext, @"Nil cgContext");
70  
71  CGContextAddPath(cgContext, cgPath);
72  CGContextStrokePath(cgContext);
73}
74
75@end