aboutsummaryrefslogtreecommitdiff
path: root/DebugUtils/GTMDebugSelectorValidation.h
diff options
context:
space:
mode:
authorGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-06-13 19:21:50 +0000
committerGravatar thomasvl <thomasvl@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2008-06-13 19:21:50 +0000
commitc53ec5520e39096e0804ce8d89a21378c0904481 (patch)
treed36a0055b59b1376d86c4ba4a01f9c479c2101a7 /DebugUtils/GTMDebugSelectorValidation.h
parent80d493da05c8d461d74bfaa919ffc487be03ffe6 (diff)
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.
Diffstat (limited to 'DebugUtils/GTMDebugSelectorValidation.h')
-rw-r--r--DebugUtils/GTMDebugSelectorValidation.h22
1 files changed, 19 insertions, 3 deletions
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 <stdarg.h>
#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