OCMStubRecorder.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2004-2015 Erik Doernenburg and contributors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. * not use these files except in compliance with the License. You may obtain
  6. * a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations
  14. * under the License.
  15. */
  16. #import "OCMRecorder.h"
  17. #import "OCMFunctions.h"
  18. #import <objc/runtime.h>
  19. @interface OCMStubRecorder : OCMRecorder
  20. - (id)andReturn:(id)anObject;
  21. - (id)andReturnValue:(NSValue *)aValue;
  22. - (id)andThrow:(NSException *)anException;
  23. - (id)andPost:(NSNotification *)aNotification;
  24. - (id)andCall:(SEL)selector onObject:(id)anObject;
  25. - (id)andDo:(void (^)(NSInvocation *invocation))block;
  26. - (id)andForwardToRealObject;
  27. @end
  28. @interface OCMStubRecorder (Properties)
  29. #define andReturn(aValue) _andReturn(({ \
  30. __typeof__(aValue) _val = (aValue); \
  31. NSValue *_nsval = [NSValue value:&_val withObjCType:@encode(__typeof__(_val))]; \
  32. if (OCMIsObjectType(@encode(__typeof(_val)))) { \
  33. objc_setAssociatedObject(_nsval, "OCMAssociatedBoxedValue", *(__unsafe_unretained id *) (void *) &_val, OBJC_ASSOCIATION_RETAIN); \
  34. } \
  35. _nsval; \
  36. }))
  37. @property (nonatomic, readonly) OCMStubRecorder *(^ _andReturn)(NSValue *);
  38. #define andThrow(anException) _andThrow(anException)
  39. @property (nonatomic, readonly) OCMStubRecorder *(^ _andThrow)(NSException *);
  40. #define andPost(aNotification) _andPost(aNotification)
  41. @property (nonatomic, readonly) OCMStubRecorder *(^ _andPost)(NSNotification *);
  42. #define andCall(anObject, aSelector) _andCall(anObject, aSelector)
  43. @property (nonatomic, readonly) OCMStubRecorder *(^ _andCall)(id, SEL);
  44. #define andDo(aBlock) _andDo(aBlock)
  45. @property (nonatomic, readonly) OCMStubRecorder *(^ _andDo)(void (^)(NSInvocation *));
  46. #define andForwardToRealObject() _andForwardToRealObject()
  47. @property (nonatomic, readonly) OCMStubRecorder *(^ _andForwardToRealObject)(void);
  48. @end