PageRenderTime 32ms CodeModel.GetById 16ms app.highlight 14ms RepoModel.GetById 0ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/UnitTesting/GTMUIKit+UnitTestingTest.m

http://macfuse.googlecode.com/
Objective C | 67 lines | 42 code | 8 blank | 17 comment | 0 complexity | 345b6e9d8c5c1a2044d7a71691a04581 MD5 | raw file
 1//
 2//  GTMUIKit+UnitTestingTest.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 <CoreGraphics/CoreGraphics.h>
20#import "GTMUIKit+UnitTesting.h"
21#import "GTMSenTestCase.h"
22
23@interface GTMUIView_UnitTestingTest : GTMTestCase <GTMUnitTestViewDrawer>
24@end
25
26@implementation GTMUIView_UnitTestingTest
27
28- (void)testDrawing {
29  GTMAssertDrawingEqualToFile(self,
30                              CGSizeMake(200,200),
31                              @"GTMUIViewUnitTestingTest",
32                              [UIApplication sharedApplication],
33                              nil);
34}
35
36- (void)testState {
37  UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)] autorelease];
38  UIView *subview = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)] autorelease];
39  [view addSubview:subview];
40  GTMAssertObjectStateEqualToStateNamed(view, @"GTMUIViewUnitTestingTest", nil);
41}
42
43- (void)testUIImage {
44  NSString* name = @"GTMUIViewUnitTestingTest";
45  NSBundle *bundle = [NSBundle bundleForClass:[self class]];
46  NSString *imagePath = [bundle pathForResource:name ofType:@"png"];
47  STAssertNotNil(imagePath, nil);
48  UIImage* image = [UIImage imageWithContentsOfFile:imagePath];
49  GTMAssertObjectImageEqualToImageNamed(image, name, nil);
50}
51
52- (void)gtm_unitTestViewDrawRect:(CGRect)rect contextInfo:(void*)contextInfo {
53  UIApplication *app = [UIApplication sharedApplication];
54  STAssertEqualObjects(app,
55                       contextInfo,
56                       @"Should be a UIApplication");
57  CGPoint center = CGPointMake(CGRectGetMidX(rect),
58                               CGRectGetMidY(rect));
59  rect = CGRectMake(center.x - 50, center.y - 50, 100, 100);
60  CGContextRef context = UIGraphicsGetCurrentContext();
61  CGContextAddEllipseInRect(context, rect);
62  CGContextSetLineWidth(context, 5);
63  [[UIColor redColor] set];
64  CGContextStrokePath(context);
65}
66
67@end