mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 12:50:55 +00:00
* Tests/gui/NSImage/basic.m: Add basic tests for NSImage.
* Tests/gui/NSCell/basic.m: Extend basic tests for NSCell. * Source/NSImage.m: Try to correct keyed encoding/decoding. Add incomplete isEqual: method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36384 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0334fe3bca
commit
e45644b3fd
5 changed files with 172 additions and 49 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2013-03-18 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Tests/gui/NSImage/basic.m: Add basic tests for NSImage.
|
||||||
|
* Tests/gui/NSCell/basic.m: Extend basic tests for NSCell.
|
||||||
|
* Source/NSImage.m: Try to correct keyed encoding/decoding. Add
|
||||||
|
incomplete isEqual: method.
|
||||||
|
|
||||||
2013-03-17 Fred Kiefer <FredKiefer@gmx.de>
|
2013-03-17 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSViewController.m: Retain the view.
|
* Source/NSViewController.m: Retain the view.
|
||||||
|
|
129
Source/NSImage.m
129
Source/NSImage.m
|
@ -446,6 +446,17 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) isEqual: (id)anObject
|
||||||
|
{
|
||||||
|
if (self == anObject)
|
||||||
|
return YES;
|
||||||
|
if (![anObject isKindOfClass: [NSImage class]])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
/* This methd sets the name of an image, updating the global name dictionary
|
/* This methd sets the name of an image, updating the global name dictionary
|
||||||
* to point to the image (or removing an image from the dictionary if the
|
* to point to the image (or removing an image from the dictionary if the
|
||||||
* new name is nil).
|
* new name is nil).
|
||||||
|
@ -1540,8 +1551,8 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
|
||||||
|
|
||||||
if ([coder allowsKeyedCoding])
|
if ([coder allowsKeyedCoding])
|
||||||
{
|
{
|
||||||
// FIXME: Not sure this is the way it goes...
|
int flags = 0;
|
||||||
/*
|
|
||||||
if (_flags.archiveByName == NO)
|
if (_flags.archiveByName == NO)
|
||||||
{
|
{
|
||||||
NSMutableArray *container = [NSMutableArray array];
|
NSMutableArray *container = [NSMutableArray array];
|
||||||
|
@ -1549,24 +1560,41 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
|
||||||
NSEnumerator *en = [_reps objectEnumerator];
|
NSEnumerator *en = [_reps objectEnumerator];
|
||||||
GSRepData *rd = nil;
|
GSRepData *rd = nil;
|
||||||
|
|
||||||
// add the reps to the container...
|
if ([_reps count] > 0)
|
||||||
[container addObject: reps];
|
|
||||||
while ((rd = [en nextObject]) != nil)
|
|
||||||
{
|
{
|
||||||
[reps addObject: rd->rep];
|
[reps addObject: [NSNumber numberWithInt: 0]];
|
||||||
|
while ((rd = [en nextObject]) != nil)
|
||||||
|
{
|
||||||
|
[reps addObject: rd->rep];
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the reps to the container...
|
||||||
|
[container addObject: reps];
|
||||||
|
[coder encodeObject: container forKey: @"NSReps"];
|
||||||
}
|
}
|
||||||
[coder encodeObject: container forKey: @"NSReps"];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[coder encodeObject: _name forKey: @"NSImageName"];
|
[coder encodeObject: _name forKey: @"NSName"];
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// encode the rest...
|
// encode the rest...
|
||||||
[coder encodeObject: _color forKey: @"NSColor"];
|
if (_color != nil)
|
||||||
[coder encodeInt: 0 forKey: @"NSImageFlags"]; // zero...
|
{
|
||||||
[coder encodeSize: _size forKey: @"NSSize"];
|
[coder encodeObject: _color forKey: @"NSColor"];
|
||||||
|
}
|
||||||
|
flags |= [self scalesWhenResized] ? 0x8000000 : 0;
|
||||||
|
flags |= _flags.sizeWasExplicitlySet ? 0x2000000 : 0;
|
||||||
|
flags |= [self usesEPSOnResolutionMismatch] ? 0x0200000 : 0;
|
||||||
|
flags |= [self prefersColorMatch] ? 0x0100000 : 0;
|
||||||
|
flags |= [self matchesOnMultipleResolution] ? 0x0080000 : 0;
|
||||||
|
flags |= [self isFlipped] ? 0x0008000 : 0;
|
||||||
|
flags |= [self cacheMode] << 11;
|
||||||
|
[coder encodeInt: flags forKey: @"NSImageFlags"];
|
||||||
|
if (_flags.sizeWasExplicitlySet)
|
||||||
|
{
|
||||||
|
[coder encodeSize: _size forKey: @"NSSize"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1635,51 +1663,68 @@ static NSSize GSResolutionOfImageRep(NSImageRep *rep)
|
||||||
_reps = [[NSMutableArray alloc] initWithCapacity: 2];
|
_reps = [[NSMutableArray alloc] initWithCapacity: 2];
|
||||||
if ([coder allowsKeyedCoding])
|
if ([coder allowsKeyedCoding])
|
||||||
{
|
{
|
||||||
|
if ([coder containsValueForKey: @"NSName"])
|
||||||
|
{
|
||||||
|
RELEASE(self);
|
||||||
|
return RETAIN([NSImage imageNamed: [coder decodeObjectForKey: @"NSName"]]);
|
||||||
|
}
|
||||||
if ([coder containsValueForKey: @"NSColor"])
|
if ([coder containsValueForKey: @"NSColor"])
|
||||||
{
|
{
|
||||||
[self setBackgroundColor: [coder decodeObjectForKey: @"NSColor"]];
|
[self setBackgroundColor: [coder decodeObjectForKey: @"NSColor"]];
|
||||||
}
|
}
|
||||||
if ([coder containsValueForKey: @"NSImageFlags"])
|
if ([coder containsValueForKey: @"NSImageFlags"])
|
||||||
{
|
{
|
||||||
//FIXME
|
int flags = [coder decodeIntForKey: @"NSImageFlags"];
|
||||||
//int flags = [coder decodeIntForKey: @"NSImageFlags"];
|
|
||||||
|
[self setScalesWhenResized: ((flags & 0x8000000) != 0)];
|
||||||
|
// _flags.sizeWasExplicitlySet = ((flags & 0x2000000) != 0);
|
||||||
|
[self setUsesEPSOnResolutionMismatch: ((flags & 0x0200000) != 0)];
|
||||||
|
[self setPrefersColorMatch: ((flags & 0x0100000) != 0)];
|
||||||
|
[self setMatchesOnMultipleResolution: ((flags & 0x0080000) != 0)];
|
||||||
|
[self setFlipped: ((flags & 0x0008000) != 0)];
|
||||||
|
// ALIASED ((flags & 0x0004000) != 0)
|
||||||
|
[self setCacheMode: ((flags & 0x0001800) >> 11)];
|
||||||
}
|
}
|
||||||
if ([coder containsValueForKey: @"NSReps"])
|
if ([coder containsValueForKey: @"NSReps"])
|
||||||
{
|
{
|
||||||
NSArray *reps;
|
NSArray *reps;
|
||||||
|
NSUInteger i;
|
||||||
|
|
||||||
// FIXME: NSReps is in a strange format. It is a mutable array with one
|
// FIXME: NSReps is in a strange format. It is a mutable array with one
|
||||||
// element which is an array with a first element 0 and than the image rep.
|
// element which is an array with a first element 0 and than the image rep.
|
||||||
reps = [coder decodeObjectForKey: @"NSReps"];
|
reps = [coder decodeObjectForKey: @"NSReps"];
|
||||||
reps = [reps objectAtIndex: 0];
|
reps = [reps objectAtIndex: 0];
|
||||||
id rep = [reps objectAtIndex: 1];
|
for (i = 1; i < [reps count]; i++)
|
||||||
if ([rep isKindOfClass: [NSImageRep class]])
|
{
|
||||||
{
|
id rep = [reps objectAtIndex: i];
|
||||||
[self addRepresentation: rep];
|
if ([rep isKindOfClass: [NSImageRep class]])
|
||||||
}
|
{
|
||||||
else
|
[self addRepresentation: rep];
|
||||||
{
|
}
|
||||||
if ([rep isKindOfClass: [NSURL class]])
|
else
|
||||||
{
|
{
|
||||||
NSURL *tmp = (NSURL*)rep;
|
if ([rep isKindOfClass: [NSURL class]])
|
||||||
rep = [NSImageRep imageRepWithContentsOfURL: rep];
|
{
|
||||||
|
NSURL *tmp = (NSURL*)rep;
|
||||||
// If we are unable to resolved the URL, try to get it from the
|
rep = [NSImageRep imageRepWithContentsOfURL: rep];
|
||||||
// resources folder.
|
|
||||||
if (rep == nil)
|
// If we are unable to resolved the URL, try to get it from the
|
||||||
{
|
// resources folder.
|
||||||
NSString *fileName = [[tmp absoluteString] lastPathComponent];
|
if (rep == nil)
|
||||||
NSString *path = [[NSBundle mainBundle] pathForImageResource: fileName];
|
{
|
||||||
rep = [NSImageRep imageRepWithContentsOfFile: path];
|
NSString *fileName = [[tmp absoluteString] lastPathComponent];
|
||||||
}
|
NSString *path = [[NSBundle mainBundle] pathForImageResource: fileName];
|
||||||
|
rep = [NSImageRep imageRepWithContentsOfFile: path];
|
||||||
// If the representation was found, add it...
|
}
|
||||||
if (rep != nil)
|
|
||||||
{
|
// If the representation was found, add it...
|
||||||
[self addRepresentation: rep];
|
if (rep != nil)
|
||||||
}
|
{
|
||||||
}
|
[self addRepresentation: rep];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ([coder containsValueForKey: @"NSSize"])
|
if ([coder containsValueForKey: @"NSSize"])
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,23 +3,33 @@
|
||||||
#import <Foundation/NSAutoreleasePool.h>
|
#import <Foundation/NSAutoreleasePool.h>
|
||||||
#import <AppKit/NSApplication.h>
|
#import <AppKit/NSApplication.h>
|
||||||
#import <AppKit/NSCell.h>
|
#import <AppKit/NSCell.h>
|
||||||
|
#import <AppKit/NSImage.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
id testObject;
|
id testObject;
|
||||||
|
id testObject1;
|
||||||
|
id testObject2;
|
||||||
|
NSArray *testObjects;
|
||||||
|
|
||||||
[NSApplication sharedApplication];
|
[NSApplication sharedApplication];
|
||||||
testObject = [NSCell new];
|
|
||||||
test_alloc(@"NSCell");
|
test_alloc(@"NSCell");
|
||||||
test_NSObject(@"NSCell",[NSArray arrayWithObject:testObject]);
|
|
||||||
test_NSCoding([NSArray arrayWithObject:testObject]);
|
testObject = [NSCell new];
|
||||||
test_keyed_NSCoding([NSArray arrayWithObject:testObject]);
|
testObject1 = [[NSCell alloc] initImageCell: [NSImage imageNamed: @"GNUstep"]];
|
||||||
|
testObject2 = [[NSCell alloc] initTextCell: @"GNUstep"];
|
||||||
|
|
||||||
|
testObjects = [NSArray arrayWithObjects: testObject, testObject1, testObject2, nil];
|
||||||
|
test_NSObject(@"NSCell", testObjects);
|
||||||
|
test_NSCoding(testObjects);
|
||||||
|
test_keyed_NSCoding(testObjects);
|
||||||
test_NSCopying(@"NSCell",
|
test_NSCopying(@"NSCell",
|
||||||
@"NSCell",
|
@"NSCell",
|
||||||
[NSArray arrayWithObject:testObject], NO, NO);
|
testObjects, NO, NO);
|
||||||
|
|
||||||
[arp release]; arp = nil;
|
[arp release];
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +45,11 @@ int main()
|
||||||
return NO;
|
return NO;
|
||||||
if (![[anObject title] isEqual: [self title]])
|
if (![[anObject title] isEqual: [self title]])
|
||||||
return NO;
|
return NO;
|
||||||
|
if (!([anObject image] == [self image]) && ![[anObject image] isEqual: [self image]])
|
||||||
|
{
|
||||||
|
NSLog(@"image differ %@ %@", [self image], [anObject image]);
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
if ([anObject type] != [self type])
|
if ([anObject type] != [self type])
|
||||||
return NO;
|
return NO;
|
||||||
if ([anObject tag] != [self tag])
|
if ([anObject tag] != [self tag])
|
||||||
|
|
0
Tests/gui/NSImage/TestInfo
Normal file
0
Tests/gui/NSImage/TestInfo
Normal file
56
Tests/gui/NSImage/basic.m
Normal file
56
Tests/gui/NSImage/basic.m
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#import "ObjectTesting.h"
|
||||||
|
#import <Foundation/NSArray.h>
|
||||||
|
#import <Foundation/NSAutoreleasePool.h>
|
||||||
|
#import <AppKit/NSApplication.h>
|
||||||
|
#import <AppKit/NSImage.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
|
id testObject;
|
||||||
|
id testObject1;
|
||||||
|
id testObject2;
|
||||||
|
NSArray *testObjects;
|
||||||
|
|
||||||
|
[NSApplication sharedApplication];
|
||||||
|
|
||||||
|
test_alloc(@"NSImage");
|
||||||
|
|
||||||
|
testObject = [NSImage new];
|
||||||
|
testObject1 = [NSImage imageNamed: @"GNUstep"];
|
||||||
|
testObject2 = [[NSImage alloc] initWithData: nil];
|
||||||
|
|
||||||
|
testObjects = [NSArray arrayWithObjects: testObject, testObject1, testObject2, nil];
|
||||||
|
RELEASE(testObject);
|
||||||
|
|
||||||
|
test_NSObject(@"NSImage", testObjects);
|
||||||
|
test_NSCoding(testObjects);
|
||||||
|
test_keyed_NSCoding(testObjects);
|
||||||
|
test_NSCopying(@"NSImage",
|
||||||
|
@"NSImage",
|
||||||
|
testObjects, NO, NO);
|
||||||
|
|
||||||
|
[arp release];
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@implementation NSImage (Testing)
|
||||||
|
|
||||||
|
- (BOOL) isEqual: (id)anObject
|
||||||
|
{
|
||||||
|
if (self == anObject)
|
||||||
|
return YES;
|
||||||
|
if (![anObject isKindOfClass: [NSImage class]])
|
||||||
|
return NO;
|
||||||
|
if (![[anObject backgroundColor] isEqual: [self backgroundColor]])
|
||||||
|
return NO;
|
||||||
|
if ([anObject isFlipped] != [self isFlipped])
|
||||||
|
return NO;
|
||||||
|
if (!NSEqualSizes([anObject size], [self size]))
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
// FIXME
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
Loading…
Reference in a new issue