diff --git a/CHANGES.md b/CHANGES.md index d74d538127..5d3279a80c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Features * [#1398](https://github.com/java-native-access/jna/pull/1398): Increase `c.s.j.p.win32.Sspi#MAX_TOKEN_SIZE` on Windows 8/Server 2012 and later - [@dbwiddis](https://github.com/dbwiddis). * [#1403](https://github.com/java-native-access/jna/pull/1403): Rebuild AIX binaries with libffi 3.4.2 (other architectures were part of 5.10) - [@matthiasblaesing](https://github.com/matthiasblaesing). * [#1404](https://github.com/java-native-access/jna/issues/1404): Added Solaris Kstat2 library - [@dbwiddis](https://github.com/dbwiddis). +* [#1416](https://github.com/java-native-access/jna/pull/1416): Add `CFDictionaryGetCount` to `c.s.j.p.mac.CoreFoundation` - [@shalupov](https://github.com/shalupov) Bug Fixes --------- diff --git a/contrib/platform/src/com/sun/jna/platform/mac/CoreFoundation.java b/contrib/platform/src/com/sun/jna/platform/mac/CoreFoundation.java index 8aa38f601c..7301ae6cc9 100644 --- a/contrib/platform/src/com/sun/jna/platform/mac/CoreFoundation.java +++ b/contrib/platform/src/com/sun/jna/platform/mac/CoreFoundation.java @@ -401,6 +401,16 @@ public Pointer getValue(PointerType key) { return INSTANCE.CFDictionaryGetValue(this, key); } + /** + * Convenience method for {@link CoreFoundation#CFDictionaryGetCount(CFDictionaryRef)} + * on this object. + * + * @return The number of key-value pairs in theDict. + */ + public long getCount() { + return INSTANCE.CFDictionaryGetCount(this).longValue(); + } + /** * Convenience method for * {@link CoreFoundation#CFDictionaryGetValueIfPresent} on this object. @@ -776,6 +786,15 @@ CFMutableDictionaryRef CFDictionaryCreateMutable(CFAllocatorRef alloc, CFIndex c */ CFIndex CFGetRetainCount(CFTypeRef cf); + /** + * Returns the number of key-value pairs in a dictionary. + * + * @param theDict + * The dictionary to examine. + * @return The number of key-value pairs in theDict. + */ + CFIndex CFDictionaryGetCount(CoreFoundation.CFDictionaryRef theDict); + /** * Returns the value associated with a given key. * diff --git a/contrib/platform/test/com/sun/jna/platform/mac/CoreFoundationTest.java b/contrib/platform/test/com/sun/jna/platform/mac/CoreFoundationTest.java index 2fedb7a988..ee5b949d00 100644 --- a/contrib/platform/test/com/sun/jna/platform/mac/CoreFoundationTest.java +++ b/contrib/platform/test/com/sun/jna/platform/mac/CoreFoundationTest.java @@ -209,6 +209,7 @@ public void testCFDictionary() { CFStringRef oneStr = CFStringRef.createCFString("one"); // Key does not exist, returns null + assertEquals(0L, dict.getCount()); assertFalse(dict.getValueIfPresent(oneStr, null)); Pointer cfNull = dict.getValue(oneStr); assertNull(cfNull); @@ -223,6 +224,7 @@ public void testCFDictionary() { IntByReference one = new IntByReference(1); CFNumberRef cfOne = CF.CFNumberCreate(null, CFNumberType.kCFNumberIntType.typeIndex(), one); dict.setValue(oneStr, cfOne); + assertEquals(1L, dict.getCount()); assertTrue(dict.getValueIfPresent(oneStr, null)); Pointer result = dict.getValue(oneStr); @@ -240,6 +242,7 @@ public void testCFDictionary() { result = dict.getValue(onePtr); CFStringRef strRef = new CFStringRef(result); assertEquals("one", strRef.stringValue()); + assertEquals(2L, dict.getCount()); oneStr.release(); cfOne.release();