gmock_class_test.py (googletest-release-1.10.0) | : | gmock_class_test.py (googletest-release-1.11.0) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
# http://www.apache.org/licenses/LICENSE-2.0 | # http://www.apache.org/licenses/LICENSE-2.0 | |||
# | # | |||
# Unless required by applicable law or agreed to in writing, software | # Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | # distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | # See the License for the specific language governing permissions and | |||
# limitations under the License. | # limitations under the License. | |||
"""Tests for gmock.scripts.generator.cpp.gmock_class.""" | """Tests for gmock.scripts.generator.cpp.gmock_class.""" | |||
__author__ = 'nnorwitz@google.com (Neal Norwitz)' | ||||
import os | import os | |||
import sys | import sys | |||
import unittest | import unittest | |||
# Allow the cpp imports below to work when run as a standalone script. | # Allow the cpp imports below to work when run as a standalone script. | |||
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |||
from cpp import ast | from cpp import ast | |||
from cpp import gmock_class | from cpp import gmock_class | |||
class TestCase(unittest.TestCase): | class TestCase(unittest.TestCase): | |||
"""Helper class that adds assert methods.""" | """Helper class that adds assert methods.""" | |||
def StripLeadingWhitespace(self, lines): | @staticmethod | |||
def StripLeadingWhitespace(lines): | ||||
"""Strip leading whitespace in each line in 'lines'.""" | """Strip leading whitespace in each line in 'lines'.""" | |||
return '\n'.join([s.lstrip() for s in lines.split('\n')]) | return '\n'.join([s.lstrip() for s in lines.split('\n')]) | |||
def assertEqualIgnoreLeadingWhitespace(self, expected_lines, lines): | def assertEqualIgnoreLeadingWhitespace(self, expected_lines, lines): | |||
"""Specialized assert that ignores the indent level.""" | """Specialized assert that ignores the indent level.""" | |||
self.assertEqual(expected_lines, self.StripLeadingWhitespace(lines)) | self.assertEqual(expected_lines, self.StripLeadingWhitespace(lines)) | |||
class GenerateMethodsTest(TestCase): | class GenerateMethodsTest(TestCase): | |||
def GenerateMethodSource(self, cpp_source): | @staticmethod | |||
def GenerateMethodSource(cpp_source): | ||||
"""Convert C++ source to Google Mock output source lines.""" | """Convert C++ source to Google Mock output source lines.""" | |||
method_source_lines = [] | method_source_lines = [] | |||
# <test> is a pseudo-filename, it is not read or written. | # <test> is a pseudo-filename, it is not read or written. | |||
builder = ast.BuilderFromSource(cpp_source, '<test>') | builder = ast.BuilderFromSource(cpp_source, '<test>') | |||
ast_list = list(builder.Generate()) | ast_list = list(builder.Generate()) | |||
gmock_class._GenerateMethods(method_source_lines, cpp_source, ast_list[0]) | gmock_class._GenerateMethods(method_source_lines, cpp_source, ast_list[0]) | |||
return '\n'.join(method_source_lines) | return '\n'.join(method_source_lines) | |||
def testSimpleMethod(self): | def testSimpleMethod(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual int Bar(); | virtual int Bar(); | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0(Bar,\nint());', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testSimpleConstructorsAndDestructor(self): | def testSimpleConstructorsAndDestructor(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
Foo(); | Foo(); | |||
Foo(int x); | Foo(int x); | |||
Foo(const Foo& f); | Foo(const Foo& f); | |||
Foo(Foo&& f); | Foo(Foo&& f); | |||
~Foo(); | ~Foo(); | |||
virtual int Bar() = 0; | virtual int Bar() = 0; | |||
}; | }; | |||
""" | """ | |||
# The constructors and destructor should be ignored. | # The constructors and destructor should be ignored. | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0(Bar,\nint());', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testVirtualDestructor(self): | def testVirtualDestructor(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual ~Foo(); | virtual ~Foo(); | |||
virtual int Bar() = 0; | virtual int Bar() = 0; | |||
}; | }; | |||
""" | """ | |||
# The destructor should be ignored. | # The destructor should be ignored. | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0(Bar,\nint());', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testExplicitlyDefaultedConstructorsAndDestructor(self): | def testExplicitlyDefaultedConstructorsAndDestructor(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
Foo() = default; | Foo() = default; | |||
Foo(const Foo& f) = default; | Foo(const Foo& f) = default; | |||
Foo(Foo&& f) = default; | Foo(Foo&& f) = default; | |||
~Foo() = default; | ~Foo() = default; | |||
virtual int Bar() = 0; | virtual int Bar() = 0; | |||
}; | }; | |||
""" | """ | |||
# The constructors and destructor should be ignored. | # The constructors and destructor should be ignored. | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0(Bar,\nint());', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testExplicitlyDeletedConstructorsAndDestructor(self): | def testExplicitlyDeletedConstructorsAndDestructor(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
Foo() = delete; | Foo() = delete; | |||
Foo(const Foo& f) = delete; | Foo(const Foo& f) = delete; | |||
Foo(Foo&& f) = delete; | Foo(Foo&& f) = delete; | |||
~Foo() = delete; | ~Foo() = delete; | |||
virtual int Bar() = 0; | virtual int Bar() = 0; | |||
}; | }; | |||
""" | """ | |||
# The constructors and destructor should be ignored. | # The constructors and destructor should be ignored. | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0(Bar,\nint());', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testSimpleOverrideMethod(self): | def testSimpleOverrideMethod(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
int Bar() override; | int Bar() override; | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0(Bar,\nint());', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testSimpleConstMethod(self): | def testSimpleConstMethod(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual void Bar(bool flag) const; | virtual void Bar(bool flag) const; | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_CONST_METHOD1(Bar,\nvoid(bool flag));', | 'MOCK_METHOD(void, Bar, (bool flag), (const, override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testExplicitVoid(self): | def testExplicitVoid(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual int Bar(void); | virtual int Bar(void); | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0(Bar,\nint(void));', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testStrangeNewlineInParameter(self): | def testStrangeNewlineInParameter(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual void Bar(int | virtual void Bar(int | |||
a) = 0; | a) = 0; | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD1(Bar,\nvoid(int a));', | 'MOCK_METHOD(void, Bar, (int a), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testDefaultParameters(self): | def testDefaultParameters(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual void Bar(int a, char c = 'x') = 0; | virtual void Bar(int a, char c = 'x') = 0; | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD2(Bar,\nvoid(int, char));', | 'MOCK_METHOD(void, Bar, (int a, char c), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testMultipleDefaultParameters(self): | def testMultipleDefaultParameters(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual void Bar(int a = 42, char c = 'x') = 0; | virtual void Bar( | |||
int a = 42, | ||||
char c = 'x', | ||||
const int* const p = nullptr, | ||||
const std::string& s = "42", | ||||
char tab[] = {'4','2'}, | ||||
int const *& rp = aDefaultPointer) = 0; | ||||
}; | ||||
""" | ||||
self.assertEqualIgnoreLeadingWhitespace( | ||||
'MOCK_METHOD(void, Bar, ' | ||||
'(int a, char c, const int* const p, const std::string& s, char tab[], i | ||||
nt const *& rp), ' | ||||
'(override));', self.GenerateMethodSource(source)) | ||||
def testMultipleSingleLineDefaultParameters(self): | ||||
source = """ | ||||
class Foo { | ||||
public: | ||||
virtual void Bar(int a = 42, int b = 43, int c = 44) = 0; | ||||
}; | ||||
""" | ||||
self.assertEqualIgnoreLeadingWhitespace( | ||||
'MOCK_METHOD(void, Bar, (int a, int b, int c), (override));', | ||||
self.GenerateMethodSource(source)) | ||||
def testConstDefaultParameter(self): | ||||
source = """ | ||||
class Test { | ||||
public: | ||||
virtual bool Bar(const int test_arg = 42) = 0; | ||||
}; | ||||
""" | ||||
self.assertEqualIgnoreLeadingWhitespace( | ||||
'MOCK_METHOD(bool, Bar, (const int test_arg), (override));', | ||||
self.GenerateMethodSource(source)) | ||||
def testConstRefDefaultParameter(self): | ||||
source = """ | ||||
class Test { | ||||
public: | ||||
virtual bool Bar(const std::string& test_arg = "42" ) = 0; | ||||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD2(Bar,\nvoid(int, char));', | 'MOCK_METHOD(bool, Bar, (const std::string& test_arg), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testRemovesCommentsWhenDefaultsArePresent(self): | def testRemovesCommentsWhenDefaultsArePresent(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual void Bar(int a = 42 /* a comment */, | virtual void Bar(int a = 42 /* a comment */, | |||
char /* other comment */ c= 'x') = 0; | char /* other comment */ c= 'x') = 0; | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD2(Bar,\nvoid(int, char));', | 'MOCK_METHOD(void, Bar, (int a, char c), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testDoubleSlashCommentsInParameterListAreRemoved(self): | def testDoubleSlashCommentsInParameterListAreRemoved(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual void Bar(int a, // inline comments should be elided. | virtual void Bar(int a, // inline comments should be elided. | |||
int b // inline comments should be elided. | int b // inline comments should be elided. | |||
) const = 0; | ) const = 0; | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_CONST_METHOD2(Bar,\nvoid(int a, int b));', | 'MOCK_METHOD(void, Bar, (int a, int b), (const, override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testCStyleCommentsInParameterListAreNotRemoved(self): | def testCStyleCommentsInParameterListAreNotRemoved(self): | |||
# NOTE(nnorwitz): I'm not sure if it's the best behavior to keep these | # NOTE(nnorwitz): I'm not sure if it's the best behavior to keep these | |||
# comments. Also note that C style comments after the last parameter | # comments. Also note that C style comments after the last parameter | |||
# are still elided. | # are still elided. | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual const string& Bar(int /* keeper */, int b); | virtual const string& Bar(int /* keeper */, int b); | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD2(Bar,\nconst string&(int /* keeper */, int b));', | 'MOCK_METHOD(const string&, Bar, (int, int b), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testArgsOfTemplateTypes(self): | def testArgsOfTemplateTypes(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual int Bar(const vector<int>& v, map<int, string>* output); | virtual int Bar(const vector<int>& v, map<int, string>* output); | |||
};""" | };""" | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD2(Bar,\n' | 'MOCK_METHOD(int, Bar, (const vector<int>& v, (map<int, string>* output) | |||
'int(const vector<int>& v, map<int, string>* output));', | ), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testReturnTypeWithOneTemplateArg(self): | def testReturnTypeWithOneTemplateArg(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual vector<int>* Bar(int n); | virtual vector<int>* Bar(int n); | |||
};""" | };""" | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD1(Bar,\nvector<int>*(int n));', | 'MOCK_METHOD(vector<int>*, Bar, (int n), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testReturnTypeWithManyTemplateArgs(self): | def testReturnTypeWithManyTemplateArgs(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual map<int, string> Bar(); | virtual map<int, string> Bar(); | |||
};""" | };""" | |||
# Comparing the comment text is brittle - we'll think of something | ||||
# better in case this gets annoying, but for now let's keep it simple. | ||||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'// The following line won\'t really compile, as the return\n' | 'MOCK_METHOD((map<int, string>), Bar, (), (override));', | |||
'// type has multiple template arguments. To fix it, use a\n' | ||||
'// typedef for the return type.\n' | ||||
'MOCK_METHOD0(Bar,\nmap<int, string>());', | ||||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testSimpleMethodInTemplatedClass(self): | def testSimpleMethodInTemplatedClass(self): | |||
source = """ | source = """ | |||
template<class T> | template<class T> | |||
class Foo { | class Foo { | |||
public: | public: | |||
virtual int Bar(); | virtual int Bar(); | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD0_T(Bar,\nint());', | 'MOCK_METHOD(int, Bar, (), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testPointerArgWithoutNames(self): | def testPointerArgWithoutNames(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
virtual int Bar(C*); | virtual int Bar(C*); | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD1(Bar,\nint(C*));', | 'MOCK_METHOD(int, Bar, (C*), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testReferenceArgWithoutNames(self): | def testReferenceArgWithoutNames(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
virtual int Bar(C&); | virtual int Bar(C&); | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD1(Bar,\nint(C&));', | 'MOCK_METHOD(int, Bar, (C&), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
def testArrayArgWithoutNames(self): | def testArrayArgWithoutNames(self): | |||
source = """ | source = """ | |||
class Foo { | class Foo { | |||
virtual int Bar(C[]); | virtual int Bar(C[]); | |||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace( | |||
'MOCK_METHOD1(Bar,\nint(C[]));', | 'MOCK_METHOD(int, Bar, (C[]), (override));', | |||
self.GenerateMethodSource(source)) | self.GenerateMethodSource(source)) | |||
class GenerateMocksTest(TestCase): | class GenerateMocksTest(TestCase): | |||
def GenerateMocks(self, cpp_source): | @staticmethod | |||
def GenerateMocks(cpp_source): | ||||
"""Convert C++ source to complete Google Mock output source.""" | """Convert C++ source to complete Google Mock output source.""" | |||
# <test> is a pseudo-filename, it is not read or written. | # <test> is a pseudo-filename, it is not read or written. | |||
filename = '<test>' | filename = '<test>' | |||
builder = ast.BuilderFromSource(cpp_source, filename) | builder = ast.BuilderFromSource(cpp_source, filename) | |||
ast_list = list(builder.Generate()) | ast_list = list(builder.Generate()) | |||
lines = gmock_class._GenerateMocks(filename, cpp_source, ast_list, None) | lines = gmock_class._GenerateMocks(filename, cpp_source, ast_list, None) | |||
return '\n'.join(lines) | return '\n'.join(lines) | |||
def testNamespaces(self): | def testNamespaces(self): | |||
source = """ | source = """ | |||
namespace Foo { | namespace Foo { | |||
namespace Bar { class Forward; } | namespace Bar { class Forward; } | |||
namespace Baz { | namespace Baz::Qux { | |||
class Test { | class Test { | |||
public: | public: | |||
virtual void Foo(); | virtual void Foo(); | |||
}; | }; | |||
} // namespace Baz | } // namespace Baz::Qux | |||
} // namespace Foo | } // namespace Foo | |||
""" | """ | |||
expected = """\ | expected = """\ | |||
namespace Foo { | namespace Foo { | |||
namespace Baz { | namespace Baz::Qux { | |||
class MockTest : public Test { | class MockTest : public Test { | |||
public: | public: | |||
MOCK_METHOD0(Foo, | MOCK_METHOD(void, Foo, (), (override)); | |||
void()); | ||||
}; | }; | |||
} // namespace Baz | } // namespace Baz::Qux | |||
} // namespace Foo | } // namespace Foo | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace(expected, | |||
expected, self.GenerateMocks(source)) | self.GenerateMocks(source)) | |||
def testClassWithStorageSpecifierMacro(self): | def testClassWithStorageSpecifierMacro(self): | |||
source = """ | source = """ | |||
class STORAGE_SPECIFIER Test { | class STORAGE_SPECIFIER Test { | |||
public: | public: | |||
virtual void Foo(); | virtual void Foo(); | |||
}; | }; | |||
""" | """ | |||
expected = """\ | expected = """\ | |||
class MockTest : public Test { | class MockTest : public Test { | |||
public: | public: | |||
MOCK_METHOD0(Foo, | MOCK_METHOD(void, Foo, (), (override)); | |||
void()); | ||||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace(expected, | |||
expected, self.GenerateMocks(source)) | self.GenerateMocks(source)) | |||
def testTemplatedForwardDeclaration(self): | def testTemplatedForwardDeclaration(self): | |||
source = """ | source = """ | |||
template <class T> class Forward; // Forward declaration should be ignored. | template <class T> class Forward; // Forward declaration should be ignored. | |||
class Test { | class Test { | |||
public: | public: | |||
virtual void Foo(); | virtual void Foo(); | |||
}; | }; | |||
""" | """ | |||
expected = """\ | expected = """\ | |||
class MockTest : public Test { | class MockTest : public Test { | |||
public: | public: | |||
MOCK_METHOD0(Foo, | MOCK_METHOD(void, Foo, (), (override)); | |||
void()); | ||||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace(expected, | |||
expected, self.GenerateMocks(source)) | self.GenerateMocks(source)) | |||
def testTemplatedClass(self): | def testTemplatedClass(self): | |||
source = """ | source = """ | |||
template <typename S, typename T> | template <typename S, typename T> | |||
class Test { | class Test { | |||
public: | public: | |||
virtual void Foo(); | virtual void Foo(); | |||
}; | }; | |||
""" | """ | |||
expected = """\ | expected = """\ | |||
template <typename T0, typename T1> | template <typename S, typename T> | |||
class MockTest : public Test<T0, T1> { | class MockTest : public Test<S, T> { | |||
public: | public: | |||
MOCK_METHOD0_T(Foo, | MOCK_METHOD(void, Foo, (), (override)); | |||
void()); | ||||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace(expected, | |||
expected, self.GenerateMocks(source)) | self.GenerateMocks(source)) | |||
def testTemplateInATemplateTypedef(self): | def testTemplateInATemplateTypedef(self): | |||
source = """ | source = """ | |||
class Test { | class Test { | |||
public: | public: | |||
typedef std::vector<std::list<int>> FooType; | typedef std::vector<std::list<int>> FooType; | |||
virtual void Bar(const FooType& test_arg); | virtual void Bar(const FooType& test_arg); | |||
}; | }; | |||
""" | """ | |||
expected = """\ | expected = """\ | |||
class MockTest : public Test { | class MockTest : public Test { | |||
public: | public: | |||
MOCK_METHOD1(Bar, | MOCK_METHOD(void, Bar, (const FooType& test_arg), (override)); | |||
void(const FooType& test_arg)); | ||||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace(expected, | |||
expected, self.GenerateMocks(source)) | self.GenerateMocks(source)) | |||
def testTemplatedClassWithTemplatedArguments(self): | ||||
source = """ | ||||
template <typename S, typename T, typename U, typename V, typename W> | ||||
class Test { | ||||
public: | ||||
virtual U Foo(T some_arg); | ||||
}; | ||||
""" | ||||
expected = """\ | ||||
template <typename S, typename T, typename U, typename V, typename W> | ||||
class MockTest : public Test<S, T, U, V, W> { | ||||
public: | ||||
MOCK_METHOD(U, Foo, (T some_arg), (override)); | ||||
}; | ||||
""" | ||||
self.assertEqualIgnoreLeadingWhitespace(expected, | ||||
self.GenerateMocks(source)) | ||||
def testTemplateInATemplateTypedefWithComma(self): | def testTemplateInATemplateTypedefWithComma(self): | |||
source = """ | source = """ | |||
class Test { | class Test { | |||
public: | public: | |||
typedef std::function<void( | typedef std::function<void( | |||
const vector<std::list<int>>&, int> FooType; | const vector<std::list<int>>&, int> FooType; | |||
virtual void Bar(const FooType& test_arg); | virtual void Bar(const FooType& test_arg); | |||
}; | }; | |||
""" | """ | |||
expected = """\ | expected = """\ | |||
class MockTest : public Test { | class MockTest : public Test { | |||
public: | public: | |||
MOCK_METHOD1(Bar, | MOCK_METHOD(void, Bar, (const FooType& test_arg), (override)); | |||
void(const FooType& test_arg)); | ||||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace(expected, | |||
expected, self.GenerateMocks(source)) | self.GenerateMocks(source)) | |||
def testEnumClass(self): | def testParenthesizedCommaInArg(self): | |||
source = """ | source = """ | |||
class Test { | class Test { | |||
public: | public: | |||
enum class Baz { BAZINGA }; | virtual void Bar(std::function<void(int, int)> f); | |||
virtual void Bar(const FooType& test_arg); | ||||
}; | }; | |||
""" | """ | |||
expected = """\ | expected = """\ | |||
class MockTest : public Test { | class MockTest : public Test { | |||
public: | public: | |||
MOCK_METHOD1(Bar, | MOCK_METHOD(void, Bar, (std::function<void(int, int)> f), (override)); | |||
void(const FooType& test_arg)); | ||||
}; | }; | |||
""" | """ | |||
self.assertEqualIgnoreLeadingWhitespace( | self.assertEqualIgnoreLeadingWhitespace(expected, | |||
expected, self.GenerateMocks(source)) | self.GenerateMocks(source)) | |||
def testEnumType(self): | ||||
source = """ | ||||
class Test { | ||||
public: | ||||
enum Bar { | ||||
BAZ, QUX, QUUX, QUUUX | ||||
}; | ||||
virtual void Foo(); | ||||
}; | ||||
""" | ||||
expected = """\ | ||||
class MockTest : public Test { | ||||
public: | ||||
MOCK_METHOD(void, Foo, (), (override)); | ||||
}; | ||||
""" | ||||
self.assertEqualIgnoreLeadingWhitespace(expected, | ||||
self.GenerateMocks(source)) | ||||
def testEnumClassType(self): | ||||
source = """ | ||||
class Test { | ||||
public: | ||||
enum class Bar { | ||||
BAZ, QUX, QUUX, QUUUX | ||||
}; | ||||
virtual void Foo(); | ||||
}; | ||||
""" | ||||
expected = """\ | ||||
class MockTest : public Test { | ||||
public: | ||||
MOCK_METHOD(void, Foo, (), (override)); | ||||
}; | ||||
""" | ||||
self.assertEqualIgnoreLeadingWhitespace(expected, | ||||
self.GenerateMocks(source)) | ||||
def testStdFunction(self): | ||||
source = """ | ||||
class Test { | ||||
public: | ||||
Test(std::function<int(std::string)> foo) : foo_(foo) {} | ||||
virtual std::function<int(std::string)> foo(); | ||||
private: | ||||
std::function<int(std::string)> foo_; | ||||
}; | ||||
""" | ||||
expected = """\ | ||||
class MockTest : public Test { | ||||
public: | ||||
MOCK_METHOD(std::function<int (std::string)>, foo, (), (override)); | ||||
}; | ||||
""" | ||||
self.assertEqualIgnoreLeadingWhitespace(expected, | ||||
self.GenerateMocks(source)) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | |||
unittest.main() | unittest.main() | |||
End of changes. 48 change blocks. | ||||
70 lines changed or deleted | 176 lines changed or added |