Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Testing exception safety

55 views
Skip to first unread message

Alf P. Steinbach

unread,
Sep 27, 2015, 8:05:14 PM9/27/15
to
On 9/27/2015 12:40 PM, Udo Steinbach wrote:
> After reading http://www.boost.org/community/exception_safety.html and
> experimenting with throwing at every point that can throw ...
> How do you test your code for exception safety?

You can use memory leak detectors to detect memory leaks. That's one aspect.

You can generate hashes of object state to detect changed object state.
That's another aspect.

These comments are just common sense. I'm not aware of special
techniques for generating exceptions within operations used by the code.
It could be very costly to create mockups of lower level operations.


> Is there any module for doing that in the world?

Don't know, sorry.

Cheers & hth.,

- Alf

Ian Collins

unread,
Sep 27, 2015, 8:12:31 PM9/27/15
to
Udo Steinbach wrote:
> After reading http://www.boost.org/community/exception_safety.html
> and experimenting with throwing at every point that can throw ... How
> do you test your code for exception safety? Is there any module for
> doing that in the world?

As part of my unit tests, I mock everything the code under test calls.
It is straightforward to get the mock functions to throw exceptions.

--
Ian Collins

Ian Collins

unread,
Oct 4, 2015, 5:09:01 AM10/4/15
to
Udo Steinbach wrote:
>> It could be very costly to create mockups of lower level
>> operations.
>
> What does Ian say on this? ("I mock everything the code under test
> calls") My variant is a macro which throws in DEBUG in combination
> with a class calling in some loops a test function until nothing is
> thrown and a list of allocated resources.

I use a framework that generates mock functions from an interface
description (basically a function prototype described in XML) so the
cost is low compared to the benefits.

--
Ian Collins
0 new messages