tesseract v5.3.3.20231005
cpp.gmock_class_test.GenerateMethodsTest Class Reference
Inheritance diagram for cpp.gmock_class_test.GenerateMethodsTest:
cpp.gmock_class_test.TestCase

Public Member Functions

def testSimpleMethod (self)
 
def testSimpleConstructorsAndDestructor (self)
 
def testVirtualDestructor (self)
 
def testExplicitlyDefaultedConstructorsAndDestructor (self)
 
def testExplicitlyDeletedConstructorsAndDestructor (self)
 
def testSimpleOverrideMethod (self)
 
def testSimpleConstMethod (self)
 
def testExplicitVoid (self)
 
def testStrangeNewlineInParameter (self)
 
def testDefaultParameters (self)
 
def testMultipleDefaultParameters (self)
 
def testMultipleSingleLineDefaultParameters (self)
 
def testConstDefaultParameter (self)
 
def testConstRefDefaultParameter (self)
 
def testRemovesCommentsWhenDefaultsArePresent (self)
 
def testDoubleSlashCommentsInParameterListAreRemoved (self)
 
def testCStyleCommentsInParameterListAreNotRemoved (self)
 
def testArgsOfTemplateTypes (self)
 
def testReturnTypeWithOneTemplateArg (self)
 
def testReturnTypeWithManyTemplateArgs (self)
 
def testSimpleMethodInTemplatedClass (self)
 
def testPointerArgWithoutNames (self)
 
def testReferenceArgWithoutNames (self)
 
def testArrayArgWithoutNames (self)
 
- Public Member Functions inherited from cpp.gmock_class_test.TestCase
def assertEqualIgnoreLeadingWhitespace (self, expected_lines, lines)
 

Static Public Member Functions

def GenerateMethodSource (cpp_source)
 
- Static Public Member Functions inherited from cpp.gmock_class_test.TestCase
def StripLeadingWhitespace (lines)
 

Detailed Description

Definition at line 44 of file gmock_class_test.py.

Member Function Documentation

◆ GenerateMethodSource()

def cpp.gmock_class_test.GenerateMethodsTest.GenerateMethodSource (   cpp_source)
static
Convert C++ source to Google Mock output source lines.

Definition at line 47 of file gmock_class_test.py.

47 def GenerateMethodSource(cpp_source):
48 """Convert C++ source to Google Mock output source lines."""
49 method_source_lines = []
50 # <test> is a pseudo-filename, it is not read or written.
51 builder = ast.BuilderFromSource(cpp_source, '<test>')
52 ast_list = list(builder.Generate())
53 gmock_class._GenerateMethods(method_source_lines, cpp_source, ast_list[0])
54 return '\n'.join(method_source_lines)
55

◆ testArgsOfTemplateTypes()

def cpp.gmock_class_test.GenerateMethodsTest.testArgsOfTemplateTypes (   self)

Definition at line 275 of file gmock_class_test.py.

275 def testArgsOfTemplateTypes(self):
276 source = """
277class Foo {
278 public:
279 virtual int Bar(const vector<int>& v, map<int, string>* output);
280};"""
281 self.assertEqualIgnoreLeadingWhitespace(
282 'MOCK_METHOD(int, Bar, (const vector<int>& v, (map<int, string>* output)), (override));',
283 self.GenerateMethodSource(source))
284

◆ testArrayArgWithoutNames()

def cpp.gmock_class_test.GenerateMethodsTest.testArrayArgWithoutNames (   self)

Definition at line 337 of file gmock_class_test.py.

337 def testArrayArgWithoutNames(self):
338 source = """
339class Foo {
340 virtual int Bar(C[]);
341};
342"""
343 self.assertEqualIgnoreLeadingWhitespace(
344 'MOCK_METHOD(int, Bar, (C[]), (override));',
345 self.GenerateMethodSource(source))
346
347

◆ testConstDefaultParameter()

def cpp.gmock_class_test.GenerateMethodsTest.testConstDefaultParameter (   self)

Definition at line 214 of file gmock_class_test.py.

214 def testConstDefaultParameter(self):
215 source = """
216class Test {
217 public:
218 virtual bool Bar(const int test_arg = 42) = 0;
219};
220"""
221 self.assertEqualIgnoreLeadingWhitespace(
222 'MOCK_METHOD(bool, Bar, (const int test_arg), (override));',
223 self.GenerateMethodSource(source))
224

