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
d8e15d9c
Commit
d8e15d9c
authored
Oct 05, 2010
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds more tests for the gmock generator.
parent
4b16e8ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
5 deletions
+66
-5
gmock_class_test.py
scripts/generator/cpp/gmock_class_test.py
+66
-5
No files found.
scripts/generator/cpp/gmock_class_test.py
View file @
d8e15d9c
...
...
@@ -34,22 +34,47 @@ from cpp import gmock_class
class
TestCase
(
unittest
.
TestCase
):
"""Helper class that adds assert methods."""
def
StripLeadingWhitespace
(
self
,
lines
):
"""Strip leading whitespace in each line in 'lines'."""
return
'
\n
'
.
join
([
s
.
lstrip
()
for
s
in
lines
.
split
(
'
\n
'
)])
def
assertEqualIgnoreLeadingWhitespace
(
self
,
expected_lines
,
lines
):
"""Specialized assert that ignores the indent level."""
stripped_lines
=
'
\n
'
.
join
([
s
.
lstrip
()
for
s
in
lines
.
split
(
'
\n
'
)])
self
.
assertEqual
(
expected_lines
,
stripped_lines
)
self
.
assertEqual
(
expected_lines
,
self
.
StripLeadingWhitespace
(
lines
))
class
GenerateMethodsTest
(
TestCase
):
def
GenerateMethodSource
(
self
,
cpp_source
):
"""
Helper method to convert C++ source to g
Mock output source lines."""
"""
Convert C++ source to Google
Mock output source lines."""
method_source_lines
=
[]
# <test> is a pseudo-filename, it is not read or written.
builder
=
ast
.
BuilderFromSource
(
cpp_source
,
'<test>'
)
ast_list
=
list
(
builder
.
Generate
())
gmock_class
.
_GenerateMethods
(
method_source_lines
,
cpp_source
,
ast_list
[
0
])
return
''
.
join
(
method_source_lines
)
return
'
\n
'
.
join
(
method_source_lines
)
def
testSimpleMethod
(
self
):
source
=
"""
class Foo {
public:
virtual int Bar();
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_METHOD0(Bar,
\n
int());'
,
self
.
GenerateMethodSource
(
source
))
def
testSimpleConstMethod
(
self
):
source
=
"""
class Foo {
public:
virtual void Bar(bool flag) const;
};
"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_CONST_METHOD1(Bar,
\n
void(bool flag));'
,
self
.
GenerateMethodSource
(
source
))
def
testStrangeNewlineInParameter
(
self
):
source
=
"""
...
...
@@ -90,11 +115,47 @@ class Foo {
'MOCK_METHOD2(Bar,
\n
const string&(int /* keeper */, int b));'
,
self
.
GenerateMethodSource
(
source
))
def
testArgsOfTemplateTypes
(
self
):
source
=
"""
class Foo {
public:
virtual int Bar(const vector<int>& v, map<int, string>* output);
};"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_METHOD2(Bar,
\n
'
'int(const vector<int>& v, map<int, string>* output));'
,
self
.
GenerateMethodSource
(
source
))
def
testReturnTypeWithOneTemplateArg
(
self
):
source
=
"""
class Foo {
public:
virtual vector<int>* Bar(int n);
};"""
self
.
assertEqualIgnoreLeadingWhitespace
(
'MOCK_METHOD1(Bar,
\n
vector<int>*(int n));'
,
self
.
GenerateMethodSource
(
source
))
def
testReturnTypeWithManyTemplateArgs
(
self
):
source
=
"""
class Foo {
public:
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
(
'// The following line won
\'
t really compile, as the return
\n
'
'// type has multiple template arguments. To fix it, use a
\n
'
'// typedef for the return type.
\n
'
'MOCK_METHOD0(Bar,
\n
map<int, string>());'
,
self
.
GenerateMethodSource
(
source
))
class
GenerateMocksTest
(
TestCase
):
def
GenerateMocks
(
self
,
cpp_source
):
"""
Helper method to convert C++ source to complete g
Mock output source."""
"""
Convert C++ source to complete Google
Mock output source."""
# <test> is a pseudo-filename, it is not read or written.
filename
=
'<test>'
builder
=
ast
.
BuilderFromSource
(
cpp_source
,
filename
)
...
...
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