Re: [Cppunit-devel] Some interesting ideas I am looking at
Brought to you by:
blep
|
From: Baptiste L. <bl...@cl...> - 2001-12-13 22:08:27
|
Some interesting ideas I am looking atHow about changing the original design
a little bit:
class Verifiable {
virtual void verify() = 0;
};
class Expectation : public Verifiable {
...
};
// A new base class for all object that contains expectation
// C++ allows mutliple inheritance, so we can use a base class
// for all object that contains Expectation
class VerifiableObject : public Verifiable {
public:
void addVerifiable( Verifiable * pVerifiable ) {
m_verifiables.push_back( pVerifiable );
}
void verify() {
for ( int index = 0; index < m_veriables.size(); ++index )
m_verifiables[index]->verify();
}
private:
std::deque<Verifiable *> m_verifiables;
}
// Our expectation register themself to an object in the constructor
class ExpectationCounter : public Expectation {
public:
ExpectationCounter( VerifiableObject *object, std::string message ) {
object->addVerifiable( this );
...
}
};
class MyMockObject : public VerifiableObject {
public:
MyMockObject()
{
m_computeCalls = new ExpectationCounter( this, "compute calls" )
}
...
};
What do you think ? It looks a lot simpler for me, though not has beautiful
as the java design, it should work.
Baptiste.
----- Original Message -----
From: King Dale
To: 'cpp...@li...'
Sent: Friday, November 30, 2001 4:44 PM
Subject: [Cppunit-devel] Some interesting ideas I am looking at
First, I recently discovered the idea of MockObjects (www.mockobjects.com)
which is sort of a framework for creating stub-like objects (mock objects
are not the same as a stub) upon which you can set expectations and they
will verify themself. For instance you could create a mock ostream object
and tell it what you expect to be written to it and if something else is
written then it will fail. Before discovering the idea, I already did
something like this, but it was all hand written as opposed to using a
ready-made framework. There are mockobjects for Java that work with Junit,
but none for C++ so I started some work on creating a C++ equivalent.
[...]
---
Baptiste Lepilleur <gai...@fr...>
http://gaiacrtn.free.fr/
|