Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -146,11 +146,10 @@ 4B325EE01605F3A0007836CA /* OFTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B325EDC1605F3A0007836CA /* OFTimer.m */; }; 4B39844213D3A24600E6F825 /* OFSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B39844013D3A24600E6F825 /* OFSet.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B39844313D3A24600E6F825 /* OFSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B39844113D3A24600E6F825 /* OFSet.m */; }; 4B39844713D3AFB400E6F825 /* OFMutableSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B39844513D3AFB400E6F825 /* OFMutableSet.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B39844813D3AFB400E6F825 /* OFMutableSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B39844613D3AFB400E6F825 /* OFMutableSet.m */; }; - 4B39844A13D3D03000E6F825 /* OFSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B39844913D3D03000E6F825 /* OFSet.m */; }; 4B3B0798166978780044E634 /* OFMapTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B3B0796166978780044E634 /* OFMapTable.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B3B0799166978780044E634 /* OFMapTable.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B3B0797166978780044E634 /* OFMapTable.m */; }; 4B3D238B1337FC0D00DD29B8 /* OFApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B175C1E116D130B003C99CB /* OFApplication.m */; }; 4B3D238C1337FC0D00DD29B8 /* OFArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B67995B1099E7C50041064A /* OFArray.m */; }; 4B3D238D1337FC0D00DD29B8 /* OFAutoreleasePool.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B67995D1099E7C50041064A /* OFAutoreleasePool.m */; }; @@ -250,10 +249,11 @@ 4B49EA6E143B3A090005BBC6 /* OFXMLCDATA.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B49EA68143B3A090005BBC6 /* OFXMLCDATA.m */; }; 4B49EA6F143B3A090005BBC6 /* OFXMLCharacters.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B49EA69143B3A090005BBC6 /* OFXMLCharacters.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B49EA70143B3A090005BBC6 /* OFXMLCharacters.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B49EA6A143B3A090005BBC6 /* OFXMLCharacters.m */; }; 4B49EA71143B3A090005BBC6 /* OFXMLComment.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B49EA6B143B3A090005BBC6 /* OFXMLComment.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B49EA72143B3A090005BBC6 /* OFXMLComment.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B49EA6C143B3A090005BBC6 /* OFXMLComment.m */; }; + 4B4B6904191437D500334775 /* OFSetTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B4B6903191437D500334775 /* OFSetTests.m */; }; 4B511B7C139C0A34003764A5 /* OFNull.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B511B7A139C0A34003764A5 /* OFNull.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4B511B7D139C0A34003764A5 /* OFNull.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B511B7B139C0A34003764A5 /* OFNull.m */; }; 4B552552147AA5DB0003BF47 /* OFMutableString_UTF8.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B55254E147AA5DB0003BF47 /* OFMutableString_UTF8.h */; }; 4B552553147AA5DB0003BF47 /* OFMutableString_UTF8.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B55254F147AA5DB0003BF47 /* OFMutableString_UTF8.m */; }; 4B552554147AA5DB0003BF47 /* OFString_UTF8.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B552550147AA5DB0003BF47 /* OFString_UTF8.h */; }; @@ -616,11 +616,10 @@ 4B325EDC1605F3A0007836CA /* OFTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFTimer.m; path = src/OFTimer.m; sourceTree = ""; }; 4B39844013D3A24600E6F825 /* OFSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSet.h; path = src/OFSet.h; sourceTree = ""; }; 4B39844113D3A24600E6F825 /* OFSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSet.m; path = src/OFSet.m; sourceTree = ""; }; 4B39844513D3AFB400E6F825 /* OFMutableSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutableSet.h; path = src/OFMutableSet.h; sourceTree = ""; }; 4B39844613D3AFB400E6F825 /* OFMutableSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutableSet.m; path = src/OFMutableSet.m; sourceTree = ""; }; - 4B39844913D3D03000E6F825 /* OFSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSet.m; path = tests/OFSet.m; sourceTree = ""; }; 4B3B0796166978780044E634 /* OFMapTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMapTable.h; path = src/OFMapTable.h; sourceTree = ""; }; 4B3B0797166978780044E634 /* OFMapTable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMapTable.m; path = src/OFMapTable.m; sourceTree = ""; }; 4B3D236D1337FB5800DD29B8 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = base64.h; path = src/base64.h; sourceTree = ""; }; 4B3D236E1337FB5800DD29B8 /* base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = base64.m; path = src/base64.m; sourceTree = ""; }; 4B3D23761337FBC800DD29B8 /* ObjFW.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObjFW.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -638,10 +637,11 @@ 4B49EA6A143B3A090005BBC6 /* OFXMLCharacters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLCharacters.m; path = src/OFXMLCharacters.m; sourceTree = ""; }; 4B49EA6B143B3A090005BBC6 /* OFXMLComment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLComment.h; path = src/OFXMLComment.h; sourceTree = ""; }; 4B49EA6C143B3A090005BBC6 /* OFXMLComment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLComment.m; path = src/OFXMLComment.m; sourceTree = ""; }; 4B4A61F212DF5EA20048F3F2 /* OFURL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFURL.h; path = src/OFURL.h; sourceTree = SOURCE_ROOT; }; 4B4A61F312DF5EA20048F3F2 /* OFURL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFURL.m; path = src/OFURL.m; sourceTree = SOURCE_ROOT; }; + 4B4B6903191437D500334775 /* OFSetTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSetTests.m; path = tests/OFSetTests.m; sourceTree = ""; }; 4B511B7A139C0A34003764A5 /* OFNull.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFNull.h; path = src/OFNull.h; sourceTree = ""; }; 4B511B7B139C0A34003764A5 /* OFNull.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFNull.m; path = src/OFNull.m; sourceTree = ""; }; 4B55254E147AA5DB0003BF47 /* OFMutableString_UTF8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFMutableString_UTF8.h; path = src/OFMutableString_UTF8.h; sourceTree = ""; }; 4B55254F147AA5DB0003BF47 /* OFMutableString_UTF8.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFMutableString_UTF8.m; path = src/OFMutableString_UTF8.m; sourceTree = ""; }; 4B552550147AA5DB0003BF47 /* OFString_UTF8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFString_UTF8.h; path = src/OFString_UTF8.h; sourceTree = ""; }; @@ -1424,11 +1424,11 @@ 4B6EF6731235358D0076B512 /* OFMD5HashTests.m */, 4B6EF6741235358D0076B512 /* OFNumberTests.m */, 4B6EF6751235358D0076B512 /* OFObjectTests.m */, 4B6EF6761235358D0076B512 /* OFPluginTests.m */, 4B3D5693139A617D0010A78F /* OFSerializationTests.m */, - 4B39844913D3D03000E6F825 /* OFSet.m */, + 4B4B6903191437D500334775 /* OFSetTests.m */, 4B6EF6771235358D0076B512 /* OFSHA1HashTests.m */, 4B6EF6781235358D0076B512 /* OFStreamTests.m */, 4B6EF6791235358D0076B512 /* OFStringTests.m */, 4B6EF67A1235358D0076B512 /* OFTCPSocketTests.m */, 4B6EF67B1235358D0076B512 /* OFThreadTests.m */, @@ -2064,11 +2064,11 @@ 4BF33B04133807A20059CEF7 /* OFMD5HashTests.m in Sources */, 4BF33B05133807A20059CEF7 /* OFNumberTests.m in Sources */, 4BF33B06133807A20059CEF7 /* OFObjectTests.m in Sources */, 4BF33B07133807A20059CEF7 /* OFPluginTests.m in Sources */, 4B3D5694139A617D0010A78F /* OFSerializationTests.m in Sources */, - 4B39844A13D3D03000E6F825 /* OFSet.m in Sources */, + 4B4B6904191437D500334775 /* OFSetTests.m in Sources */, 4BF33B08133807A20059CEF7 /* OFSHA1HashTests.m in Sources */, 4BF33B09133807A20059CEF7 /* OFStreamTests.m in Sources */, 4BF33B0A133807A20059CEF7 /* OFStringTests.m in Sources */, 4BF33B0B133807A20059CEF7 /* OFTCPSocketTests.m in Sources */, 4BF33B0C133807A20059CEF7 /* OFThreadTests.m in Sources */, Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -16,11 +16,11 @@ OFDictionaryTests.m \ OFJSONTests.m \ OFListTests.m \ OFNumberTests.m \ OFObjectTests.m \ - OFSet.m \ + OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFURLTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ DELETED tests/OFSet.m Index: tests/OFSet.m ================================================================== --- tests/OFSet.m +++ tests/OFSet.m @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFSet.h" -#import "OFArray.h" -#import "OFAutoreleasePool.h" - -#import "OFEnumerationMutationException.h" - -#import "TestsAppDelegate.h" - -static OFString *module = @"OFSet"; - -@implementation TestsAppDelegate (OFSetTests) -- (void)setTests -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFSet *set1, *set2; - OFMutableSet *mutableSet; -#ifdef OF_HAVE_FAST_ENUMERATION - bool ok; - size_t i; -#endif - - TEST(@"+[setWithArray:]", - (set1 = [OFSet setWithArray: [OFArray arrayWithObjects: @"foo", - @"bar", @"baz", @"foo", @"x", nil]])) - - TEST(@"+[setWithObjects:]", - (set2 = [OFSet setWithObjects: @"foo", @"bar", @"baz", @"bar", @"x", - nil])) - - TEST(@"-[isEqual:]", [set1 isEqual: set2]) - - TEST(@"-[hash]", [set1 hash] == [set2 hash]) - - TEST(@"-[description]", - [[set1 description] - isEqual: @"{(\n\tx,\n\tbar,\n\tfoo,\n\tbaz\n)}"] && - [[set1 description] isEqual: [set2 description]]) - - TEST(@"-[copy]", [set1 isEqual: [[set1 copy] autorelease]]) - - TEST(@"-[mutableCopy]", - (mutableSet = [[set1 mutableCopy] autorelease])); - - TEST(@"-[addObject:]", - R([mutableSet addObject: @"baz"]) && [mutableSet isEqual: set2] && - R([mutableSet addObject: @"y"]) && [mutableSet isEqual: - ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", @"y", nil])]) - - TEST(@"-[removeObject:]", - R([mutableSet removeObject: @"y"]) && [mutableSet isEqual: set1]) - - TEST(@"-[isSubsetOfSet:]", - R([mutableSet removeObject: @"foo"]) && - [mutableSet isSubsetOfSet: set1] && - ![set1 isSubsetOfSet: mutableSet]); - - TEST(@"-[intersectsSet:]", - [(set2 = [OFSet setWithObjects: @"x", nil]) intersectsSet: set1] && - [set1 intersectsSet: set2] && - ![([OFSet setWithObjects: @"1", nil]) intersectsSet: set1]); - - TEST(@"-[minusSet:]", - R([mutableSet minusSet: ([OFSet setWithObjects: @"x", nil])]) && - [mutableSet isEqual: ([OFSet setWithObjects: @"baz", @"bar", nil])]) - - TEST(@"-[intersectSet:]", - R([mutableSet intersectSet: ([OFSet setWithObjects: @"baz", - nil])]) && [mutableSet isEqual: ([OFSet setWithObjects: @"baz", - nil])]) - - TEST(@"-[unionSet:]", - R([mutableSet unionSet: ([OFSet setWithObjects: @"x", @"bar", - nil])]) && [mutableSet isEqual: ([OFSet setWithObjects: @"baz", - @"bar", @"x", nil])]) - -#ifdef OF_HAVE_FAST_ENUMERATION - ok = true; - i = 0; - - for (OFString *s in set1) { - switch (i) { - case 0: - if (![s isEqual: @"x"]) - ok = false; - break; - case 1: - if (![s isEqual: @"bar"]) - ok = false; - break; - case 2: - if (![s isEqual: @"foo"]) - ok = false; - break; - case 3: - if (![s isEqual: @"baz"]) - ok = false; - break; - } - - i++; - } - - if (i != 4) - ok = false; - - TEST(@"Fast enumeration", ok) - - ok = false; - @try { - for (OFString *s in mutableSet) - [mutableSet removeObject: s]; - } @catch (OFEnumerationMutationException *e) { - ok = true; - } - - TEST(@"Detection of mutation during Fast Enumeration", ok); -#endif - - [pool drain]; -} -@end ADDED tests/OFSetTests.m Index: tests/OFSetTests.m ================================================================== --- tests/OFSetTests.m +++ tests/OFSetTests.m @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFSet.h" +#import "OFArray.h" +#import "OFAutoreleasePool.h" + +#import "OFEnumerationMutationException.h" + +#import "TestsAppDelegate.h" + +static OFString *module = @"OFSet"; + +@implementation TestsAppDelegate (OFSetTests) +- (void)setTests +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFSet *set1, *set2; + OFMutableSet *mutableSet; +#ifdef OF_HAVE_FAST_ENUMERATION + bool ok; + size_t i; +#endif + + TEST(@"+[setWithArray:]", + (set1 = [OFSet setWithArray: [OFArray arrayWithObjects: @"foo", + @"bar", @"baz", @"foo", @"x", nil]])) + + TEST(@"+[setWithObjects:]", + (set2 = [OFSet setWithObjects: @"foo", @"bar", @"baz", @"bar", @"x", + nil])) + + TEST(@"-[isEqual:]", [set1 isEqual: set2]) + + TEST(@"-[hash]", [set1 hash] == [set2 hash]) + + TEST(@"-[description]", + [[set1 description] + isEqual: @"{(\n\tx,\n\tbar,\n\tfoo,\n\tbaz\n)}"] && + [[set1 description] isEqual: [set2 description]]) + + TEST(@"-[copy]", [set1 isEqual: [[set1 copy] autorelease]]) + + TEST(@"-[mutableCopy]", + (mutableSet = [[set1 mutableCopy] autorelease])); + + TEST(@"-[addObject:]", + R([mutableSet addObject: @"baz"]) && [mutableSet isEqual: set2] && + R([mutableSet addObject: @"y"]) && [mutableSet isEqual: + ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", @"y", nil])]) + + TEST(@"-[removeObject:]", + R([mutableSet removeObject: @"y"]) && [mutableSet isEqual: set1]) + + TEST(@"-[isSubsetOfSet:]", + R([mutableSet removeObject: @"foo"]) && + [mutableSet isSubsetOfSet: set1] && + ![set1 isSubsetOfSet: mutableSet]); + + TEST(@"-[intersectsSet:]", + [(set2 = [OFSet setWithObjects: @"x", nil]) intersectsSet: set1] && + [set1 intersectsSet: set2] && + ![([OFSet setWithObjects: @"1", nil]) intersectsSet: set1]); + + TEST(@"-[minusSet:]", + R([mutableSet minusSet: ([OFSet setWithObjects: @"x", nil])]) && + [mutableSet isEqual: ([OFSet setWithObjects: @"baz", @"bar", nil])]) + + TEST(@"-[intersectSet:]", + R([mutableSet intersectSet: ([OFSet setWithObjects: @"baz", + nil])]) && [mutableSet isEqual: ([OFSet setWithObjects: @"baz", + nil])]) + + TEST(@"-[unionSet:]", + R([mutableSet unionSet: ([OFSet setWithObjects: @"x", @"bar", + nil])]) && [mutableSet isEqual: ([OFSet setWithObjects: @"baz", + @"bar", @"x", nil])]) + +#ifdef OF_HAVE_FAST_ENUMERATION + ok = true; + i = 0; + + for (OFString *s in set1) { + switch (i) { + case 0: + if (![s isEqual: @"x"]) + ok = false; + break; + case 1: + if (![s isEqual: @"bar"]) + ok = false; + break; + case 2: + if (![s isEqual: @"foo"]) + ok = false; + break; + case 3: + if (![s isEqual: @"baz"]) + ok = false; + break; + } + + i++; + } + + if (i != 4) + ok = false; + + TEST(@"Fast enumeration", ok) + + ok = false; + @try { + for (OFString *s in mutableSet) + [mutableSet removeObject: s]; + } @catch (OFEnumerationMutationException *e) { + ok = true; + } + + TEST(@"Detection of mutation during Fast Enumeration", ok); +#endif + + [pool drain]; +} +@end