[PyObjC-svn] r2053 - in trunk/pyobjc/pyobjc-framework-SearchKit: . Exceptions Lib/SearchKit PyObjCTest

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Tue Feb  3 10:03:56 2009
New Revision: 2053

Log:
- Complete coverage of the SearchKit headerfiles
- Adds workarounds for problems in the SearchKit to ensure
  that all functionality is properly exposed.
  (This is another reason why I want these unittests, bridgesupport
   files were mostly correct, but some functionality is not properly
   exposed by the framework itself and that made these wrappers
   completely unusable from Python).


Modified:
   trunk/pyobjc/pyobjc-framework-SearchKit/Exceptions/SearchKit.bridgesupport
   trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/PyObjC.bridgesupport
   trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/__init__.py
   trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_skdocument.py
   trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_sksearch.py
   trunk/pyobjc/pyobjc-framework-SearchKit/setup.py

Modified: trunk/pyobjc/pyobjc-framework-SearchKit/Exceptions/SearchKit.bridgesupport
==============================================================================
--- trunk/pyobjc/pyobjc-framework-SearchKit/Exceptions/SearchKit.bridgesupport	(original)
+++ trunk/pyobjc/pyobjc-framework-SearchKit/Exceptions/SearchKit.bridgesupport	Tue Feb  3 10:03:56 2009
@@ -46,12 +46,12 @@
     <arg index='1' type='@' type64='@' />
   </function>
   <function name='SKIndexCopyDocumentRefsForDocumentIDs'>
-    <arg c_array_length_in_arg='1' index='2' />
-    <arg c_array_length_in_arg='1' index='3' type='^@' type64='^@' />
+    <arg c_array_length_in_arg='1' index='2' type_modifier='n' />
+    <arg c_array_length_in_arg='1' index='3' type='^@' type64='^@' type_modifier='o' />
   </function>
   <function name='SKIndexCopyDocumentURLsForDocumentIDs'>
-    <arg c_array_length_in_arg='1' index='2' />
-    <arg already_retained='true' c_array_length_in_arg='1' index='3' />
+    <arg c_array_length_in_arg='1' index='2' type_modifier='n' />
+    <arg already_retained='true' c_array_length_in_arg='1' index='3' type_modifier='o' />
   </function>
   <function name='SKIndexCopyInfoForDocumentIDs'>
     <arg c_array_length_in_arg='1' index='2' type_modifier='n' />
@@ -127,7 +127,7 @@
     <retval already_cfretained='true' already_retained='true' />
     <arg comment='context' index='4' type='^v' type64='^v' />
     <arg function_pointer='true' index='5' type='^?' type64='^?'>
-      <retval type='b' />
+      <retval type='B' />
       <arg type='@' />
       <arg type='@' />
       <arg type='^v' />

Modified: trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/PyObjC.bridgesupport
==============================================================================
--- trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/PyObjC.bridgesupport	(original)
+++ trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/PyObjC.bridgesupport	Tue Feb  3 10:03:56 2009
@@ -6,9 +6,9 @@
   <cftype gettypeid_func='SKIndexDocumentIteratorGetTypeID' name='SKIndexDocumentIteratorRef' type='^{__SKIndexDocumentIterator=}' type64='^{__SKIndexDocumentIterator=}' />
   <cftype gettypeid_func='SKIndexGetTypeID' name='SKIndexRef' type='^{__SKIndex=}' type64='^{__SKIndex=}' />
   <cftype gettypeid_func='SKSearchGroupGetTypeID' name='SKSearchGroupRef' type='^{__SKSearchGroup=}' type64='^{__SKSearchGroup=}' />
-  <cftype gettypeid_func='SKSearchGetTypeID' name='SKSearchRef' type='^{__SKSearch=}' type64='^{__SKSearch=}' />
   <cftype gettypeid_func='SKSearchResultsGetTypeID' name='SKSearchResultsRef' type='^{__SKSearchResults=}' type64='^{__SKSearchResults=}' />
   <cftype gettypeid_func='SKSummaryGetTypeID' name='SKSummaryRef' type='^{__SKSummary=}' type64='^{__SKSummary=}' />
+  <cftype gettypeid_func='SKSearchGetTypeID' name='SKSearchRef' type='^{__SKSearch=}' type64='^{__SKSearch=}' />
   <constant name='kSKEndTermChars' type='^{__CFString=}' />
   <constant name='kSKLanguageTypes' type='^{__CFString=}' />
   <constant name='kSKMaximumTerms' type='^{__CFString=}' />
@@ -102,14 +102,14 @@
   <function name='SKIndexCopyDocumentRefsForDocumentIDs'>
     <arg type='^{__SKIndex=}' />
     <arg type='l' type64='l' />
-    <arg c_array_length_in_arg='1' type='^i' type64='^i' />
-    <arg c_array_length_in_arg='1' type='^@' type64='^@' />
+    <arg c_array_length_in_arg='1' type='^i' type64='^i' type_modifier='n' />
+    <arg c_array_length_in_arg='1' type='^@' type64='^@' type_modifier='o' />
   </function>
   <function name='SKIndexCopyDocumentURLsForDocumentIDs'>
     <arg type='^{__SKIndex=}' />
     <arg type='l' type64='l' />
-    <arg c_array_length_in_arg='1' type='^i' type64='^i' />
-    <arg already_retained='true' c_array_length_in_arg='1' type='^^{__CFURL}' />
+    <arg c_array_length_in_arg='1' type='^i' type64='^i' type_modifier='n' />
+    <arg already_retained='true' c_array_length_in_arg='1' type='^^{__CFURL}' type_modifier='o' />
   </function>
   <function name='SKIndexCopyInfoForDocumentIDs'>
     <arg type='^{__SKIndex=}' />
@@ -317,7 +317,7 @@
     <arg type='l' type64='l' />
     <arg type='^v' type64='^v' />
     <arg function_pointer='true' type='^?' type64='^?'>
-      <retval type='b' />
+      <retval type='B' />
       <arg type='@' />
       <arg type='@' />
       <arg type='^v' />

Modified: trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/__init__.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/__init__.py	(original)
+++ trunk/pyobjc/pyobjc-framework-SearchKit/Lib/SearchKit/__init__.py	Tue Feb  3 10:03:56 2009
@@ -28,14 +28,37 @@
 
         pool = NSAutoreleasePool.alloc().init()
         try:
-            r = SKIndexCreateWithMutableData(NSMutableData.data(),
+            rI = SKIndexCreateWithMutableData(NSMutableData.data(),
                     None, kSKIndexInverted, None)
 
-            indexID = CFGetTypeID(r)
+            indexID = CFGetTypeID(rI)
 
-            r = SKIndexDocumentIteratorCreate(r, None)
+            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
@@ -46,12 +69,45 @@
         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)
-
-        return (SKIndexGetTypeID, indexType, SKIndexDocumentIteratorGetTypeID, iterType)
+        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)
 
     (SKIndexGetTypeID, SKIndexRef, 
-            SKIndexDocumentIteratorGetTypeID, SKIndexDocumentRef) = workaround()
+        SKIndexDocumentIteratorGetTypeID, SKIndexDocumentRef, 
+        SKSearchGroupGetTypeID, SKSearchGroupRef,
+        SKSearchResultsGetTypeID, SKSearchResultsRef,
+        SKSummaryGetTypeID, SKSummaryRef,
+        SKDocumentRef, SKSearchRef,
+    ) = workaround()
+
+    del workaround

Modified: trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_skdocument.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_skdocument.py	(original)
+++ trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_skdocument.py	Tue Feb  3 10:03:56 2009
@@ -4,7 +4,7 @@
 
 class TestSKDocument (TestCase):
     def testTypes(self):
-        self.failUnlessIsInstance(SKDocumentRef, objc.objc_class)
+        self.failUnlessIsCFType(SKDocumentRef)
 
     def testFunctions(self):
         self.failUnlessIsInstance(SKDocumentGetTypeID(), (int,  long))

Modified: trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_sksearch.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_sksearch.py	(original)
+++ trunk/pyobjc/pyobjc-framework-SearchKit/PyObjCTest/test_sksearch.py	Tue Feb  3 10:03:56 2009
@@ -29,36 +29,50 @@
         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)
 
-        self.failUnlessResultIsCFRetained(SKSearchGroupCopyIndexes)
-        a = SKSearchGroupCopyIndexes(grp)
-        self.failUnlessIsInstance(a, CFArrayRef)
 
         l = []
 
-        @objc.selectorFor(SKSearchResultsCreateWithQuery)
+        @objc.callbackFor(SKSearchResultsCreateWithQuery)
         def callback(idx, doc, ctx):
             l.append([idx, doc, ctx])
