Skip to content

Commit d10ad8d

Browse files
committed
Get tests passing on macOS 13
macOS 13 uses NSTaggedPointerString for short CFStrings which means the retain counts aren't meaningful. Increasing the length of the strings avoids this. Empty arrays also seem to refer to a shared constant object that doesn't have meaningful retain counts either. Fixes #597
1 parent 133d7ef commit d10ad8d

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

core-foundation/src/array.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ impl<'a, T: FromVoid> IntoIterator for &'a CFArray<T> {
162162

163163
#[cfg(test)]
164164
mod tests {
165+
use crate::number::CFNumber;
166+
165167
use super::*;
166168
use std::mem;
167169
use base::CFType;
168170

169171
#[test]
170172
fn to_untyped_correct_retain_count() {
171-
let array = CFArray::<CFType>::from_CFTypes(&[]);
173+
let array = CFArray::<CFType>::from_CFTypes(&[CFNumber::from(4).as_CFType()]);
172174
assert_eq!(array.retain_count(), 1);
173175

174176
let untyped_array = array.to_untyped();
@@ -181,7 +183,7 @@ mod tests {
181183

182184
#[test]
183185
fn into_untyped() {
184-
let array = CFArray::<CFType>::from_CFTypes(&[]);
186+
let array = CFArray::<CFType>::from_CFTypes(&[CFNumber::from(4).as_CFType()]);
185187
let array2 = array.to_untyped();
186188
assert_eq!(array.retain_count(), 2);
187189

@@ -196,7 +198,7 @@ mod tests {
196198
fn borrow() {
197199
use string::CFString;
198200

199-
let string = CFString::from_static_string("bar");
201+
let string = CFString::from_static_string("alongerstring");
200202
assert_eq!(string.retain_count(), 1);
201203
let x;
202204
{
@@ -208,7 +210,7 @@ mod tests {
208210
{
209211
x = arr.get(0).unwrap().clone();
210212
assert_eq!(x.retain_count(), 2);
211-
assert_eq!(x.to_string(), "bar");
213+
assert_eq!(x.to_string(), "alongerstring");
212214
}
213215
}
214216
assert_eq!(x.retain_count(), 1);
@@ -219,15 +221,15 @@ mod tests {
219221
use string::{CFString, CFStringRef};
220222
use base::TCFTypeRef;
221223

222-
let cf_string = CFString::from_static_string("bar");
224+
let cf_string = CFString::from_static_string("alongerstring");
223225
let array: CFArray = CFArray::from_CFTypes(&[cf_string.clone()]).into_untyped();
224226

225227
let cf_strings = array.iter().map(|ptr| {
226228
unsafe { CFString::wrap_under_get_rule(CFStringRef::from_void_ptr(*ptr)) }
227229
}).collect::<Vec<_>>();
228230
let strings = cf_strings.iter().map(|s| s.to_string()).collect::<Vec<_>>();
229231
assert_eq!(cf_string.retain_count(), 3);
230-
assert_eq!(&strings[..], &["bar"]);
232+
assert_eq!(&strings[..], &["alongerstring"]);
231233
}
232234

233235
#[test]

core-foundation/src/base.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ mod tests {
413413

414414
#[test]
415415
fn as_cftype_retain_count() {
416-
let string = CFString::from_static_string("bar");
416+
let string = CFString::from_static_string("alongerstring");
417417
assert_eq!(string.retain_count(), 1);
418418
let cftype = string.as_CFType();
419419
assert_eq!(cftype.retain_count(), 2);
@@ -423,18 +423,18 @@ mod tests {
423423

424424
#[test]
425425
fn into_cftype_retain_count() {
426-
let string = CFString::from_static_string("bar");
426+
let string = CFString::from_static_string("alongerstring");
427427
assert_eq!(string.retain_count(), 1);
428428
let cftype = string.into_CFType();
429429
assert_eq!(cftype.retain_count(), 1);
430430
}
431431

432432
#[test]
433433
fn as_cftype_and_downcast() {
434-
let string = CFString::from_static_string("bar");
434+
let string = CFString::from_static_string("alongerstring");
435435
let cftype = string.as_CFType();
436436
let string2 = cftype.downcast::<CFString>().unwrap();
437-
assert_eq!(string2.to_string(), "bar");
437+
assert_eq!(string2.to_string(), "alongerstring");
438438

439439
assert_eq!(string.retain_count(), 3);
440440
assert_eq!(cftype.retain_count(), 3);
@@ -443,10 +443,10 @@ mod tests {
443443

444444
#[test]
445445
fn into_cftype_and_downcast_into() {
446-
let string = CFString::from_static_string("bar");
446+
let string = CFString::from_static_string("alongerstring");
447447
let cftype = string.into_CFType();
448448
let string2 = cftype.downcast_into::<CFString>().unwrap();
449-
assert_eq!(string2.to_string(), "bar");
449+
assert_eq!(string2.to_string(), "alongerstring");
450450
assert_eq!(string2.retain_count(), 1);
451451
}
452452
}

core-foundation/src/propertylist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub mod test {
281281

282282
#[test]
283283
fn to_propertylist_retain_count() {
284-
let string = CFString::from_static_string("Bar");
284+
let string = CFString::from_static_string("alongerstring");
285285
assert_eq!(string.retain_count(), 1);
286286

287287
let propertylist = string.to_CFPropertyList();
@@ -308,7 +308,7 @@ pub mod test {
308308

309309
#[test]
310310
fn downcast_into_fail() {
311-
let string = CFString::from_static_string("Bar");
311+
let string = CFString::from_static_string("alongerstring");
312312
let propertylist = string.to_CFPropertyList();
313313
assert_eq!(string.retain_count(), 2);
314314

@@ -318,12 +318,12 @@ pub mod test {
318318

319319
#[test]
320320
fn downcast_into() {
321-
let string = CFString::from_static_string("Bar");
321+
let string = CFString::from_static_string("alongerstring");
322322
let propertylist = string.to_CFPropertyList();
323323
assert_eq!(string.retain_count(), 2);
324324

325325
let string2 = propertylist.downcast_into::<CFString>().unwrap();
326-
assert_eq!(string2.to_string(), "Bar");
326+
assert_eq!(string2.to_string(), "alongerstring");
327327
assert_eq!(string2.retain_count(), 2);
328328
}
329329
}

core-text/src/font.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ fn out_of_range_variations() {
839839
// attributes greater than max are dropped on macOS <= 11
840840
// on macOS 12 they seem to be preserved as is.
841841
let var_attrs = var_attrs.find(variation_attribute);
842-
if macos_version() >= (12, 0, 0) {
842+
if macos_version() >= (12, 0, 0) && macos_version() < (13, 0, 0) {
843843
let var_attrs = var_attrs.unwrap().downcast::<CFDictionary>().unwrap();
844844
assert!(!var_attrs.is_empty());
845845
let var_attrs: CFDictionary<CFType, CFType> = unsafe { std::mem::transmute(var_attrs) };

0 commit comments

Comments
 (0)