diff options
author | kosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386> | 2014-11-17 02:49:22 +0000 |
---|---|---|
committer | kosak@google.com <kosak@google.com@8415998a-534a-0410-bf83-d39667b30386> | 2014-11-17 02:49:22 +0000 |
commit | ff531679309cbc8aeb7d4eb7efacaaed81e99903 (patch) | |
tree | 59e9d99433365685738be11c4dda1b1352260d6a | |
parent | b839f8e397815fc7b7b884625111aa7ec92e3bc4 (diff) | |
download | googlemock-ff531679309cbc8aeb7d4eb7efacaaed81e99903.tar.gz |
Add support for C++11 explicitly defaulted and deleted special member functions in the gmock generator.
git-svn-id: http://googlemock.googlecode.com/svn/trunk@500 8415998a-534a-0410-bf83-d39667b30386
-rwxr-xr-x | scripts/generator/cpp/ast.py | 15 | ||||
-rwxr-xr-x | scripts/generator/cpp/gmock_class_test.py | 62 |
2 files changed, 73 insertions, 4 deletions
diff --git a/scripts/generator/cpp/ast.py b/scripts/generator/cpp/ast.py index 9504cee..201bf3a 100755 --- a/scripts/generator/cpp/ast.py +++ b/scripts/generator/cpp/ast.py @@ -1081,10 +1081,17 @@ class AstBuilder(object): body = None if token.name == '=': token = self._GetNextToken() - assert token.token_type == tokenize.CONSTANT, token - assert token.name == '0', token - modifiers |= FUNCTION_PURE_VIRTUAL - token = self._GetNextToken() + + if token.name == 'default' or token.name == 'delete': + # Ignore explicitly defaulted and deleted special members + # in C++11. + token = self._GetNextToken() + else: + # Handle pure-virtual declarations. + assert token.token_type == tokenize.CONSTANT, token + assert token.name == '0', token + modifiers |= FUNCTION_PURE_VIRTUAL + token = self._GetNextToken() if token.name == '[': # TODO(nnorwitz): store tokens and improve parsing. diff --git a/scripts/generator/cpp/gmock_class_test.py b/scripts/generator/cpp/gmock_class_test.py index ae3739a..27eb86c 100755 --- a/scripts/generator/cpp/gmock_class_test.py +++ b/scripts/generator/cpp/gmock_class_test.py @@ -65,6 +65,68 @@ class Foo { 'MOCK_METHOD0(Bar,\nint());', self.GenerateMethodSource(source)) + def testSimpleConstructorsAndDestructor(self): + source = """ +class Foo { + public: + Foo(); + Foo(int x); + Foo(const Foo& f); + Foo(Foo&& f); + ~Foo(); + virtual int Bar() = 0; +}; +""" + # The constructors and destructor should be ignored. + self.assertEqualIgnoreLeadingWhitespace( + 'MOCK_METHOD0(Bar,\nint());', + self.GenerateMethodSource(source)) + + def testVirtualDestructor(self): + source = """ +class Foo { + public: + virtual ~Foo(); + virtual int Bar() = 0; +}; +""" + # The destructor should be ignored. + self.assertEqualIgnoreLeadingWhitespace( + 'MOCK_METHOD0(Bar,\nint());', + self.GenerateMethodSource(source)) + + def testExplicitlyDefaultedConstructorsAndDestructor(self): + source = """ +class Foo { + public: + Foo() = default; + Foo(const Foo& f) = default; + Foo(Foo&& f) = default; + ~Foo() = default; + virtual int Bar() = 0; +}; +""" + # The constructors and destructor should be ignored. + self.assertEqualIgnoreLeadingWhitespace( + 'MOCK_METHOD0(Bar,\nint());', + self.GenerateMethodSource(source)) + + def testExplicitlyDeletedConstructorsAndDestructor(self): + source = """ +class Foo { + public: + Foo() = delete; + Foo(const Foo& f) = delete; + Foo(Foo&& f) = delete; + ~Foo() = delete; + virtual int Bar() = 0; +}; +""" + # The constructors and destructor should be ignored. + self.assertEqualIgnoreLeadingWhitespace( + 'MOCK_METHOD0(Bar,\nint());', + self.GenerateMethodSource(source)) + def testSimpleOverrideMethod(self): source = """ class Foo { |