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

Public Member Functions

def testNamespaces (self)
 
def testClassWithStorageSpecifierMacro (self)
 
def testTemplatedForwardDeclaration (self)
 
def testTemplatedClass (self)
 
def testTemplateInATemplateTypedef (self)
 
def testTemplatedClassWithTemplatedArguments (self)
 
def testTemplateInATemplateTypedefWithComma (self)
 
def testParenthesizedCommaInArg (self)
 
def testEnumType (self)
 
def testEnumClassType (self)
 
def testStdFunction (self)
 
- Public Member Functions inherited from cpp.gmock_class_test.TestCase
def assertEqualIgnoreLeadingWhitespace (self, expected_lines, lines)
 

Static Public Member Functions

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

Detailed Description

Definition at line 348 of file gmock_class_test.py.

Member Function Documentation

◆ GenerateMocks()

def cpp.gmock_class_test.GenerateMocksTest.GenerateMocks (   cpp_source)
static
Convert C++ source to complete Google Mock output source.

Definition at line 351 of file gmock_class_test.py.

351 def GenerateMocks(cpp_source):
352 """Convert C++ source to complete Google Mock output source."""
353 # <test> is a pseudo-filename, it is not read or written.
354 filename = '<test>'
355 builder = ast.BuilderFromSource(cpp_source, filename)
356 ast_list = list(builder.Generate())
357 lines = gmock_class._GenerateMocks(filename, cpp_source, ast_list, None)
358 return '\n'.join(lines)
359

◆ testClassWithStorageSpecifierMacro()

def cpp.gmock_class_test.GenerateMocksTest.testClassWithStorageSpecifierMacro (   self)

Definition at line 389 of file gmock_class_test.py.

389 def testClassWithStorageSpecifierMacro(self):
390 source = """
391class STORAGE_SPECIFIER Test {
392 public:
393 virtual void Foo();
394};
395"""
396 expected = """\
397class MockTest : public Test {
398public:
399MOCK_METHOD(void, Foo, (), (override));
400};
401"""
402 self.assertEqualIgnoreLeadingWhitespace(expected,
403 self.GenerateMocks(source))
404

◆ testEnumClassType()

def cpp.gmock_class_test.GenerateMocksTest.testEnumClassType (   self)

Definition at line 528 of file gmock_class_test.py.

528 def testEnumClassType(self):
529 source = """
530class Test {
531 public:
532 enum class Bar {
533 BAZ, QUX, QUUX, QUUUX
534 };
535 virtual void Foo();
536};
537"""
538 expected = """\
539class MockTest : public Test {
540public:
541MOCK_METHOD(void, Foo, (), (override));
542};
543"""
544 self.assertEqualIgnoreLeadingWhitespace(expected,
545 self.GenerateMocks(source))
546

◆ testEnumType()

def cpp.gmock_class_test.GenerateMocksTest.testEnumType (   self)

Definition at line 509 of file gmock_class_test.py.

509 def testEnumType(self):
510 source = """
511class Test {
512 public:
513 enum Bar {
514 BAZ, QUX, QUUX, QUUUX
515 };
516 virtual void Foo();
517};
518"""
519 expected = """\
520class MockTest : public Test {
521public:
522MOCK_METHOD(void, Foo, (), (override));
523};
524"""
525 self.assertEqualIgnoreLeadingWhitespace(expected,
526 self.GenerateMocks(source))
527

◆ testNamespaces()

def cpp.gmock_class_test.GenerateMocksTest.testNamespaces (   self)

Definition at line 360 of file gmock_class_test.py.

360 def testNamespaces(self):
361 source = """
362namespace Foo {
363namespace Bar { class Forward; }
364namespace Baz::Qux {
365
366class Test {
367 public:
368 virtual void Foo();
369};
370
371} // namespace Baz::Qux
372} // namespace Foo
373"""
374 expected = """\
375namespace Foo {
376namespace Baz::Qux {
377
378class MockTest : public Test {
379public:
380MOCK_METHOD(void, Foo, (), (override));
381};
382
383} // namespace Baz::Qux
384} // namespace Foo
385"""
386 self.assertEqualIgnoreLeadingWhitespace(expected,
387 self.GenerateMocks(source))
388

◆ testParenthesizedCommaInArg()

def cpp.gmock_class_test.GenerateMocksTest.testParenthesizedCommaInArg (   self)

Definition at line 493 of file gmock_class_test.py.

