1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/*
(C) Copyright 2012 Wolfgang Lux
Check that no dangling pointers are left when elements of a text network
are deallocated.
FIXME In its present form, this test is unlikely to yield correct results
with a garbage collected runtime.
*/
#import "Testing.h"
#import <Foundation/NSAutoreleasePool.h>
#import <AppKit/NSApplication.h>
#import <AppKit/NSLayoutManager.h>
#import <AppKit/NSTextContainer.h>
#import <AppKit/NSTextStorage.h>
#import <AppKit/NSTextView.h>
int
main(int argc, char **argv)
{
NSLayoutManager *lm;
NSTextStorage *ts;
NSTextContainer *tc;
NSTextView *tv;
START_SET("TextSystem GNUstep deallocation")
CREATE_AUTORELEASE_POOL(arp);
NS_DURING
{
// Create shared application object (required by NSTextView)
[NSApplication sharedApplication];
}
NS_HANDLER
{
if ([[localException name] isEqualToString: NSInternalInconsistencyException ])
SKIP("It looks like GNUstep backend is not yet installed")
}
NS_ENDHANDLER
// Set up text network retaining all elements
ts = [NSTextStorage new];
lm = [NSLayoutManager new];
[ts addLayoutManager: lm];
tc = [[NSTextContainer alloc] initWithContainerSize: NSMakeSize(100, 100)];
[lm addTextContainer: tc];
tv =
[[NSTextView alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)
textContainer: tc];
// Check text view returns the expected elements
pass([tv textContainer] == tc,
"NSTextView -textContainer returns text container");
pass([tv layoutManager] == lm,
"NSTextView -layoutManager returns layout manager");
pass([tv textStorage] == ts,
"NSTextView -textStorage returns text storage");
// Release text storage
[ts release];
RECREATE_AUTORELEASE_POOL(arp);
pass([tv textContainer] == tc,
"NSTextView -textContainer returns text container");
pass([tv layoutManager] == lm,
"NSTextView -layoutManager returns layout manager");
pass([tv textStorage] == nil, "NSTextView -textStorage returns nil");
// Release layout manager
[lm release];
RECREATE_AUTORELEASE_POOL(arp);
pass([tv textContainer] == tc,
"NSTextView -textContainer returns text container");
pass([tv layoutManager] == nil, "NSTextView -layoutManager returns nil");
pass([tv textStorage] == nil, "NSTextView -textStorage returns nil");
// Release text container
[tc release];
RECREATE_AUTORELEASE_POOL(arp);
pass([tv textContainer] == nil, "NSTextView -textContainer returns nil");
pass([tv layoutManager] == nil, "NSTextView -layoutManager returns nil");
pass([tv textStorage] == nil, "NSTextView -textStorage returns nil");
DESTROY(arp);
END_SET("TextSystem GNUstep deallocation")
return 0;
}
|