[Substrate-commits] SF.net SVN: substrate: [267] trunk
Brought to you by:
landonf
|
From: <la...@us...> - 2006-08-30 23:20:32
|
Revision: 267
http://svn.sourceforge.net/substrate/?rev=267&view=rev
Author: landonf
Date: 2006-08-30 16:20:17 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
r5681@zadder: landonf | 2006-08-30 15:35:05 -0700
Fixes for designated initializers, minor test reorganization
r5682@zadder: landonf | 2006-08-30 16:19:30 -0700
Fix a small bug in NSObject's methodForSelector
Modified Paths:
--------------
trunk/Foundation/NSObject.m
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSObject.m
trunk/Tests/NSString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5679
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5682
Modified: trunk/Foundation/NSObject.m
===================================================================
--- trunk/Foundation/NSObject.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Foundation/NSObject.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -423,7 +423,7 @@
if (aSelector == NULL)
[NSException raise: NSInvalidArgumentException format: @"null selector"];
- method = LFObjectGetInstanceMethod(LFObjectGetClass(self), aSelector);
+ method = LFObjectGetInstanceMethod(self, aSelector);
return LFMethodGetIMP(method);
}
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Foundation/NSUnicodeString.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -99,7 +99,8 @@
UErrorCode err = U_ZERO_ERROR;
size_t allocSize;
- if(![self init])
+ self = [super init];
+ if (!self)
return nil;
/* Acquire a converter, and make an educated guess as to the correct allocation */
@@ -267,9 +268,6 @@
* Unless the string is encoded as UTF-16 in the host's native byte order, it will be copied.
*/
- (id) initWithBytesNoCopy:(void *)bytes length:(unsigned int)length encoding:(NSStringEncoding)encoding freeWhenDone:(BOOL)freeWhenDone {
- if (![self init])
- return self;
-
/* If we're supplied a UTF-16 string, we might just be able to use it ... */
if (encoding == NSUnicodeStringEncoding && length) {
BOOL isNativeBOM;
@@ -302,6 +300,11 @@
/* UTF-16 in native byte order */
if (isNativeBOM) {
+ /* We're the designated initializer! */
+ self = [super init];
+ if (!self)
+ return nil;
+
if (stripBOM) {
/* Strip off the BOM and make sure we free() the
* original pointer */
Modified: trunk/Tests/NSObject.m
===================================================================
--- trunk/Tests/NSObject.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Tests/NSObject.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -348,6 +348,19 @@
}
END_TEST
+START_TEST (test_NSObject_methodForSelector) {
+ Test *tst = [Test new];
+
+ fail_if([tst methodForSelector:@selector(init)] == nil, "-[Test respondsToSelector:] returned nil for an inherited instance method (-[NSObject init].");
+ fail_if([tst methodForSelector:@selector(testInstanceMethod)] == nil, "-[Test respondsToSelector:] returned nil for a valid instance method (testInstanceMethod).");
+ fail_unless([tst methodForSelector:@selector(nonsense)] == nil, "-[Test respondsToSelector:] returned nil for a non-existent instance method ('nonsense').");
+
+ [tst release];
+}
+END_TEST
+
+
+
START_TEST (test_NSObject_conformsToProtocol) {
NSObject *obj = [NSObject new];
Test *tst = [Test new];
@@ -403,6 +416,7 @@
tcase_add_test(tc_introspection, test_NSObject_isMemberOfClass);
tcase_add_test(tc_introspection, test_NSObject_instancesRespondToSelector);
tcase_add_test(tc_introspection, test_NSObject_respondsToSelector);
+ tcase_add_test(tc_introspection, test_NSObject_methodForSelector);
tcase_add_test(tc_introspection, test_NSObject_conformsToProtocol);
return (s);
Modified: trunk/Tests/NSString.m
===================================================================
--- trunk/Tests/NSString.m 2006-08-30 21:43:26 UTC (rev 266)
+++ trunk/Tests/NSString.m 2006-08-30 23:20:17 UTC (rev 267)
@@ -45,6 +45,18 @@
@implementation NSStringBrokenSubclass
@end
+@interface NSDumbString : NSString
+@end
+@implementation NSDumbString
+- (unichar) characterAtIndex:(unsigned int) index {
+ return (unichar) TEST_STRING[index];
+}
+
+- (unsigned int) length {
+ return sizeof(TEST_STRING) - 1;
+}
+@end
+
static NSAutoreleasePool *releasePool;
static void setUp(void) {
@@ -160,15 +172,10 @@
suite_add_tcase(s, tc_constant);
tcase_add_test(tc_constant, test_NSConstantString);
- TCase *tc_subclass = tcase_create("Subclassing");
- tcase_add_checked_fixture(tc_subclass, setUp, tearDown);
- suite_add_tcase(s, tc_subclass);
- tcase_add_test(tc_subclass, test_subclass_initWithBytes);
-
TCase *tc_encoding = tcase_create("Encodings");
tcase_add_checked_fixture(tc_encoding, setUp, tearDown);
suite_add_tcase(s, tc_encoding);
- tcase_add_test(tc_subclass, test_cls_defaultCStringEncoding);
+ tcase_add_test(tc_encoding, test_cls_defaultCStringEncoding);
TCase *tc_init = tcase_create("Initialization");
tcase_add_checked_fixture(tc_init, setUp, tearDown);
@@ -179,5 +186,10 @@
tcase_add_test(tc_init, test_initWithBytes);
tcase_add_test(tc_init, test_initWithBytesNoCopyLengthEncodingFreeWhenDone);
+ TCase *tc_subclass = tcase_create("Subclassing");
+ tcase_add_checked_fixture(tc_subclass, setUp, tearDown);
+ suite_add_tcase(s, tc_subclass);
+ tcase_add_test(tc_subclass, test_subclass_initWithBytes);
+
return (s);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|