OCMIndirectReturnValueProvider.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2009-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 "NSMethodSignature+OCMAdditions.h"
  17. #import "OCMIndirectReturnValueProvider.h"
  18. #import "NSInvocation+OCMAdditions.h"
  19. @implementation OCMIndirectReturnValueProvider
  20. - (id)initWithProvider:(id)aProvider andSelector:(SEL)aSelector
  21. {
  22. if ((self = [super init]))
  23. {
  24. provider = [aProvider retain];
  25. selector = aSelector;
  26. }
  27. return self;
  28. }
  29. - (void)dealloc
  30. {
  31. [provider release];
  32. [super dealloc];
  33. }
  34. - (void)handleInvocation:(NSInvocation *)anInvocation
  35. {
  36. id originalTarget = [anInvocation target];
  37. SEL originalSelector = [anInvocation selector];
  38. [anInvocation setTarget:provider];
  39. [anInvocation setSelector:selector];
  40. [anInvocation invoke];
  41. [anInvocation setTarget:originalTarget];
  42. [anInvocation setSelector:originalSelector];
  43. }
  44. @end