From 2c33be9bece9cce2fbf3ced2c493701ee9f3c0cd Mon Sep 17 00:00:00 2001 From: Leonid Shalupov Date: Thu, 10 Mar 2022 22:42:17 +0300 Subject: [PATCH 1/3] Add CFDictionaryGetCount to c.s.j.p.mac.CoreFoundation --- CHANGES.md | 1 + .../sun/jna/platform/mac/CoreFoundation.java | 19 +++++++++++++++++++ .../jna/platform/mac/CoreFoundationTest.java | 3 +++ 3 files changed, 23 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d74d538127..5ba00d23e0 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). +* 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..4aac0cd203 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(0, 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(1, 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(2, dict.getCount()); oneStr.release(); cfOne.release(); From 16ba805660ab7b3c90c8e68516f133e917da9290 Mon Sep 17 00:00:00 2001 From: Leonid Shalupov Date: Thu, 10 Mar 2022 22:43:51 +0300 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 5ba00d23e0..5d3279a80c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,7 +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). -* Add `CFDictionaryGetCount` to `c.s.j.p.mac.CoreFoundation` - [@shalupov](https://github.com/shalupov) +* [#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 --------- From 5e60b78773be09a770e3eed24d7bc0a29e3fcbe4 Mon Sep 17 00:00:00 2001 From: Leonid Shalupov Date: Fri, 11 Mar 2022 03:42:30 +0300 Subject: [PATCH 3/3] Add CFDictionaryGetCount: review fixes --- .../test/com/sun/jna/platform/mac/CoreFoundationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 4aac0cd203..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,7 +209,7 @@ public void testCFDictionary() { CFStringRef oneStr = CFStringRef.createCFString("one"); // Key does not exist, returns null - assertEquals(0, dict.getCount()); + assertEquals(0L, dict.getCount()); assertFalse(dict.getValueIfPresent(oneStr, null)); Pointer cfNull = dict.getValue(oneStr); assertNull(cfNull); @@ -224,7 +224,7 @@ public void testCFDictionary() { IntByReference one = new IntByReference(1); CFNumberRef cfOne = CF.CFNumberCreate(null, CFNumberType.kCFNumberIntType.typeIndex(), one); dict.setValue(oneStr, cfOne); - assertEquals(1, dict.getCount()); + assertEquals(1L, dict.getCount()); assertTrue(dict.getValueIfPresent(oneStr, null)); Pointer result = dict.getValue(oneStr); @@ -242,7 +242,7 @@ public void testCFDictionary() { result = dict.getValue(onePtr); CFStringRef strRef = new CFStringRef(result); assertEquals("one", strRef.stringValue()); - assertEquals(2, dict.getCount()); + assertEquals(2L, dict.getCount()); oneStr.release(); cfOne.release();