Updated BlockImpTest asserts. Fixes #126

assert now directly compares block self with expected class, avoiding
objc_msgSend.
main
Rupert Daniel 6 years ago committed by David Chisnall
parent 710b2368cc
commit 108d4e19c0

@ -24,9 +24,10 @@ __attribute__((objc_root_class))
int main(void) int main(void)
{ {
__block Class cls = objc_getClass("Foo");
__block int b = 0; __block int b = 0;
void* blk = ^(id self, int a) { void* blk = ^(id self, int a) {
assert([self class] == [Foo class]); assert(self == cls);
b += a; b += a;
return b; }; return b; };
blk = Block_copy(blk); blk = Block_copy(blk);
@ -34,7 +35,6 @@ int main(void)
char *type = block_copyIMPTypeEncoding_np(blk); char *type = block_copyIMPTypeEncoding_np(blk);
assert(NULL != type); assert(NULL != type);
class_addMethod((objc_getMetaClass("Foo")), @selector(count:), imp, type); class_addMethod((objc_getMetaClass("Foo")), @selector(count:), imp, type);
Class cls = objc_getClass("Foo");
assert(2 == ((int(*)(id,SEL,int))imp)(cls, @selector(count:), 2)); assert(2 == ((int(*)(id,SEL,int))imp)(cls, @selector(count:), 2));
free(type); free(type);
assert(4 == [Foo count: 2]); assert(4 == [Foo count: 2]);
@ -46,7 +46,7 @@ int main(void)
assert(imp_getBlock(imp) != (blk)); assert(imp_getBlock(imp) != (blk));
blk = ^(id self) { blk = ^(id self) {
assert([self class] == [Foo class]); assert(self == cls);
struct big b = {1, 2, 3, 4, 5}; struct big b = {1, 2, 3, 4, 5};
return b; return b;
}; };

Loading…
Cancel
Save