From 6a4d8a24be35668eb7c7f415ad0c4d93548e7c3c Mon Sep 17 00:00:00 2001 From: Gerrit Riessen Date: Mon, 25 Apr 2011 13:34:52 +0200 Subject: [PATCH] unit test for CGContext --- Tests/AppKit/CGContextTest.j | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Tests/AppKit/CGContextTest.j diff --git a/Tests/AppKit/CGContextTest.j b/Tests/AppKit/CGContextTest.j new file mode 100644 index 000000000..0ed6242e6 --- /dev/null +++ b/Tests/AppKit/CGContextTest.j @@ -0,0 +1,78 @@ +@import +@import "CGTestCase.j" + +@implementation CGContextTest : CGTestCase + +- (void)testEnsureTestingCanvas +{ + /* + Ensure that we have no canvas nor vml support. + */ + [self assert:YES equals:!CPFeatureIsCompatible(CPHTMLCanvasFeature)]; + [self assert:YES equals:!CPFeatureIsCompatible(CPVMLFeature)]; +} + +- (void)testGStateCreate +{ + var gstate = CGGStateCreate(), + testdata = { alpha: 1.0, + strokeStyle: "#000", + fillStyle: "#ccc", + lineWidth: 1.0, + lineJoin: kCGLineJoinMiter, + lineCap: kCGLineCapButt, + miterLimit: 10.0, + globalAlpha: 1.0, + blendMode: kCGBlendModeNormal, + shadowBlur: 0.0, + shadowColor: NULL }; + + for ( var key in testdata ) + [self assert:testdata[key] equals:gstate[key] message:"Failed for " + key]; + + [self compareSize:CGSizeMakeZero() + with:gstate.shadowOffset + message:"Failed for shadowOffset"]; + + [self compareTransform:CGAffineTransformMakeIdentity() + with:gstate.CTM + message:"Failed for CTM"]; +} + +- (void)testGStateCreateCopy +{ + var gstate = CGGStateCreate(), + gstatecopy = CGGStateCreateCopy(gstate), + testdata = { alpha: 1.0, + strokeStyle: "#000", + fillStyle: "#ccc", + lineWidth: 1.0, + lineJoin: kCGLineJoinMiter, + lineCap: kCGLineCapButt, + miterLimit: 10.0, + globalAlpha: 1.0, + blendMode: kCGBlendModeNormal, + shadowBlur: 0.0, + shadowColor: NULL }; + + for ( var key in testdata ) + [self assert:testdata[key] equals:gstatecopy[key] message:"Failed for " + key]; + + // ensure that the size is copied + var sizecopy = CGSizeMakeCopy( gstate.shadowOffset ); + gstate.shadowOffset.width += 1000; + gstate.shadowOffset.height += 2000; + [self compareSize:sizecopy with:gstatecopy.shadowOffset message:"Failed for shadowOffset"]; + + // ensure that the transform is copied + var transformcopy = CGAffineTransformMakeCopy( gstate.CTM ); + gstate.CTM.a += 1000; + gstate.CTM.b += 1000; + gstate.CTM.c += 1000; + gstate.CTM.d += 1000; + gstate.CTM.tx += 1000; + gstate.CTM.ty += 1000; + [self compareTransform:transformcopy with:gstatecopy.CTM message:"Failed with CTM"]; +} + +@end