mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix -getObjects:andKeys:
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@40036 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c2be055c3e
commit
ad428b99d5
3 changed files with 88 additions and 56 deletions
22
ChangeLog
22
ChangeLog
|
@ -1,3 +1,9 @@
|
|||
2016-07-26 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
||||
* Source/NSDictionary.m
|
||||
* Tests/base/NSDictionary/general.m:
|
||||
Fix -getObjects:andKeys:
|
||||
|
||||
2016-07-26 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
||||
* Headers/Foundation/NSData.h
|
||||
|
@ -66,7 +72,7 @@
|
|||
|
||||
* Headers/Foundation/NSObjCRuntime.h
|
||||
* Headers/GNUstepBase/GNUstep.h:
|
||||
|
||||
|
||||
Add NS_DESIGNATED_INITIALIZER macro
|
||||
|
||||
2016-07-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
@ -78,7 +84,7 @@
|
|||
like a date in the distant past (ie loop terminates at once), and the
|
||||
(-runUntilDate:) method fires any pending timers when given a date in
|
||||
the past.
|
||||
|
||||
|
||||
2016-07-12 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||
|
||||
* Source/GSICUString.m (UTextNSStringAccess): Fix unsigned
|
||||
|
@ -170,9 +176,9 @@
|
|||
to use a directory whose name is of the form architecture/library-combo
|
||||
rather than nested directories of the form cpu/os-abi/library-combo.
|
||||
The architecture name format is a sanitised triplet cpu-os-abi (where
|
||||
previously we had cpu/os-abi).
|
||||
These changes are the first step in making GNUstep work seamlessly
|
||||
with Debian multiarch. To use them you will need to rebuild your
|
||||
previously we had cpu/os-abi).
|
||||
These changes are the first step in making GNUstep work seamlessly
|
||||
with Debian multiarch. To use them you will need to rebuild your
|
||||
entire gnustep installation using a version of gnustep-make which
|
||||
has correspoinding changes to know where to install bbinaries and
|
||||
resources. However, the changes should have no effect on a flattened
|
||||
|
@ -226,7 +232,7 @@
|
|||
* Tests/base/NSRegularExpression/basic.m:
|
||||
|
||||
Implement resource limits for regular expression evaluation. Tweaked
|
||||
to roughly match the Cocoa behaviour, but can be changed through
|
||||
to roughly match the Cocoa behaviour, but can be changed through
|
||||
the GSRegularExpressionWorkLimit user default.
|
||||
|
||||
2016-06-17 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
@ -276,8 +282,8 @@
|
|||
|
||||
2016-05-27 Niels Grewe <niels.grewe@halbordnung.de>
|
||||
|
||||
* Tools/AGSParser.m: Ignore __asm__ directives
|
||||
|
||||
* Tools/AGSParser.m: Ignore __asm__ directives
|
||||
|
||||
2016-05-19 Seong Gu Lee <sgleehd@gmail.com>
|
||||
|
||||
* GNUmakefile:
|
||||
|
|
|
@ -863,10 +863,11 @@ static SEL appSel;
|
|||
- (void)getObjects: (__unsafe_unretained id[])objects
|
||||
andKeys: (__unsafe_unretained id<NSCopying>[])keys
|
||||
{
|
||||
int i=0;
|
||||
NSUInteger i=0;
|
||||
FOR_IN(id, key, self)
|
||||
keys[i] = key;
|
||||
objects[i] = [self objectForKey: key];
|
||||
if (keys != NULL) keys[i] = key;
|
||||
if (objects != NULL) objects[i] = [self objectForKey: key];
|
||||
i++;
|
||||
END_FOR_IN(self)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@ int main()
|
|||
NSArray *keys1, *keys2, *keys3, *keys4, *vals1, *vals2, *vals3, *vals4;
|
||||
id obj;
|
||||
NSDictionary *dict;
|
||||
|
||||
id vals1Array[2] = { nil, nil };
|
||||
id keys1Array[2] = { nil, nil };
|
||||
key1 = @"Key1";
|
||||
key2 = @"Key2";
|
||||
key3 = @"Key3";
|
||||
|
@ -33,16 +34,16 @@ int main()
|
|||
vals1 = [NSArray arrayWithObjects:val1,val2,nil];
|
||||
vals2 = [NSArray arrayWithObjects:val1,val2,val2,nil]; /* duplicate vals */
|
||||
vals3 = [NSArray arrayWithObjects:val1,val2,val3,nil];
|
||||
vals4 = [NSArray arrayWithObjects:val1, val2, val3, [NSDate date],
|
||||
vals4 = [NSArray arrayWithObjects:val1, val2, val3, [NSDate date],
|
||||
[NSNumber numberWithInt:2],
|
||||
[NSData data], nil];
|
||||
keys4 = [NSArray arrayWithObjects:key1, key2, key2, @"date", @"number",
|
||||
@"data",nil];
|
||||
|
||||
|
||||
|
||||
|
||||
dict = [NSDictionary new];
|
||||
PASS(dict != nil &&
|
||||
[dict isKindOfClass:[NSDictionary class]]
|
||||
PASS(dict != nil &&
|
||||
[dict isKindOfClass:[NSDictionary class]]
|
||||
&& [dict count] == 0,
|
||||
"-count returns zero for an empty dictionary");
|
||||
|
||||
|
@ -52,7 +53,7 @@ int main()
|
|||
[obj isKindOfClass:[NSArray class]] &&
|
||||
[obj count] == 0,
|
||||
"-allKeys gives an empty array for an empty dictionary");
|
||||
|
||||
|
||||
obj = [dict allKeysForObject:nil];
|
||||
PASS(obj == nil, "-allKeysForObject: gives nil for an empty dictionary");
|
||||
|
||||
|
@ -67,20 +68,20 @@ int main()
|
|||
|
||||
o1 = [dict objectForKey:nil];
|
||||
o2 = [dict objectForKey:key1];
|
||||
PASS(o1 == nil && o2 == nil,
|
||||
PASS(o1 == nil && o2 == nil,
|
||||
"-objectForKey: gives nil for an empty dictionary");
|
||||
}
|
||||
|
||||
{
|
||||
NSEnumerator *e = [dict keyEnumerator];
|
||||
id k1,k2;
|
||||
|
||||
|
||||
k1 = [e nextObject];
|
||||
k2 = [e nextObject];
|
||||
PASS(e != nil && k1 == nil && k2 == nil,
|
||||
PASS(e != nil && k1 == nil && k2 == nil,
|
||||
"-keyEnumerator: is ok for empty dictionary");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
NSEnumerator *e = [dict objectEnumerator];
|
||||
id v1,v2;
|
||||
|
@ -90,7 +91,7 @@ int main()
|
|||
PASS(e != nil && v1 == nil && v2 == nil,
|
||||
"-objectEnumerator: is ok for empty dictionary");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
NSString *notFound = @"notFound";
|
||||
NSArray *a = [dict objectsForKeys:keys1 notFoundMarker:notFound];
|
||||
|
@ -101,30 +102,30 @@ int main()
|
|||
[a objectAtIndex:1] == notFound,
|
||||
"-objectsForKeys:notFoundMarker: is ok for empty dictionary");
|
||||
}
|
||||
|
||||
|
||||
obj = [dict description];
|
||||
obj = [obj propertyList];
|
||||
PASS(obj != nil &&
|
||||
[obj isKindOfClass:[NSDictionary class]] &&
|
||||
PASS(obj != nil &&
|
||||
[obj isKindOfClass:[NSDictionary class]] &&
|
||||
[obj count] == 0,
|
||||
"-description gives us a text property-list");
|
||||
|
||||
|
||||
dict = [[NSDictionary dictionaryWithObjects:vals1 forKeys:keys1] retain];
|
||||
PASS(dict != nil &&
|
||||
[dict isKindOfClass:[NSDictionary class]] &&
|
||||
PASS(dict != nil &&
|
||||
[dict isKindOfClass:[NSDictionary class]] &&
|
||||
[dict count] == 2,
|
||||
"-count returns two for an dictionary with two keys");
|
||||
|
||||
|
||||
PASS([dict hash] == 2, "-hash returns two for a dictionary with two keys");
|
||||
|
||||
|
||||
obj = [dict allKeys];
|
||||
PASS(obj != nil &&
|
||||
[obj isKindOfClass:[NSArray class]] &&
|
||||
[obj count] == 2 &&
|
||||
[obj containsObject:key1] &&
|
||||
[obj containsObject:key1],
|
||||
[obj containsObject:key1],
|
||||
"-allKeys gives the keys we put in the dictionary");
|
||||
|
||||
|
||||
{
|
||||
NSArray *o1,*o2;
|
||||
o1 = [dict allKeysForObject:val1];
|
||||
|
@ -146,53 +147,53 @@ int main()
|
|||
[obj containsObject:val1] &&
|
||||
[obj containsObject:val2],
|
||||
"-allValues gives the values we put in the dictionary");
|
||||
|
||||
|
||||
PASS([dict objectForKey:nil] == nil,"-objectForKey: gives nil for a nil key");
|
||||
PASS([dict objectForKey:key3] == nil,
|
||||
"-objectForKey: gives nil for a key not in the dictionary");
|
||||
|
||||
|
||||
{
|
||||
id o1 = [dict objectForKey: key1];
|
||||
id o2 = [dict objectForKey: key2];
|
||||
PASS(o1 == val1 && o2 == val2,
|
||||
PASS(o1 == val1 && o2 == val2,
|
||||
"-objectForKey: gives the objects we added for the keys");
|
||||
}
|
||||
|
||||
{
|
||||
NSEnumerator *e = [dict keyEnumerator];
|
||||
id k1,k2,k3;
|
||||
k1 = [e nextObject];
|
||||
k2 = [e nextObject];
|
||||
k3 = [e nextObject];
|
||||
k1 = [e nextObject];
|
||||
k2 = [e nextObject];
|
||||
k3 = [e nextObject];
|
||||
PASS(k1 != nil &&
|
||||
k2 != nil &&
|
||||
k3 == nil &&
|
||||
k1 != k2 &&
|
||||
[keys1 containsObject:k1] &&
|
||||
[keys1 containsObject:k2],
|
||||
"-keyEnumerator: enumerates the dictionary");
|
||||
[keys1 containsObject:k2],
|
||||
"-keyEnumerator: enumerates the dictionary");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
NSEnumerator *e = [dict objectEnumerator];
|
||||
id v1,v2,v3;
|
||||
v1 = [e nextObject];
|
||||
v2 = [e nextObject];
|
||||
v3 = [e nextObject];
|
||||
|
||||
v1 = [e nextObject];
|
||||
v2 = [e nextObject];
|
||||
v3 = [e nextObject];
|
||||
|
||||
PASS(v1 != nil &&
|
||||
v2 != nil &&
|
||||
v3 == nil &&
|
||||
v1 != v2 &&
|
||||
[vals1 containsObject:v1] &&
|
||||
[vals1 containsObject:v2],
|
||||
"-objectEnumerator: enumerates the dictionary");
|
||||
[vals1 containsObject:v2],
|
||||
"-objectEnumerator: enumerates the dictionary");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
NSString *notFound = @"notFound";
|
||||
NSArray *a = [dict objectsForKeys:keys2 notFoundMarker:notFound];
|
||||
|
||||
|
||||
PASS(a != nil &&
|
||||
[a isKindOfClass:[NSArray class]] &&
|
||||
[a count] == 3 &&
|
||||
|
@ -201,7 +202,7 @@ int main()
|
|||
[a objectAtIndex:2] == notFound,
|
||||
"-objectsForKeys:notFoundMarker: is ok for dictionary");
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
NSArray *a = [dict keysSortedByValueUsingSelector:@selector(compare:)];
|
||||
PASS(a != nil &&
|
||||
|
@ -211,18 +212,42 @@ int main()
|
|||
[a objectAtIndex:1] == key1,
|
||||
"-keysSortedByValueUsingSelector: seems ok");
|
||||
}
|
||||
|
||||
|
||||
obj = [dict description];
|
||||
obj = [obj propertyList];
|
||||
PASS(obj != nil &&
|
||||
PASS(obj != nil &&
|
||||
[obj isKindOfClass:[NSDictionary class]] &&
|
||||
[obj isEqual:dict],
|
||||
"-description gives us a text property-list");
|
||||
|
||||
|
||||
[dict getObjects: &vals1Array andKeys: &keys1Array];
|
||||
uint8_t found = 0;
|
||||
if (vals1Array[0] == val1 || vals1Array[1] == val1)
|
||||
{
|
||||
found |= 1;
|
||||
}
|
||||
if (vals1Array[0] == val2 || vals1Array[1] == val2)
|
||||
{
|
||||
found |= 1 << 1;
|
||||
}
|
||||
if (keys1Array[0] == key1 || keys1Array[1] == key1)
|
||||
{
|
||||
found |= 1 << 2;
|
||||
}
|
||||
if (keys1Array[0] == key2 || keys1Array[1] == key2)
|
||||
{
|
||||
found |= 1 << 3;
|
||||
}
|
||||
PASS(found == 0b1111, "-getObjects:andKeys: returns correct objects");
|
||||
PASS_RUNS([dict getObjects: NULL andKeys: &keys1Array],
|
||||
"-getObjects:andKeys: can ignore objects");
|
||||
PASS_RUNS([dict getObjects: &vals1Array andKeys: NULL],
|
||||
"-getObjects:andKeys: can ignore keys");
|
||||
|
||||
|
||||
ASSIGN(dict,[NSDictionary dictionaryWithObjects:vals4 forKeys:keys4]);
|
||||
PASS(dict != nil, "we can create a dictionary with several keys");
|
||||
|
||||
|
||||
#if defined(GNUSTEP_BASE_LIBRARY)
|
||||
obj = [NSSerializer serializePropertyList:dict];
|
||||
obj = [NSDeserializer deserializePropertyListFromData:obj
|
||||
|
@ -232,7 +257,7 @@ int main()
|
|||
[obj isEqual:dict],
|
||||
"data/number/data are ok in serialized property-list");
|
||||
#endif
|
||||
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue