mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 19:01:15 +00:00
Add new test for NSNibLoading. Add method loadNibNamed:owner:topLevelObjects:
This commit is contained in:
parent
2214368e53
commit
9c3f0fbbf3
7 changed files with 89 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
3
Tests/gui/NSNibLoading/Test-gorm.gorm/data.classes
Normal file
3
Tests/gui/NSNibLoading/Test-gorm.gorm/data.classes
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"## Comment" = "Do NOT change this file, Gorm maintains it";
|
||||
}
|
BIN
Tests/gui/NSNibLoading/Test-gorm.gorm/data.info
Normal file
BIN
Tests/gui/NSNibLoading/Test-gorm.gorm/data.info
Normal file
Binary file not shown.
BIN
Tests/gui/NSNibLoading/Test-gorm.gorm/objects.gorm
Normal file
BIN
Tests/gui/NSNibLoading/Test-gorm.gorm/objects.gorm
Normal file
Binary file not shown.
0
Tests/gui/NSNibLoading/TestInfo
Normal file
0
Tests/gui/NSNibLoading/TestInfo
Normal file
49
Tests/gui/NSNibLoading/basic.m
Normal file
49
Tests/gui/NSNibLoading/basic.m
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue