Author: thebeing
Date: Sat May 2 10:03:05 2015
New Revision: 38470
URL: http://svn.gna.org/viewcvs/gnustep?rev=38470&view=rev
Log:
Fix bug #43915 (equality not checked correctly for NSCountedSet)
Added:
libs/base/trunk/Tests/base/NSCountedSet/equality.m
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Source/GSSet.m
libs/base/trunk/Source/NSCountedSet.m
libs/base/trunk/Source/NSSet.m
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=38470&r1=38469&r2=38470&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Sat May 2 10:03:05 2015
@@ -1,3 +1,13 @@
+2015-05-02 Niels Grewe <[email protected]>
+
+ * Source/GSSet.m
+ * Source/NSCountedSet.m
+ * Source/NSSet.m:
+ Implement a private method -_countForObject: that enables to correctly
+ compare NSSet and NSCountedSet (behaviour verified to match OS X).
+ Fixes bug #43915.
+ * Tests/base/NSCountedSet/equality.m: Test cases for equality behaviour.
+
2015-04-20 Richard Frith-Macdonald <[email protected]>
* Source/NSTimeZone.m: Improve caching of common absolute timezones.
Modified: libs/base/trunk/Source/GSSet.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSSet.m?rev=38470&r1=38469&r2=38470&view=diff
==============================================================================
--- libs/base/trunk/Source/GSSet.m (original)
+++ libs/base/trunk/Source/GSSet.m Sat May 2 10:03:05 2015
@@ -48,7 +48,7 @@
#include "GNUstepBase/GSIMap.h"
static SEL memberSel;
-
+static SEL privateCountOfSel;
@interface GSSet : NSSet
{
@public
@@ -128,6 +128,7 @@
setClass = [GSSet class];
mutableSetClass = [GSMutableSet class];
memberSel = @selector(member:);
+ privateCountOfSel = @selector(_countForObject:);
}
}
@@ -424,8 +425,10 @@
GSIMapEnumerator_t enumerator;
GSIMapNode node;
IMP imp;
+ IMP countImp;
imp = [other methodForSelector: memberSel];
+ countImp = [other methodForSelector: privateCountOfSel];
enumerator = GSIMapEnumeratorForMap(&map);
node = GSIMapEnumeratorNextNode(&enumerator);
@@ -436,6 +439,16 @@
GSIMapEndEnumerator(&enumerator);
return NO;
}
+ else
+ {
+ NSUInteger c = (NSUInteger)
+ countImp(other,privateCountOfSel,node->key.obj);
+ // GSSet does not have duplicate entries
+ if (c != 1)
+ {
+ return NO;
+ }
+ }
node = GSIMapEnumeratorNextNode(&enumerator);
}
GSIMapEndEnumerator(&enumerator);
Modified: libs/base/trunk/Source/NSCountedSet.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSCountedSet.m?rev=38470&r1=38469&r2=38470&view=diff
==============================================================================
--- libs/base/trunk/Source/NSCountedSet.m (original)
+++ libs/base/trunk/Source/NSCountedSet.m Sat May 2 10:03:05 2015
@@ -91,6 +91,11 @@
}
}
+- (NSUInteger) _countForObject: (id)anObject
+{
+ return [self countForObject: anObject];
+}
+
/**
* Returns the number of times that an object that is equal to the
* specified object (as determined by the [-isEqual:] method) has
Modified: libs/base/trunk/Source/NSSet.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/NSSet.m?rev=38470&r1=38469&r2=38470&view=diff
==============================================================================
--- libs/base/trunk/Source/NSSet.m (original)
+++ libs/base/trunk/Source/NSSet.m Sat May 2 10:03:05 2015
@@ -590,6 +590,11 @@
return NO;
}
+- (NSUInteger)_countForObject: (id)object
+{
+ return 1;
+}
+
/**
* Return whether each set is subset of the other.
*/
@@ -602,8 +607,19 @@
id o, e = [self objectEnumerator];
while ((o = [e nextObject]))
- if (![other member: o])
- return NO;
+ {
+ if (![other member: o])
+ {
+ return NO;
+ }
+ else
+ {
+ if ([self _countForObject: o] != [other _countForObject: o])
+ {
+ return NO;
+ }
+ }
+ }
}
/* xxx Recheck this. */
return YES;
Added: libs/base/trunk/Tests/base/NSCountedSet/equality.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Tests/base/NSCountedSet/equality.m?rev=38470&view=auto
==============================================================================
--- libs/base/trunk/Tests/base/NSCountedSet/equality.m (added)
+++ libs/base/trunk/Tests/base/NSCountedSet/equality.m Sat May 2 10:03:05 2015
@@ -0,0 +1,21 @@
+#import "ObjectTesting.h"
+#import <Foundation/NSSet.h>
+#import <Foundation/NSAutoreleasePool.h>
+
+int main()
+{
+ NSAutoreleasePool *arp = [NSAutoreleasePool new];
+ NSCountedSet *count1 = [NSCountedSet setWithObjects: @"1", @"1", nil];
+ NSCountedSet *count2 = [NSCountedSet setWithObjects: @"1", @"1", nil];
+ NSCountedSet *count3 = [NSCountedSet setWithObjects: @"1", nil];
+ NSSet *set = [NSSet setWithObjects: @"1", nil];
+ PASS([count1 isEqualToSet: count2], "Identical counted sets are equal");
+ PASS(![count1 isEqualToSet: count3], "Different counted sets are not equal");
+ PASS([count3 isEqualToSet: set], "Counted set is equal to plain set");
+ PASS([set isEqualToSet: count3], "Plain set is equal to counted set");
+ PASS(![count1 isEqualToSet: set], "Counted set with different counts is not
equal to plain set");
+ PASS(![set isEqualToSet: count1], "Plain set is not equal to counted set
with different counts");
+ [arp release]; arp = nil;
+ return 0;
+}
+
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs