Add new test to verify proper deallocation of text network elements.

NB This test is unlikely to yield correct results with a garbage
collected runtime; volunteers?


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@35179 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Wolfgang Lux 2012-06-05 12:11:41 +00:00
parent 70fe303412
commit 4470b2e655
2 changed files with 80 additions and 0 deletions

View file

@ -1,3 +1,8 @@
2012-06-05 Wolfgang Lux <wolfgang.lux@gmail.com>
* Tests/gui/TextSystem/deallocation.m: Add new test to verify
proper deallocation of text network elements.
2012-06-05 Wolfgang Lux <wolfgang.lux@gmail.com>
* Source/GSLayoutManager.m (-dealloc): Set layout manager of every

View file

@ -0,0 +1,75 @@
/*
(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;
CREATE_AUTORELEASE_POOL(arp);
// Create shared application object (required by NSTextView)
[NSApplication sharedApplication];
// 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);
return 0;
}