Skip to content

Commit e9ad55b

Browse files
committed
[Core Graphics] Add test case for renamed APIs
1 parent c955037 commit e9ad55b

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %target-swift-frontend -emit-ir -O %s | FileCheck %s
2+
3+
// Test some imported CG APIs
4+
import CoreGraphics
5+
6+
// REQUIRES: OS=macosx
7+
8+
// Get a transform that will rotate around a given offset
9+
public func rotationAround(offset: CGPoint, angle: CGFloat,
10+
transform: CGAffineTransform = .identity) -> CGAffineTransform {
11+
// FIXME: consistent API namings
12+
return transform.translateBy(x: offset.x, y: offset.y)
13+
.rotate(angle)
14+
.translateBy(x: -offset.x, y: -offset.y)
15+
16+
// CHECK: call void @CGAffineTransformTranslate(%{{.*}}.CGAffineTransform* {{.*}}, %{{.*}}.CGAffineTransform* {{.*}},{{.*}}, {{.*}})
17+
// CHECK: call void @CGAffineTransformRotate(%{{.*}}.CGAffineTransform* {{.*}}, %{{.*}}.CGAffineTransform* {{.*}},{{.*}})
18+
// CHECK: call void @CGAffineTransformTranslate(%{{.*}}.CGAffineTransform* {{.*}}, %{{.*}}.CGAffineTransform* {{.*}},{{.*}}, {{.*}})
19+
}
20+
21+
// Trace a path in red
22+
public func trace(in context: CGContext, path: CGPath) {
23+
let red = CGColor(red: 1, green: 0, blue: 0, alpha: 1)
24+
context.saveGState()
25+
context.addPath(path)
26+
context.setStrokeColor(red)
27+
context.strokePath()
28+
context.restoreGState()
29+
// CHECK: call %{{.*}}.CGColor* @CGColorCreateGenericRGB(double 1.000000e+00, double 0.000000e+00, double 0.000000e+00, double 1.000000e+00)
30+
// CHECK: call void @CGContextSaveGState(%{{.*}}.CGContext* %{{.*}})
31+
// CHECK: call void @CGContextAddPath(%{{.*}}.CGContext* %{{.*}}, %{{.*}}.CGPath* %{{.*}})
32+
// CHECK: call void @CGContextSetStrokeColorWithColor(%{{.*}}.CGContext* %{{.*}}, %{{.*}}.CGColor* %{{.*}})
33+
// CHECK: call void @CGContextStrokePath(%{{.*}}.CGContext* %{{.*}})
34+
// CHECK: call void @CGContextRestoreGState(%{{.*}}.CGContext* %{{.*}})
35+
}
36+
37+
public func pdfOperations(_ context: CGContext) {
38+
context.beginPDFPage(nil)
39+
context.endPDFPage()
40+
context.closePDF()
41+
// CHECK: call void @CGPDFContextBeginPage(%{{.*}}.CGContext* %{{.*}}, %{{.*}}.__CFDictionary* {{.*}})
42+
// CHECK: call void @CGPDFContextEndPage(%{{.*}}.CGContext* %{{.*}})
43+
// CHECK: call void @CGPDFContextClose(%{{.*}}.CGContext* %{{.*}})
44+
45+
}
46+

0 commit comments

Comments
 (0)