stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <>
Subject Re: structure of tuple tests ([Fwd: Re: svn commit: r675044 - in /stdcxx/branches/4.3.x: include/rw/_tuple.h include/tuple tests/utilities/20.tuple.cnstr.cpp tests/utilities/20.tuple.creation.cpp tests/utilities/20.tuple.h tests/utilities/20.tuple.helpers
Date Fri, 11 Jul 2008 19:05:36 GMT
Eric Lemings wrote:
> Question.  Given a type T, how do I determine the format specifier for
> outputing values of T?  Would I need to write something like this?
> 	template <class T>
> 	const char* fmtspec ();
> 	template <>
> 	const char* fmtspec<int> { return "%d"; }
> Or is there an easier method?

That's one approach. The other approach taken by a number of tests
is to pass the format specifier as an argument to the generic test
function and having the generic function pass it to rw_printf() or
rw_assert() as an argument to the "%{@}" directive. Like so:

     template <class T>
     void test_equal (T x, T y, int line, const char *fmt) {
         rw_assert (x == y, 0, line, "%{@} == %{@}, got %{@}",
                    fmt, x, fmt, y, fmt, y);

     void test_equal_int () {
     #define TEST(x, y)   test_equal (x, y, __LINE__, "%d")

         TEST (1, 1);
         TEST (2, 2);

As to the structure of the tuple tests, I'd like us to come up
with a generic function template that can verify the expected
effects of each tuple member function (including ctors). The
template will take a set of arguments to pass to the tuple
function, along with a description of the result and of the
observable effects (such as the number of calls of copy or
move ctors). Each test would call the function template
multiple times with different arguments to exercise all the
interesting test cases.

The description of the result could be just a character string
with the values of the tuple members. For example, for the ctor
tuple<int, int>(1, 2), the description of the expected result
could be "{1,2}" To implement the formatting in a general way
you might want to make use of the rw_printf() callbacks. See
test_user_defined_formatting() in the self/0.printf.cpp test.

The description of the observable effects can be as simple as
a couple of integers, one for the expected number of copy ctors
and the other for move ctors. Obviously, these can only be
verified for user-defined element types. To make sure we
exercise the primary template as well as any specializations
(such as tuple<T, T, T>) we'll need to use more than one user
defined type. E.g.,

     struct TupleElem {
         // ...
         int typid_;   // unique Id for each type
         int objid_;   // unique Id for each object

         // number of copy ctor invocations
         static int n_copy_ctors_;

         // number of move ctor invocations
         static int n_move_ctors_;

         // ...

     template <int N>
     struct TupleElem: TupleElemBase { };

You might want to consider extending the UserClass class defined
in tests/include/rw_value.h, or at least borrowing code or ideas
from it.


View raw message