|
34 | 34 | #define OCMObserverMock() [OCMockObject observerMock] |
35 | 35 |
|
36 | 36 |
|
37 | | -#define OCMStub(invocation) \ |
| 37 | +#define OCMStubWithStateClass(MacroStateClass, invocation) \ |
38 | 38 | ({ \ |
39 | 39 | _OCMSilenceWarnings( \ |
40 | | - [OCMMacroState beginStubMacro]; \ |
| 40 | + [MacroStateClass beginStubMacro]; \ |
41 | 41 | OCMStubRecorder *recorder = nil; \ |
42 | 42 | @try{ \ |
43 | 43 | invocation; \ |
44 | 44 | }@catch(...){ \ |
45 | | - [[OCMMacroState globalState] setInvocationDidThrow:YES]; \ |
| 45 | + [[MacroStateClass globalState] setInvocationDidThrow:YES]; \ |
46 | 46 | /* NOLINTNEXTLINE(google-objc-avoid-throwing-exception) */ \ |
47 | 47 | @throw; \ |
48 | 48 | }@finally{ \ |
49 | | - recorder = [OCMMacroState endStubMacro]; \ |
| 49 | + recorder = [MacroStateClass endStubMacro]; \ |
50 | 50 | } \ |
51 | 51 | recorder; \ |
52 | 52 | ); \ |
53 | 53 | }) |
54 | 54 |
|
55 | | -#define OCMExpect(invocation) \ |
| 55 | +#define OCMStub(invocation) OCMStubWithStateClass(OCMMacroState, invocation) |
| 56 | + |
| 57 | +#define OCMExpectWithStateClass(MacroStateClass, invocation) \ |
56 | 58 | ({ \ |
57 | 59 | _OCMSilenceWarnings( \ |
58 | | - [OCMMacroState beginExpectMacro]; \ |
| 60 | + [MacroStateClass beginExpectMacro]; \ |
59 | 61 | OCMStubRecorder *recorder = nil; \ |
60 | 62 | @try{ \ |
61 | 63 | invocation; \ |
62 | 64 | }@catch(...){ \ |
63 | | - [[OCMMacroState globalState] setInvocationDidThrow:YES]; \ |
| 65 | + [[MacroStateClass globalState] setInvocationDidThrow:YES]; \ |
64 | 66 | /* NOLINTNEXTLINE(google-objc-avoid-throwing-exception) */ \ |
65 | 67 | @throw; \ |
66 | 68 | }@finally{ \ |
67 | | - recorder = [OCMMacroState endExpectMacro]; \ |
| 69 | + recorder = [MacroStateClass endExpectMacro]; \ |
68 | 70 | } \ |
69 | 71 | recorder; \ |
70 | 72 | ); \ |
71 | 73 | }) |
72 | 74 |
|
73 | | -#define OCMReject(invocation) \ |
| 75 | +#define OCMExpect(invocation) OCMExpectWithStateClass(OCMMacroState, invocation) |
| 76 | + |
| 77 | +#define OCMRejectWithStateClass(MacroStateClass, invocation) \ |
74 | 78 | ({ \ |
75 | 79 | _OCMSilenceWarnings( \ |
76 | | - [OCMMacroState beginRejectMacro]; \ |
| 80 | + [MacroStateClass beginRejectMacro]; \ |
77 | 81 | OCMStubRecorder *recorder = nil; \ |
78 | 82 | @try{ \ |
79 | 83 | invocation; \ |
80 | 84 | }@catch(...){ \ |
81 | | - [[OCMMacroState globalState] setInvocationDidThrow:YES]; \ |
| 85 | + [[MacroStateClass globalState] setInvocationDidThrow:YES]; \ |
82 | 86 | /* NOLINTNEXTLINE(google-objc-avoid-throwing-exception) */ \ |
83 | 87 | @throw; \ |
84 | 88 | }@finally{ \ |
85 | | - recorder = [OCMMacroState endRejectMacro]; \ |
| 89 | + recorder = [MacroStateClass endRejectMacro]; \ |
86 | 90 | } \ |
87 | 91 | recorder; \ |
88 | 92 | ); \ |
89 | 93 | }) |
90 | 94 |
|
| 95 | +#define OCMReject(invocation) OCMRejectWithStateClass(OCMMacroState, invocation) |
91 | 96 |
|
92 | 97 |
|
93 | | -#define OCMClassMethod(invocation) \ |
| 98 | + |
| 99 | +#define OCMClassMethodWithStateClass(MacroStateClass, invocation) \ |
94 | 100 | _OCMSilenceWarnings( \ |
95 | | - [[OCMMacroState globalState] switchToClassMethod]; \ |
| 101 | + [[MacroStateClass globalState] switchToClassMethod]; \ |
96 | 102 | invocation; \ |
97 | 103 | ); |
98 | 104 |
|
| 105 | +#define OCMClassMethod(invocation) OCMClassMethodWithStateClass(OCMMacroState, invocation) |
| 106 | + |
99 | 107 |
|
100 | 108 | #ifndef OCM_DISABLE_SHORT_SYNTAX |
101 | 109 | #define ClassMethod(invocation) OCMClassMethod(invocation) |
|
106 | 114 |
|
107 | 115 | #define OCMVerifyAllWithDelay(mock, delay) [(OCMockObject *)mock verifyWithDelay:delay atLocation:OCMMakeLocation(self, __FILE__, __LINE__)] |
108 | 116 |
|
109 | | -#define _OCMVerify(invocation) \ |
| 117 | +#define _OCMVerifyWithStateClass(MacroStateClass, invocation) \ |
110 | 118 | ({ \ |
111 | 119 | _OCMSilenceWarnings( \ |
112 | | - [OCMMacroState beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]; \ |
| 120 | + [MacroStateClass beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__)]; \ |
113 | 121 | @try{ \ |
114 | 122 | invocation; \ |
115 | 123 | }@catch(...){ \ |
116 | | - [[OCMMacroState globalState] setInvocationDidThrow:YES]; \ |
| 124 | + [[MacroStateClass globalState] setInvocationDidThrow:YES]; \ |
117 | 125 | /* NOLINTNEXTLINE(google-objc-avoid-throwing-exception) */ \ |
118 | 126 | @throw; \ |
119 | 127 | }@finally{ \ |
120 | | - [OCMMacroState endVerifyMacro]; \ |
| 128 | + [MacroStateClass endVerifyMacro]; \ |
121 | 129 | } \ |
122 | 130 | ); \ |
123 | 131 | }) |
124 | 132 |
|
125 | | -#define _OCMVerifyWithQuantifier(quantifier, invocation) \ |
| 133 | +#define _OCMVerify(invocation) _OCMVerifyWithStateClass(OCMMacroState, invocation) |
| 134 | + |
| 135 | + |
| 136 | +#define _OCMVerifyWithQuantifierAndStateClass(MacroStateClass, quantifier, invocation) \ |
126 | 137 | ({ \ |
127 | 138 | _OCMSilenceWarnings( \ |
128 | | - [OCMMacroState beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__) withQuantifier:quantifier]; \ |
| 139 | + [MacroStateClass beginVerifyMacroAtLocation:OCMMakeLocation(self, __FILE__, __LINE__) withQuantifier:quantifier]; \ |
129 | 140 | @try{ \ |
130 | 141 | invocation; \ |
131 | 142 | }@catch(...){ \ |
132 | | - [[OCMMacroState globalState] setInvocationDidThrow:YES]; \ |
| 143 | + [[MacroStateClass globalState] setInvocationDidThrow:YES]; \ |
133 | 144 | /* NOLINTNEXTLINE(google-objc-avoid-throwing-exception) */ \ |
134 | 145 | @throw; \ |
135 | 146 | }@finally{ \ |
136 | | - [OCMMacroState endVerifyMacro]; \ |
| 147 | + [MacroStateClass endVerifyMacro]; \ |
137 | 148 | } \ |
138 | 149 | ); \ |
139 | 150 | }) |
140 | 151 |
|
| 152 | +#define _OCMVerifyWithQuantifier(quantifier, invocation) _OCMVerifyWithQuantifierAndStateClass(OCMMacroState, quantifier, invocation) |
| 153 | + |
141 | 154 | // explanation for macros below here: https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros |
142 | 155 |
|
143 | 156 | #define _OCMVerify_1(A) _OCMVerify(A) |
|
0 commit comments