Пример #1
0
    def testFunctions(self):
        data = NSMutableData.data()
        self.assertIsInstance(data, CFMutableDataRef)

        consumer = CGDataConsumerCreateWithCFData(data)
        self.assertIsInstance(consumer, CGDataConsumerRef)

        self.assertArgIsIn(CGPDFContextCreate, 1)
        self.assertResultIsCFRetained(CGPDFContextCreate)
        context = CGPDFContextCreate(consumer, None, None)
        self.assertIsInstance(context, CGContextRef)

        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(context)

        self.assertResultIsCFRetained(CGPDFContextCreateWithURL)
        url = CFURLCreateWithFileSystemPath(None, "/tmp/pyobjc.test.pdf",
                                            kCFURLPOSIXPathStyle, False)
        self.assertArgIsIn(CGPDFContextCreateWithURL, 1)
        context = CGPDFContextCreateWithURL(url, None, None)
        self.assertIsInstance(context, CGContextRef)

        CGPDFContextBeginPage(context, None)

        CGPDFContextSetURLForRect(context, url, ((0, 0), (10, 10)))
        CGPDFContextAddDestinationAtPoint(context, "target", (50, 50))

        CGPDFContextSetDestinationForRect(context, "target",
                                          ((100, 120), (50, 60)))

        CGPDFContextEndPage(context)

        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(context)
