react-native-navigation的迁移库

OCMStubRecorder.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2004-2016 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 <OCMock/OCMRecorder.h>
  17. #import <OCMock/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