From c53ec5520e39096e0804ce8d89a21378c0904481 Mon Sep 17 00:00:00 2001 From: thomasvl Date: Fri, 13 Jun 2008 19:21:50 +0000 Subject: Landing a log of AppleScript/AppleEvent support code. Landing GTMHTTPServer as a simple server but mainly for use in unittesting. _GTMCompileAssert for doing compile time assertions to GTMDefines.h Lots of improvments for UnitTesting, Dave's gonna put up a wiki page shortly with the full details of what can be done. --- DebugUtils/GTMDebugSelectorValidation.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'DebugUtils/GTMDebugSelectorValidation.h') diff --git a/DebugUtils/GTMDebugSelectorValidation.h b/DebugUtils/GTMDebugSelectorValidation.h index 82d00e8..19d8b8e 100644 --- a/DebugUtils/GTMDebugSelectorValidation.h +++ b/DebugUtils/GTMDebugSelectorValidation.h @@ -5,6 +5,8 @@ // function that takes an object and selector to invoke, you should call: // // GTMAssertSelectorNilOrImplementedWithArguments(obj, sel, @encode(arg1type), ..., NULL) +// or +// GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(obj, sel, @encode(returnType), @encode(arg1type), ..., NULL) // // This will then validate that the selector is defined and using the right // type(s), this can help catch errors much earlier then waiting for the @@ -31,12 +33,12 @@ #import #import "GTMDefines.h" -static void GTMAssertSelectorNilOrImplementedWithArguments(id obj, SEL sel, ...) { - +static void GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(id obj, SEL sel, const char *retType, ...) { + // verify that the object's selector is implemented with the proper // number and type of arguments va_list argList; - va_start(argList, sel); + va_start(argList, retType); if (obj && sel) { // check that the selector is implemented @@ -71,14 +73,28 @@ static void GTMAssertSelectorNilOrImplementedWithArguments(id obj, SEL sel, ...) NSStringFromClass([obj class]), NSStringFromSelector(sel), (argCount - 2)); + + // if asked, validate the return type + 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 // DEBUG // make it go away if not debug +#define GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(obj, sel, retType, ...) do { } while (0) #define GTMAssertSelectorNilOrImplementedWithArguments(obj, sel, ...) do { } while (0) #endif // DEBUG -- cgit v1.2.3