OCMock.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <OCMock/OCMockObject.h>
  17. #import <OCMock/OCMRecorder.h>
  18. #import <OCMock/OCMStubRecorder.h>
  19. #import <OCMock/OCMConstraint.h>
  20. #import <OCMock/OCMArg.h>
  21. #import <OCMock/OCMLocation.h>
  22. #import <OCMock/OCMMacroState.h>
  23. #import <OCMock/NSNotificationCenter+OCMAdditions.h>
  24. #define OCMClassMock(cls) [OCMockObject niceMockForClass:cls]
  25. #define OCMStrictClassMock(cls) [OCMockObject mockForClass:cls]
  26. #define OCMProtocolMock(protocol) [OCMockObject niceMockForProtocol:protocol]
  27. #define OCMStrictProtocolMock(protocol) [OCMockObject mockForProtocol:protocol]
  28. #define OCMPartialMock(obj) [OCMockObject partialMockForObject:obj]
  29. #define OCMObserverMock() [OCMockObject observerMock]
  30. #define OCMStub(invocation) \
  31. ({ \
  32. _OCMSilenceWarnings( \
  33. [OCMMacroState beginStubMacro]; \
  34. invocation; \
  35. [OCMMacroState endStubMacro]; \
  36. ); \
  37. })
  38. #define OCMExpect(invocation) \
  39. ({ \
  40. _OCMSilenceWarnings( \
  41. [OCMMacroState beginExpectMacro]; \
  42. invocation; \
  43. [OCMMacroState endExpectMacro]; \
  44. ); \
  45. })
  46. #define ClassMethod(invocation) \
  47. _OCMSilenceWarnings( \
  48. [[OCMMacroState globalState] switchToClassMethod]; \
  49. invocation; \
  50. );
  51. #define OCMVerifyAll(mock) [mock verifyAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]
  52. #define OCMVerifyAllWithDelay(mock, delay) [mock verifyWithDelay:delay atLocation:OCMMakeLocation(self, __FILE__, __LINE__)]
  53. #define OCMVerify(invocation) \
  54. ({ \
  55. _OCMSilenceWarnings( \
  56. [OCMMacroState beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]; \
  57. invocation; \
  58. [OCMMacroState endVerifyMacro]; \
  59. ); \
  60. })
  61. #define _OCMSilenceWarnings(macro) \
  62. ({ \
  63. _Pragma("clang diagnostic push") \
  64. _Pragma("clang diagnostic ignored \"-Wunused-value\"") \
  65. _Pragma("clang diagnostic ignored \"-Wunused-getter-return-value\"") \
  66. macro \
  67. _Pragma("clang diagnostic pop") \
  68. })