Пример #2
0
    def testFunctions(self):
        data = NSMutableData.data()
        self.assertIsInstance(data, CFMutableDataRef)

        consumer = CGDataConsumerCreateWithCFData(data)
        self.assertIsInstance(consumer, CGDataConsumerRef)

        self.assertArgIsIn(CGPDFContextCreate, 1)
        self.assertResultIsCFRetained(CGPDFContextCreate)
        context = CGPDFContextCreate(consumer, None, None)
        self.assertIsInstance(context, CGContextRef)

        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(context)

        self.assertResultIsCFRetained(CGPDFContextCreateWithURL)
        url = CFURLCreateWithFileSystemPath(None,
            "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False)
        self.assertArgIsIn(CGPDFContextCreateWithURL, 1)
        context = CGPDFContextCreateWithURL(url, None, None)
        self.assertIsInstance(context, CGContextRef)

        CGPDFContextBeginPage(context, None)

        CGPDFContextSetURLForRect(context, url, ((0, 0), (10, 10)))
        CGPDFContextAddDestinationAtPoint(context, "target", (50, 50))

        CGPDFContextSetDestinationForRect(context, "target", ((100, 120), (50, 60)))

        CGPDFContextEndPage(context)

        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(context)
Пример #3
0
    def testFunctions10_7(self):
        data = NSMutableData.data()
        consumer = CGDataConsumerCreateWithCFData(data)
        context = CGPDFContextCreate(consumer, None, None)

        metadata = b'''<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><?xpacket end='w'?>'''
        CGPDFContextAddDocumentMetadata(context,
                NSMutableData.dataWithBytes_length_(metadata, len(metadata)))
Пример #4
0
    def testFunctions(self):
        self.assertIsInstance(Quartz.CGDataConsumerGetTypeID(), int)

        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        try:
            consumer = Quartz.CGDataConsumerCreateWithURL(url)
            self.assertIsInstance(consumer, Quartz.CGDataConsumerRef)

            data = NSMutableData.data()
            self.assertIsInstance(data, Quartz.CFMutableDataRef)

            consumer = Quartz.CGDataConsumerCreateWithCFData(data)
            self.assertIsInstance(consumer, Quartz.CGDataConsumerRef)

            v = Quartz.CGDataConsumerRetain(consumer)
            self.assertTrue(v is consumer)
            Quartz.CGDataConsumerRelease(consumer)

        finally:
            del url
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")

        def putBytes(info, a_buffer, bufsize):
            self.assertIsInstance(a_buffer, bytes)
            self.assertEqual(len(a_buffer), bufsize)
            info.append(a_buffer)
            return bufsize

        def release(info):
            released.append(info)

        output = []
        released = []
        consumer = Quartz.CGDataConsumerCreate(output, (putBytes, release))
        self.assertIsInstance(consumer, Quartz.CGDataConsumerRef)

        ctx = Quartz.CGPDFContextCreate(consumer,
                                        Quartz.CGRectMake(0, 0, 500, 500),
                                        None)
        self.assertIsInstance(ctx, Quartz.CGContextRef)
        Quartz.CGContextBeginPage(ctx, None)
        Quartz.CGContextFillRect(ctx, ((10, 10), (50, 30)))
        Quartz.CGContextEndPage(ctx)
        Quartz.CGContextFlush(ctx)
        if hasattr(Quartz, "CGPDFContextClose"):
            Quartz.CGPDFContextClose(ctx)

        del ctx
        del consumer

        self.assertNotEqual(len(output), 0)
        self.assertNotEqual(len(released), 0)
Пример #5
0
    def testFunctions10_7(self):
        data = NSMutableData.data()
        consumer = CGDataConsumerCreateWithCFData(data)
        context = CGPDFContextCreate(consumer, None, None)

        metadata = b'''<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><?xpacket end='w'?>'''
        CGPDFContextAddDocumentMetadata(
            context,
            NSMutableData.dataWithBytes_length_(metadata, len(metadata)))
Пример #6
0
    def testFunctions(self):
        self.assertIsInstance(CGImageDestinationGetTypeID(), (int, long))

        self.assertResultIsCFRetained(CGImageDestinationCopyTypeIdentifiers)
        v = CGImageDestinationCopyTypeIdentifiers()
        self.assertIsInstance(v, CFArrayRef)
        if v:
            self.assertIsInstance(v[0], unicode)

        data = NSMutableData.data()
        self.assertResultIsCFRetained(CGImageDestinationCreateWithData)
        dest = CGImageDestinationCreateWithData(data, v[0], 1, None)
        self.assertIsInstance(dest, CGImageDestinationRef)

        url = CFURLCreateWithFileSystemPath(None, "/tmp/pyobjc.test.pdf",
                                            kCFURLPOSIXPathStyle, False)
        self.assertResultIsCFRetained(CGImageDestinationCreateWithURL)
        dest = CGImageDestinationCreateWithURL(url, "public.tiff", 2, None)
        self.assertIsInstance(dest, CGImageDestinationRef)

        CGImageDestinationSetProperties(
            dest, {b'key'.decode('latin1'): b'value'.decode('latin1')})

        provider = CGDataProviderCreateWithCFData(buffer("1" * 4 * 100 * 80))
        img = CGImageCreate(100, 80, 8, 32, 400, CGColorSpaceCreateDeviceRGB(),
                            kCGImageAlphaPremultipliedLast, provider, None,
                            False, kCGRenderingIntentDefault)
        self.assertIsInstance(img, CGImageRef)

        CGImageDestinationAddImage(dest, img, None)

        image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/bullet.tif"
        if not os.path.exists(image_path):
            image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.png"
        if not os.path.exists(image_path):
            image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.tiff"
        url = CFURLCreateWithFileSystemPath(None, image_path,
                                            kCFURLPOSIXPathStyle, False)

        isrc = CGImageSourceCreateWithURL(url, None)
        CGImageDestinationAddImageFromSource(dest, isrc, 0, None)

        self.assertResultHasType(CGImageDestinationFinalize, objc._C_BOOL)
        v = CGImageDestinationFinalize(dest)
        self.assertIsInstance(v, bool)
        self.assertIs(v, True)

        dta = NSMutableData.alloc().init()
        cons = CGDataConsumerCreateWithCFData(dta)

        self.assertResultIsCFRetained(CGImageDestinationCreateWithDataConsumer)
        c = CGImageDestinationCreateWithDataConsumer(cons, 'public.tiff', 1,
                                                     None)
        self.assertIsInstance(c, CGImageDestinationRef)
Пример #7
0
    def testFunctions(self):
        self.assertIsInstance(CGDataConsumerGetTypeID(), (int, long))

        url = CFURLCreateWithFileSystemPath(None,
            "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False)
        self.assertIsInstance(url, CFURLRef)
        try:
            consumer = CGDataConsumerCreateWithURL(url)
            self.assertIsInstance(consumer, CGDataConsumerRef)

            data = NSMutableData.data()
            self.assertIsInstance(data, CFMutableDataRef)

            consumer = CGDataConsumerCreateWithCFData(data)
            self.assertIsInstance(consumer, CGDataConsumerRef)

            v = CGDataConsumerRetain(consumer)
            self.assertTrue(v is consumer)
            CGDataConsumerRelease(consumer)

        finally:
            del url
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")

        def putBytes(info, buffer, bufsize):
            self.assertIsInstance(buffer, bytes)
            self.assertEqual(len(buffer), bufsize)
            info.append(buffer)
            return bufsize

        def release(info):
            released.append(info)


        output = []
        released = []
        consumer = CGDataConsumerCreate(output, (putBytes, release))
        self.assertIsInstance(consumer, CGDataConsumerRef)

        ctx = CGPDFContextCreate(consumer, CGRectMake(0, 0, 500, 500), None)
        self.assertIsInstance(ctx, CGContextRef)
        CGContextBeginPage(ctx, None)
        CGContextFillRect(ctx, ((10, 10), (50, 30)))
        CGContextEndPage(ctx)
        CGContextFlush(ctx)
        if hasattr(Quartz, 'CGPDFContextClose'): CGPDFContextClose(ctx)

        del ctx
        del consumer

        self.assertNotEqual(len(output), 0)
        self.assertNotEqual(len(released), 0)
    def testFunctions(self):
        self.assertIsInstance(CGImageDestinationGetTypeID(), (int, long))

        self.assertResultIsCFRetained(CGImageDestinationCopyTypeIdentifiers)
        v = CGImageDestinationCopyTypeIdentifiers()
        self.assertIsInstance(v, CFArrayRef)
        if v:
            self.assertIsInstance(v[0], unicode)

        data = NSMutableData.data()
        self.assertResultIsCFRetained(CGImageDestinationCreateWithData)
        dest = CGImageDestinationCreateWithData(data, v[0], 1, None)
        self.assertIsInstance(dest, CGImageDestinationRef)

        url = CFURLCreateWithFileSystemPath(None,
                "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False)
        self.assertResultIsCFRetained(CGImageDestinationCreateWithURL)
        dest = CGImageDestinationCreateWithURL(url, "public.tiff", 2, None)
        self.assertIsInstance(dest, CGImageDestinationRef)

        CGImageDestinationSetProperties(dest, {b'key'.decode('latin1'): b'value'.decode('latin1')})

        provider = CGDataProviderCreateWithCFData(buffer("1" * 4 * 100 * 80))
        img = CGImageCreate(100, 80, 8, 32, 400, CGColorSpaceCreateDeviceRGB(),
                kCGImageAlphaPremultipliedLast, provider, None, False, kCGRenderingIntentDefault)
        self.assertIsInstance(img, CGImageRef)

        CGImageDestinationAddImage(dest, img, None)

        image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/bullet.tif"
        if not os.path.exists(image_path):
            image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.png"
        if not os.path.exists(image_path):
            image_path = "/System/Library//ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.tiff"
        url = CFURLCreateWithFileSystemPath(None,
            image_path,
            kCFURLPOSIXPathStyle, False)

        isrc = CGImageSourceCreateWithURL(url, None)
        CGImageDestinationAddImageFromSource(dest,  isrc, 0, None)

        self.assertResultHasType(CGImageDestinationFinalize, objc._C_BOOL)
        v = CGImageDestinationFinalize(dest)
        self.assertIsInstance(v, bool)
        self.assertIs(v, True)

        dta = NSMutableData.alloc().init()
        cons = CGDataConsumerCreateWithCFData(dta)

        self.assertResultIsCFRetained(CGImageDestinationCreateWithDataConsumer)
        c = CGImageDestinationCreateWithDataConsumer(cons, 'public.tiff', 1, None)
        self.assertIsInstance(c, CGImageDestinationRef)
Пример #9
0
    def testFunctions(self):
        self.failUnlessIsInstance(CGDataConsumerGetTypeID(), (int, long))

        url = CFURLCreateWithFileSystemPath(None, "/tmp/pyobjc.test.pdf",
                                            kCFURLPOSIXPathStyle, False)
        self.failUnlessIsInstance(url, CFURLRef)
        try:
            consumer = CGDataConsumerCreateWithURL(url)
            self.failUnlessIsInstance(consumer, CGDataConsumerRef)

            data = NSMutableData.data()
            self.failUnlessIsInstance(data, CFMutableDataRef)

            consumer = CGDataConsumerCreateWithCFData(data)
            self.failUnlessIsInstance(consumer, CGDataConsumerRef)

            v = CGDataConsumerRetain(consumer)
            self.failUnless(v is consumer)
            CGDataConsumerRelease(consumer)

        finally:
            del url
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")

        def putBytes(info, buffer, bufsize):
            self.failUnlessIsInstance(buffer, str)
            self.failUnlessEqual(len(buffer), bufsize)
            info.append(buffer)
            return bufsize

        def release(info):
            released.append(info)

        output = []
        released = []
        consumer = CGDataConsumerCreate(output, (putBytes, release))
        self.failUnlessIsInstance(consumer, CGDataConsumerRef)

        ctx = CGPDFContextCreate(consumer, CGRectMake(0, 0, 500, 500), None)
        self.failUnlessIsInstance(ctx, CGContextRef)
        CGContextBeginPage(ctx, None)
        CGContextFillRect(ctx, ((10, 10), (50, 30)))
        CGContextEndPage(ctx)
        CGContextFlush(ctx)
        CGPDFContextClose(ctx)

        del ctx
        del consumer

        self.failIfEqual(len(output), 0)
        self.failIfEqual(len(released), 0)
Пример #10
0
    def workaround():
        from Foundation import NSMutableData, NSAutoreleasePool

        pool = NSAutoreleasePool.alloc().init()
        try:
            rI = SKIndexCreateWithMutableData(NSMutableData.data(), None,
                                              kSKIndexInverted, None)

            indexID = CFGetTypeID(rI)

            r = SKIndexDocumentIteratorCreate(rI, None)
            iterID = CFGetTypeID(r)
            del r

            r = SKSearchGroupCreate([rI])
            groupID = CFGetTypeID(r)

            r = SKSearchResultsCreateWithQuery(r, ".*", kSKSearchRanked, 1,
                                               None, None)
            resultID = CFGetTypeID(r)

            if SKSearchGetTypeID() == 0:
                # Type doesn't get registered unless you try to use it.
                # That's no good for PyObjC, therefore forcefully create
                # a SKSearch object
                SKSearchCreate(rI, "q", 0)
                searchref = objc.registerCFSignature("SKSearchRef",
                                                     b"^{__SKSearch=}",
                                                     SKSearchGetTypeID())
            else:
                searchref = SKSearchRef

            del r
            del rI

            r = SKSummaryCreateWithString("foo")
            summaryID = CFGetTypeID(r)
            del r

        finally:
            del pool

        def SKIndexGetTypeID():
            return indexID

        def SKIndexDocumentIteratorGetTypeID():
            return iterID

        def SKSearchGroupGetTypeID():
            return groupID

        def SKSearchResultsGetTypeID():
            return resultID

        def SKSummaryGetTypeID():
            return summaryID

        indexType = objc.registerCFSignature("SKIndexRef", b"^{__SKIndex=}",
                                             indexID)
        iterType = objc.registerCFSignature("SKIndexDocumentIteratorRef",
                                            b"^{__SKIndexDocumentIterator=}",
                                            iterID)
        groupType = objc.registerCFSignature("SKSearchGroupRef",
                                             b"^{__SKSearchGroup=}", groupID)
        resultType = objc.registerCFSignature("SKSearchResultsRef",
                                              b"^{__SKSearchResults=}",
                                              resultID)
        summaryType = objc.registerCFSignature("SKSummaryRef",
                                               b"^{__SKSummary=}", summaryID)

        # For some reason SKDocumentGetTypeID doesn't return the right value
        # when the framework loader calls it the first time around,
        # by this time the framework is fully initialized and we get
        # the correct result.
        SKDocumentRef = objc.registerCFSignature("SKDocumentRef", b"@",
                                                 SKDocumentGetTypeID())

        return (SKIndexGetTypeID, indexType, SKIndexDocumentIteratorGetTypeID,
                iterType, SKSearchGroupGetTypeID, groupType,
                SKSearchResultsGetTypeID, resultType, SKSummaryGetTypeID,
                summaryType, iterType, SKDocumentRef, searchref)
Пример #11
0
    def workaround():
        from Foundation import NSMutableData, NSAutoreleasePool

        pool = NSAutoreleasePool.alloc().init()
        try:
            rI = SKIndexCreateWithMutableData(NSMutableData.data(),
                    None, kSKIndexInverted, None)

            indexID = CFGetTypeID(rI)

            r = SKIndexDocumentIteratorCreate(rI, None)
            iterID = CFGetTypeID(r)
            del r

            r = SKSearchGroupCreate([rI])
            groupID = CFGetTypeID(r)

            r = SKSearchResultsCreateWithQuery(r, ".*", kSKSearchRanked, 1, None, None)
            resultID = CFGetTypeID(r)

            if SKSearchGetTypeID() == 0:
                # Type doesn't get registered unless you try to use it.
                # That's no good for PyObjC, therefore forcefully create
                # a SKSearch object
                SKSearchCreate(rI, "q", 0)
                searchref = objc.registerCFSignature(
                        "SKSearchRef", "^{__SKSearch=}", SKSearchGetTypeID())
            else:
                searchref = SKSearchRef

            del r
            del rI

            r = SKSummaryCreateWithString("foo")
            summaryID = CFGetTypeID(r)
            del r

        finally:
            del pool

        def SKIndexGetTypeID():
            return indexID

        def SKIndexDocumentIteratorGetTypeID():
            return iterID

        def SKSearchGroupGetTypeID():
            return groupID

        def SKSearchResultsGetTypeID():
            return resultID

        def SKSummaryGetTypeID():
            return summaryID

        indexType = objc.registerCFSignature(
                "SKIndexRef", "^{__SKIndex=}", indexID)
        iterType = objc.registerCFSignature(
                "SKIndexDocumentIteratorRef", "^{__SKIndexDocumentIterator=}", indexID)
        groupType = objc.registerCFSignature(
                "SKSearchGroupRef", "^{__SKSearchGroup=}", groupID)
        resultType = objc.registerCFSignature(
                "SKSearchResultsRef", "^{__SKSearchResults=}", resultID)
        summaryType = objc.registerCFSignature(
                "SKSummaryRef", "^{__SKSummary=}", summaryID)

        # For some reason SKDocumentGetTypeID doesn't return the right value
        # when the framework loader calls it the first time around,
        # by this time the framework is fully initialized and we get
        # the correct result.
        SKDocumentRef = objc.registerCFSignature(
                "SKDocumentRef", "@", SKDocumentGetTypeID())


        return (SKIndexGetTypeID, indexType, SKIndexDocumentIteratorGetTypeID, iterType, 
                SKSearchGroupGetTypeID, groupType, SKSearchResultsGetTypeID, resultType,
                SKSummaryGetTypeID, summaryType,
                SKDocumentRef, searchref)
Пример #12
0
    def testFunctions(self):
        self.assertIsInstance(SKSearchGroupGetTypeID(), (int, long))
        self.assertIsInstance(SKSearchResultsGetTypeID(), (int, long))
        self.assertIsInstance(SKSearchGetTypeID(), (int, long))

        data = NSMutableData.data()
        index = SKIndexCreateWithMutableData(
                data, "pyobjc.test", kSKIndexInverted, None)
        self.assertIsInstance(index, SKIndexRef)
        doc = SKDocumentCreateWithURL(
            CFURLCreateWithFileSystemPath(
            None, u"/Library/Documentation/Acknowledgements.rtf",
            kCFURLPOSIXPathStyle, False))
        doc2 = SKDocumentCreateWithURL(
            CFURLCreateWithFileSystemPath(
            None, u"/Library/Documentation/iPod/Acknowledgements.rtf",
            kCFURLPOSIXPathStyle, False))
        SKIndexAddDocumentWithText(index, doc, "copyright and licenses", True)
        SKIndexAddDocumentWithText(index, doc2, "copyright and licenses for iPod", True)
        SKIndexFlush(index)


        grp = SKSearchGroupCreate([index])
        self.assertIsInstance(grp, SKSearchGroupRef)


        l = []

        @objc.callbackFor(SKSearchResultsCreateWithQuery)
        def callback(idx, doc, ctx):
            l.append([idx, doc, ctx])
            return True

        ctx = 10

        res = SKSearchResultsCreateWithQuery(
                grp, u"apache", kSKSearchRequiredRanked, 2, ctx, callback)
        self.assertIsInstance(res, SKSearchResultsRef)

        res = SKSearchResultsCreateWithDocuments(
                grp, [doc], 10, ctx, callback)
        self.assertIsInstance(res, SKSearchResultsRef)
        self.assertEqual(len(l), 2)
        self.assertEqual(l[0][0], index)
        self.assertIsInstance(l[0][1], SKDocumentRef)
        self.assertEqual(l[0][2], ctx)

        cnt = SKSearchResultsGetCount(res)
        self.assertIsInstance(cnt, (int, long))
        self.failUnless(cnt > 0)


        v, o1, o2, o3 = SKSearchResultsGetInfoInRange(res, CFRange(0, cnt), None, None, None)
        self.assertIsInstance(v, int)
        self.assertIsInstance(o1, tuple)
        if o1:
            self.assertIsInstance(o1[0], SKDocumentRef)
        self.assertIsInstance(o2, tuple)
        if o2:
            self.assertIsInstance(o2[0], SKIndexRef)
        self.assertIsInstance(o3, tuple)
        if o3:
            self.assertIsInstance(o3[0], float)

        v = SKSearchResultsCopyMatchingTerms(res, 1)
        self.assertIsInstance(v, CFArrayRef)

        src = SKSearchCreate(index, "copyright", kSKSearchOptionFindSimilar)
        self.assertIsInstance(src, SKSearchRef)

        v, o1, o2, o3 = SKSearchFindMatches(src, 10, None, None, 1.0, None)
        self.assertIsInstance(v, bool)
        self.assertIsInstance(o1, tuple)
        if o1:
            self.assertIsInstance(o1[0], (int, long))
        self.assertIsInstance(o2, tuple)
        if o2:
            self.assertIsInstance(o2[0], float)
        self.assertIsInstance(o3, (int, long))

        v1, v2 = SKIndexCopyInfoForDocumentIDs(
                index, o3, o1, None, None)
        if v1:
            self.assertIsInstance(v1[0], unicode)
        self.assertIsInstance(v2, tuple)
        if v2:
            self.assertIsInstance(v2[0], (int, long))

        v = SKIndexCopyDocumentRefsForDocumentIDs(
            index, o3, o1, None)
        self.assertIsInstance(v, tuple)
        if v:
            self.assertIsInstance(v[0], SKDocumentRef)

        v = SKIndexCopyDocumentURLsForDocumentIDs(
                index, o3, o1, None)
        self.assertIsInstance(v, tuple)
        if v:
            self.assertIsInstance(v[0], CFURLRef)

        self.assertResultIsCFRetained(SKSearchGroupCopyIndexes)
        a = SKSearchGroupCopyIndexes(grp)
        self.assertIsInstance(a, CFArrayRef)

        SKSearchCancel(src)
Пример #13
0
    def testFunctions(self):

        self.assertIsInstance(SKIndexGetTypeID(), (int, long))
        self.assertIsInstance(SKIndexDocumentIteratorGetTypeID(), (int, long))

        self.assertResultIsCFRetained(SKIndexCreateWithURL)
        try:
            url = CFURLCreateWithFileSystemPath(
                        None, b"/tmp/pyobjc.test.index".decode('latin1'),
                        kCFURLPOSIXPathStyle, False)
            self.assertIsInstance(url, CFURLRef)
            ref = SKIndexCreateWithURL(
                    url,
                    "pyobjc.test",
                    kSKIndexInverted,
                    None)
            self.assertIsInstance(ref, SKIndexRef)

            v = SKIndexFlush(ref)
            self.assertIsInstance(v, bool)
            CFRetain(ref)
            SKIndexClose(ref)

            del ref

            ref = SKIndexOpenWithURL(url, "pyobjc.test", False)
            if ref is not None:
                # XXX: Don't understand why this doesn't work as planned...
                self.assertIsInstance(ref, SKIndexRef)

        finally:
            os.unlink('/tmp/pyobjc.test.index')

        data = NSMutableData.data()

        self.assertResultIsCFRetained(SKIndexCreateWithMutableData)
        ref = SKIndexCreateWithMutableData(
                data,
                "pyobjc.test", kSKIndexInverted, None)
        self.assertIsInstance(ref, SKIndexRef)
        del ref

        ref = SKIndexOpenWithData(
                data,
                "pyobjc.test")
        self.assertIsInstance(ref, SKIndexRef)
        del ref

        ref = SKIndexOpenWithMutableData(
                data,
                "pyobjc.test")
        if ref is not None:
            self.assertIsInstance(ref, SKIndexRef)

        data = NSMutableData.data()
        self.assertResultIsCFRetained(SKIndexCreateWithMutableData)
        ref = SKIndexCreateWithMutableData(
                data,
                "pyobjc.test", kSKIndexInverted, None)
        self.assertIsInstance(ref, SKIndexRef)


        SKIndexSetMaximumBytesBeforeFlush(ref, 10000)

        v = SKIndexGetMaximumBytesBeforeFlush(ref)
        self.assertIsInstance(v, (int, long))

        v = SKIndexCompact(ref)
        self.assertIsInstance(v, bool)

        v = SKIndexGetIndexType(ref)
        self.assertIsInstance(v, (int, long))

        v = SKIndexGetAnalysisProperties(ref)
        self.failUnless(v is None)

        v = SKIndexGetDocumentCount(ref)
        self.assertIsInstance(v, (int, long))


        self.assertResultIsBOOL(SKIndexAddDocumentWithText)
        self.assertArgIsBOOL(SKIndexAddDocumentWithText, 3)


        fn = b"/Library/Documentation/Acknowledgements.rtf".decode('latin1')
        if not os.path.exists(fn):
            fn = b"/Library/Documentation/AirPort Acknowledgements.rtf".decode('latin1')

        doc = SKDocumentCreateWithURL(
                CFURLCreateWithFileSystemPath(
                    None, fn,
                    kCFURLPOSIXPathStyle, False))

        v = SKIndexAddDocumentWithText(ref,
                doc, "hello world", True)
        self.failUnless(v)

        self.assertResultIsBOOL(SKIndexAddDocument)
        self.assertArgIsBOOL(SKIndexAddDocument, 3)
        v = SKIndexAddDocument(ref, doc, None, True)
        self.failUnless(v is True)

        SKIndexSetDocumentProperties(ref, doc, {"demo": "pyobjc"})

        v = SKIndexCopyDocumentProperties(ref, doc)
        self.assertIsInstance(v, CFDictionaryRef)

        v = SKIndexGetDocumentState(ref, doc)
        self.assertIsInstance(v, (int, long))

        v = docID = SKIndexGetDocumentID(ref, doc)
        self.assertIsInstance(v, (int, long))

        self.assertResultIsCFRetained(SKIndexCopyDocumentForDocumentID)
        v = SKIndexCopyDocumentForDocumentID(ref, v)
        self.failUnless(v is doc)

        r = SKIndexFlush(ref)
        self.assertIs(r, True)

        self.assertResultIsCFRetained(SKIndexDocumentIteratorCreate)
        it = SKIndexDocumentIteratorCreate(ref, None)
        self.assertIsInstance(it, SKIndexDocumentIteratorRef)

        self.assertResultIsCFRetained(SKIndexDocumentIteratorCopyNext)
        v = SKIndexDocumentIteratorCopyNext(it)
        self.assertIsInstance(v, SKDocumentRef)

        v = SKIndexDocumentIteratorCopyNext(it)
        self.failUnless(v is None)

        v = SKIndexGetMaximumDocumentID(ref)
        self.assertIsInstance(v, (int, long))

        v = SKIndexGetDocumentTermCount(ref, docID)
        self.assertIsInstance(v, (int, long))


        v = SKIndexCopyTermIDArrayForDocumentID(ref, docID)
        self.assertIsInstance(v, CFArrayRef)

        tID =  SKIndexGetMaximumTermID(ref) - 1


        v = SKIndexGetDocumentTermFrequency(ref, docID, tID)
        self.assertIsInstance(v, (int, long))

        v = SKIndexGetMaximumTermID(ref)
        self.assertIsInstance(v, (int, long))

        v = SKIndexGetTermDocumentCount(ref, tID)
        self.assertIsInstance(v, (int, long))

        v = SKIndexCopyDocumentIDArrayForTermID(ref, tID)
        self.assertIsInstance(v, (CFArrayRef, type(None)))

        v = SKIndexCopyTermStringForTermID(ref, tID)
        self.assertIsInstance(v, (unicode, type(None)))

        v = SKIndexGetTermIDForTermString(ref, v)
        self.assertIsInstance(v, (int, long))

        SKLoadDefaultExtractorPlugIns()

        v = SKIndexRenameDocument(ref, doc, "osx-acks.rtf")
        self.failUnless(v is True)

        v = SKIndexMoveDocument(ref, doc, None)
        self.failUnless(v is True)

        v = SKIndexRemoveDocument(ref, doc)
        self.failUnless(v)
Пример #14
0
    def testFunctions(self):

        self.failUnlessIsInstance(SKIndexGetTypeID(), (int, long))
        self.failUnlessIsInstance(SKIndexDocumentIteratorGetTypeID(), (int, long))

        self.failUnlessResultIsCFRetained(SKIndexCreateWithURL)
        try:
            url = CFURLCreateWithFileSystemPath(
                        None, u"/tmp/pyobjc.test.index",
                        kCFURLPOSIXPathStyle, False)
            self.failUnlessIsInstance(url, CFURLRef)
            ref = SKIndexCreateWithURL(
                    url,
                    "pyobjc.test",
                    kSKIndexInverted,
                    None)
            self.failUnlessIsInstance(ref, SKIndexRef)

            v = SKIndexFlush(ref)
            self.failUnlessIsInstance(v, bool)
            CFRetain(ref)
            SKIndexClose(ref)

            del ref

            ref = SKIndexOpenWithURL(url, "pyobjc.test", False)
            if ref is not None:
                # XXX: Don't understand why this doesn't work as planned...
                self.failUnlessIsInstance(ref, SKIndexRef)

        finally:
            os.unlink('/tmp/pyobjc.test.index')

        data = NSMutableData.data()

        self.failUnlessResultIsCFRetained(SKIndexCreateWithMutableData)
        ref = SKIndexCreateWithMutableData(
                data,
                "pyobjc.test", kSKIndexInverted, None)
        self.failUnlessIsInstance(ref, SKIndexRef)
        del ref

        ref = SKIndexOpenWithData(
                data,
                "pyobjc.test")
        self.failUnlessIsInstance(ref, SKIndexRef)
        del ref

        ref = SKIndexOpenWithMutableData(
                data,
                "pyobjc.test")
        if ref is not None:
            self.failUnlessIsInstance(ref, SKIndexRef)

        data = NSMutableData.data()
        self.failUnlessResultIsCFRetained(SKIndexCreateWithMutableData)
        ref = SKIndexCreateWithMutableData(
                data,
                "pyobjc.test", kSKIndexInverted, None)
        self.failUnlessIsInstance(ref, SKIndexRef)


        SKIndexSetMaximumBytesBeforeFlush(ref, 10000)

        v = SKIndexGetMaximumBytesBeforeFlush(ref)
        self.failUnlessIsInstance(v, (int, long))

        v = SKIndexCompact(ref)
        self.failUnlessIsInstance(v, bool)

        v = SKIndexGetIndexType(ref)
        self.failUnlessIsInstance(v, (int, long))

        v = SKIndexGetAnalysisProperties(ref)
        self.failUnless(v is None)

        v = SKIndexGetDocumentCount(ref)
        self.failUnlessIsInstance(v, (int, long))


        self.failUnlessResultIsBOOL(SKIndexAddDocumentWithText)
        self.failUnlessArgIsBOOL(SKIndexAddDocumentWithText, 3)


        doc = SKDocumentCreateWithURL(
                CFURLCreateWithFileSystemPath(
                    None, u"/Library/Documentation/Acknowledgements.rtf",
                    kCFURLPOSIXPathStyle, False))


        v = SKIndexAddDocumentWithText(ref, 
                doc, "hello world", True)
        self.failUnless(v)


        self.failUnlessResultIsBOOL(SKIndexAddDocument)
        self.failUnlessArgIsBOOL(SKIndexAddDocument, 3)
        v = SKIndexAddDocument(ref, doc, None, True)
        self.failUnless(v is True)

        SKIndexSetDocumentProperties(ref, doc, {"demo": "pyobjc"})

        v = SKIndexCopyDocumentProperties(ref, doc)
        self.failUnlessIsInstance(v, CFDictionaryRef)

        v = SKIndexGetDocumentState(ref, doc)
        self.failUnlessIsInstance(v, (int, long))

        v = docID = SKIndexGetDocumentID(ref, doc)
        self.failUnlessIsInstance(v, (int, long))

        self.failUnlessResultIsCFRetained(SKIndexCopyDocumentForDocumentID)
        v = SKIndexCopyDocumentForDocumentID(ref, v)
        self.failUnless(v is doc)

        v = SKIndexRenameDocument(ref, doc, "osx-acks.rtf")
        self.failUnless(v is True)

        v = SKIndexMoveDocument(ref, doc, None)
        self.failUnless(v is True)

        self.failUnlessResultIsCFRetained(SKIndexDocumentIteratorCreate)
        it = SKIndexDocumentIteratorCreate(ref, None)
        self.failUnlessIsInstance(it, SKIndexDocumentIteratorRef)

        self.failUnlessResultIsCFRetained(SKIndexDocumentIteratorCopyNext)
        v = SKIndexDocumentIteratorCopyNext(it)
        self.failUnlessIsInstance(v, SKDocumentRef)

        v = SKIndexDocumentIteratorCopyNext(it)
        self.failUnless(v is None)

        v = SKIndexGetMaximumDocumentID(ref)
        self.failUnlessIsInstance(v, (int, long))

        v = SKIndexGetDocumentTermCount(ref, docID)
        self.failUnlessIsInstance(v, (int, long))

        v = SKIndexCopyTermIDArrayForDocumentID(ref, docID)
        self.failUnlessIsInstance(v, CFArrayRef)
        tID = v[0]

        v = SKIndexGetDocumentTermFrequency(ref, docID, tID)
        self.failUnlessIsInstance(v, (int, long))

        v = SKIndexGetMaximumTermID(ref)
        self.failUnlessIsInstance(v, (int, long))

        v = SKIndexGetTermDocumentCount(ref, tID)
        self.failUnlessIsInstance(v, (int, long))

        v = SKIndexCopyDocumentIDArrayForTermID(ref, tID)
        self.failUnlessIsInstance(v, CFArrayRef)

        v = SKIndexCopyTermStringForTermID(ref, tID)
        self.failUnlessIsInstance(v, unicode)

        v = SKIndexGetTermIDForTermString(ref, v)
        self.failUnlessIsInstance(v, (int, long))

        SKLoadDefaultExtractorPlugIns()

        v = SKIndexRemoveDocument(ref, doc)
        self.failUnless(v)
Пример #15
0
    def testFunctions(self):
        self.failUnlessIsInstance(SKSearchGroupGetTypeID(), (int, long))
        self.failUnlessIsInstance(SKSearchResultsGetTypeID(), (int, long))
        self.failUnlessIsInstance(SKSearchGetTypeID(), (int, long))

        data = NSMutableData.data()
        index = SKIndexCreateWithMutableData(data, "pyobjc.test",
                                             kSKIndexInverted, None)
        self.failUnlessIsInstance(index, SKIndexRef)
        doc = SKDocumentCreateWithURL(
            CFURLCreateWithFileSystemPath(
                None, u"/Library/Documentation/Acknowledgements.rtf",
                kCFURLPOSIXPathStyle, False))
        doc2 = SKDocumentCreateWithURL(
            CFURLCreateWithFileSystemPath(
                None, u"/Library/Documentation/iPod/Acknowledgements.rtf",
                kCFURLPOSIXPathStyle, False))
        SKIndexAddDocumentWithText(index, doc, "copyright and licenses", True)
        SKIndexAddDocumentWithText(index, doc2,
                                   "copyright and licenses for iPod", True)
        SKIndexFlush(index)

        grp = SKSearchGroupCreate([index])
        self.failUnlessIsInstance(grp, SKSearchGroupRef)

        l = []

        @objc.callbackFor(SKSearchResultsCreateWithQuery)
        def callback(idx, doc, ctx):
            l.append([idx, doc, ctx])
            return True

        ctx = 10

        res = SKSearchResultsCreateWithQuery(grp, u"apache",
                                             kSKSearchRequiredRanked, 2, ctx,
                                             callback)
        self.failUnlessIsInstance(res, SKSearchResultsRef)

        res = SKSearchResultsCreateWithDocuments(grp, [doc], 10, ctx, callback)
        self.failUnlessIsInstance(res, SKSearchResultsRef)
        self.failUnlessEqual(len(l), 2)
        self.failUnlessEqual(l[0][0], index)
        self.failUnlessIsInstance(l[0][1], SKDocumentRef)
        self.failUnlessEqual(l[0][2], ctx)

        cnt = SKSearchResultsGetCount(res)
        self.failUnlessIsInstance(cnt, (int, long))
        self.failUnless(cnt > 0)

        v, o1, o2, o3 = SKSearchResultsGetInfoInRange(res, CFRange(0, cnt),
                                                      None, None, None)
        self.failUnlessIsInstance(v, int)
        self.failUnlessIsInstance(o1, tuple)
        if o1:
            self.failUnlessIsInstance(o1[0], SKDocumentRef)
        self.failUnlessIsInstance(o2, tuple)
        if o2:
            self.failUnlessIsInstance(o2[0], SKIndexRef)
        self.failUnlessIsInstance(o3, tuple)
        if o3:
            self.failUnlessIsInstance(o3[0], float)

        v = SKSearchResultsCopyMatchingTerms(res, 1)
        self.failUnlessIsInstance(v, CFArrayRef)

        src = SKSearchCreate(index, "copyright", kSKSearchOptionFindSimilar)
        self.failUnlessIsInstance(src, SKSearchRef)

        v, o1, o2, o3 = SKSearchFindMatches(src, 10, None, None, 1.0, None)
        self.failUnlessIsInstance(v, bool)
        self.failUnlessIsInstance(o1, tuple)
        if o1:
            self.failUnlessIsInstance(o1[0], (int, long))
        self.failUnlessIsInstance(o2, tuple)
        if o2:
            self.failUnlessIsInstance(o2[0], float)
        self.failUnlessIsInstance(o3, (int, long))

        v1, v2 = SKIndexCopyInfoForDocumentIDs(index, o3, o1, None, None)
        if v1:
            self.failUnlessIsInstance(v1[0], unicode)
        self.failUnlessIsInstance(v2, tuple)
        if v2:
            self.failUnlessIsInstance(v2[0], (int, long))

        v = SKIndexCopyDocumentRefsForDocumentIDs(index, o3, o1, None)
        self.failUnlessIsInstance(v, tuple)
        if v:
            self.failUnlessIsInstance(v[0], SKDocumentRef)

        v = SKIndexCopyDocumentURLsForDocumentIDs(index, o3, o1, None)
        self.failUnlessIsInstance(v, tuple)
        if v:
            self.failUnlessIsInstance(v[0], CFURLRef)

        self.failUnlessResultIsCFRetained(SKSearchGroupCopyIndexes)
        a = SKSearchGroupCopyIndexes(grp)
        self.failUnlessIsInstance(a, CFArrayRef)

        SKSearchCancel(src)