18 """Tests for gmock.scripts.generator.cpp.gmock_class."""
20 __author__ =
'nnorwitz@google.com (Neal Norwitz)'
28 sys.path.append(os.path.join(os.path.dirname(__file__),
'..'))
31 from cpp
import gmock_class
35 """Helper class that adds assert methods."""
38 """Strip leading whitespace in each line in 'lines'."""
39 return '\n'.
join([s.lstrip()
for s
in lines.split(
'\n')])
42 """Specialized assert that ignores the indent level."""
49 """Convert C++ source to Google Mock output source lines."""
50 method_source_lines = []
52 builder = ast.BuilderFromSource(cpp_source,
'<test>')
53 ast_list = list(builder.Generate())
54 gmock_class._GenerateMethods(method_source_lines, cpp_source, ast_list[0])
55 return '\n'.
join(method_source_lines)
65 'MOCK_METHOD0(Bar,\nint());',
77 virtual int Bar() = 0;
82 'MOCK_METHOD0(Bar,\nint());',
90 virtual int Bar() = 0;
95 'MOCK_METHOD0(Bar,\nint());',
103 Foo(const Foo& f) = default;
104 Foo(Foo&& f) = default;
106 virtual int Bar() = 0;
111 'MOCK_METHOD0(Bar,\nint());',
119 Foo(const Foo& f) = delete;
120 Foo(Foo&& f) = delete;
122 virtual int Bar() = 0;
127 'MOCK_METHOD0(Bar,\nint());',
138 'MOCK_METHOD0(Bar,\nint());',
145 virtual void Bar(bool flag) const;
149 'MOCK_CONST_METHOD1(Bar,\nvoid(bool flag));',
156 virtual int Bar(void);
160 'MOCK_METHOD0(Bar,\nint(void));',
172 'MOCK_METHOD1(Bar,\nvoid(int a));',
179 virtual void Bar(int a, char c = 'x') = 0;
183 'MOCK_METHOD2(Bar,\nvoid(int, char));',
190 virtual void Bar(int a = 42, char c = 'x') = 0;
194 'MOCK_METHOD2(Bar,\nvoid(int, char));',
201 virtual void Bar(int a = 42 /* a comment */,
202 char /* other comment */ c= 'x') = 0;
206 'MOCK_METHOD2(Bar,\nvoid(int, char));',
213 virtual void Bar(int a, // inline comments should be elided.
214 int b // inline comments should be elided.
219 'MOCK_CONST_METHOD2(Bar,\nvoid(int a, int b));',
229 virtual const string& Bar(int /* keeper */, int b);
233 'MOCK_METHOD2(Bar,\nconst string&(int /* keeper */, int b));',
240 virtual int Bar(const vector<int>& v, map<int, string>* output);
243 'MOCK_METHOD2(Bar,\n'
244 'int(const vector<int>& v, map<int, string>* output));',
251 virtual vector<int>* Bar(int n);
254 'MOCK_METHOD1(Bar,\nvector<int>*(int n));',
261 virtual map<int, string> Bar();
266 '// The following line won\'t really compile, as the return\n'
267 '// type has multiple template arguments. To fix it, use a\n'
268 '// typedef for the return type.\n'
269 'MOCK_METHOD0(Bar,\nmap<int, string>());',
281 'MOCK_METHOD0_T(Bar,\nint());',
291 'MOCK_METHOD1(Bar,\nint(C*));',
301 'MOCK_METHOD1(Bar,\nint(C&));',
307 virtual int Bar(C[]);
311 'MOCK_METHOD1(Bar,\nint(C[]));',
318 """Convert C++ source to complete Google Mock output source."""
321 builder = ast.BuilderFromSource(cpp_source, filename)
322 ast_list = list(builder.Generate())
323 lines = gmock_class._GenerateMocks(filename, cpp_source, ast_list,
None)
324 return '\n'.
join(lines)
329 namespace Bar { class Forward; }
344 class MockTest : public Test {
358 class STORAGE_SPECIFIER Test {
364 class MockTest : public Test {
375 template <class T> class Forward; // Forward declaration should be ignored.
382 class MockTest : public Test {
393 template <typename S, typename T>
400 template <typename T0, typename T1>
401 class MockTest : public Test<T0, T1> {
414 typedef std::vector<std::list<int>> FooType;
415 virtual void Bar(const FooType& test_arg);
419 class MockTest : public Test {
422 void(const FooType& test_arg));
432 typedef std::function<void(
433 const vector<std::list<int>>&, int> FooType;
434 virtual void Bar(const FooType& test_arg);
438 class MockTest : public Test {
441 void(const FooType& test_arg));
447 if __name__ ==
'__main__':