◆ testConstRefDefaultParameter()

def cpp.gmock_class_test.GenerateMethodsTest.testConstRefDefaultParameter (   self)

Definition at line 225 of file gmock_class_test.py.

225 def testConstRefDefaultParameter(self):
226 source = """
227class Test {
228 public:
229 virtual bool Bar(const std::string& test_arg = "42" ) = 0;
230};
231"""
232 self.assertEqualIgnoreLeadingWhitespace(
233 'MOCK_METHOD(bool, Bar, (const std::string& test_arg), (override));',
234 self.GenerateMethodSource(source))
235

◆ testCStyleCommentsInParameterListAreNotRemoved()

def cpp.gmock_class_test.GenerateMethodsTest.testCStyleCommentsInParameterListAreNotRemoved (   self)

Definition at line 261 of file gmock_class_test.py.

261 def testCStyleCommentsInParameterListAreNotRemoved(self):
262 # NOTE(nnorwitz): I'm not sure if it's the best behavior to keep these
263 # comments. Also note that C style comments after the last parameter
264 # are still elided.
265 source = """
266class Foo {
267 public:
268 virtual const string& Bar(int /* keeper */, int b);
269};
270"""
271 self.assertEqualIgnoreLeadingWhitespace(
272 'MOCK_METHOD(const string&, Bar, (int, int b), (override));',
273 self.GenerateMethodSource(source))
274

◆ testDefaultParameters()

def cpp.gmock_class_test.GenerateMethodsTest.testDefaultParameters (   self)

Definition at line 174 of file gmock_class_test.py.

174 def testDefaultParameters(self):
175 source = """
176class Foo {
177 public:
178 virtual void Bar(int a, char c = 'x') = 0;
179};
180"""
181 self.assertEqualIgnoreLeadingWhitespace(
182 'MOCK_METHOD(void, Bar, (int a, char c), (override));',
183 self.GenerateMethodSource(source))
184

◆ testDoubleSlashCommentsInParameterListAreRemoved()

def cpp.gmock_class_test.GenerateMethodsTest.testDoubleSlashCommentsInParameterListAreRemoved (   self)

Definition at line 248 of file gmock_class_test.py.

248 def testDoubleSlashCommentsInParameterListAreRemoved(self):
249 source = """
250class Foo {
251 public:
252 virtual void Bar(int a, // inline comments should be elided.
253 int b // inline comments should be elided.
254 ) const = 0;
255};
256"""
257 self.assertEqualIgnoreLeadingWhitespace(
258 'MOCK_METHOD(void, Bar, (int a, int b), (const, override));',
259 self.GenerateMethodSource(source))
260

◆ testExplicitlyDefaultedConstructorsAndDestructor()

def cpp.gmock_class_test.GenerateMethodsTest.testExplicitlyDefaultedConstructorsAndDestructor (   self)

Definition at line 97 of file gmock_class_test.py.

97 def testExplicitlyDefaultedConstructorsAndDestructor(self):
98 source = """
99class Foo {
100 public:
101 Foo() = default;
102 Foo(const Foo& f) = default;
103 Foo(Foo&& f) = default;
104 ~Foo() = default;
105 virtual int Bar() = 0;
106};
107"""
108 # The constructors and destructor should be ignored.
109 self.assertEqualIgnoreLeadingWhitespace(
110 'MOCK_METHOD(int, Bar, (), (override));',
111 self.GenerateMethodSource(source))
112

◆ testExplicitlyDeletedConstructorsAndDestructor()

def cpp.gmock_class_test.GenerateMethodsTest.testExplicitlyDeletedConstructorsAndDestructor (   self)

Definition at line 113 of file gmock_class_test.py.

113 def testExplicitlyDeletedConstructorsAndDestructor(self):
114 source = """
115class Foo {
116 public:
117 Foo() = delete;
118 Foo(const Foo& f) = delete;
119 Foo(Foo&& f) = delete;
120 ~Foo() = delete;
121 virtual int Bar() = 0;
122};
123"""
124 # The constructors and destructor should be ignored.
125 self.assertEqualIgnoreLeadingWhitespace(
126 'MOCK_METHOD(int, Bar, (), (override));',
127 self.GenerateMethodSource(source))
128

◆ testExplicitVoid()

def cpp.gmock_class_test.GenerateMethodsTest.testExplicitVoid (   self)

