Testing

Overview
Jamfiles
Supported Platforms
Summary of Tests
Construction
Assignment
Function Arguments and Return Values
Explicit Moving
Implicit Moving
Incomplete Types
Deletion Policies
Arrays

Overview

The library comes with thirty-five regression tests and two Jamfiles: <libs/move_ptr/test/static/Jamfile> and <libs/move_ptr/test/dynamic/Jamfile>. The tests make use of the preprocessor symbol BOOST_MOVE_PTR; depending on how this symbol is defined, the tests can be applied to static_move_ptr or to dynamic_move_ptr.

One of the tests, static_deleter.cpp, assumes that the smart pointer template takes a deleter as a second template parameter, and so is not appropriate for use with dynamic_move_ptr. Another test, dynamic_deleter.cpp, assumes that the smart pointer template can be passed a deleter at construction even when only one template argument has been provided, and so is not appropriate for use with static_move_ptr.

In the following discussion, move_ptr is used to mean either static_move_ptr or dynamic_move_ptr.

Jamiles

<libs/move_ptr/test/dynamic/Jamfile>
<libs/move_ptr/test/static/Jamfile>

Supported Platforms

The regression tests for static_move_ptr and dynamic_move_ptr have been run successfully on the following platforms:

Summary of Tests

The entries pass and fail in the below tables indicate expected outcomes.

Construction

static_move_ptr dynamic_move_ptr
construction.cpp pass pass
construction_non_virtual.cpp fail pass

These tests excercise the move_ptr copy constructors and the constructors taking raw pointers, including cases of derived-to-base conversions. They use instance-counting to verify that all constructed instances are freed correctly. The base class has a virtual destructor in the first test but not the second.

Assignment

static_move_ptr dynamic_move_ptr
assignment.cpp pass pass
assignment_non_virtual.cpp fail pass

These tests excercise the move_ptr assignment operators, including cases of derived-to-base conversions. They use instance-counting to verify that all constructed instances are freed correctly. The base class has a virtual destructor in the first test but not the second.

Function Arguments and Return Values

static_move_ptr dynamic_move_ptr
source_sink.cpp pass pass
source_sink_non_virtual.cpp fail pass

These test excercise the ability of instances of move_ptr to be passed to and returned from functions, including cases of derived-to-base conversions. They use instance-counting to verify that all constructed instances are freed correctly. The base class has a virtual destructor in the first test but not the second.

Explicit Moving

static_move_ptr dynamic_move_ptr
move.cpp pass pass
move_non_virtual.cpp fail pass

These test use the function template move to transfer ownership in cases where implicit transfer of ownership is disallowed, including cases of derived-to-base conversions. They use instance-counting to verify that all constructed instances are freed correctly. The base class has a virtual destructor in the first test but not the second.

Implicit Moving

static_move_ptr dynamic_move_ptr
fail_move1.cpp fail fail
fail_move2.cpp fail fail
fail_move3.cpp fail fail
fail_move_array1.cpp fail fail
fail_move_array2.cpp fail fail
fail_move_array3.cpp fail fail

These compile-only tests excercise the ability of move_ptr to disallow dangerous implicit transfers of ownersip, including cases of derived-to-base conversions. Accoring to the philosophy of move_ptr, the desirable behavior is to fail these tests.

Incomplete Types

static_move_ptr dynamic_move_ptr
delete_incomplete_type.cpp pass pass
fail_delete_incomplete_type.cpp fail fail

The first test determines whether a pointer owned by an instance of move_ptr is freed correctly after ownership is transfered to an instance of move_ptr declared at a point at which its element_type is incomplete. The second test, which is compile-only, determines whether an instance of move_ptr can be constructed from a pointer to an incomplete type.

Desirable behavior is to pass the first test and fail the second.

Deletion Policies

static_move_ptr dynamic_move_ptr
sizeof.cpp pass fail
static_deleter.cpp pass n/a
static_deleter_reference.cpp pass n/a
dynamic_deleter.cpp n/a pass

The first test, which is compile only, determines whether move_ptr<T> has the same size as T* (std::string is used as T). The second test involves custom deleters, specified as template parameters, and so only applies to static_move_ptr. The third test involves custom deleters of reference type, specified as template parameters; as above, it only applies to static_move_ptr. The final test involves custom stateless deleters passed to the move_ptr constructor, independent of the move_ptr's template parameters. As such, it applies only to dynamic_move_ptr.

Arrays

static_move_ptr dynamic_move_ptr
fail_array_to_scalar_conversion.cpp fail fail
fail_scalar_to_array_conversion.cpp fail fail
fail_array_conversion1.cpp fail fail
fail_array_conversion2.cpp fail fail
fail_array_conversion3.cpp fail fail
const_volatile_conversion.cpp pass pass
fail_const_volatile_conversion1.cpp fail fail
fail_const_volatile_conversion2.cpp fail fail
fail_const_volatile_conversion3.cpp fail fail
fail_const_volatile_conversion4.cpp fail fail
fail_const_volatile_conversion5.cpp fail fail
fail_const_volatile_conversion6.cpp fail fail
fail_const_volatile_conversion7.cpp fail fail
fail_array_dereference1.cpp fail fail
fail_array_dereference2.cpp fail fail

These compile-only tests involve the special treatment of array types, using the syntax move_ptr<T[]>.

The first two tests verify that specializations of move_ptr for array types and specializations for non-array types are not interconvertible. The next three tests verify that derived-to-base conversions are disabled in the case of arrays. The next test verifies that conversions which simply add const-volatile qualification are allowed. The next seven tests verify that conversions which remove const-volatile qualification are disabled. The final two tests verify that operator* and operator-> are disabled for arrays.


[1]GCC 3.4.1 (Cygwin) fails the last of the four tests in <libs/move_ptr/test/static_deleter_reference.cpp> when BOOST_MOVE_PTR is defined as static_move_ptr.


Sha'arei Tefila, an Orthodox Shul (Synagogue) in Salt Lake City, Utah Chabad Lubavitch of Utah