mdewolfe / googlemock Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/googlemock
License: BSD 3-Clause "New" or "Revised" License
Automatically exported from code.google.com/p/googlemock
License: BSD 3-Clause "New" or "Revised" License
A user can define a custom matcher either by defining a free function or
implementing the MatcherInterface. Google Mock provides several helpers to
make the latter easier, but still they are not quite straightforward.
We can provide macros like
MOCK_MATCHER(MatcherName) { .... matcher body ... }
MOCK_MATCHER_P2(MatcherName, arg1_name, arg2_name) { ... matcher body ...
}
to make defining single-use matchers even easier.
Original issue reported on code.google.com by [email protected]
on 23 Dec 2008 at 5:13
A user can define a custom action either by defining a free function or
implementing the ActionInterface. Google Mock provides several helpers to
make the latter easier, but still they are not quite straightforward.
We can provide macros like
MOCK_ACTION(ActionName) { .... action body ... }
MOCK_ACTION_P2(ActionName, arg1_name, arg2_name) { ... action body ... }
to make defining single-use actions even easier.
Original issue reported on code.google.com by [email protected]
on 23 Dec 2008 at 5:11
What steps will reproduce the problem?
1. Install Google Mock on a computer on which Google Test is not installed.
2. run gmock-config --version
What is the expected output? What do you see instead?
Expected -- 1.1.0
Instead -- "The Google Test found is not the same version as Google Mock
was built against"
What version of the product are you using? On what operating system?
Happens on both the current svn trunk and version 1.1.0.
Please provide any additional information below.
gmock-config is insisting on Google Test version 1.2.1. But it is built
with version 1.3.0. Changing the GTEST_MIN_VERSION variable in
configure.ac from 1.2.1 to 1.3.0 fixes it.
Original issue reported on code.google.com by [email protected]
on 18 May 2009 at 1:23
Attachments:
ON_CALL and EXPECT_CALL cause a mock object to be referenced in a global
table Google Mock keeps. Therefore if the user code forgets to delete a
mock object, a leak checker won't be able to detect it since the object is
still reachable from the global table. This is bad as the verification of
expectations is done in the mock object's destructor.
We should use some kind of weak pointer instead of void* to reference the
mock objects in the global table.
Original issue reported on code.google.com by [email protected]
on 6 Feb 2009 at 7:48
We already have functions for manually verifying a
single mock:
bool Mock::VerifyAndClearExpectations(&mock_obj);
bool Mock::VerifyAndClear(&mock_obj);
(See
http://code.google.com/p/googlemock/wiki/CheatSheet#Verifying_and_Resetting_a_Mo
ck
for more info.)
We should also support manually verifying *all* mocks:
bool Mock::VerifyAndClearExpectationsOfAllMocks();
bool Mock::VerifyAndClearAllMocks();
Original issue reported on code.google.com by [email protected]
on 17 Apr 2009 at 9:53
Chandler Carruth wrote:
"This might actually feasible, and solves the problem below as well --
why don't we provide our own TR1 in the same manner as we provide
gtest? Specifically we could have the following preference:
1) look for a compiler provided tr1
2) look for a system installed boost
2b) (I don't actually think this would be needed) expose a flag
indicating "boost is over here"
3) add include paths which point into an internal snapshot of (for
instance) the boost tr1, potentially configuring gmock to #include it
out of an internal directory, so that once installed, it'll never be
used by some other project."
We can use bcp (http://www.boost.org/doc/libs/1_36_0/tools/bcp/bcp.html) to
extract the subset of Boost needed by tr1/tuple, which can significantly
reduce the size of boost files.
Original issue reported on code.google.com by [email protected]
on 16 Dec 2008 at 8:55
Currently, when we detect a leaked mock object, we print the source file
location where it was first set expectations on. Sometimes the user do
that in a subroutine shared by several tests, and it's unclear which test
leaked the mock.
We should also print which test method the leaked mock object is from.
Original issue reported on code.google.com by [email protected]
on 4 May 2009 at 5:56
We need a matcher to do bitwise comparison. This is useful for validating
binary data or POD types that don't have operator== defined. For example,
BitEq(x) -- the value equals x bitwise.
We'll also need a variant where the size is specified by the user.
Original issue reported on code.google.com by [email protected]
on 16 Dec 2008 at 6:19
[deleted issue]
Leveraging Google Mock as a subdirectory package via Autotools (likely a
common configuration) requires quite a bit of manual setup for the client
project, the vast majority of which will be identical with every other
client project. We should provide a M4-based macro that not only can
leverage an installed copy of Google Mock, but can automate some (if not
all) of the process of configuring and building Google Mock as a subdir
package with Autotools.
Original issue reported on code.google.com by [email protected]
on 11 Dec 2008 at 6:45
What steps will reproduce the problem?
1. make check on a big-endian architecture.
What is the expected output? What do you see instead?
I'm seeing a failure in the unit tests of googlemock on OSX 10.4 on PowerPC
../test/gmock-printers_test.cc:800: Failure
Value of: Print(UnprintableTemplateInGlobal<bool>())
Actual: "4-byte object <0000 0000>"
Expected: "1-byte object <00>"
[ FAILED ] PrintUnprintableTypeTest.InGlobalNamespace
[...]
../test/gmock-printers_test.cc:806: Failure
Value of: Print(::foo::UnprintableInFoo())
Actual: "16-byte object <0000 12EF 0000 AB34 0000 0000 0000 0000>"
Expected: "16-byte object <EF12 0000 34AB 0000 0000 0000 0000 0000>"
[ FAILED ] PrintUnprintableTypeTest.InUserNamespace
[...]
../test/gmock-printers_test.cc:888: Failure
Value of: PrintByRef(x)
Actual: "@0xbffff07c 16-byte object <0000 12EF 0000 AB34 0000 0000 0000 0000>"
Expected: "@" + PrintPointer(&x) + " 16-byte object " "<EF12 0000 34AB
0000 0000 0000 0000 0000>"
Which is: "@0xbffff07c 16-byte object <EF12 0000 34AB 0000 0000 0000 0000
0000>"
[ FAILED ] PrintReferenceTest.PrintsAddressAndValue
[...]
[ FAILED ] 3 tests, listed below:
[ FAILED ] PrintUnprintableTypeTest.InGlobalNamespace
[ FAILED ] PrintUnprintableTypeTest.InUserNamespace
[ FAILED ] PrintReferenceTest.PrintsAddressAndValue
3 FAILED TESTS
FAIL: test/gmock-printers_test
Note that this only affects pretty-printing of values on big-endian
machines, so it's not a big deal.
Please use labels and text to provide additional information.
Darwin 8.8.0 Darwin Kernel Version 8.8.0: Fri Sep 8 17:18:57 PDT
2006; root:xnu-792.12.6.obj~1/RELEASE_PPC Power Macintosh powerpc
powerpc-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
Original issue reported on code.google.com by [email protected]
on 11 Dec 2008 at 11:21
it maybe more informative if a print function exists. Like
[=========] Running 3 tests from 3 test cases.
[---------] Global test environment set-up.
[---------] 1 test from Test
[ RUN ] Test.user_test01
[ OK ] Test.user_test01
||
||
\/
[ver 1.0 ] googlemock <=== here!!!
[=========] Running 3 tests from 3 test cases.
[---------] Global test environment set-up.
[---------] 1 test from Test
[ RUN ] Test.user_test01
[ OK ] Test.user_test01
cheol
Original issue reported on code.google.com by [email protected]
on 13 Mar 2009 at 7:31
What steps will reproduce the problem?
1. Lets say we add the following test in test/gmock-spec-builders_test.cc:
TEST(UninterestingCallTest, FailureOnUndefinedDefaultAction) {
MockA a;
Result r = a.ReturnResult(0);
}
2. Or a test like this:
TEST(UnexpectedCallTest, FailyureOnUnderfinedDefaultAction) {
FLAGS_gmock_verbose = "info";
MockA a;
EXPECT_CALL(a, ReturnResult(1)).WillOnce(Return(Result()));
Result r = a.ReturnResult(0);
}
What is the expected output? What do you see instead?
To my understanding the first one is an Uninteresting call while the second
is an Unexpected call. Both have the same output:
Stack trace:
./include/gmock/gmock-actions.h:73: Failure
Default action undefined for the function return type.
Abort trap
What version of the product are you using? On what operating system?
1.0
Mac OS X
Please provide any additional information below.
I would like to see test output like this:
Uninteresting mock function call - returning default value.
Function call: ReturnResult(0)
Undefined default return value.
Abort trap
And like this:
Unexpected mock function call - returning default value.
Function call: ReturnResult(0)
Undefined default return value.
Abort trap
This is caused because we are trying do a
BuiltInDefaultValue<Result>::Get() which dies since Result has no default
value. I suggest we add a way to check whether we have a defined default
value before we call FunctionMockerBase::PerformDefaultAction(...)
I have a patch which does this.
Original issue reported on code.google.com by [email protected]
on 18 Dec 2008 at 9:07
GoogleMock's autotools build script is compiling GoogleMock and
its tests with -O2. As a result, it takes a lot of time to do a clean
make. We shouldn't bother with -O2 for the tests at least.
Original issue reported on code.google.com by [email protected]
on 9 Feb 2009 at 7:46
What steps will reproduce the problem?
1. Install google mock
2. run `gmock-config --ldflags`
What is the expected output? What do you see instead?
Should say something like -L/usr/local/lib -L/usr/local/lib, in fact it says:
"-L/usr/local/lib-L/usr/local/lib"
Note the lack of a space between the two -L values.
This means that using pkg-config macros in the configure step of a build
process would fail. My workaround is to use `gtest-config --ldflags` and
then check for the existence of gmock-config without actually using its
output. I assume that both libraries are installed to the same place.
It looks like a straightforward fix. On line 262 in scripts/gmock-config.in
when gmock_ldflags is set there is a space missing.
What version of the product are you using? On what operating system?
Version 1.1.0 on Linux, with gtest 1.3.0.
Original issue reported on code.google.com by richard.quirk
on 2 Jun 2009 at 8:08
JJ wrote:
I'd like to talk about the test sequencing features. As explained in
the Cookbook,
it's possible to place expectations into an arbitrary directed acyclic
graph in
their sequencing, in theory. However, I'm finding this sometimes
extremely
cumbersome, and occasionally impossible, in practice. Let me give some
examples:
Suppose that I have a simple mock class
class MockA: public AInterface
{
MOCK_METHOD0(a, void());
MOCK_METHOD0(b, void());
MOCK_METHOD0(c, void());
MOCK_METHOD0(final, void());
};
and I want to expect that all of a(), b() and c() are called in
unspecified order,
and then final() is called after all three of them, my understanding
is that my
only recourse is to specify the following:
MockA myMock;
Sequence s, t, u;
EXPECT_CALL(myMock, a()).InSequence(s);
EXPECT_CALL(myMock, b()).InSequence(t);
EXPECT_CALL(myMock, c()).InSequence(u);
EXPECT_CALL(myMock, final()).InSequence(s, t, u);
This is starting to get a bit unwieldy, and would only get more so as
the number
of expectations increased. More telling, though, is that this setup
requires
knowledge of exactly how many expectations are going to be in the
initial group before
the expectation for final() can be created, so that the correct number
of sequences
can be created. Unfortunately, I don't think this is always the case:
consider the
situation in which the group of expectations is being created by a
polymorphic or
templated function, such as the following:
struct Tester
{
void setAllExpectations
{
MockA myMock;
//How many sequences would I create here? We don't know how
many
//expectations the virtual method is going to create, and we
can't even
//*call* it without that information, because we'd have to
pass all the
//sequences into it to replicate the previous code.
setABCExpectations(myMock);
EXPECT_CALL(myMock, final());
}
protected:
virtual void setABCExpectations(MockA& myMock) = 0;
};
Now, unless I've just missed a much more natural way to do what I want
to do there,
it's now impossible to create the desired ordering.
Has anyone else run into this situation? Is it worth adding
functionality to
enhance the ordering possibilities for expectations?
Thanks for your time,
JJ
One possible natural syntax for such an enhancement follows, provided
for the
purposes of discussion -- I don't claim to be sufficiently conversant
with the
internal code of Google Mock to know how difficult it would be to make
this
happen, though.
MockA myMock;
Sequence s;
{
Group g(s);
//alternatively an object of type InGroup could obviate the need
for the
//InGroup clauses on the expectations, in the same way as
InSequence objects.
EXPECT_CALL(myMock, a()).InGroup(g);
EXPECT_CALL(myMock, b()).InGroup(g);
EXPECT_CALL(myMock, c()).InGroup(g);
}
EXPECT_CALL(myMock, final()).InSequence(s);
Semantically, the above Group object would have to create some kind of
temporary
collection of Expectations that could be inserted in the sequence s
instead of
an individual expectation. The group would naturally be complete when
all expectations
within it were complete, and therefore only then could the call to
final() succeed.
------------------------------------------------------------------------
I wrote:
I agree that your use case is not well supported right now (you can
use the trick Chris suggested, but it doesn't scale well when your
expectations are more complex. A more natural encoding of your intent
will make the test much easier to read.).
Our philosophy is to keep Google Mock conceptually as simple as
possible. Therefore we tend to wait for actual needs to come up
before we implement something. That way we can be more sure that our
design does solve the user's problem, and that we don't bloat Google
Mock with "features" that don't match the reality.
- Show quoted text -
> One possible natural syntax for such an enhancement follows, provided
> for the
> purposes of discussion -- I don't claim to be sufficiently conversant
> with the
> internal code of Google Mock to know how difficult it would be to make
> this
> happen, though.
>
> MockA myMock;
>
> Sequence s;
>
> {
> Group g(s);
>
> //alternatively an object of type InGroup could obviate the need
> for the
> //InGroup clauses on the expectations, in the same way as
> InSequence objects.
>
> EXPECT_CALL(myMock, a()).InGroup(g);
> EXPECT_CALL(myMock, b()).InGroup(g);
> EXPECT_CALL(myMock, c()).InGroup(g);
> }
>
> EXPECT_CALL(myMock, final()).InSequence(s);
>
>
> Semantically, the above Group object would have to create some kind of
> temporary
> collection of Expectations that could be inserted in the sequence s
> instead of
> an individual expectation. The group would naturally be complete when
> all expectations
> within it were complete, and therefore only then could the call to
> final() succeed.
Something like this might be made to work. However, it's unclear to
me what the relationship between groups and sequences should be. The
"Group g(s);" syntax suggests that there's some connection between g
and s, but what is it? I can understand it in your specific example,
but what about the general case? How do you associate one group with
multiple sequences? And how do you associate multiple groups with one
sequence? What's the semantics of these combinations? Is the
semantics sound? In the end, it can get muddy quickly.
As you stated, the problem you are having is that the InSequence()
syntax requires you to know the number of sequences when you *write*
the code, which is not always possible. We can fix this by allowing
InSequence() (or use a different name like InSequenceSet()) to accept a
container of sequences. Then the above program can be written as:
MockA myMock;
SequenceSet ss;
EXPECT_CALL(myMock, a()).InSequence(ss.AddNew());
EXPECT_CALL(myMock, b()).InSequence(ss.AddNew());
EXPECT_CALL(myMock, c()).InSequence(ss.AddNew());
EXPECT_CALL(myMock, final()).InSequenceSet(ss);
Notes:
- "Set" emphasizes that the order of the elements is unimportant.
- ss.AddNew() creates a new Sequence, adds it to ss, and returns the
Sequence.
- An expectation can accepts multiple InSequence()s and/or multiple
InSequenceSet()s.
- We provide SequenceSet as a convenience. However, the user is not
restricted to it. You can pass any STL-style containers to
InSequenceSet().
It's easy to see that the semantics of InSequenceSet(ss) is sound, as
it can be viewed as a syntactic sugar of InSequence(s1, ..., sn) where
s1, ..., and sn are the members of ss. Being a syntactic sugar also
means a user can learn this construct easily.
Original issue reported on code.google.com by [email protected]
on 5 Jun 2009 at 12:22
What steps will reproduce the problem?
1. Download latest version of googlemock from the website
2. # make && make check && sudo make install
3. # gmock-config --version
What is the expected output? What do you see instead?
Expected output: 1.1.0
Actual output: The Google Test found is not the same version as Google
Mock was built against
What version of the product are you using? On what operating system?
Version: 1.1.0
OS: Gentoo Linux
Please provide any additional information below.
The gmock-config script is checking for version 1.2.1 of gtest, but is
being shipped with version 1.3.0. The attached patch file will fix this
problem
Original issue reported on code.google.com by [email protected]
on 28 May 2009 at 1:54
Attachments:
Possible Enhancement:
template <size_t N, typename A, bool kIsProto>
class SetArgumentRefereeAction {
public:
// Constructs an action that sets the variable pointed to by the
// N-th function argument to 'value'.
explicit SetArgumentRefereeAction(const A& value) : value_(value) {}
template <typename Result, typename ArgumentTuple>
void Perform(const ArgumentTuple& args) const {
CompileAssertTypesEqual<void, Result>();
::std::tr1::get<N>(args) = value_;
}
private:
const A value_;
};
template <size_t N, typename T>
PolymorphicAction<
internal::SetArgumentRefereeAction<
N, T, internal::IsAProtocolMessage<T>::value> >
SetArgumentReferee(const T& x) {
return MakePolymorphicAction(internal::SetArgumentRefereeAction<
N, T, internal::IsAProtocolMessage<T>::value>(x));
}
with following test case:
#include <gmock/gmock.h>
#include <memory>
using testing::_;
using testing::Return;
using testing::Action;
using testing::ActionInterface;
using testing::MakeAction;
using testing::DoAll;
using testing::SetArgumentPointee;
using testing::SetArgumentReferee;
using testing::internal::Function;
class Foo
{
public:
virtual bool func(int*) = 0;
virtual bool funcRef(int&) = 0;
};
class MockFoo : public Foo
{
public:
MOCK_METHOD1(func, bool(int*));
MOCK_METHOD1(funcRef, bool(int&));
};
class Bar
{
public:
explicit Bar(Foo* pFoo) : m_pFoo(pFoo)
{
}
int CallIt()
{
int i = 0;
m_pFoo->func(&i);
return i;
}
int CallItRef()
{
int i = 0;
m_pFoo->funcRef(i);
return i;
}
Foo* m_pFoo;
};
TEST(Testitout, argpointee)
{
MockFoo foo;
EXPECT_CALL(foo, func(_))
.WillOnce(DoAll(SetArgumentPointee<0>(5),Return(true)));
EXPECT_CALL(foo, funcRef(_))
.WillOnce(DoAll(SetArgumentReferee<0>(5),Return(true)));
Bar bar(&foo);
EXPECT_EQ(5, bar.CallIt());
EXPECT_EQ(5, bar.CallItRef());
}
int main(int argc, char **argv) {
std::cout << "Running main() from gtest_main.cc\n";
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Original issue reported on code.google.com by [email protected]
on 25 Dec 2008 at 6:02
Google Test has a fuse_gtest_files.py script for fusing all source files
into a .h and a .cc, making it easy to deploy. We should do the same for
Google Mock.
Original issue reported on code.google.com by [email protected]
on 9 Feb 2009 at 12:08
Hamcrest (http://code.google.com/p/hamcrest/) defines many useful matchers
for Java. We should study it and port the good ones to GoogleMock.
Original issue reported on code.google.com by [email protected]
on 11 Feb 2009 at 6:20
Using gmock 1.0.0 on Ubuntu 7.04 with g++ 4.1.2
What steps will reproduce the problem?
The following program will show the problem
#include <gmock/gmock.h>
#include <memory>
using testing::_;
using testing::Return;
using testing::Action;
using testing::ActionInterface;
using testing::MakeAction;
using testing::DoAll;
using testing::SetArgumentPointee;
using testing::internal::Function;
class Foo
{
public:
virtual bool func(int*) = 0;
};
class MockFoo : public Foo
{
public:
MOCK_METHOD1(func, bool(int*));
};
class Bar
{
public:
explicit Bar(Foo* pFoo) : m_pFoo(pFoo)
{
}
int CallIt()
{
int i = 0;
m_pFoo->func(&i);
return i;
}
Foo* m_pFoo;
};
TEST(Testitout, argpointee)
{
MockFoo foo;
EXPECT_CALL(foo, func(_))
.WillOnce(SetArgumentPointee<0>(5));
Bar bar(&foo);
EXPECT_EQ(5, bar.CallIt());
}
int main(int argc, char **argv) {
std::cout << "Running main() from gtest_main.cc\n";
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
yields the following compile error:
/home/trask/gmock/gmock-1.0.0/include/gmock/gmock-actions.h: In member
function �$-1òøtypename testing::internal::Function<F>::Result
testing::PolymorphicAction<Impl>::MonomorphicImpl<F>::Perform(const
typename testing::internal::Function<F>::ArgumentTuple&) [with F = bool
()(int*), Impl = testing::internal::SetArgumentPointeeAction<0u, int,
false>]òù:
test.cpp:57: instantiated from here
/home/trask/gmock/gmock-1.0.0/include/gmock/gmock-actions.h:373: error:
void value not ignored as it ought to be
/home/trask/gmock/gmock-1.0.0/include/gmock/gmock-actions.h: In member
function �$-1òøvoid testing::internal::SetArgumentPointeeAction<N, A,
kIsProto>::Perform(const ArgumentTuple&) const [with Result = bool,
ArgumentTuple = std::tr1::tuple<int*, std::tr1::_NullClass,
std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass,
std::tr1::_NullClass, std::tr1::_NullClass, std::tr1::_NullClass,
std::tr1::_NullClass, std::tr1::_NullClass>, unsigned int N = 0u, A = int,
bool kIsProto = false]òù:
/home/trask/gmock/gmock-1.0.0/include/gmock/gmock-actions.h:373:
instantiated from �$-1òøtypename testing::internal::Function<F>::Result
testing::PolymorphicAction<Impl>::MonomorphicImpl<F>::Perform(const
typename testing::internal::Function<F>::ArgumentTuple&) [with F = bool
()(int*), Impl = testing::internal::SetArgumentPointeeAction<0u, int,
false>]òù
test.cpp:57: instantiated from here
/home/trask/gmock/gmock-1.0.0/include/gmock/gmock-actions.h:616: error:
invalid use of undefined type �$-1òøstruct
testing::internal::CompileAssertTypesEqual<void, bool>òù
/home/trask/gmock/gmock-1.0.0/include/gmock/internal/gmock-internal-utils.h:69:
error: declaration of �$-1òøstruct
testing::internal::CompileAssertTypesEqual<void, bool>òù
make: *** [test.o] Error 1
Compilation exited abnormally with code 2 at Wed Dec 24 20:51:26
What is the expected output? What do you see instead?
When I change the func to have return type void. It compiles fine.
What version of the product are you using? On what operating system?
Using gmock 1.0.0 on Ubuntu 7.04 with g++ 4.1.2
Please provide any additional information below.
I believe the culprit is the Perform function in:
template <size_t N, typename A, bool kIsProto>
class SetArgumentPointeeAction {
public:
// Constructs an action that sets the variable pointed to by the
// N-th function argument to 'value'.
explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
template <typename Result, typename ArgumentTuple>
void Perform(const ArgumentTuple& args) const {
CompileAssertTypesEqual<void, Result>();
*::std::tr1::get<N>(args) = value_;
}
private:
const A value_;
};
the Perform function returns void which is problem when called from
template <typename Impl>
class PolymorphicAction {
public:
explicit PolymorphicAction(const Impl& impl) : impl_(impl) {}
template <typename F>
operator Action<F>() const {
return Action<F>(new MonomorphicImpl<F>(impl_));
}
private:
template <typename F>
class MonomorphicImpl : public ActionInterface<F> {
public:
typedef typename internal::Function<F>::Result Result;
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
virtual Result Perform(const ArgumentTuple& args) {
return impl_.template Perform<Result>(args);
}
private:
Impl impl_;
};
Impl impl_;
};
When I change to
template <size_t N, typename A, bool kIsProto>
class SetArgumentPointeeAction {
public:
// Constructs an action that sets the variable pointed to by the
// N-th function argument to 'value'.
explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
template <typename Result, typename ArgumentTuple>
Result Perform(const ArgumentTuple& args) const {
*::std::tr1::get<N>(args) = value_;
return Result();
}
which works for my program but is not the final solution as it needs to
work with void return types and default values. I am working on a more
generic solution but just wanted to submit in case I was missing something
or doing something incorrectly or someone was already working on it.
Let me know.
Thanks.
Bruce
Original issue reported on code.google.com by [email protected]
on 25 Dec 2008 at 2:09
Compare googlemock with the following frameworks such that the users know
which one to use:
mockpp: http://mockpp.sourceforge.net/
mockcpp: http://code.google.com/p/mockcpp/
mockitopp: http://code.google.com/p/mockitopp/
amop: http://code.google.com/p/amop/
Original issue reported on code.google.com by [email protected]
on 6 Oct 2008 at 5:46
http://code.google.com/p/googlemock/wiki/CookBook#Using_Check_Points
describes a pattern of using check points. The CheckPoint class defined
there should be added to Google Mock.
Original issue reported on code.google.com by [email protected]
on 6 Feb 2009 at 7:37
This is Chandler's idea:
To make it easier for people to contribute, we should bundle upload.py in
the release package, and customize it such that it automatically adds
[email protected] to the cc line.
Original issue reported on code.google.com by [email protected]
on 11 Feb 2009 at 7:05
This is not a bug report but an enhancement request.
Currently, it expects a boost or part of boost to provide a tuple
implementation for gmock user on Windows platform. But it's not so
convenient and need a VS setting change.
Do you have plan to include a tuple implementation in gmock directly? Just
like amop, another c++ mocking framework as good as gmock.
Original issue reported on code.google.com by [email protected]
on 9 Feb 2009 at 3:02
What steps will reproduce the problem?
execute gmock_gen.py on a class containing the following type of method:
class AbstractObject{
public:
virtual const char* getObject() const = 0;
};
file MockBug.h containing a class with this type of method is attached.
What is the expected output?
MOCK_CONST_METHOD0(getObject, const char*() );
What do you see instead?
MOCK_CONST_METHOD0(getObject, char*() );
file mock_test_output.txt is attached.
What version of the product are you using? On what operating system?
googlemock 1.1.0
python 2.6
windows xp
Used this googlemock cookbook example as a reference that const should be
included:
for method in the cookbook: virtual const Bar& GetBar() const;
cookbook example: MOCK_CONST_METHOD0(GetBar, const Bar&());
Original issue reported on code.google.com by [email protected]
on 28 Apr 2009 at 9:18
Attachments:
From the user email:
//test1.cpp
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace testing;
#include <iostream>
using namespace std;
class test1
{
public:
virtual int get(string *name)=0;
};
class mock_test1: public test1
{
public:
MOCK_METHOD1(get, int(string *name));
};
class use_test1
{
public:
explicit use_test1(test1 *ptr_test1):
ptr_test1_(ptr_test1)
{
}
void use_get()
{
string name;
int ret=ptr_test1_->get(&name);
cout<<"ret="<<ret<<" name="<<name<<endl;
}
private:
test1 *ptr_test1_;
};
TEST(use_test1, test1)
{
mock_test1 mock_test1_obj;
EXPECT_CALL(mock_test1_obj, get(_))
.WillOnce(DoAll(SetArgumentPointee<0>(string("ddd")),
Return(0)));
use_test1 use_test1_obj(&mock_test1_obj);
use_test1_obj.use_get();
}
// test2.cpp
#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace testing;
#include <iostream>
using namespace std;
class test2
{
public:
virtual int get(string *name)=0;
};
class mock_test2: public test2
{
public:
MOCK_METHOD1(get, int(string *name));
};
class use_test2
{
public:
explicit use_test2(test2 *ptr_test2):
ptr_test2_(ptr_test2)
{
}
void use_get()
{
string name;
int ret=ptr_test2_->get(&name);
cout<<"ret="<<ret<<" name="<<name<<endl;
}
private:
test2 *ptr_test2_;
};
TEST(use_test2, test2)
{
mock_test2 mock_test2_obj;
EXPECT_CALL(mock_test2_obj, get(_))
.WillOnce(DoAll(SetArgumentPointee<0>(string("ddd")),
Return(0)));
use_test2 use_test2_obj(&mock_test2_obj);
use_test2_obj.use_get();
}
error when linking:
test2.obj : error LNK2005: "public: __thiscall `public: __thiscall
testing::internal::DoBothAction<class testing::PolymorphicAction<class
testing::internal::SetArgumentPointeeAction<0,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,0> >,class testing::internal::ReturnAction<int>
>::operator<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)> class
testing::Action<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)>(void)const
'::`2'::Impl::Impl(class testing::Action<void __cdecl(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *)> const &,class testing::Action<int __cdecl
(class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *)> const &)" (??0Impl@?1???$?B$$A6AHPAV?
$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@?
$DoBothAction@V?$PolymorphicAction@V?$SetArgumentPointeeAction@$0A@V?
$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@
$0A@@internal@testing@@@testing@@V?
$ReturnAction@H@internal@2@@internal@testing@@QBE?AV?$Action@$$A6AHPAV?
$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@3@XZ@QAE@ABV?$Action@$$A6AXPAV?
$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@3@ABV43@@Z) 已经在 test1.obj 中定义
test2.obj : error LNK2005: "public: virtual int __thiscall `public:
__thiscall testing::internal::DoBothAction<class
testing::PolymorphicAction<class
testing::internal::SetArgumentPointeeAction<0,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,0> >,class testing::internal::ReturnAction<int>
>::operator<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)> class
testing::Action<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)>(void)const
'::`2'::Impl::Perform(struct boost::fusion::tuple<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_> const &)" (?
Perform@Impl@?1???$?B$$A6AHPAV?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@?$DoBothAction@V?$PolymorphicAction@V?
$SetArgumentPointeeAction@$0A@V?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@$0A@@internal@testing@@@testing@@V?
$ReturnAction@H@internal@2@@internal@testing@@QBE?AV?$Action@$$A6AHPAV?
$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@4@XZ@UAEHABU?$tuple@PAV?$basic_string@DU?
$char_traits@D@std@@V?
$allocator@D@2@@std@@Uvoid_@fusion@boost@@U345@U345@U345@U345@U345@U345@U345@U34
5@@fusion@boost@@@Z)
已经在 test1.obj 中定义
test2.obj : error LNK2005: "public: __thiscall `public: __thiscall
testing::internal::DoBothAction<class testing::PolymorphicAction<class
testing::internal::SetArgumentPointeeAction<0,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,0> >,class testing::internal::ReturnAction<int>
>::operator<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)> class
testing::Action<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)>(void)const
'::`2'::Impl::Impl(class testing::Action<void __cdecl(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *)> const &,class testing::Action<int __cdecl
(class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *)> const &)" (??0Impl@?1???$?B$$A6AHPAV?
$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@?
$DoBothAction@V?$PolymorphicAction@V?$SetArgumentPointeeAction@$0A@V?
$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@
$0A@@internal@testing@@@testing@@V?
$ReturnAction@H@internal@2@@internal@testing@@QBE?AV?$Action@$$A6AHPAV?
$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@3@XZ@QAE@ABV?$Action@$$A6AXPAV?
$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@3@ABV43@@Z) 已经在 test1.obj 中定义
test2.obj : error LNK2005: "public: virtual int __thiscall `public:
__thiscall testing::internal::DoBothAction<class
testing::PolymorphicAction<class
testing::internal::SetArgumentPointeeAction<0,class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,0> >,class testing::internal::ReturnAction<int>
>::operator<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)> class
testing::Action<int __cdecl(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > *)>(void)const
'::`2'::Impl::Perform(struct boost::fusion::tuple<class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > *,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_,struct
boost::fusion::void_,struct boost::fusion::void_> const &)" (?
Perform@Impl@?1???$?B$$A6AHPAV?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@?$DoBothAction@V?$PolymorphicAction@V?
$SetArgumentPointeeAction@$0A@V?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@$0A@@internal@testing@@@testing@@V?
$ReturnAction@H@internal@2@@internal@testing@@QBE?AV?$Action@$$A6AHPAV?
$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@@Z@4@XZ@UAEHABU?$tuple@PAV?$basic_string@DU?
$char_traits@D@std@@V?
$allocator@D@2@@std@@Uvoid_@fusion@boost@@U345@U345@U345@U345@U345@U345@U345@U34
5@@fusion@boost@@@Z)
已经在 test1.obj 中定义
Original issue reported on code.google.com by vladlosev
on 23 Jan 2009 at 1:07
What steps will reproduce the problem?
1. Configure and build gtest
2. Configure gmock: ../configure --with-gtest=<path-to-gtest-build-dir>
3. Build gmock
4. sudo make install
What is the expected output? What do you see instead?
make install is expected to install libraries and include files for gmock
_and_ gtest. Instead it installs libraries and include files for gmock only.
Original issue reported on code.google.com by vladlosev
on 18 Mar 2009 at 11:59
Google Mock has many .h files, but a user should always #include
<gmock/gmock.h>. The other .h files' paths may change and thus cannot be
depended on.
We should warn the user at the beginning of each .h file that it shouldn't
be #included directly.
Original issue reported on code.google.com by [email protected]
on 16 Dec 2008 at 11:38
When GoogleMock sees an unexpected call, it prints out
information in the following order:
1. Which function is being called and with what arguments,
2. What value it returns, and
3. What expectations gMock has tried to match the call with.
The reason for picking this order is that #1 and #2 are usually short
while #3 can be very lengthy. If we print #3 before #2, it can be
very hard to tell where #3 ends and spot the function's return value,
which in my opinion is bad user experience.
This usually works fine. However, if the function returns a class type, no
default action is set for it, and no default value is set for the return
type, the program will crash in
step #2, and #3 never gets a chance to be printed.
It should be possible for GoogleMock to do #3 before #2 when no default
return value is set.
Original issue reported on code.google.com by [email protected]
on 4 Mar 2009 at 7:09
Sometimes people use (const) char* for binary data that aren't really
0-terminated C strings. This confuses Google Mock. Write a recipe on how
to deal with it.
Original issue reported on code.google.com by [email protected]
on 6 Feb 2009 at 7:52
Thx to the wonderful Mock framework. I am using gtest already.
But, I am a novice here. I found the lack of examples in your latest
distribution of Google Mock. But, gtest does.
Could you post some examples(fully compilable) of Google Mock. At
least for the show cases in the article "Google C++ Mocking Framework
for Dummies".
Then, it will be great helpful the novice like me.
Original issue reported on code.google.com by [email protected]
on 18 Dec 2008 at 1:10
It would be nice to make Contains() accept a matcher for matching an
element instead of a value.
Original issue reported on code.google.com by [email protected]
on 20 Feb 2009 at 6:08
These actions would be useful:
// Saves arg #0 to foo. We may want to enforce that the function
// takes exactly one argument.
SaveArgTo(&foo)
// Saves arg #3 to foo. Shorthand for WithArg<3>(SaveArgTo(&foo)).
SaveArg<3>(&foo)
Original issue reported on code.google.com by [email protected]
on 13 Feb 2009 at 8:48
What steps will reproduce the problem?
1.
2.
3.
What is the expected output? What do you see instead?
Please use labels and text to provide additional information.
Original issue reported on code.google.com by vladlosev
on 18 Mar 2009 at 5:04
Bug Neal Norwitz to make his mock generator script available.
Original issue reported on code.google.com by [email protected]
on 2 Dec 2008 at 9:28
Some users still use gcc 3.3, which Google Mock doesn't work with yet. It
would be nice to make Google Mock compatible with gcc 3.3.
Original issue reported on code.google.com by [email protected]
on 13 Jan 2009 at 5:38
Possible Enhancement:
I have legacy code that uses exceptions from collaborating classes.
I would like to do something like:
EXPECT_CALL(obj, func())
.Times(1)
.WillOnce(Throw(MyException()));
I have some prototypes working but have more to do.
What steps will reproduce the problem?
1.
2.
3.
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 25 Dec 2008 at 4:34
The compiler complains "ambiguous overload" in this case.
I have a fix waiting to be verified by the user and reviewed:
http://codereview.appspot.com/14072/show
Original issue reported on code.google.com by [email protected]
on 10 Feb 2009 at 7:31
Just like googletest.
Original issue reported on code.google.com by [email protected]
on 16 Mar 2009 at 5:42
2009/4/16 Simon Bowden:
> As a suggestion, it would be convenient if there were a function to call any
> time [mainly at the end of a single test case] to assert the no-leaks check
> earlier. Specifically, I'd like all of my test cases to assert no leaks at
> the end of the case so that error reporting is better targetted.
I like it. Does
// Returns true if the mock registry is empty; otherwise
// generates a non-fatal failure for each leaked mock object
// and returns false.
bool Mock::CatchLeakedMock();
sound good?
Original issue reported on code.google.com by [email protected]
on 17 Apr 2009 at 9:51
now google mock framework implement the mock object in the corresponding
class. And when I used the mock object, I have to include the mock class in
my source code, if the interface that I mocked is big, when I compile my
source code, it is very very slowy.
I hope that when google mock implement the mock object, it can sperate
the declare file and implement file, that means I can comiple the mock
object to a single .obj file. I think this way can compile my source code
fastly.
Original issue reported on code.google.com by [email protected]
on 17 Feb 2009 at 11:04
Google Mock currently requires the user to use Google Test. This hampers
the adoption as many potential users may not be able to ditch their
existing C++ testing framework yet, or may not want to. We should allow a
user to use Google Mock with a testing framework of his choice.
One low-cost solution is to give Google Mock an option to throw an
exception when there's a failure. Most testing frameworks will treat
uncaught exceptions as failures, so this should work.
Original issue reported on code.google.com by [email protected]
on 16 Dec 2008 at 11:34
What steps will reproduce the problem?
1. I builded googletest.
./configure LD_LIBRARY_PATH=:some_path/stlport_5.1.5/gcc4/lib:some_path/
stlport_5.1.5/gcc4/lib --prefix=some_path/gtest-1.2.1 CPPFLAGS='-
Isome_path/stlport_5.1.5/gcc4/stlport -DGTEST_HAS_TR1_TUPLE=0 -
DGTEST_HAS_CLONE=0 -D_STLP_THREADS' LDFLAGS=-Lsome_path/stlport_5.1.5/gcc4/
lib LIBS=-lstlport
make
make install
OK
2. The googlemock has not got flags GTEST_HAS_TR1_TUPLE.
I tried to build gmock:
./configure LD_LIBRARY_PATH=:some_path/stlport_5.1.5/gcc4/lib:some_path/
stlport_5.1.5/gcc4/lib --prefix=some_path/gmock-1.0.0/ --with-
test=some_path/gtest CPPFLAGS='-Isome_path/stlport_5.1.5/gcc4/st
lport -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_CLONE=0 -D_STLP_THREADS '
LDFLAGS=-Lsome_path/stlport_5.1.5/gcc4/lib LIBS=-lstlport
make
In file included from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/../utility:66,
from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/utility:37,
from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/tuple:39,
from ./include/gmock/internal/gmock-port.h:54,
from ./include/gmock/internal/gmock-generated-internal-
utils.h:42,
from ./include/gmock/internal/gmock-internal-utils.h:45,
from ./include/gmock/gmock-actions.h:42,
from ./include/gmock/gmock.h:58,
from src/gmock.cc:32:
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_relops.h:92: error: redefinition of 'template<class _Tp> bool
stlp_std::rel_ops::ope
rator!=(const _Tp&, const _Tp&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:129: error:
'template<class _Tp> bool stlp_std::rel_ops::operator!=(const _Tp&, const
_Tp&)' previo
usly declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_relops.h:105: error: redefinition of 'template<class _Tp> bool
stlp_std::rel_ops::op
erator>(const _Tp&, const _Tp&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:133: error:
'template<class _Tp> bool stlp_std::rel_ops::operator>(const _Tp&, const
_Tp&)' previou
sly declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_relops.h:118: error: redefinition of 'template<class _Tp> bool
stlp_std::rel_ops::op
erator<=(const _Tp&, const _Tp&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:137: error:
'template<class _Tp> bool stlp_std::rel_ops::operator<=(const _Tp&, const
_Tp&)' previo
usly declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_relops.h:131: error: redefinition of 'template<class _Tp> bool
stlp_std::rel_ops::op
erator>=(const _Tp&, const _Tp&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:141: error:
'template<class _Tp> bool stlp_std::rel_ops::operator>=(const _Tp&, const
_Tp&)' previo
usly declared here
In file included from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/../utility:67,
from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/utility:37,
from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/tuple:39,
from ./include/gmock/internal/gmock-port.h:54,
from ./include/gmock/internal/gmock-generated-internal-
utils.h:42,
from ./include/gmock/internal/gmock-internal-utils.h:45,
from ./include/gmock/gmock-actions.h:42,
from ./include/gmock/gmock.h:58,
from src/gmock.cc:32:
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:68: error: redefinition of 'struct stlp_std::pair<_T1, _T2>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:45: error:
previous definition of 'struct stlp_std::pair<_T1, _T2>'
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:96: error: redefinition of 'template<class _T1, class _T2> bool
stlp_std::ope
rator==(const stlp_std::pair<_T1, _T2>&, const stlp_std::pair<_T1, _T2>&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:73: error:
'template<class _T1, class _T2> bool stlp_std::operator==(const
stlp_std::pair<_T1, _T2>
&, const stlp_std::pair<_T1, _T2>&)' previously declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:102: error: redefinition of 'template<class _T1, class _T2>
bool stlp_std::op
erator<(const stlp_std::pair<_T1, _T2>&, const stlp_std::pair<_T1, _T2>&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:77: error:
'template<class _T1, class _T2> bool stlp_std::operator<(const
stlp_std::pair<_T1, _T2>&
, const stlp_std::pair<_T1, _T2>&)' previously declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:109: error: redefinition of 'template<class _T1, class _T2>
bool stlp_std::op
erator!=(const stlp_std::pair<_T1, _T2>&, const stlp_std::pair<_T1, _T2>&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:84: error:
'template<class _T1, class _T2> bool stlp_std::operator!=(const
stlp_std::pair<_T1, _T2>
&, const stlp_std::pair<_T1, _T2>&)' previously declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:115: error: redefinition of 'template<class _T1, class _T2>
bool stlp_std::op
erator>(const stlp_std::pair<_T1, _T2>&, const stlp_std::pair<_T1, _T2>&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:88: error:
'template<class _T1, class _T2> bool stlp_std::operator>(const
stlp_std::pair<_T1, _T2>&
, const stlp_std::pair<_T1, _T2>&)' previously declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:121: error: redefinition of 'template<class _T1, class _T2>
bool stlp_std::op
erator<=(const stlp_std::pair<_T1, _T2>&, const stlp_std::pair<_T1, _T2>&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:92: error:
'template<class _T1, class _T2> bool stlp_std::operator<=(const
stlp_std::pair<_T1, _T2>
&, const stlp_std::pair<_T1, _T2>&)' previously declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:127: error: redefinition of 'template<class _T1, class _T2>
bool stlp_std::op
erator>=(const stlp_std::pair<_T1, _T2>&, const stlp_std::pair<_T1, _T2>&)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:96: error:
'template<class _T1, class _T2> bool stlp_std::operator>=(const
stlp_std::pair<_T1, _T2>
&, const stlp_std::pair<_T1, _T2>&)' previously declared here
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_pair.h:144: error: redefinition of 'template<class _T1, class _T2>
stlp_std::pair<_T
1, _T2> stlp_std::make_pair(_T1, _T2)'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_pair.h:120: error:
'template<class _T1, class _T2> stlp_std::pair<_T1, _T2>
stlp_std::make_pair(_T1, _T2)'
previously declared here
In file included from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/../functional:55,
from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/functional:39,
from /usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../
include/c++/4.2.2/tr1/tuple:159,
from ./include/gmock/internal/gmock-port.h:54,
from ./include/gmock/internal/gmock-generated-internal-
utils.h:42,
from ./include/gmock/internal/gmock-internal-utils.h:45,
from ./include/gmock/gmock-actions.h:42,
from ./include/gmock/gmock.h:58,
from src/gmock.cc:32:
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_function.h:102: error: redefinition of 'struct
stlp_std::unary_function<_Arg, _Resul
t>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_function_base.h:40:
error: previous definition of 'struct stlp_std::unary_function<_Arg,
_Result>'
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_function.h:114: error: redefinition of 'struct
stlp_std::binary_function<_Arg1, _Arg
2, _Result>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_function_base.h:46:
error: previous definition of 'struct stlp_std::binary_function<_Arg1,
_Arg2, _Result>
'
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_function.h:134: error: redefinition of 'struct stlp_std::plus<_Tp>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_function_base.h:104:
error: previous definition of 'struct stlp_std::plus<_Tp>'
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_function.h:143: error: redefinition of 'struct stlp_std::minus<_Tp>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_function_base.h:109:
error: previous definition of 'struct stlp_std::minus<_Tp>'
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_function.h:152: error: redefinition of 'struct
stlp_std::multiplies<_Tp>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_function_base.h:124:
error: previous definition of 'struct stlp_std::multiplies<_Tp>'
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_function.h:196: error: redefinition of 'struct stlp_std::equal_to<_Tp>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_function_base.h:53:
error: previous definition of 'struct stlp_std::equal_to<_Tp>'
/usr/lib/gcc/i386-redhat-linux/4.2.2/../../../../include/c++/4.2.2/bits/
stl_function.h:223: error: redefinition of 'struct stlp_std::less<_Tp>'
/home/ecsdev/Linux2.4/stlport_5.1.5/gcc4/stlport/stl/_function_base.h:66:
error: previous definition of 'struct stlp_std::less<_Tp>'
In file included from ./include/gmock/gmock-spec-builders.h:71,
from ./include/gmock/gmock-generated-function-
mockers.h:41,
from ./include/gmock/gmock.h:61,
from src/gmock.cc:32:
./include/gmock/gmock-matchers.h:850: error: expected ',' or '...' before
'*' token
./include/gmock/gmock-matchers.h:850: error: ISO C++ forbids declaration
of 'RE' with no type
./include/gmock/gmock-matchers.h:878: error: ISO C++ forbids declaration
of 'type name' with no type
./include/gmock/gmock-matchers.h:878: error: template argument 1 is invalid
./include/gmock/gmock-matchers.h: In constructor
'testing::internal::MatchesRegexMatcher::MatchesRegexMatcher(int)':
./include/gmock/gmock-matchers.h:851: error: 'regex' was not declared in
this scope
./include/gmock/gmock-matchers.h:851: error: 'full_match' was not declared
in this scope
./include/gmock/gmock-matchers.h: In member function 'bool
testing::internal::MatchesRegexMatcher::Matches(const
testing::internal::string&) const':
./include/gmock/gmock-matchers.h:862: error: 'RE' has not been declared
./include/gmock/gmock-matchers.h:862: error: invalid type argument of
'unary *'
./include/gmock/gmock-matchers.h:863: error: 'RE' has not been declared
./include/gmock/gmock-matchers.h:863: error: invalid type argument of
'unary *'
./include/gmock/gmock-matchers.h: In member function 'void
testing::internal::MatchesRegexMatcher::DescribeTo(stlp_std::ostream*)
const':
./include/gmock/gmock-matchers.h:869: error: base operand of '->' is not a
pointer
./include/gmock/gmock-matchers.h: In member function 'void
testing::internal::MatchesRegexMatcher::DescribeNegationTo
(stlp_std::ostream*) const':
./include/gmock/gmock-matchers.h:875: error: base operand of '->' is not a
pointer
./include/gmock/gmock-matchers.h: At global scope:
./include/gmock/gmock-matchers.h:1884: error: expected unqualified-id
before '*' token
./include/gmock/gmock-matchers.h:1884: error: expected ',' or '...' before
'*' token
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex()':
./include/gmock/gmock-matchers.h:1885: error: 'regex' was not declared in
this scope
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex(const testing::internal
::string&)':
./include/gmock/gmock-matchers.h:1889: error: expected type-specifier
./include/gmock/gmock-matchers.h:1889: error: expected `)'
./include/gmock/gmock-matchers.h:1889: error: no matching function for
call to 'MatchesRegex(int*)'
./include/gmock/gmock-matchers.h:1884: note: candidates are:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex()
./include/gmock/gmock-matchers.h:1888: note:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex(const tes
ting::internal::string&)
./include/gmock/gmock-matchers.h: At global scope:
./include/gmock/gmock-matchers.h:1895: error: expected unqualified-id
before '*' token
./include/gmock/gmock-matchers.h:1895: error: expected ',' or '...' before
'*' token
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex()':
./include/gmock/gmock-matchers.h:1896: error: 'regex' was not declared in
this scope
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex(const testing::interna
l::string&)':
./include/gmock/gmock-matchers.h:1900: error: expected type-specifier
./include/gmock/gmock-matchers.h:1900: error: expected `)'
./include/gmock/gmock-matchers.h:1900: error: no matching function for
call to 'ContainsRegex(int*)'
./include/gmock/gmock-matchers.h:1895: note: candidates are:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex()
./include/gmock/gmock-matchers.h:1899: note:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex(const te
sting::internal::string&)
make[1]: *** [src/gmock.lo] Error 1
make[1]: Leaving directory `/home/abondare/distrib/gmock-1.0.0'
3. I tried to used boost/tr1
./configure LD_LIBRARY_PATH=:some_path/stlport_5.1.5/gcc4/lib:some_path/
stlport_5.1.5/gcc4/lib --prefix=some_path/gmock-1.0.0/ --with-
gtest=some_path/gtest CPPFLAGS='-Isome_path/boost_1_35_0/boost/tr1 -
Isome_path/boost_1_35_0 -Isome_path/stlport_5.1.5/gcc4/stlport -
DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_CLONE=0 -D_STLP_THREADS ' LDFLA
GS=-Lsome_path/stlport_5.1.5/gcc4/lib LIBS=-lstlport
make
In file included from ./include/gmock/gmock-spec-builders.h:71,
from ./include/gmock/gmock-generated-function-
mockers.h:41,
from ./include/gmock/gmock.h:61,
from src/gmock.cc:32:
./include/gmock/gmock-matchers.h:850: error: expected ',' or '...' before
'*' token
./include/gmock/gmock-matchers.h:850: error: ISO C++ forbids declaration
of 'RE' with no type
./include/gmock/gmock-matchers.h:878: error: ISO C++ forbids declaration
of 'type name' with no type
./include/gmock/gmock-matchers.h:878: error: template argument 1 is invalid
./include/gmock/gmock-matchers.h: In constructor
'testing::internal::MatchesRegexMatcher::MatchesRegexMatcher(int)':
./include/gmock/gmock-matchers.h:851: error: 'regex' was not declared in
this scope
./include/gmock/gmock-matchers.h:851: error: 'full_match' was not declared
in this scope
./include/gmock/gmock-matchers.h: In member function 'bool
testing::internal::MatchesRegexMatcher::Matches(const
testing::internal::string&) const':
./include/gmock/gmock-matchers.h:862: error: 'RE' has not been declared
./include/gmock/gmock-matchers.h:862: error: invalid type argument of
'unary *'
./include/gmock/gmock-matchers.h:863: error: 'RE' has not been declared
./include/gmock/gmock-matchers.h:863: error: invalid type argument of
'unary *'
./include/gmock/gmock-matchers.h: In member function 'void
testing::internal::MatchesRegexMatcher::DescribeTo(stlp_std::ostream*)
const':
./include/gmock/gmock-matchers.h:869: error: base operand of '->' is not a
pointer
./include/gmock/gmock-matchers.h: In member function 'void
testing::internal::MatchesRegexMatcher::DescribeNegationTo
(stlp_std::ostream*) const':
./include/gmock/gmock-matchers.h:875: error: base operand of '->' is not a
pointer
./include/gmock/gmock-matchers.h: At global scope:
./include/gmock/gmock-matchers.h:1884: error: expected unqualified-id
before '*' token
./include/gmock/gmock-matchers.h:1884: error: expected ',' or '...' before
'*' token
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex()':
./include/gmock/gmock-matchers.h:1885: error: 'regex' was not declared in
this scope
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex(const testing::internal
::string&)':
./include/gmock/gmock-matchers.h:1889: error: expected type-specifier
./include/gmock/gmock-matchers.h:1889: error: expected `)'
./include/gmock/gmock-matchers.h:1889: error: no matching function for
call to 'MatchesRegex(int*)'
./include/gmock/gmock-matchers.h:1884: note: candidates are:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex()
./include/gmock/gmock-matchers.h:1888: note:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::MatchesRegex(const tes
ting::internal::string&)
./include/gmock/gmock-matchers.h: At global scope:
./include/gmock/gmock-matchers.h:1895: error: expected unqualified-id
before '*' token
./include/gmock/gmock-matchers.h:1895: error: expected ',' or '...' before
'*' token
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex()':
./include/gmock/gmock-matchers.h:1896: error: 'regex' was not declared in
this scope
./include/gmock/gmock-matchers.h: In function
'testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex(const testing::interna
l::string&)':
./include/gmock/gmock-matchers.h:1900: error: expected type-specifier
./include/gmock/gmock-matchers.h:1900: error: expected `)'
./include/gmock/gmock-matchers.h:1900: error: no matching function for
call to 'ContainsRegex(int*)'
./include/gmock/gmock-matchers.h:1895: note: candidates are:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex()
./include/gmock/gmock-matchers.h:1899: note:
testing::PolymorphicMatcher<testing::internal::MatchesRegexMatcher>
testing::ContainsRegex(const te
sting::internal::string&)
make[1]: *** [src/gmock.lo] Error 1
make[1]: Leaving directory `/home/abondare/distrib/gmock-1.0.0'
What version of the product are you using? On what operating system?
v. 1.0.0.
OS Linux
gcc 4.2.2.
Original issue reported on code.google.com by [email protected]
on 18 Feb 2009 at 12:44
As the title. gordoncww is playing with it.
Original issue reported on code.google.com by [email protected]
on 14 Jan 2009 at 10:40
= The problem =
To assist debugging, Google Mock sometimes prints the argument values
a mock function receives and its return value. Some people run into
problems with that, as they mock APIs where char* is used to pass a
buffer (as opposed to a NUL-terminated string). When Google Mock
tries to print such an argument or return value, the user sees trash;
worse, the program could crash for access violation.
We could avoid the problem by making Google Mock always print char* as
a pointer, but that doesn't work well for people using char* for
strings, which is a standard practice.
So far, we have been asking the users to change their buffer-passing
API to use something like unsigned char* instead of char*, such that
Google Mock won't mistaken it as a string. Doing that also makes the
code more readable as the intent of the argument is less ambiguous.
Sometimes the user isn't free to make that change. For that we
recommend this pattern:
// The base class has virtual void Foo(const char* buffer, int len).
MOCK_METHOD2(Foo, void(const unsigned char* buffer, int len));
virtual void Foo(const char* buffer, int len) {
// Forwards to the mock function.
Foo(reinterpret_cast<const unsigned char*>(buffer), len);
}
While this works, it's tedious.
Also, sometimes a user uses an array or container that has elements of
type char* inside. Google Mock will print the container elements as C
strings. The above wrapper pattern is harder to implement for
this case.
= Solution 1 =
We could introduce a global flag that makes all char* being printed as
pointers. However, this is a hack as the decision often needs to be
made locally: char* may mean a C string in one API and a pointer in
another, and you may be using both APIs in the same test program; even
different arguments of the same function may use char* in different
ways.
Therefore this is not a good solution.
= Solution 2 (the Proposal) =
In MOCK_METHOD*(), we can let the user annotate types that need to be
printed specially. If you want to leave it to gmock to decide how to
print an argument, you write MOCK_METHOD* the same as before. Otherwise, you
change the argument type from T to PrintBy<Format, T>, where Format is
a class for selecting the print format.
For example, to mock:
// 'buffer' points to some bytes, not necessarily NUL-terminated.
virtual void Foo(const char* buffer, int len);
you could write:
MOCK_METHOD2(Foo, void(PrintBy<CharStarAsPointer, const char*>
buffer, int len));
where CharStarAsPointer is defined by Google Mock. Advanced users can
define their own print format classes, but we'll discuss the details
later.
If you need to do this repeatedly, you can give the annotated type a
name using typedef:
typedef PrintBy<CharStarAsPointer, const char*> Buffer;
MOCK_METHOD2(Foo, void(Buffer buffer, int len));
MOCK_METHOD3(Compare, int(Buffer lhs, Buffer rhs, int len));
MOCK_METHOD0(GetBuffer, Buffer());
You may wonder why we need to expose the PrintBy template and the
CharStarAsPointer class. Can't Google Mock just define the Buffer
type and ask people to use it?
The answer is that there are unbounded number of container types out
there that can be used to contain char* values, and we cannot make
Google Mock aware of all of them. Suppose you use a class (written by
someone else) BufferTable which contains char* values, and you want
the values printed as pointers, you can tell Google Mock by:
MOCK_METHOD1(Blah, void(PrintBy<CharStarAsPointer, const
BufferTable&> table));
The T in PrintBy<CharStarAsPointer, T> doesn't have to be a char*. If
it's an array or container, Google Mock will print the elements
recursively. CharStarAsPointer tells Google Mock to treat elements of
char* type as pointers.
You may also wonder why we don't just ask the user to define a <<
operator or PrintTo() for the BufferTable class. The problem is that
often a container type is general-purpose and the char* elements it
carries may be C strings in one API and pointers in another. Since we
can only define one << or PrintTo() for each type, it's not
fine-grained enough.
Original issue reported on code.google.com by [email protected]
on 22 May 2009 at 4:31
What steps will reproduce the problem?
1. try to open gmock-1.0.0\msvc\gmock.sln with vs2005.
2. open the .sln file with txt editor, the following information can be found:
Microsoft Visual Studio Solution File, Format Version 9.00
It seems it's for VS2008.
What is the expected output? What do you see instead?
The solution should be opened.
But nothing happens.
As claimed in the project home page, VS2005(8.0) SP1 should be supported.
What version of the product are you using? On what operating system?
1.0.0
WinXP
Please provide any additional information below.
No.
Original issue reported on code.google.com by [email protected]
on 18 Dec 2008 at 4:42
Vlad reported that gcc 3.4 works with Boost TR1, while a user reported that
gcc 3.3 causes many compiler and test errors. Add this to the system
requirement section of the wiki and README.
Original issue reported on code.google.com by [email protected]
on 13 Jan 2009 at 5:36
Currently ON_CALL() and EXPECT_CALL() accepts a
.WithArguments(tuple_matcher) clause for specifying constraints on multiple
arguments, but it's not very easy to use. The proposal:
- Allow optional template arguments to select the function arguments that
will participate in the matching, ala the WithArgs(callable) action.
- Allow the clause to be used more than once in an expectation.
For example,
ON_CALL(foo, Bar(_, _, _))
.WithArguments(A())
.WithArguments<0, 2>(B())
.WithArguments<2, 1>(C());
says that:
- argument 0, 1, and 2 should match matcher A(),
- argument 0 and 2 should match matcher B(), and
- argument 2 and 1 should match matcher C().
One use case is that often a function passes a pointer to a buffer in one
argument and the size of the buffer in another argument, and we may want to
verify that the contents of the buffer are expected.
Original issue reported on code.google.com by [email protected]
on 2 Oct 2008 at 9:27
Make sure that functions specific to Microsoft's runtime libraries are used
only inside #ifdef _MSC_VER section. Moreover, there are functions specific
to particular versions of MS compiler, such as secure versions of CRT
functions, like _snprintf_s.
They should be handled like this:
#if _MSC_VER >= 1400
// use _snprintf_s
#endif _MSC_VER >= 1400
Original issue reported on code.google.com by vladlosev
on 12 Mar 2009 at 12:04
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.