493 def testParenthesizedCommaInArg(self):
494 source = """
495class Test {
496 public:
497 virtual void Bar(std::function<void(int, int)> f);
498};
499"""
500 expected = """\
501class MockTest : public Test {
502public:
503MOCK_METHOD(void, Bar, (std::function<void(int, int)> f), (override));
504};
505"""
506 self.assertEqualIgnoreLeadingWhitespace(expected,
507 self.GenerateMocks(source))
508

◆ testStdFunction()

def cpp.gmock_class_test.GenerateMocksTest.testStdFunction (   self)

Definition at line 547 of file gmock_class_test.py.

547 def testStdFunction(self):
548 source = """
549class Test {
550 public:
551 Test(std::function<int(std::string)> foo) : foo_(foo) {}
552
553 virtual std::function<int(std::string)> foo();
554
555 private:
556 std::function<int(std::string)> foo_;
557};
558"""
559 expected = """\
560class MockTest : public Test {
561public:
562MOCK_METHOD(std::function<int (std::string)>, foo, (), (override));
563};
564"""
565 self.assertEqualIgnoreLeadingWhitespace(expected,
566 self.GenerateMocks(source))
567
568

◆ testTemplatedClass()

def cpp.gmock_class_test.GenerateMocksTest.testTemplatedClass (   self)

Definition at line 422 of file gmock_class_test.py.

422 def testTemplatedClass(self):
423 source = """
424template <typename S, typename T>
425class Test {
426 public:
427 virtual void Foo();
428};
429"""
430 expected = """\
431template <typename S, typename T>
432class MockTest : public Test<S, T> {
433public:
434MOCK_METHOD(void, Foo, (), (override));
435};
436"""
437 self.assertEqualIgnoreLeadingWhitespace(expected,
438 self.GenerateMocks(source))
439

◆ testTemplatedClassWithTemplatedArguments()

def cpp.gmock_class_test.GenerateMocksTest.testTemplatedClassWithTemplatedArguments (   self)

Definition at line 457 of file gmock_class_test.py.

457 def testTemplatedClassWithTemplatedArguments(self):
458 source = """
459template <typename S, typename T, typename U, typename V, typename W>
460class Test {
461 public:
462 virtual U Foo(T some_arg);
463};
464"""
465 expected = """\
466template <typename S, typename T, typename U, typename V, typename W>
467class MockTest : public Test<S, T, U, V, W> {
468public:
469MOCK_METHOD(U, Foo, (T some_arg), (override));
470};
471"""
472 self.assertEqualIgnoreLeadingWhitespace(expected,
473 self.GenerateMocks(source))
474

◆ testTemplatedForwardDeclaration()

def cpp.gmock_class_test.GenerateMocksTest.testTemplatedForwardDeclaration (   self)

Definition at line 405 of file gmock_class_test.py.

405 def testTemplatedForwardDeclaration(self):
406 source = """
407template <class T> class Forward; // Forward declaration should be ignored.
408class Test {
409 public:
410 virtual void Foo();
411};
412"""
413 expected = """\
414class MockTest : public Test {
415public:
416MOCK_METHOD(void, Foo, (), (override));
417};
418"""
419 self.assertEqualIgnoreLeadingWhitespace(expected,
420 self.GenerateMocks(source))
421

◆ testTemplateInATemplateTypedef()

def cpp.gmock_class_test.GenerateMocksTest.testTemplateInATemplateTypedef (   self)

Definition at line 440 of file gmock_class_test.py.

440 def testTemplateInATemplateTypedef(self):
441 source = """
442class Test {
443 public:
444 typedef std::vector<std::list<int>> FooType;
445 virtual void Bar(const FooType& test_arg);
446};
447"""
448 expected = """\
449class MockTest : public Test {
450public:
451MOCK_METHOD(void, Bar, (const FooType& test_arg), (override));
452};
453"""
454 self.assertEqualIgnoreLeadingWhitespace(expected,
455 self.GenerateMocks(source))
456

◆ testTemplateInATemplateTypedefWithComma()

def cpp.gmock_class_test.GenerateMocksTest.testTemplateInATemplateTypedefWithComma (   self)

Definition at line 475 of file gmock_class_test.py.

475 def testTemplateInATemplateTypedefWithComma(self):
476 source = """
477class Test {
478 public:
479 typedef std::function<void(
480 const vector<std::list<int>>&, int> FooType;
481 virtual void Bar(const FooType& test_arg);
482};
483"""
484 expected = """\
485class MockTest : public Test {
486public:
487MOCK_METHOD(void, Bar, (const FooType& test_arg), (override));
488};
489"""
490 self.assertEqualIgnoreLeadingWhitespace(expected,
491 self.GenerateMocks(source))
492

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