1
2from PyObjCTools.TestSupport import *
3from Quartz.PDFKit import *
4
5try:
6    unicode
7except NameError:
8    unicode = str
9
10class TestPDFViewHelper (NSObject):
11    def PDFViewWillChangeScaleFactor_toScale_(self, f, s): return 1.0
12    def PDFViewWillClickOnLink_withURL_(self, s, u): pass
13    def PDFViewPrintJobTitle_(self, s): return b'a'.decode('latin1')
14    def PDFViewPerformFind_(self, s): pass
15    def PDFViewPerformGoToPage_(self, s): pass
16    def PDFViewPerformPrint_(self, s): pass
17    def PDFViewOpenPDF_forRemoteGoToAction_(self, s, a): pass
18
19
20class TestPDFView (TestCase):
21    def testConstants(self):
22        self.assertEqual(kPDFDisplaySinglePage, 0)
23        self.assertEqual(kPDFDisplaySinglePageContinuous, 1)
24        self.assertEqual(kPDFDisplayTwoUp, 2)
25        self.assertEqual(kPDFDisplayTwoUpContinuous, 3)
26        self.assertEqual(kPDFNoArea, 0)
27        self.assertEqual(kPDFPageArea, 1)
28        self.assertEqual(kPDFTextArea, 2)
29        self.assertEqual(kPDFAnnotationArea, 4)
30        self.assertEqual(kPDFLinkArea, 8)
31        self.assertEqual(kPDFControlArea, 16)
32        self.assertEqual(kPDFTextFieldArea, 32)
33        self.assertEqual(kPDFIconArea, 64)
34        self.assertEqual(kPDFPopupArea, 128)
35
36        self.assertIsInstance(PDFViewDocumentChangedNotification, unicode)
37        self.assertIsInstance(PDFViewChangedHistoryNotification, unicode)
38        self.assertIsInstance(PDFViewPageChangedNotification, unicode)
39        self.assertIsInstance(PDFViewScaleChangedNotification, unicode)
40        self.assertIsInstance(PDFViewAnnotationHitNotification, unicode)
41        self.assertIsInstance(PDFViewCopyPermissionNotification, unicode)
42        self.assertIsInstance(PDFViewPrintPermissionNotification, unicode)
43
44    @min_os_level('10.5')
45    def testConstants10_5(self):
46        self.assertIsInstance(PDFViewAnnotationWillHitNotification, unicode)
47        self.assertIsInstance(PDFViewSelectionChangedNotification, unicode)
48        self.assertIsInstance(PDFViewDisplayModeChangedNotification, unicode)
49        self.assertIsInstance(PDFViewDisplayBoxChangedNotification, unicode)
50
51    @min_os_level('10.7')
52    def testConstants10_7(self):
53        self.assertEqual(kPDFInterpolationQualityNone, 0)
54        self.assertEqual(kPDFInterpolationQualityLow, 1)
55        self.assertEqual(kPDFInterpolationQualityHigh, 2)
56
57    def testMethods(self):
58        self.assertResultIsBOOL(PDFView.canGoToFirstPage)
59        self.assertResultIsBOOL(PDFView.canGoToLastPage)
60        self.assertResultIsBOOL(PDFView.canGoToNextPage)
61        self.assertResultIsBOOL(PDFView.canGoToPreviousPage)
62        self.assertResultIsBOOL(PDFView.canGoBack)
63        self.assertResultIsBOOL(PDFView.canGoForward)
64
65        self.assertResultIsBOOL(PDFView.displaysPageBreaks)
66        self.assertArgIsBOOL(PDFView.setDisplaysPageBreaks_, 0)
67        self.assertResultIsBOOL(PDFView.displaysAsBook)
68        self.assertArgIsBOOL(PDFView.setDisplaysAsBook_, 0)
69        self.assertResultIsBOOL(PDFView.shouldAntiAlias)
70        self.assertArgIsBOOL(PDFView.setShouldAntiAlias_, 0)
71
72        self.assertResultIsBOOL(PDFView.canZoomIn)
73        self.assertResultIsBOOL(PDFView.canZoomOut)
74        self.assertResultIsBOOL(PDFView.autoScales)
75        self.assertArgIsBOOL(PDFView.setAutoScales_, 0)
76
77        self.assertArgIsBOOL(PDFView.pageForPoint_nearest_, 1)
78
79        self.assertResultIsBOOL(PDFView.allowsDragging)
80        self.assertArgIsBOOL(PDFView.setAllowsDragging_, 0)
81
82    @min_os_level('10.5')
83    def testMethods10_5(self):
84        self.assertArgIsBOOL(PDFView.setCurrentSelection_animate_, 1)
85        self.assertArgIsBOOL(PDFView.printWithInfo_autoRotate_, 1)
86        self.assertArgIsBOOL(PDFView.printWithInfo_autoRotate_pageScaling_, 1)
87
88    @min_os_level('10.6')
89    def testMethods10_6(self):
90        self.assertResultIsBOOL(PDFView.enableDataDetectors)
91        self.assertArgIsBOOL(PDFView.setEnableDataDetectors_, 0)
92
93    def testProtocols(self):
94        self.assertIsInstance(protocols.PDFViewDelegate, objc.informal_protocol)
95
96        self.assertArgHasType(TestPDFViewHelper.PDFViewWillChangeScaleFactor_toScale_, 1, objc._C_CGFloat)
97        self.assertResultHasType(TestPDFViewHelper.PDFViewWillChangeScaleFactor_toScale_, objc._C_CGFloat)
98
99if __name__ == "__main__":
100    main()
101