Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
f4eeaedb
Commit
f4eeaedb
authored
May 20, 2011
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue 139 and issue 140.
parent
bce8134d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
12 deletions
+73
-12
gmock_class.py
scripts/generator/cpp/gmock_class.py
+28
-12
gmock_class_test.py
scripts/generator/cpp/gmock_class_test.py
+45
-0
No files found.
scripts/generator/cpp/gmock_class.py
View file @
f4eeaedb
...
@@ -82,20 +82,36 @@ def _GenerateMethods(output_lines, source, class_node):
...
@@ -82,20 +82,36 @@ def _GenerateMethods(output_lines, source, class_node):
return_type
+=
'*'
return_type
+=
'*'
if
node
.
return_type
.
reference
:
if
node
.
return_type
.
reference
:
return_type
+=
'&'
return_type
+=
'&'
mock_method_macro
=
'MOCK_
%
sMETHOD
%
d'
%
(
const
,
len
(
node
.
parameters
))
num_parameters
=
len
(
node
.
parameters
)
if
len
(
node
.
parameters
)
==
1
:
first_param
=
node
.
parameters
[
0
]
if
source
[
first_param
.
start
:
first_param
.
end
]
.
strip
()
==
'void'
:
# We must treat T(void) as a function with no parameters.
num_parameters
=
0
mock_method_macro
=
'MOCK_
%
sMETHOD
%
d'
%
(
const
,
num_parameters
)
args
=
''
args
=
''
if
node
.
parameters
:
if
node
.
parameters
:
# Get the full text of the parameters from the start
# Due to the parser limitations, it is impossible to keep comments
# of the first parameter to the end of the last parameter.
# while stripping the default parameters. When defaults are
start
=
node
.
parameters
[
0
]
.
start
# present, we choose to strip them and comments (and produce
end
=
node
.
parameters
[
-
1
]
.
end
# compilable code).
# Remove // comments.
# TODO(nnorwitz@google.com): Investigate whether it is possible to
args_strings
=
re
.
sub
(
r'//.*'
,
''
,
source
[
start
:
end
])
# preserve parameter name when reconstructing parameter text from
# Condense multiple spaces and eliminate newlines putting the
# the AST.
# parameters together on a single line. Ensure there is a
if
len
([
param
for
param
in
node
.
parameters
if
param
.
default
])
>
0
:
# space in an argument which is split by a newline without
args
=
', '
.
join
(
param
.
type
.
name
for
param
in
node
.
parameters
)
# intervening whitespace, e.g.: int\nBar
else
:
args
=
re
.
sub
(
' +'
,
' '
,
args_strings
.
replace
(
'
\n
'
,
' '
))
# Get the full text of the parameters from the start
# of the first parameter to the end of the last parameter.
start
=
node
.
parameters
[
0
]
.
start
end
=
node
.
parameters
[
-
1
]
.
end
# Remove // comments.
args_strings
=
re
.
sub
(
r'//.*'
,
''
,
source
[
start
:
end
])
# Condense multiple spaces and eliminate newlines putting the
# parameters together on a single line. Ensure there is a
# space in an argument which is split by a newline without
# intervening whitespace, e.g.: int\nBar
args
=
re
.
sub
(
' +'
,
' '
,
args_strings
.
replace
(
'
\n
'
,
' '
))
# Create the mock method definition.
# Create the mock method definition.
output_lines
.
extend
([
'
%
s
%
s(
%
s,'
%
(
indent
,
mock_method_macro
,
node
.
name
),
output_lines
.
extend
([
'
%
s
%
s(
%
s,'
%
(
indent
,
mock_method_macro
,
node
.
name
),
...
...
scripts/generator/cpp/gmock_class_test.py
View file @
f4eeaedb
...
@@ -76,6 +76,17 @@ class Foo {
...
@@ -76,6 +76,17 @@ class Foo {
'MOCK_CONST_METHOD1(Bar,
\n
void(bool flag));'
,
'MOCK_CONST_METHOD1(Bar,
\n
void(bool flag));'
,
self
.
GenerateMethodSource
(
source
))
self
.
GenerateMethodSource
(
source
))
def
testExplicitVoid
(
self
):
source
=
"""
class Foo {
public:
virtual int Bar(void);
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_METHOD0(Bar,
\n
int(void));'
,
self
.
GenerateMethodSource
(
source
))
def
testStrangeNewlineInParameter
(
self
):
def
testStrangeNewlineInParameter
(
self
):
source
=
"""
source
=
"""
class Foo {
class Foo {
...
@@ -88,6 +99,40 @@ a) = 0;
...
@@ -88,6 +99,40 @@ a) = 0;
'MOCK_METHOD1(Bar,
\n
void(int a));'
,
'MOCK_METHOD1(Bar,
\n
void(int a));'
,
self
.
GenerateMethodSource
(
source
))
self
.
GenerateMethodSource
(
source
))
def
testDefaultParameters
(
self
):
source
=
"""
class Foo {
public:
virtual void Bar(int a, char c = 'x') = 0;
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_METHOD2(Bar,
\n
void(int, char));'
,
self
.
GenerateMethodSource
(
source
))
def
testMultipleDefaultParameters
(
self
):
source
=
"""
class Foo {
public:
virtual void Bar(int a = 42, char c = 'x') = 0;
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_METHOD2(Bar,
\n
void(int, char));'
,
self
.
GenerateMethodSource
(
source
))
def
testRemovesCommentsWhenDefaultsArePresent
(
self
):
source
=
"""
class Foo {
public:
virtual void Bar(int a = 42 /* a comment */,
char /* other comment */ c= 'x') = 0;
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_METHOD2(Bar,
\n
void(int, char));'
,
self
.
GenerateMethodSource
(
source
))
def
testDoubleSlashCommentsInParameterListAreRemoved
(
self
):
def
testDoubleSlashCommentsInParameterListAreRemoved
(
self
):
source
=
"""
source
=
"""
class Foo {
class Foo {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment