def generate_mock_method(CppMethod): num_args = len(CppMethod.arguments()) method_name = CppMethod.name() return_type = CppMethod.return_type() arguments = _generate_arguments(CppMethod.arguments()) mock_macro = 'MOCK_METHOD' if CppMethod.is_const(): mock_macro = 'MOCK_CONST_METHOD' template = '{mock_macro}{num_args}({method_name}, {return_type}({arguments}));' return template.format(mock_macro=mock_macro, num_args=num_args, method_name=method_name, return_type=return_type, arguments=arguments)
def test_will_create_method_with_multiple_arguments(self): expected_output = 'MOCK_METHOD2(methodName, void(QString myString, QVector myVector));' method = CppMethod('methodName', 'void', [('QString', 'myString'), ('QVector', 'myVector')], True, False) self.assertEqual(generate_mock_method(method), expected_output)
def test_will_create_method_with_argument(self): expected_output = 'MOCK_METHOD1(methodName, void(QString myString));' method = CppMethod('methodName', 'void', [( 'QString', 'myString', )], True, False) self.assertEqual(generate_mock_method(method), expected_output)
def test_will_create_simple_method(self): expected_output = 'MOCK_METHOD0(methodName, void());' method = CppMethod('methodName', 'void', [], True, False) self.assertEqual(generate_mock_method(method), expected_output)
def test_will_create_const_method_with_const_reference_return_type(self): expected_output = 'MOCK_CONST_METHOD0(methodName, const QString&());' method = CppMethod('methodName', 'const QString&', [], True, True) self.assertEqual(generate_mock_method(method), expected_output)
def test_will_create_method_with_simple_return_type(self): expected_output = 'MOCK_METHOD0(methodName, bool());' method = CppMethod('methodName', 'bool', [], True, False) self.assertEqual(generate_mock_method(method), expected_output)