Add new test for NSNibLoading. Add method loadNibNamed:owner:topLevelObjects:

This commit is contained in:
Gregory John Casamento 2021-10-11 09:42:46 -04:00
parent 2214368e53
commit 9c3f0fbbf3
7 changed files with 89 additions and 0 deletions

View file

@ -62,6 +62,12 @@
externalNameTable: (NSDictionary *)context
withZone: (NSZone *)zone;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_8, GS_API_LATEST)
- (BOOL) loadNibNamed: (NSString *)aNibName
owner: (id)owner
topLevelObjects: (NSArray **)topLevelObjects;
#endif
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
- (NSString *) pathForNibResource: (NSString *)fileName;
#endif // GS_API_NONE

View file

@ -154,5 +154,36 @@
return NO;
}
}
- (BOOL) loadNibNamed: (NSString *)aNibName
owner: (id)owner
topLevelObjects: (NSArray **)topLevelObjects
{
BOOL success = NO;
if (owner != nil && aNibName != nil)
{
NSDictionary *table = [NSDictionary dictionaryWithObject: owner forKey: NSNibOwner];
success = [self loadNibFile: aNibName
externalNameTable: table
withZone: [owner zone]];
// When using the newer topLevelObjects API, conform to the cocoa standard of letting the caller own
// the TLOs these were previously retained by [GSXibLoader awake:withContext:] so we need to
// autorelease them. See cocoa docs for loadNibNamed:owner:topLevelObjects:
if (success && topLevelObjects && [table objectForKey: NSNibTopLevelObjects])
{
*topLevelObjects = [table objectForKey: NSNibTopLevelObjects];
for (NSObject *obj in *topLevelObjects)
{
AUTORELEASE(obj);
}
}
}
return success;
}
@end
// end of NSBundleAdditions

View file

@ -0,0 +1,3 @@
{
"## Comment" = "Do NOT change this file, Gorm maintains it";
}

Binary file not shown.

Binary file not shown.

View file

View file

@ -0,0 +1,49 @@
#import "ObjectTesting.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSFileManager.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSImage.h>
#import <AppKit/NSNibLoading.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSArray **testObjects;
BOOL success = NO;
NSFileManager *mgr = [NSFileManager defaultManager];
NSString *path = [mgr currentDirectoryPath];
NSBundle *bundle = [[NSBundle alloc] initWithPath: path];
START_SET("NSNibLoading GNUstep basic")
NS_DURING
{
[NSApplication sharedApplication];
}
NS_HANDLER
{
if ([[localException name] isEqualToString: NSInternalInconsistencyException ])
SKIP("It looks like GNUstep backend is not yet installed")
}
NS_ENDHANDLER;
if ([[path lastPathComponent] isEqualToString: @"obj"])
{
path = [path stringByDeletingLastPathComponent];
}
pass(bundle != NO, "NSBundle was initialized");
success = [bundle loadNibNamed: @"Test-gorm"
owner: [NSApplication sharedApplication]
topLevelObjects: testObjects];
pass(success == YES, ".gorm file was loaded properly using loadNibNamed:owner:topLevelObjects:");
NSLog(@"%@", *testObjects);
END_SET("NSNibLoading GNUstep basic")
[arp release];
return 0;
}