Fix to work without fast enumeration, also fix codign style errors and compiler warnings about operator precedence.

This commit is contained in:
rfm 2024-06-03 16:06:00 +01:00
parent f93ca6eeb6
commit 51ed6a9608

View file

@ -8,44 +8,57 @@
int main()
{
START_SET("NSButtonCell encoding tests")
START_SET("NSButtonCell encoding tests")
NS_DURING
{
[NSApplication sharedApplication];
}
{
[NSApplication sharedApplication];
}
NS_HANDLER
{
if ([[localException name] isEqualToString: NSInternalInconsistencyException ])
SKIP("It looks like GNUstep backend is not yet installed")
}
{
if ([[localException name]
isEqualToString: NSInternalInconsistencyException ])
{
SKIP("It looks like GNUstep backend is not yet installed")
}
}
NS_ENDHANDLER
NSString* mask = @"NSButtonFlags2";
NSButtonCell* item = [[NSButtonCell alloc] init];
NSString *mask = @"NSButtonFlags2";
NSButtonCell *item = [[NSButtonCell alloc] init];
item.keyEquivalent = @"A";
item.keyEquivalentModifierMask = NSShiftKeyMask;
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver;
[archiver encodeRootObject:item];
archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data];
[archiver encodeRootObject: item];
[archiver finishEncoding];
NSError* error;
NSDictionary* archive = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:nil error:&error];
NSError *error;
NSDictionary *archive;
NSArray* topLevelObjects = [archive objectForKey:@"$objects"];
archive = [NSPropertyListSerialization
propertyListWithData: data
options: NSPropertyListImmutable
format: nil
error: &error];
NSDictionary* dict;
NSArray *topLevelObjects = [archive objectForKey: @"$objects"];
NSEnumerator *enumerator = [topLevelObjects objectEnumerator];
NSDictionary *dict;
id element;
for (id element in topLevelObjects)
while ((element = [enumerator nextObject]) != nil)
{
if ([element isKindOfClass:[NSDictionary class]])
if ([element isKindOfClass: [NSDictionary class]])
{
dict = (NSDictionary*)element;
if ([[dict allKeys] containsObject:mask])
if ([[dict allKeys] containsObject: mask])
{
break;
}
@ -53,14 +66,20 @@ int main()
{
dict = nil;
}
}
}
}
}
PASS(dict != nil, "Found a dict with a NSButtonFlags2 entry");
NSNumber* encodedKeyMask = [dict valueForKey:mask];
NSNumber *encodedKeyMask = [dict valueForKey: mask];
int expect = (NSShiftKeyMask << 8);
int modMask = (NSEventModifierFlagDeviceIndependentFlagsMask << 8);
int found = [encodedKeyMask intValue] & modMask;
PASS(encodedKeyMask != nil, "Retrieved the NSButtonFlags2 value");
PASS([encodedKeyMask intValue] & NSEventModifierFlagDeviceIndependentFlagsMask << 8 == NSShiftKeyMask, "Encoded key mask 0x%x matches expected key mask 0x%x", [encodedKeyMask intValue] & NSEventModifierFlagDeviceIndependentFlagsMask << 8, NSShiftKeyMask << 8);
PASS(found == expect,
"Encoded key mask 0x%x matches expected key mask 0x%x",
found, expect);
END_SET("NSButtonCell encoding tests")
}
END_SET("NSButtonCell encoding tests")
}