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