stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: test for lig.alg.swap
Date Wed, 18 Jan 2006 19:44:18 GMT
Anton Pevtsov wrote:
> Martin Sebor wrote:
> 
[...]
> 
> Great idea! Thank you!
> The attach contains the updated test version.

Okay, thanks.

I spotted a few more minor issues with the test and corrected
them before committing the final version:
http://svn.apache.org/viewcvs.cgi?rev=370230&view=rev

Attached is a diff between what you sent me and the final version.
You might want to look over the changes and keep them in mind for
future reference. Let me also note some of the more important ones
here:

--- your 25.swap.cpp	Wed Jan 18 11:39:06 2006
+++ my 25.swap.cpp	Wed Jan 18 12:06:10 2006
@@ -67,7 +68,7 @@
      const std::size_t nseq = std::strlen (seq);

      // construct a sequence of `nseq' elements to pass to swap
-    T* const tseq = T::from_char (seq, nseq);
+    T* const tseq = T::from_char (seq, nseq + 1);

We need to make sure the sequence is never empty since the
rw_assert() calls unconditionally dereference the pointers
even when (nseq == 0) holds.


      int a_val, b_val;
      bool success = true;
@@ -92,8 +93,8 @@
      }

      rw_assert (success, 0, line,
-               "std::%s<%s%{?}, %s%{;}> ('%c', '%c'): got: ('%c', '%c') "
-               "expected: ('%5$c', '%4$c') at step %zu",
+               "%s<%s%{?}, %s%{;}>(%#c, %#c): got: { %#c, %#c } "
+               "expected: { %5$#c, %4$#c } at step %zu",

Use the %#c specifier (note the pound sign -- it's our extension)
when formatting characters in diagnostic output to automatically
quote them and to format non-printable characters using standard
escape sequences (e.g., the linefeed character will be formatted
as '\n' including the quotes instead of inserting a newline into
the output.

                 fname, it1name, it_swap, it2name, a_val, b_val, 
tseq->val_,
                 (tseq + i)->val_, i);

@@ -154,6 +155,10 @@
      const ForwardIterator2 last2 =
          make_iter (tseq2 + nseq, tseq2, tseq2 + nseq, it2);

+    // silence bogus EDG eccp remark #550-D: variable was set
+    // but never used
+    _RWSTD_UNUSED (last2);

You might want to compile the tests using the EDG eccp I sent you
and silence these (bogus) warnings. The EDG compiler is the most
conforming C++ compiler and it might reveal problems that other
compilers don't.

@@ -162,17 +167,22 @@

      std::size_t assigns_per_swap = T::n_total_op_assign_ - 
last_n_op_assign;

-    // exercise 25.2.3 - std::swap_ranges<> ()
      last_n_op_assign = T::n_total_op_assign_;

+    // exercise 25.2.3 - std::swap_ranges()
      const ForwardIterator2 res = std::swap_ranges(first1, last1, first2);

+    // silence bogus EDG eccp remark #550-D: variable was set
+    // but never used
+    _RWSTD_UNUSED (res);
+
      // check the returned value, 25.2.2 p5
      bool success = res.cur_ == last2.cur_;
      rw_assert (success, 0, line,
-               "std::swap_ranges<%s, %s> (\"%s\", \"%s\") returns: "
-               "got: %p, expected: %p",
-               it1name, it2name, seq1, seq2, res.cur_, last2.cur_);
+               "swap_ranges<%s, %s>(\"%s\", \"%s\") == first + %td, "
+               "got first + %td",
+               it1name, it2name, seq1, seq2, res.cur_ - tseq2,
+               last2.cur_ - tseq2);

Printing out offsets rather than pointers is more informative.

Martin

Mime
View raw message