+            return True
 
         ctx = 10
+
         res = SKSearchResultsCreateWithQuery(
-                grp, "copyright", kSKSearchRanked, 10, ctx, callback)
+                grp, u"apache", kSKSearchRequiredRanked, 2, ctx, callback)
+        self.failUnlessIsInstance(res, SKSearchResultsRef)
+
+        res = SKSearchResultsCreateWithDocuments(
+                grp, [doc], 10, ctx, callback)
         self.failUnlessIsInstance(res, SKSearchResultsRef)
-        print l
+        self.failUnlessEqual(len(l), 2)
+        self.failUnlessEqual(l[0][0], index)
+        self.failUnlessIsInstance(l[0][1], SKDocumentRef)
+        self.failUnlessEqual(l[0][2], ctx)
 
-        v = SKSearchResultsCreateWithDocuments(
-                grp, [], 0, ctx, callback)
-        self.failUnlessIsInstance(v, SKSearchResultsRef)
-        print l
+        cnt = SKSearchResultsGetCount(res)
+        self.failUnlessIsInstance(cnt, (int, long))
+        self.failUnless(cnt > 0)
 
-        v = SKSearchResultsGetCount(res)
-        self.failUnlessIsInstance(v, (int, long))
 
-        v, o1, o2, o3 = SKSearchResultsGetInfoInRange(res, CFRange(0, 10), None, None, None)
+        v, o1, o2, o3 = SKSearchResultsGetInfoInRange(res, CFRange(0, cnt), None, None, None)
         self.failUnlessIsInstance(v, int)
         self.failUnlessIsInstance(o1, tuple)
         if o1:
@@ -70,33 +84,32 @@
         if o3:
             self.failUnlessIsInstance(o3[0], float)
 
-        v = SKSearchResultsCopyMatchingTerms(res, 0)
+        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.failUnlessEqual(v, bool)
-        self.failUnlessEqual(o1, tuple)
+        self.failUnlessIsInstance(v, bool)
+        self.failUnlessIsInstance(o1, tuple)
         if o1:
-            self.failUnlesssInstance(o1[0], (int, long))
-        self.failUnlessEqual(o2, tuple)
+            self.failUnlessIsInstance(o1[0], (int, long))
+        self.failUnlessIsInstance(o2, tuple)
         if o2:
-            self.failUnlesssInstance(o2[0], (int, long))
-        self.failUnlessEqual(o3, float)
+            self.failUnlessIsInstance(o2[0], float)
+        self.failUnlessIsInstance(o3, (int, long))
 
         v1, v2 = SKIndexCopyInfoForDocumentIDs(
                 index, o3, o1, None, None)
         if v1:
-            self.failUnlesssInstance(v1[0], unicode)
-        self.failUnlessEqual(v2, tuple)
+            self.failUnlessIsInstance(v1[0], unicode)
+        self.failUnlessIsInstance(v2, tuple)
         if v2:
-            self.failUnlesssInstance(v2[0], (int, long))
+            self.failUnlessIsInstance(v2[0], (int, long))
 
         v = SKIndexCopyDocumentRefsForDocumentIDs(
-            index,
-            o3, o1, None)
+            index, o3, o1, None)
         self.failUnlessIsInstance(v, tuple)
         if v:
             self.failUnlessIsInstance(v[0], SKDocumentRef)
@@ -107,6 +120,10 @@
         if v:
             self.failUnlessIsInstance(v[0], CFURLRef)
 
+        self.failUnlessResultIsCFRetained(SKSearchGroupCopyIndexes)
+        a = SKSearchGroupCopyIndexes(grp)
+        self.failUnlessIsInstance(a, CFArrayRef)
+
         SKSearchCancel(src)
 
 if __name__ == "__main__":

Modified: trunk/pyobjc/pyobjc-framework-SearchKit/setup.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-SearchKit/setup.py	(original)
+++ trunk/pyobjc/pyobjc-framework-SearchKit/setup.py	Tue Feb  3 10:03:56 2009
@@ -18,7 +18,7 @@
 
 setup(
     name='pyobjc-framework-SearchKit',
-    version='2.0',
+    version='2.2b1',
     description = "Wrappers for the framework SearchKit on Mac OS X",
     long_description = __doc__,
     author='Ronald Oussoren',

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.