uia 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/.rspec +1 -0
  2. data/ChangeLog +11 -0
  3. data/README.md +18 -1
  4. data/Rakefile +6 -1
  5. data/ext/UiaDll/UIA.Helper/Element.cs +52 -32
  6. data/ext/UiaDll/UiaDll.Test/AssemblyInfo.cpp +40 -0
  7. data/ext/UiaDll/UiaDll.Test/ElementInformationTest.cpp +89 -0
  8. data/ext/UiaDll/UiaDll.Test/ElementStub.h +59 -0
  9. data/ext/UiaDll/UiaDll.Test/ElementsTest.cpp +22 -0
  10. data/ext/UiaDll/UiaDll.Test/MemoryLeakDetector.h +47 -0
  11. data/ext/UiaDll/UiaDll.Test/ReadMe.txt +35 -0
  12. data/ext/UiaDll/UiaDll.Test/StringHelperTest.cpp +14 -0
  13. data/ext/UiaDll/UiaDll.Test/UiaDll.Test.cpp +16 -0
  14. data/ext/UiaDll/UiaDll.Test/UiaDll.Test.vcxproj +127 -0
  15. data/ext/UiaDll/UiaDll.Test/UiaDll.Test.vcxproj.filters +67 -0
  16. data/ext/UiaDll/UiaDll.Test/app.ico +0 -0
  17. data/ext/UiaDll/UiaDll.Test/app.rc +0 -0
  18. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-actions.h +1078 -0
  19. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-cardinalities.h +147 -0
  20. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-actions.h +2415 -0
  21. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-actions.h.pump +821 -0
  22. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-function-mockers.h +991 -0
  23. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-function-mockers.h.pump +265 -0
  24. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-matchers.h +2190 -0
  25. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-matchers.h.pump +674 -0
  26. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-nice-strict.h +397 -0
  27. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-generated-nice-strict.h.pump +161 -0
  28. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-matchers.h +3986 -0
  29. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-more-actions.h +233 -0
  30. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-more-matchers.h +58 -0
  31. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock-spec-builders.h +1791 -0
  32. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/gmock.h +94 -0
  33. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/internal/gmock-generated-internal-utils.h +279 -0
  34. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/internal/gmock-generated-internal-utils.h.pump +136 -0
  35. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/internal/gmock-internal-utils.h +498 -0
  36. data/ext/UiaDll/UiaDll.Test/gmock/include/gmock/internal/gmock-port.h +78 -0
  37. data/ext/UiaDll/UiaDll.Test/gmock/lib/gmock.lib +0 -0
  38. data/ext/UiaDll/UiaDll.Test/gmock/lib/gmockd.lib +0 -0
  39. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-death-test.h +294 -0
  40. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-message.h +250 -0
  41. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-param-test.h +1421 -0
  42. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-param-test.h.pump +487 -0
  43. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-printers.h +855 -0
  44. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-spi.h +232 -0
  45. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-test-part.h +179 -0
  46. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest-typed-test.h +259 -0
  47. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest.h +2291 -0
  48. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest_pred_impl.h +358 -0
  49. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/gtest_prod.h +58 -0
  50. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-death-test-internal.h +319 -0
  51. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-filepath.h +206 -0
  52. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-internal.h +1158 -0
  53. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-linked_ptr.h +233 -0
  54. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-param-util-generated.h +5143 -0
  55. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
  56. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-param-util.h +619 -0
  57. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-port.h +1947 -0
  58. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-string.h +167 -0
  59. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-tuple.h +1012 -0
  60. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-tuple.h.pump +339 -0
  61. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-type-util.h +3331 -0
  62. data/ext/UiaDll/UiaDll.Test/gtest/include/gtest/internal/gtest-type-util.h.pump +297 -0
  63. data/ext/UiaDll/UiaDll.Test/gtest/lib/gtest.lib +0 -0
  64. data/ext/UiaDll/UiaDll.Test/gtest/lib/gtestd.lib +0 -0
  65. data/ext/UiaDll/UiaDll.Test/resource.h +3 -0
  66. data/ext/UiaDll/UiaDll.Test/stdafx.cpp +7 -0
  67. data/ext/UiaDll/UiaDll.Test/stdafx.h +7 -0
  68. data/ext/UiaDll/UiaDll.sln +15 -0
  69. data/ext/UiaDll/UiaDll/ArrayHelper.h +20 -2
  70. data/ext/UiaDll/UiaDll/ElementMethods.cpp +18 -0
  71. data/ext/UiaDll/UiaDll/ElementStructures.h +36 -24
  72. data/ext/UiaDll/UiaDll/StringHelper.h +16 -2
  73. data/ext/UiaDll/UiaDll/UiaDll.vcxproj +0 -2
  74. data/ext/UiaDll/UiaDll/UiaDll.vcxproj.filters +0 -6
  75. data/lib/uia.rb +23 -117
  76. data/lib/uia/element.rb +38 -0
  77. data/lib/uia/library.rb +60 -0
  78. data/lib/uia/library/constants.rb +85 -0
  79. data/lib/uia/library/structs.rb +85 -0
  80. data/lib/uia/version.rb +1 -1
  81. data/spec/app/FizzWare.NBuilder.dll +0 -0
  82. data/spec/app/UIA.Extensions.dll +0 -0
  83. data/spec/app/WindowsForms.exe +0 -0
  84. data/spec/spec_helper.rb +21 -0
  85. data/spec/uia/element_spec.rb +56 -0
  86. data/spec/uia_spec.rb +28 -0
  87. data/uia.gemspec +13 -10
  88. metadata +134 -8
  89. data/ext/UiaDll/UiaDll/ArrayHelper.cpp +0 -22
  90. data/ext/UiaDll/UiaDll/StringHelper.cpp +0 -17
@@ -0,0 +1,674 @@
1
+ $$ -*- mode: c++; -*-
2
+ $$ This is a Pump source file. Please use Pump to convert it to
3
+ $$ gmock-generated-actions.h.
4
+ $$
5
+ $var n = 10 $$ The maximum arity we support.
6
+ $$ }} This line fixes auto-indentation of the following code in Emacs.
7
+ // Copyright 2008, Google Inc.
8
+ // All rights reserved.
9
+ //
10
+ // Redistribution and use in source and binary forms, with or without
11
+ // modification, are permitted provided that the following conditions are
12
+ // met:
13
+ //
14
+ // * Redistributions of source code must retain the above copyright
15
+ // notice, this list of conditions and the following disclaimer.
16
+ // * Redistributions in binary form must reproduce the above
17
+ // copyright notice, this list of conditions and the following disclaimer
18
+ // in the documentation and/or other materials provided with the
19
+ // distribution.
20
+ // * Neither the name of Google Inc. nor the names of its
21
+ // contributors may be used to endorse or promote products derived from
22
+ // this software without specific prior written permission.
23
+ //
24
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
+
36
+ // Google Mock - a framework for writing C++ mock classes.
37
+ //
38
+ // This file implements some commonly used variadic matchers.
39
+
40
+ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
41
+ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
42
+
43
+ #include <iterator>
44
+ #include <sstream>
45
+ #include <string>
46
+ #include <vector>
47
+ #include "gmock/gmock-matchers.h"
48
+
49
+ namespace testing {
50
+ namespace internal {
51
+
52
+ $range i 0..n-1
53
+
54
+ // The type of the i-th (0-based) field of Tuple.
55
+ #define GMOCK_FIELD_TYPE_(Tuple, i) \
56
+ typename ::std::tr1::tuple_element<i, Tuple>::type
57
+
58
+ // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
59
+ // tuple of type Tuple. It has two members:
60
+ //
61
+ // type: a tuple type whose i-th field is the ki-th field of Tuple.
62
+ // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
63
+ //
64
+ // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
65
+ //
66
+ // type is tuple<int, bool>, and
67
+ // GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
68
+
69
+ template <class Tuple$for i [[, int k$i = -1]]>
70
+ class TupleFields;
71
+
72
+ // This generic version is used when there are $n selectors.
73
+ template <class Tuple$for i [[, int k$i]]>
74
+ class TupleFields {
75
+ public:
76
+ typedef ::std::tr1::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type;
77
+ static type GetSelectedFields(const Tuple& t) {
78
+ using ::std::tr1::get;
79
+ return type($for i, [[get<k$i>(t)]]);
80
+ }
81
+ };
82
+
83
+ // The following specialization is used for 0 ~ $(n-1) selectors.
84
+
85
+ $for i [[
86
+ $$ }}}
87
+ $range j 0..i-1
88
+ $range k 0..n-1
89
+
90
+ template <class Tuple$for j [[, int k$j]]>
91
+ class TupleFields<Tuple, $for k, [[$if k < i [[k$k]] $else [[-1]]]]> {
92
+ public:
93
+ typedef ::std::tr1::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type;
94
+ static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) {
95
+ using ::std::tr1::get;
96
+ return type($for j, [[get<k$j>(t)]]);
97
+ }
98
+ };
99
+
100
+ ]]
101
+
102
+ #undef GMOCK_FIELD_TYPE_
103
+
104
+ // Implements the Args() matcher.
105
+
106
+ $var ks = [[$for i, [[k$i]]]]
107
+ template <class ArgsTuple$for i [[, int k$i = -1]]>
108
+ class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
109
+ public:
110
+ // ArgsTuple may have top-level const or reference modifiers.
111
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
112
+ typedef typename internal::TupleFields<RawArgsTuple, $ks>::type SelectedArgs;
113
+ typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
114
+
115
+ template <typename InnerMatcher>
116
+ explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
117
+ : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
118
+
119
+ virtual bool MatchAndExplain(ArgsTuple args,
120
+ MatchResultListener* listener) const {
121
+ const SelectedArgs& selected_args = GetSelectedArgs(args);
122
+ if (!listener->IsInterested())
123
+ return inner_matcher_.Matches(selected_args);
124
+
125
+ PrintIndices(listener->stream());
126
+ *listener << "are " << PrintToString(selected_args);
127
+
128
+ StringMatchResultListener inner_listener;
129
+ const bool match = inner_matcher_.MatchAndExplain(selected_args,
130
+ &inner_listener);
131
+ PrintIfNotEmpty(inner_listener.str(), listener->stream());
132
+ return match;
133
+ }
134
+
135
+ virtual void DescribeTo(::std::ostream* os) const {
136
+ *os << "are a tuple ";
137
+ PrintIndices(os);
138
+ inner_matcher_.DescribeTo(os);
139
+ }
140
+
141
+ virtual void DescribeNegationTo(::std::ostream* os) const {
142
+ *os << "are a tuple ";
143
+ PrintIndices(os);
144
+ inner_matcher_.DescribeNegationTo(os);
145
+ }
146
+
147
+ private:
148
+ static SelectedArgs GetSelectedArgs(ArgsTuple args) {
149
+ return TupleFields<RawArgsTuple, $ks>::GetSelectedFields(args);
150
+ }
151
+
152
+ // Prints the indices of the selected fields.
153
+ static void PrintIndices(::std::ostream* os) {
154
+ *os << "whose fields (";
155
+ const int indices[$n] = { $ks };
156
+ for (int i = 0; i < $n; i++) {
157
+ if (indices[i] < 0)
158
+ break;
159
+
160
+ if (i >= 1)
161
+ *os << ", ";
162
+
163
+ *os << "#" << indices[i];
164
+ }
165
+ *os << ") ";
166
+ }
167
+
168
+ const MonomorphicInnerMatcher inner_matcher_;
169
+
170
+ GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
171
+ };
172
+
173
+ template <class InnerMatcher$for i [[, int k$i = -1]]>
174
+ class ArgsMatcher {
175
+ public:
176
+ explicit ArgsMatcher(const InnerMatcher& inner_matcher)
177
+ : inner_matcher_(inner_matcher) {}
178
+
179
+ template <typename ArgsTuple>
180
+ operator Matcher<ArgsTuple>() const {
181
+ return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, $ks>(inner_matcher_));
182
+ }
183
+
184
+ private:
185
+ const InnerMatcher inner_matcher_;
186
+
187
+ GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
188
+ };
189
+
190
+ // A set of metafunctions for computing the result type of AllOf.
191
+ // AllOf(m1, ..., mN) returns
192
+ // AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
193
+
194
+ // Although AllOf isn't defined for one argument, AllOfResult1 is defined
195
+ // to simplify the implementation.
196
+ template <typename M1>
197
+ struct AllOfResult1 {
198
+ typedef M1 type;
199
+ };
200
+
201
+ $range i 1..n
202
+
203
+ $range i 2..n
204
+ $for i [[
205
+ $range j 2..i
206
+ $var m = i/2
207
+ $range k 1..m
208
+ $range t m+1..i
209
+
210
+ template <typename M1$for j [[, typename M$j]]>
211
+ struct AllOfResult$i {
212
+ typedef BothOfMatcher<
213
+ typename AllOfResult$m<$for k, [[M$k]]>::type,
214
+ typename AllOfResult$(i-m)<$for t, [[M$t]]>::type
215
+ > type;
216
+ };
217
+
218
+ ]]
219
+
220
+ // A set of metafunctions for computing the result type of AnyOf.
221
+ // AnyOf(m1, ..., mN) returns
222
+ // AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
223
+
224
+ // Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
225
+ // to simplify the implementation.
226
+ template <typename M1>
227
+ struct AnyOfResult1 {
228
+ typedef M1 type;
229
+ };
230
+
231
+ $range i 1..n
232
+
233
+ $range i 2..n
234
+ $for i [[
235
+ $range j 2..i
236
+ $var m = i/2
237
+ $range k 1..m
238
+ $range t m+1..i
239
+
240
+ template <typename M1$for j [[, typename M$j]]>
241
+ struct AnyOfResult$i {
242
+ typedef EitherOfMatcher<
243
+ typename AnyOfResult$m<$for k, [[M$k]]>::type,
244
+ typename AnyOfResult$(i-m)<$for t, [[M$t]]>::type
245
+ > type;
246
+ };
247
+
248
+ ]]
249
+
250
+ } // namespace internal
251
+
252
+ // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
253
+ // fields of it matches a_matcher. C++ doesn't support default
254
+ // arguments for function templates, so we have to overload it.
255
+
256
+ $range i 0..n
257
+ $for i [[
258
+ $range j 1..i
259
+ template <$for j [[int k$j, ]]typename InnerMatcher>
260
+ inline internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]>
261
+ Args(const InnerMatcher& matcher) {
262
+ return internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]>(matcher);
263
+ }
264
+
265
+
266
+ ]]
267
+ // ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
268
+ // n elements, where the i-th element in the container must
269
+ // match the i-th argument in the list. Each argument of
270
+ // ElementsAre() can be either a value or a matcher. We support up to
271
+ // $n arguments.
272
+ //
273
+ // The use of DecayArray in the implementation allows ElementsAre()
274
+ // to accept string literals, whose type is const char[N], but we
275
+ // want to treat them as const char*.
276
+ //
277
+ // NOTE: Since ElementsAre() cares about the order of the elements, it
278
+ // must not be used with containers whose elements's order is
279
+ // undefined (e.g. hash_map).
280
+
281
+ $range i 0..n
282
+ $for i [[
283
+
284
+ $range j 1..i
285
+
286
+ $if i>0 [[
287
+
288
+ template <$for j, [[typename T$j]]>
289
+ ]]
290
+
291
+ inline internal::ElementsAreMatcher<
292
+ std::tr1::tuple<
293
+ $for j, [[
294
+
295
+ typename internal::DecayArray<T$j[[]]>::type]]> >
296
+ ElementsAre($for j, [[const T$j& e$j]]) {
297
+ typedef std::tr1::tuple<
298
+ $for j, [[
299
+
300
+ typename internal::DecayArray<T$j[[]]>::type]]> Args;
301
+ return internal::ElementsAreMatcher<Args>(Args($for j, [[e$j]]));
302
+ }
303
+
304
+ ]]
305
+
306
+ // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
307
+ // that matches n elements in any order. We support up to n=$n arguments.
308
+
309
+ $range i 0..n
310
+ $for i [[
311
+
312
+ $range j 1..i
313
+
314
+ $if i>0 [[
315
+
316
+ template <$for j, [[typename T$j]]>
317
+ ]]
318
+
319
+ inline internal::UnorderedElementsAreMatcher<
320
+ std::tr1::tuple<
321
+ $for j, [[
322
+
323
+ typename internal::DecayArray<T$j[[]]>::type]]> >
324
+ UnorderedElementsAre($for j, [[const T$j& e$j]]) {
325
+ typedef std::tr1::tuple<
326
+ $for j, [[
327
+
328
+ typename internal::DecayArray<T$j[[]]>::type]]> Args;
329
+ return internal::UnorderedElementsAreMatcher<Args>(Args($for j, [[e$j]]));
330
+ }
331
+
332
+ ]]
333
+
334
+ // AllOf(m1, m2, ..., mk) matches any value that matches all of the given
335
+ // sub-matchers. AllOf is called fully qualified to prevent ADL from firing.
336
+
337
+ $range i 2..n
338
+ $for i [[
339
+ $range j 1..i
340
+ $var m = i/2
341
+ $range k 1..m
342
+ $range t m+1..i
343
+
344
+ template <$for j, [[typename M$j]]>
345
+ inline typename internal::AllOfResult$i<$for j, [[M$j]]>::type
346
+ AllOf($for j, [[M$j m$j]]) {
347
+ return typename internal::AllOfResult$i<$for j, [[M$j]]>::type(
348
+ $if m == 1 [[m1]] $else [[::testing::AllOf($for k, [[m$k]])]],
349
+ $if m+1 == i [[m$i]] $else [[::testing::AllOf($for t, [[m$t]])]]);
350
+ }
351
+
352
+ ]]
353
+
354
+ // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
355
+ // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
356
+
357
+ $range i 2..n
358
+ $for i [[
359
+ $range j 1..i
360
+ $var m = i/2
361
+ $range k 1..m
362
+ $range t m+1..i
363
+
364
+ template <$for j, [[typename M$j]]>
365
+ inline typename internal::AnyOfResult$i<$for j, [[M$j]]>::type
366
+ AnyOf($for j, [[M$j m$j]]) {
367
+ return typename internal::AnyOfResult$i<$for j, [[M$j]]>::type(
368
+ $if m == 1 [[m1]] $else [[::testing::AnyOf($for k, [[m$k]])]],
369
+ $if m+1 == i [[m$i]] $else [[::testing::AnyOf($for t, [[m$t]])]]);
370
+ }
371
+
372
+ ]]
373
+
374
+ } // namespace testing
375
+ $$ } // This Pump meta comment fixes auto-indentation in Emacs. It will not
376
+ $$ // show up in the generated code.
377
+
378
+
379
+ // The MATCHER* family of macros can be used in a namespace scope to
380
+ // define custom matchers easily.
381
+ //
382
+ // Basic Usage
383
+ // ===========
384
+ //
385
+ // The syntax
386
+ //
387
+ // MATCHER(name, description_string) { statements; }
388
+ //
389
+ // defines a matcher with the given name that executes the statements,
390
+ // which must return a bool to indicate if the match succeeds. Inside
391
+ // the statements, you can refer to the value being matched by 'arg',
392
+ // and refer to its type by 'arg_type'.
393
+ //
394
+ // The description string documents what the matcher does, and is used
395
+ // to generate the failure message when the match fails. Since a
396
+ // MATCHER() is usually defined in a header file shared by multiple
397
+ // C++ source files, we require the description to be a C-string
398
+ // literal to avoid possible side effects. It can be empty, in which
399
+ // case we'll use the sequence of words in the matcher name as the
400
+ // description.
401
+ //
402
+ // For example:
403
+ //
404
+ // MATCHER(IsEven, "") { return (arg % 2) == 0; }
405
+ //
406
+ // allows you to write
407
+ //
408
+ // // Expects mock_foo.Bar(n) to be called where n is even.
409
+ // EXPECT_CALL(mock_foo, Bar(IsEven()));
410
+ //
411
+ // or,
412
+ //
413
+ // // Verifies that the value of some_expression is even.
414
+ // EXPECT_THAT(some_expression, IsEven());
415
+ //
416
+ // If the above assertion fails, it will print something like:
417
+ //
418
+ // Value of: some_expression
419
+ // Expected: is even
420
+ // Actual: 7
421
+ //
422
+ // where the description "is even" is automatically calculated from the
423
+ // matcher name IsEven.
424
+ //
425
+ // Argument Type
426
+ // =============
427
+ //
428
+ // Note that the type of the value being matched (arg_type) is
429
+ // determined by the context in which you use the matcher and is
430
+ // supplied to you by the compiler, so you don't need to worry about
431
+ // declaring it (nor can you). This allows the matcher to be
432
+ // polymorphic. For example, IsEven() can be used to match any type
433
+ // where the value of "(arg % 2) == 0" can be implicitly converted to
434
+ // a bool. In the "Bar(IsEven())" example above, if method Bar()
435
+ // takes an int, 'arg_type' will be int; if it takes an unsigned long,
436
+ // 'arg_type' will be unsigned long; and so on.
437
+ //
438
+ // Parameterizing Matchers
439
+ // =======================
440
+ //
441
+ // Sometimes you'll want to parameterize the matcher. For that you
442
+ // can use another macro:
443
+ //
444
+ // MATCHER_P(name, param_name, description_string) { statements; }
445
+ //
446
+ // For example:
447
+ //
448
+ // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
449
+ //
450
+ // will allow you to write:
451
+ //
452
+ // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
453
+ //
454
+ // which may lead to this message (assuming n is 10):
455
+ //
456
+ // Value of: Blah("a")
457
+ // Expected: has absolute value 10
458
+ // Actual: -9
459
+ //
460
+ // Note that both the matcher description and its parameter are
461
+ // printed, making the message human-friendly.
462
+ //
463
+ // In the matcher definition body, you can write 'foo_type' to
464
+ // reference the type of a parameter named 'foo'. For example, in the
465
+ // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
466
+ // 'value_type' to refer to the type of 'value'.
467
+ //
468
+ // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P$n to
469
+ // support multi-parameter matchers.
470
+ //
471
+ // Describing Parameterized Matchers
472
+ // =================================
473
+ //
474
+ // The last argument to MATCHER*() is a string-typed expression. The
475
+ // expression can reference all of the matcher's parameters and a
476
+ // special bool-typed variable named 'negation'. When 'negation' is
477
+ // false, the expression should evaluate to the matcher's description;
478
+ // otherwise it should evaluate to the description of the negation of
479
+ // the matcher. For example,
480
+ //
481
+ // using testing::PrintToString;
482
+ //
483
+ // MATCHER_P2(InClosedRange, low, hi,
484
+ // string(negation ? "is not" : "is") + " in range [" +
485
+ // PrintToString(low) + ", " + PrintToString(hi) + "]") {
486
+ // return low <= arg && arg <= hi;
487
+ // }
488
+ // ...
489
+ // EXPECT_THAT(3, InClosedRange(4, 6));
490
+ // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
491
+ //
492
+ // would generate two failures that contain the text:
493
+ //
494
+ // Expected: is in range [4, 6]
495
+ // ...
496
+ // Expected: is not in range [2, 4]
497
+ //
498
+ // If you specify "" as the description, the failure message will
499
+ // contain the sequence of words in the matcher name followed by the
500
+ // parameter values printed as a tuple. For example,
501
+ //
502
+ // MATCHER_P2(InClosedRange, low, hi, "") { ... }
503
+ // ...
504
+ // EXPECT_THAT(3, InClosedRange(4, 6));
505
+ // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
506
+ //
507
+ // would generate two failures that contain the text:
508
+ //
509
+ // Expected: in closed range (4, 6)
510
+ // ...
511
+ // Expected: not (in closed range (2, 4))
512
+ //
513
+ // Types of Matcher Parameters
514
+ // ===========================
515
+ //
516
+ // For the purpose of typing, you can view
517
+ //
518
+ // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
519
+ //
520
+ // as shorthand for
521
+ //
522
+ // template <typename p1_type, ..., typename pk_type>
523
+ // FooMatcherPk<p1_type, ..., pk_type>
524
+ // Foo(p1_type p1, ..., pk_type pk) { ... }
525
+ //
526
+ // When you write Foo(v1, ..., vk), the compiler infers the types of
527
+ // the parameters v1, ..., and vk for you. If you are not happy with
528
+ // the result of the type inference, you can specify the types by
529
+ // explicitly instantiating the template, as in Foo<long, bool>(5,
530
+ // false). As said earlier, you don't get to (or need to) specify
531
+ // 'arg_type' as that's determined by the context in which the matcher
532
+ // is used. You can assign the result of expression Foo(p1, ..., pk)
533
+ // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
534
+ // can be useful when composing matchers.
535
+ //
536
+ // While you can instantiate a matcher template with reference types,
537
+ // passing the parameters by pointer usually makes your code more
538
+ // readable. If, however, you still want to pass a parameter by
539
+ // reference, be aware that in the failure message generated by the
540
+ // matcher you will see the value of the referenced object but not its
541
+ // address.
542
+ //
543
+ // Explaining Match Results
544
+ // ========================
545
+ //
546
+ // Sometimes the matcher description alone isn't enough to explain why
547
+ // the match has failed or succeeded. For example, when expecting a
548
+ // long string, it can be very helpful to also print the diff between
549
+ // the expected string and the actual one. To achieve that, you can
550
+ // optionally stream additional information to a special variable
551
+ // named result_listener, whose type is a pointer to class
552
+ // MatchResultListener:
553
+ //
554
+ // MATCHER_P(EqualsLongString, str, "") {
555
+ // if (arg == str) return true;
556
+ //
557
+ // *result_listener << "the difference: "
558
+ /// << DiffStrings(str, arg);
559
+ // return false;
560
+ // }
561
+ //
562
+ // Overloading Matchers
563
+ // ====================
564
+ //
565
+ // You can overload matchers with different numbers of parameters:
566
+ //
567
+ // MATCHER_P(Blah, a, description_string1) { ... }
568
+ // MATCHER_P2(Blah, a, b, description_string2) { ... }
569
+ //
570
+ // Caveats
571
+ // =======
572
+ //
573
+ // When defining a new matcher, you should also consider implementing
574
+ // MatcherInterface or using MakePolymorphicMatcher(). These
575
+ // approaches require more work than the MATCHER* macros, but also
576
+ // give you more control on the types of the value being matched and
577
+ // the matcher parameters, which may leads to better compiler error
578
+ // messages when the matcher is used wrong. They also allow
579
+ // overloading matchers based on parameter types (as opposed to just
580
+ // based on the number of parameters).
581
+ //
582
+ // MATCHER*() can only be used in a namespace scope. The reason is
583
+ // that C++ doesn't yet allow function-local types to be used to
584
+ // instantiate templates. The up-coming C++0x standard will fix this.
585
+ // Once that's done, we'll consider supporting using MATCHER*() inside
586
+ // a function.
587
+ //
588
+ // More Information
589
+ // ================
590
+ //
591
+ // To learn more about using these macros, please search for 'MATCHER'
592
+ // on http://code.google.com/p/googlemock/wiki/CookBook.
593
+
594
+ $range i 0..n
595
+ $for i
596
+
597
+ [[
598
+ $var macro_name = [[$if i==0 [[MATCHER]] $elif i==1 [[MATCHER_P]]
599
+ $else [[MATCHER_P$i]]]]
600
+ $var class_name = [[name##Matcher[[$if i==0 [[]] $elif i==1 [[P]]
601
+ $else [[P$i]]]]]]
602
+ $range j 0..i-1
603
+ $var template = [[$if i==0 [[]] $else [[
604
+
605
+ template <$for j, [[typename p$j##_type]]>\
606
+ ]]]]
607
+ $var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
608
+ $var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
609
+ $var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
610
+ $var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
611
+ $var params = [[$for j, [[p$j]]]]
612
+ $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
613
+ $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
614
+ $var param_field_decls = [[$for j
615
+ [[
616
+
617
+ p$j##_type p$j;\
618
+ ]]]]
619
+ $var param_field_decls2 = [[$for j
620
+ [[
621
+
622
+ p$j##_type p$j;\
623
+ ]]]]
624
+
625
+ #define $macro_name(name$for j [[, p$j]], description)\$template
626
+ class $class_name {\
627
+ public:\
628
+ template <typename arg_type>\
629
+ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
630
+ public:\
631
+ [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\
632
+ $impl_inits {}\
633
+ virtual bool MatchAndExplain(\
634
+ arg_type arg, ::testing::MatchResultListener* result_listener) const;\
635
+ virtual void DescribeTo(::std::ostream* gmock_os) const {\
636
+ *gmock_os << FormatDescription(false);\
637
+ }\
638
+ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
639
+ *gmock_os << FormatDescription(true);\
640
+ }\$param_field_decls
641
+ private:\
642
+ ::testing::internal::string FormatDescription(bool negation) const {\
643
+ const ::testing::internal::string gmock_description = (description);\
644
+ if (!gmock_description.empty())\
645
+ return gmock_description;\
646
+ return ::testing::internal::FormatMatcherDescription(\
647
+ negation, #name, \
648
+ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
649
+ ::std::tr1::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
650
+ }\
651
+ GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
652
+ };\
653
+ template <typename arg_type>\
654
+ operator ::testing::Matcher<arg_type>() const {\
655
+ return ::testing::Matcher<arg_type>(\
656
+ new gmock_Impl<arg_type>($params));\
657
+ }\
658
+ $class_name($ctor_param_list)$inits {\
659
+ }\$param_field_decls2
660
+ private:\
661
+ GTEST_DISALLOW_ASSIGN_($class_name);\
662
+ };\$template
663
+ inline $class_name$param_types name($param_types_and_names) {\
664
+ return $class_name$param_types($params);\
665
+ }\$template
666
+ template <typename arg_type>\
667
+ bool $class_name$param_types::gmock_Impl<arg_type>::MatchAndExplain(\
668
+ arg_type arg, \
669
+ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
670
+ const
671
+ ]]
672
+
673
+
674
+ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_