|
5 | 5 | #![cfg(target_vendor = "apple")] |
6 | 6 | #![cfg(feature = "exception")] // For `should_panic` to work |
7 | 7 |
|
8 | | -use core::{panic::AssertUnwindSafe, ptr::NonNull}; |
| 8 | +use core::panic::AssertUnwindSafe; |
9 | 9 | use std::string::ToString; |
10 | 10 |
|
11 | 11 | use objc2::AnyThread; |
| 12 | +use objc2_core_foundation::{CFArray, CFNumber}; |
12 | 13 | use objc2_foundation::{ |
13 | 14 | NSArray, NSAttributedString, NSDictionary, NSException, NSIndexSet, NSMethodSignature, |
14 | 15 | NSMutableArray, NSNotFound, NSObject, NSOrderedSet, NSPointerArray, NSRange, NSString, |
@@ -63,6 +64,24 @@ fn array() { |
63 | 64 | }); |
64 | 65 | } |
65 | 66 |
|
| 67 | +#[test] |
| 68 | +// FIXME: Encoding checks shouldn't be this strict. |
| 69 | +#[cfg_attr( |
| 70 | + debug_assertions, |
| 71 | + ignore = "type encoding is apparently... ^{__CFNumber=}" |
| 72 | +)] |
| 73 | +fn cf_array_toll_free_bridged() { |
| 74 | + let arr = CFArray::from_retained_objects(&[CFNumber::new_i32(42), CFNumber::new_f32(64.0)]); |
| 75 | + let arr: &NSArray<CFNumber> = arr.as_ref(); |
| 76 | + |
| 77 | + let _ = arr.objectAtIndex(0); |
| 78 | + let _ = arr.objectAtIndex(1); |
| 79 | + |
| 80 | + assert_throws("index 100 beyond bounds [0 .. 1]", || { |
| 81 | + arr.objectAtIndex(100) |
| 82 | + }); |
| 83 | +} |
| 84 | + |
66 | 85 | #[test] |
67 | 86 | fn attributed_string() { |
68 | 87 | let arr = unsafe { |
@@ -90,7 +109,7 @@ fn index_set() { |
90 | 109 | #[test] |
91 | 110 | fn method_signature() { |
92 | 111 | let sig = c"c@:@"; |
93 | | - let sig = unsafe { NSMethodSignature::signatureWithObjCTypes(sig) }.unwrap(); |
| 112 | + let sig = NSMethodSignature::signatureWithObjCTypes(sig).unwrap(); |
94 | 113 | assert_throws("index (100) out of bounds [0, 2]", || { |
95 | 114 | sig.getArgumentTypeAtIndex(100) |
96 | 115 | }); |
|
0 commit comments