Skip to content

Commit

Permalink
Fixup bad testcases with non-portable code
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Jun 6, 2024
1 parent a5410d9 commit c9a0e74
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 200 deletions.
59 changes: 35 additions & 24 deletions Tests/gui/GSXib5KeyedUnarchiver/buttonCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,60 @@

int main()
{
START_SET("GSXib5KeyedUnarchiver NSButtonCell tests")
START_SET("GSXib5KeyedUnarchiver NSButtonCell 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

NSData* data = [NSData dataWithContentsOfFile:@"ButtonCell.xib"];
GSXibKeyedUnarchiver* unarchiver = [GSXibKeyedUnarchiver unarchiverForReadingWithData:data];
NSData *data;
GSXibKeyedUnarchiver *unarchiver;
NSArray *rootObjects;
NSEnumerator *enumerator;
NSMatrix *matrix;
id element;

NSArray *rootObjects;
data = [NSData dataWithContentsOfFile: @"ButtonCell.xib"];
unarchiver = [GSXibKeyedUnarchiver unarchiverForReadingWithData:data];
rootObjects = [unarchiver decodeObjectForKey: @"IBDocument.RootObjects"];

NSMatrix* matrix;

for (id element in rootObjects) {
if ([element isKindOfClass:[NSMatrix class]]) {
enumerator = [rootObjects objectEnumerator];
while ((element = [enumerator nextObject]) != nil)
{
if ([element isKindOfClass: [NSMatrix class]])
{
matrix = (NSMatrix*)element;
break;
}
}
}
}

PASS(matrix != nil, "Top-level NSMatrix was found");
PASS(matrix != nil, "Top-level NSMatrix was found")

NSArray* cells = [matrix cells];
NSArray *cells = [matrix cells];

// <modifierMask key="keyEquivalentModifierMask" shift="YES"/> node
PASS_MODIFIER(0, NSShiftKeyMask);
PASS_MODIFIER(0, NSShiftKeyMask)

// <modifierMask key="keyEquivalentModifierMask" command="YES"/> node
PASS_MODIFIER(1, NSCommandKeyMask);
PASS_MODIFIER(1, NSCommandKeyMask)

// <modifierMask key="keyEquivalentModifierMask" />
PASS_MODIFIER(2, 0);
PASS_MODIFIER(2, 0)

// Unlike NSMenuItem, the default for NSButtonCell is 0
PASS_MODIFIER(3, 0);
PASS_MODIFIER(3, 0)

END_SET("GSXib5KeyedUnarchiver NSButtonCell tests")
END_SET("GSXib5KeyedUnarchiver NSButtonCell tests")

return 0;
}
67 changes: 39 additions & 28 deletions Tests/gui/GSXib5KeyedUnarchiver/menu.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,67 @@

int main()
{
START_SET("GSXib5KeyedUnarchiver NSMenu tests")
START_SET("GSXib5KeyedUnarchiver NSMenu 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

NSData* data = [NSData dataWithContentsOfFile:@"Menu.xib"];
GSXibKeyedUnarchiver* unarchiver = [GSXibKeyedUnarchiver unarchiverForReadingWithData:data];
NSData *data
GSXibKeyedUnarchiver *unarchiver;
NSArray *rootObjects;
NSEnumerator *enumerator;
id element;
NSMenu *menu;

NSArray *rootObjects;
data = [NSData dataWithContentsOfFile:@"Menu.xib"];
unarchiver = [GSXibKeyedUnarchiver unarchiverForReadingWithData:data];
rootObjects = [unarchiver decodeObjectForKey: @"IBDocument.RootObjects"];
enumerator = [rootObjects objectenumerator];

NSMenu* menu;

for (id element in rootObjects) {
if ([element isKindOfClass:[NSMenu class]]) {
while ((element = [enumerator nextObject]) != nil)
{
if ([element isKindOfClass: [NSMenu class]])
{
menu = (NSMenu*)element;
break;
}
}
}
}

PASS(menu != nil, "Top-level NSMenu was found");
PASS(menu != nil, "Top-level NSMenu was found")


// Empty <modifierMask key="keyEquivalentModifierMask"/> node
PASS_MODIFIER(0, 0);
PASS_MODIFIER(0, 0)
// <modifierMask key="keyEquivalentModifierMask" shift="YES"/>
PASS_MODIFIER(1, NSShiftKeyMask);
PASS_MODIFIER(1, NSShiftKeyMask)
// <modifierMask key="keyEquivalentModifierMask" command="YES"/>
PASS_MODIFIER(2, NSCommandKeyMask);
PASS_MODIFIER(2, NSCommandKeyMask)
// <modifierMask key="keyEquivalentModifierMask" option="YES"/>
PASS_MODIFIER(3, NSAlternateKeyMask);
PASS_MODIFIER(3, NSAlternateKeyMask)
// No modifierMask element
PASS_MODIFIER(4, NSCommandKeyMask);
PASS_MODIFIER(4, NSCommandKeyMask)
// No modifierMask element and no keyEquivalent attribute
PASS_MODIFIER(5, NSCommandKeyMask);
PASS_MODIFIER(5, NSCommandKeyMask)

// no modfierMask
PASS_MODIFIER(6, NSCommandKeyMask);
PASS_MODIFIER(6, NSCommandKeyMask)
// empty modifierMask
PASS_MODIFIER(7, 0);
PASS_MODIFIER(7, 0)
// explicit modifier mask
PASS_MODIFIER(8, NSCommandKeyMask);
PASS_MODIFIER(8, NSCommandKeyMask)

END_SET("GSXib5KeyedUnarchiver NSMenu tests")
END_SET("GSXib5KeyedUnarchiver NSMenu tests")

return 0;
}
Loading

0 comments on commit c9a0e74

Please sign in to comment.