Definition at line 151 of file gmock_class_test.py.

151 def testExplicitVoid(self):
152 source = """
153class Foo {
154 public:
155 virtual int Bar(void);
156};
157"""
158 self.assertEqualIgnoreLeadingWhitespace(
159 'MOCK_METHOD(int, Bar, (), (override));',
160 self.GenerateMethodSource(source))
161

◆ testMultipleDefaultParameters()

def cpp.gmock_class_test.GenerateMethodsTest.testMultipleDefaultParameters (   self)

Definition at line 185 of file gmock_class_test.py.

185 def testMultipleDefaultParameters(self):
186 source = """
187class Foo {
188 public:
189 virtual void Bar(
190 int a = 42,
191 char c = 'x',
192 const int* const p = nullptr,
193 const std::string& s = "42",
194 char tab[] = {'4','2'},
195 int const *& rp = aDefaultPointer) = 0;
196};
197"""
198 self.assertEqualIgnoreLeadingWhitespace(
199 'MOCK_METHOD(void, Bar, '
200 '(int a, char c, const int* const p, const std::string& s, char tab[], int const *& rp), '
201 '(override));', self.GenerateMethodSource(source))
202

◆ testMultipleSingleLineDefaultParameters()

def cpp.gmock_class_test.GenerateMethodsTest.testMultipleSingleLineDefaultParameters (   self)

Definition at line 203 of file gmock_class_test.py.

203 def testMultipleSingleLineDefaultParameters(self):
204 source = """
205class Foo {
206 public:
207 virtual void Bar(int a = 42, int b = 43, int c = 44) = 0;
208};
209"""
210 self.assertEqualIgnoreLeadingWhitespace(
211 'MOCK_METHOD(void, Bar, (int a, int b, int c), (override));',
212 self.GenerateMethodSource(source))
213

◆ testPointerArgWithoutNames()

def cpp.gmock_class_test.GenerateMethodsTest.testPointerArgWithoutNames (   self)

Definition at line 317 of file gmock_class_test.py.

317 def testPointerArgWithoutNames(self):
318 source = """
319class Foo {
320 virtual int Bar(C*);
321};
322"""
323 self.assertEqualIgnoreLeadingWhitespace(
324 'MOCK_METHOD(int, Bar, (C*), (override));',
325 self.GenerateMethodSource(source))
326

◆ testReferenceArgWithoutNames()

def cpp.gmock_class_test.GenerateMethodsTest.testReferenceArgWithoutNames (   self)

Definition at line 327 of file gmock_class_test.py.

327 def testReferenceArgWithoutNames(self):
328 source = """
329class Foo {
330 virtual int Bar(C&);
331};
332"""
333 self.assertEqualIgnoreLeadingWhitespace(
334 'MOCK_METHOD(int, Bar, (C&), (override));',
335 self.GenerateMethodSource(source))
336

◆ testRemovesCommentsWhenDefaultsArePresent()

def cpp.gmock_class_test.GenerateMethodsTest.testRemovesCommentsWhenDefaultsArePresent (   self)

Definition at line 236 of file gmock_class_test.py.

236 def testRemovesCommentsWhenDefaultsArePresent(self):
237 source = """
238class Foo {
239 public:
240 virtual void Bar(int a = 42 /* a comment */,
241 char /* other comment */ c= 'x') = 0;
242};
243"""
244 self.assertEqualIgnoreLeadingWhitespace(
245 'MOCK_METHOD(void, Bar, (int a, char c), (override));',
246 self.GenerateMethodSource(source))
247

◆ testReturnTypeWithManyTemplateArgs()

def cpp.gmock_class_test.GenerateMethodsTest.testReturnTypeWithManyTemplateArgs (   self)

Definition at line 295 of file gmock_class_test.py.

295 def testReturnTypeWithManyTemplateArgs(self):
296 source = """
297class Foo {
298 public:
299 virtual map<int, string> Bar();
300};"""
301 self.assertEqualIgnoreLeadingWhitespace(
302 'MOCK_METHOD((map<int, string>), Bar, (), (override));',
303 self.GenerateMethodSource(source))
304

◆ testReturnTypeWithOneTemplateArg()

def cpp.gmock_class_test.GenerateMethodsTest.testReturnTypeWithOneTemplateArg (   self)

Definition at line 285 of file gmock_class_test.py.

