1
2from PyObjCTools.TestSupport import *
3from Quartz import *
4import Quartz
5from Foundation import NSMutableData
6
7try:
8    unicode
9except NameError:
10    unicode = str
11
12class TestCGPDFContext (TestCase):
13
14    @min_os_level('10.7')
15    def testFunctions10_7(self):
16        data = NSMutableData.data()
17        consumer = CGDataConsumerCreateWithCFData(data)
18        context = CGPDFContextCreate(consumer, None, None)
19
20        metadata = b'''<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><?xpacket end='w'?>'''
21        CGPDFContextAddDocumentMetadata(context,
22                NSMutableData.dataWithBytes_length_(metadata, len(metadata)))
23
24
25    @min_os_level('10.5')
26    def testFunctions10_5(self):
27        # Note actual test is in the function below this one.
28        CGPDFContextClose
29
30    def testFunctions(self):
31        data = NSMutableData.data()
32        self.assertIsInstance(data, CFMutableDataRef)
33
34        consumer = CGDataConsumerCreateWithCFData(data)
35        self.assertIsInstance(consumer, CGDataConsumerRef)
36
37        self.assertArgIsIn(CGPDFContextCreate, 1)
38        self.assertResultIsCFRetained(CGPDFContextCreate)
39        context = CGPDFContextCreate(consumer, None, None)
40        self.assertIsInstance(context, CGContextRef)
41
42        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(context)
43
44        self.assertResultIsCFRetained(CGPDFContextCreateWithURL)
45        url = CFURLCreateWithFileSystemPath(None,
46            "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False)
47        self.assertArgIsIn(CGPDFContextCreateWithURL, 1)
48        context = CGPDFContextCreateWithURL(url, None, None)
49        self.assertIsInstance(context, CGContextRef)
50
51        CGPDFContextBeginPage(context, None)
52
53        CGPDFContextSetURLForRect(context, url, ((0, 0), (10, 10)))
54        CGPDFContextAddDestinationAtPoint(context, "target", (50, 50))
55
56        CGPDFContextSetDestinationForRect(context, "target", ((100, 120), (50, 60)))
57
58        CGPDFContextEndPage(context)
59
60        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(context)
61
62    @min_os_level('10.5')
63    def testConstants10_5(self):
64        self.assertIsInstance(kCGPDFContextSubject, unicode)
65
66    def testConstants(self):
67        self.assertIsInstance(kCGPDFContextMediaBox, unicode)
68        self.assertIsInstance(kCGPDFContextCropBox, unicode)
69        self.assertIsInstance(kCGPDFContextBleedBox, unicode)
70        self.assertIsInstance(kCGPDFContextTrimBox, unicode)
71        self.assertIsInstance(kCGPDFContextArtBox, unicode)
72        self.assertIsInstance(kCGPDFContextTitle, unicode)
73        self.assertIsInstance(kCGPDFContextAuthor, unicode)
74        self.assertIsInstance(kCGPDFContextKeywords, unicode)
75        self.assertIsInstance(kCGPDFContextCreator, unicode)
76        self.assertIsInstance(kCGPDFContextOwnerPassword, unicode)
77        self.assertIsInstance(kCGPDFContextUserPassword, unicode)
78        self.assertIsInstance(kCGPDFContextEncryptionKeyLength, unicode)
79        self.assertIsInstance(kCGPDFContextAllowsPrinting, unicode)
80        self.assertIsInstance(kCGPDFContextAllowsCopying, unicode)
81        self.assertIsInstance(kCGPDFContextOutputIntent, unicode)
82        self.assertIsInstance(kCGPDFXOutputIntentSubtype, unicode)
83        self.assertIsInstance(kCGPDFXOutputConditionIdentifier, unicode)
84        self.assertIsInstance(kCGPDFXOutputCondition, unicode)
85        self.assertIsInstance(kCGPDFXRegistryName, unicode)
86        self.assertIsInstance(kCGPDFXInfo, unicode)
87        self.assertIsInstance(kCGPDFXDestinationOutputProfile, unicode)
88        self.assertIsInstance(kCGPDFContextOutputIntents, unicode)
89
90
91
92
93
94if __name__ == "__main__":
95    main()
96