Boost logo

Boost :

Subject: Re: [boost] [test] mock objects
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2010-01-22 01:27:48


Michael Robinson <michaelrobinson <at> netzero.net> writes:

>
> Hi,
>
> I am a boost unit test newbie.
>
> I have been looking at the documentation and examples and would like
> to know if there is any documentation that specifically addresses
> the use of mock objects:

Unfortunately, no.

> I am specifically interested in how to interpret the output of
> est_example1.cpp

This example demonstrates how you can count how many execution path
exists in your function under the test. Just run it with
--log_level=message

> and est_example2.cpp;

This example illustrates how to use mocks to test for basic and
strong exception safety.

If any errors detected on particular execution path, the path is
printed. For example

.../boost/test/mock_object.hpp(209): error in "test_stack_push": 1
memory leak detected in the execution path 9:
> "mock_object::mock_object"
< "mock_object::mock_object"
> "mock_object::mock_object"
< "mock_object::mock_object"
> "stack::stack"
< "stack::stack"
> "stack::push"
> "mock_object::operator ="
   < "mock_object::operator ="
< "stack::push"
> "stack::push"
> "mock_object::operator ="
   < "mock_object::operator ="
< "stack::push"
> "stack::push"
   Allocated memory block 0x0036CC20, 4 bytes long: <....> CD CD CD CD
> "mock_object::mock_object"
   < "mock_object::mock_object"
> "mock_object::mock_object"
   < "mock_object::mock_object"
> "mock_object::mock_object"
   < "mock_object::mock_object"
> "mock_object::mock_object"
   < "mock_object::mock_object"
> "mock_object::operator ="
     Forced failure: Copy assignment
   < "mock_object::operator ="
< "stack::push"

Here "> scope name" designate where we enter some scope and "< scope
name" designate where we are leaving one.

> as well as learning what the
> required format of the expectations log file (.elog) to be used for
> logged_exp_example.cpp is.

The good thing about the solution is that you do not really need to know
the format.

You run the test first with --save_pattern=yes and the expectations are
logged into pattern file. Next time you run the test interactions are
validated against these logged expectations.

The format is pretty straightforward, but I hope above answers your
question.

Gennadiy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk