PDA

View Full Version : Mocking Win32 API


John Elrick
07-03-2003, 08:13 AM
"Alvin777" <alvin777@mail.ru> wrote in message
news:1c9319e1.0307030807.64f25c31@posting.google.com... How can I use something like mock objects when calling Win API functions like this? [C++] class WrMAPISession { public: void Logon(); ... } void WrMAPISession::Logon() { ... MAPILogonEx(....); ... } Write a class, which consists of one function - MAPILogonEx - and use its instance as a parameter when calling Logon()? That doesn't sound good.

Sure...why not? Adapter Pattern. You reduce the area of potential breakage
to a very narrow point.

You could pass it in, create a Singleton, or create a MAPIGateway
Adapter...whichever makes the most sense for your project.

I've found Adapters to be invaluable in simplifying testing.


John Elrick

John Roth
07-03-2003, 09:13 AM
"John Elrick" <jelrick@adelphia.net> wrote in message
news:rCYMa.9763$Hw.6661167@news2.news.adelphia.net... "Alvin777" <alvin777@mail.ru> wrote in message news:1c9319e1.0307030807.64f25c31@posting.google.com... How can I use something like mock objects when calling Win API functions like this? [C++] class WrMAPISession { public: void Logon(); ... } void WrMAPISession::Logon() { ... MAPILogonEx(....); ... } Write a class, which consists of one function - MAPILogonEx - and
use its instance as a parameter when calling Logon()? That doesn't sound good. Sure...why not? Adapter Pattern. You reduce the area of potential
breakage to a very narrow point. You could pass it in, create a Singleton, or create a MAPIGateway Adapter...whichever makes the most sense for your project. I've found Adapters to be invaluable in simplifying testing.

Oh, absolutely. I've found that too. There are things I couldn't have
tested adequately without them.

John Roth John Elrick

Alvin777
07-04-2003, 04:35 AM
"John Elrick" <jelrick@adelphia.net> wrote in message news:<rCYMa.9763$Hw.6661167@news2.news.adelphia.net>... "Alvin777" <alvin777@mail.ru> wrote in message news:1c9319e1.0307030807.64f25c31@posting.google.com... How can I use something like mock objects when calling Win API functions like this? [C++] class WrMAPISession { public: void Logon(); ... } void WrMAPISession::Logon() { ... MAPILogonEx(....); ... } Write a class, which consists of one function - MAPILogonEx - and use its instance as a parameter when calling Logon()? That doesn't sound good. Sure...why not? Adapter Pattern. You reduce the area of potential breakage to a very narrow point. You could pass it in, create a Singleton, or create a MAPIGateway Adapter...whichever makes the most sense for your project. I've found Adapters to be invaluable in simplifying testing. John Elrick

Hm. Can you give C++ examples of creating Singleton (I know the
pattern, but no ideas how to use it in my case) and creating
MAPIGatewayAdapter?

--
Alvin777

David Postill
07-04-2003, 05:31 AM
[This followup was posted to comp.software.extreme-programming, cc: the cited
author, Alvin777]

In article <1c9319e1.0307040435.79505b74@posting.google.com>, on 4 Jul 2003
05:35:00 -0700, alvin777@mail.ru (Alvin777) wrote:

| "John Elrick" <jelrick@adelphia.net> wrote in message news:<rCYMa.9763$Hw.6661167@news2.news.adelphia.net>...
| > "Alvin777" <alvin777@mail.ru> wrote in message
| > news:1c9319e1.0307030807.64f25c31@posting.google.com...
| > > How can I use something like mock objects when calling Win API
| > > functions like this?

<snip>

| > > Write a class, which consists of one function - MAPILogonEx - and use
| > > its instance as a parameter when calling Logon()? That doesn't sound
| > > good.
| >
| > Sure...why not? Adapter Pattern. You reduce the area of potential breakage
| > to a very narrow point.
| >
| > You could pass it in, create a Singleton, or create a MAPIGateway
| > Adapter...whichever makes the most sense for your project.
| >
| > I've found Adapters to be invaluable in simplifying testing.
| >
| >
| > John Elrick
|
| Hm. Can you give C++ examples of creating Singleton (I know the
| pattern, but no ideas how to use it in my case) and creating
| MAPIGatewayAdapter?

"Implementing the Singleton Design Pattern"
<http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp>

<davidp />

--
David Postill

Alvin777
07-05-2003, 05:24 AM
"Michael Feathers" <mfeathers@objectmentorNOSPAM.com> wrote in message news:<be47vt$vv7$1@slb4.atl.mindspring.net>... "David Postill" <david.postill@pobox.com> wrote in message news:9huagv85kc3ad4tfafcp2atqp6ck8dgeip@4ax.com... [This followup was posted to comp.software.extreme-programming, cc: the cited author, Alvin777] In article <1c9319e1.0307040435.79505b74@posting.google.com>, on 4 Jul 2003 05:35:00 -0700, alvin777@mail.ru (Alvin777) wrote: | "John Elrick" <jelrick@adelphia.net> wrote in message news:<rCYMa.9763$Hw.6661167@news2.news.adelphia.net>... | > "Alvin777" <alvin777@mail.ru> wrote in message | > news:1c9319e1.0307030807.64f25c31@posting.google.com... | > > How can I use something like mock objects when calling Win API | > > functions like this? <snip> | > > Write a class, which consists of one function - MAPILogonEx - and use | > > its instance as a parameter when calling Logon()? That doesn't sound | > > good. | > | > Sure...why not? Adapter Pattern. You reduce the area of potential breakage | > to a very narrow point. | > | > You could pass it in, create a Singleton, or create a MAPIGateway | > Adapter...whichever makes the most sense for your project. | > | > I've found Adapters to be invaluable in simplifying testing. | > | > | > John Elrick | | Hm. Can you give C++ examples of creating Singleton (I know the | pattern, but no ideas how to use it in my case) and creating | MAPIGatewayAdapter? "Implementing the Singleton Design Pattern" <http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp> Wait. Why do you want to use a singleton? Michael Feathers www.objectmentor.com

I don't want :) I was offered to use and I'd like to understand how
can I apply this pattern in my case.
| > You could pass it in, create a Singleton, or create a MAPIGateway
^^^^^^^^^^^^^^^^^^ | > Adapter...whichever makes the most sense for your project.

--
Alvin777


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service