123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #if DEBUG
- #import <stdarg.h>
- #import "GTMDefines.h"
- static void GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(id obj, SEL sel, const char *retType, ...) {
-
-
- va_list argList;
- va_start(argList, retType);
- if (obj && sel) {
-
- _GTMDevAssert([obj respondsToSelector:sel],
- @"\"%@\" selector \"%@\" is unimplemented or misnamed",
- NSStringFromClass([obj class]),
- NSStringFromSelector(sel));
- const char *expectedArgType;
- NSUInteger argCount = 2;
- NSMethodSignature *sig = [obj methodSignatureForSelector:sel];
-
- while ((expectedArgType = va_arg(argList, const char*)) != 0) {
- if ([sig numberOfArguments] > argCount) {
- const char *foundArgType = [sig getArgumentTypeAtIndex:argCount];
- _GTMDevAssert(0 == strncmp(foundArgType, expectedArgType, strlen(expectedArgType)),
- @"\"%@\" selector \"%@\" argument %u should be type %s",
- NSStringFromClass([obj class]),
- NSStringFromSelector(sel),
- (uint32_t)(argCount - 2),
- expectedArgType);
- }
- argCount++;
- }
-
- _GTMDevAssert(argCount == [sig numberOfArguments],
- @"\"%@\" selector \"%@\" should have %u arguments",
- NSStringFromClass([obj class]),
- NSStringFromSelector(sel),
- (uint32_t)(argCount - 2));
-
- if (retType && (strcmp("gtm_skip_return_test", retType) != 0)) {
- const char *foundRetType = [sig methodReturnType];
- _GTMDevAssert(0 == strncmp(foundRetType, retType, strlen(retType)),
- @"\"%@\" selector \"%@\" return type should be type %s",
- NSStringFromClass([obj class]),
- NSStringFromSelector(sel),
- retType);
- }
- }
- va_end(argList);
- }
- #define GTMAssertSelectorNilOrImplementedWithArguments(obj, sel, ...) \
- GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments((obj), (sel), "gtm_skip_return_test", __VA_ARGS__)
- #else
- #define GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(obj, sel, retType, ...) do { } while (0)
- #define GTMAssertSelectorNilOrImplementedWithArguments(obj, sel, ...) do { } while (0)
- #endif
|