1
2from PyObjCTools.TestSupport import *
3from Quartz import *
4import Quartz
5import os
6
7try:
8    long
9except NameError:
10    long = int
11
12class TestCGLayer (TestCase):
13    def testTypes(self):
14        self.assertIsCFType(CGLayerRef)
15
16    def setUp(self):
17        url = CFURLCreateWithFileSystemPath(None,
18            "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False)
19        self.assertIsInstance(url, CFURLRef)
20        context = CGPDFContextCreateWithURL(url,
21            ((0, 0), (1000, 1000)), None)
22        self.assertIsInstance(context, CGContextRef)
23        CGContextBeginPage(context, objc.NULL)
24
25        self.context = context
26
27    def tearDown(self):
28        CGContextEndPage(self.context)
29        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(self.context)
30        self.context = None
31        if os.path.exists("/tmp/pyobjc.test.pdf"):
32            os.unlink("/tmp/pyobjc.test.pdf")
33
34
35    def testFunctions(self):
36        self.assertResultIsCFRetained(CGLayerCreateWithContext)
37        layer = CGLayerCreateWithContext(self.context, CGSize(50, 100), None)
38        self.assertIsInstance(layer, CGLayerRef)
39
40        v = CGLayerRetain(layer)
41        self.assertTrue(v is layer)
42        CGLayerRelease(layer)
43
44        sz = CGLayerGetSize(layer)
45        self.assertIsInstance(sz, CGSize)
46        self.assertEqual(sz, CGSize(50, 100))
47
48        self.assertResultIsNotCFRetained(CGLayerGetContext)
49        ctx = CGLayerGetContext(layer)
50        self.assertIsInstance(ctx, CGContextRef)
51        self.assertIsNot(ctx, self.context)
52
53        CGContextDrawLayerInRect(self.context, CGRectMake(0, 0, 50, 50), layer)
54        CGContextDrawLayerAtPoint(self.context, CGPoint(10, 10), layer)
55
56        self.assertIsInstance(CGLayerGetTypeID(), (int, long))
57
58if __name__ == "__main__":
59    main()
60