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