285 def testReturnTypeWithOneTemplateArg(self):
286 source = """
287class Foo {
288 public:
289 virtual vector<int>* Bar(int n);
290};"""
291 self.assertEqualIgnoreLeadingWhitespace(
292 'MOCK_METHOD(vector<int>*, Bar, (int n), (override));',
293 self.GenerateMethodSource(source))
294

◆ testSimpleConstMethod()

def cpp.gmock_class_test.GenerateMethodsTest.testSimpleConstMethod (   self)

Definition at line 140 of file gmock_class_test.py.

140 def testSimpleConstMethod(self):
141 source = """
142class Foo {
143 public:
144 virtual void Bar(bool flag) const;
145};
146"""
147 self.assertEqualIgnoreLeadingWhitespace(
148 'MOCK_METHOD(void, Bar, (bool flag), (const, override));',
149 self.GenerateMethodSource(source))
150

◆ testSimpleConstructorsAndDestructor()

def cpp.gmock_class_test.GenerateMethodsTest.testSimpleConstructorsAndDestructor (   self)

Definition at line 67 of file gmock_class_test.py.

67 def testSimpleConstructorsAndDestructor(self):
68 source = """
69class Foo {
70 public:
71 Foo();
72 Foo(int x);
73 Foo(const Foo& f);
74 Foo(Foo&& f);
75 ~Foo();
76 virtual int Bar() = 0;
77};
78"""
79 # The constructors and destructor should be ignored.
80 self.assertEqualIgnoreLeadingWhitespace(
81 'MOCK_METHOD(int, Bar, (), (override));',
82 self.GenerateMethodSource(source))
83

◆ testSimpleMethod()

def cpp.gmock_class_test.GenerateMethodsTest.testSimpleMethod (   self)

Definition at line 56 of file gmock_class_test.py.

56 def testSimpleMethod(self):
57 source = """
58class Foo {
59 public:
60 virtual int Bar();
61};
62"""
63 self.assertEqualIgnoreLeadingWhitespace(
64 'MOCK_METHOD(int, Bar, (), (override));',
65 self.GenerateMethodSource(source))
66

◆ testSimpleMethodInTemplatedClass()

def cpp.gmock_class_test.GenerateMethodsTest.testSimpleMethodInTemplatedClass (   self)

Definition at line 305 of file gmock_class_test.py.

305 def testSimpleMethodInTemplatedClass(self):
306 source = """
307template<class T>
308class Foo {
309 public:
310 virtual int Bar();
311};
312"""
313 self.assertEqualIgnoreLeadingWhitespace(
314 'MOCK_METHOD(int, Bar, (), (override));',
315 self.GenerateMethodSource(source))
316

◆ testSimpleOverrideMethod()

def cpp.gmock_class_test.GenerateMethodsTest.testSimpleOverrideMethod (   self)

Definition at line 129 of file gmock_class_test.py.

129 def testSimpleOverrideMethod(self):
130 source = """
131class Foo {
132 public:
133 int Bar() override;
134};
135"""
136 self.assertEqualIgnoreLeadingWhitespace(
137 'MOCK_METHOD(int, Bar, (), (override));',
138 self.GenerateMethodSource(source))
139

◆ testStrangeNewlineInParameter()

def cpp.gmock_class_test.GenerateMethodsTest.testStrangeNewlineInParameter (   self)

Definition at line 162 of file gmock_class_test.py.

162 def testStrangeNewlineInParameter(self):
163 source = """
164class Foo {
165 public:
166 virtual void Bar(int
167a) = 0;
168};
169"""
170 self.assertEqualIgnoreLeadingWhitespace(
171 'MOCK_METHOD(void, Bar, (int a), (override));',
172 self.GenerateMethodSource(source))
173

◆ testVirtualDestructor()

def cpp.gmock_class_test.GenerateMethodsTest.testVirtualDestructor (   self)

Definition at line 84 of file gmock_class_test.py.

84 def testVirtualDestructor(self):
85 source = """
86class Foo {
87 public:
88 virtual ~Foo();
89 virtual int Bar() = 0;
90};
91"""
92 # The destructor should be ignored.
93 self.assertEqualIgnoreLeadingWhitespace(
94 'MOCK_METHOD(int, Bar, (), (override));',
95 self.GenerateMethodSource(source))
96

The documentation for this class was generated from the following file: