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

Unit test for resource-managing class

10 views
Skip to first unread message

bitrex

unread,
Feb 17, 2017, 3:12:22 PM2/17/17
to
Is there a set of "canonical" constructors and assignments that can be
used as a unit test to ensure a resource-managing class, which has all
of the "Rule of Five" constructors and assignment operators explicitly
defined is working properly?

Ian Collins

unread,
Feb 17, 2017, 5:09:42 PM2/17/17
to
That wouldn't be straightforward considering the resource management
choices on offer. The testing of a unique_ptr like object would be
different form a shared_ptr like object.

--
Ian

Öö Tiib

unread,
Feb 18, 2017, 2:12:14 PM2/18/17
to
No, but for most types of resources managed (like thread, file, hardware
device, network socket and the like) copy constructor and copy assignment
do not make any sense. Therefore those two short tests are usually handy:

ststic_assert(!std::is_copy_constructible<Foo>::value
, "Foo should not be copy constructible");

ststic_assert(!std::is_copy_assignable<Foo>::value
, "Foo should not be copy assignable");

If to generalize, then it makes sense to test such type traits as
first thing for any class.
0 new messages