2009-05-07 Farid Zaripov <faridz@apache.org>
Merged r772559 from 4.2.x branch
STDCXX-994
* tests/src/value.cpp (_rw_fmtxarrayv): Function modified to
accept UserClass and UserPOD arrays.
* tests/self/0.printf.cpp (test_userclass_format): Pass width
of the element in rw_sprintfa().
(test_userpod_format): New function to exercise "%{X=*}"
rw_sprintfa() directive with UserPOD data.
* tests/algorithms/25.heap.cpp: Pass width of the element as
first parameter for "%{X=*}" directive.
* tests/algorithms/25.libc.cpp: Ditto.
* tests/algorithms/25.merge.cpp: Ditto.
* tests/algorithms/25.nth.element.cpp: Ditto.
* tests/algorithms/25.partial.sort.cpp: Ditto.
* tests/algorithms/25.partitions.cpp: Ditto.
* tests/algorithms/25.permutation.cpp: Ditto.
* tests/algorithms/25.random.shuffle.cpp: Ditto.
* tests/algorithms/25.remove.cpp: Ditto.
* tests/algorithms/25.replace.cpp: Ditto.
* tests/algorithms/25.reverse.cpp: Ditto.
* tests/algorithms/25.rotate.cpp: Ditto.
* tests/algorithms/25.set.difference.cpp: Ditto.
* tests/algorithms/25.set.intersection.cpp: Ditto.
* tests/algorithms/25.set.sym.difference.cpp: Ditto.
* tests/algorithms/25.set.union.cpp: Ditto.
* tests/algorithms/25.sort.cpp: Ditto.
* tests/algorithms/25.unique.cpp: Ditto.
* tests/containers/23.deque.modifiers.cpp: Ditto.
* tests/containers/23.deque.special.cpp: Ditto.
* tests/containers/23.vector.modifiers.cpp: Ditto.
* tests/numerics/26.adjacent.diff.cpp: Ditto.
* tests/numerics/26.inner.product.cpp: Ditto.
* tests/numerics/26.partial.sum.cpp: Ditto.
git-svn-id: https://svn.apache.org/repos/asf/stdcxx/trunk@772579 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tests/algorithms/25.heap.cpp b/tests/algorithms/25.heap.cpp
index 90e89c7..6fa92f1 100644
--- a/tests/algorithms/25.heap.cpp
+++ b/tests/algorithms/25.heap.cpp
@@ -196,6 +196,7 @@
Predicate::funcalls_ : T::n_total_op_lt_ - last_n_op_lt;
const std::size_t len = 2 != finx ? nsrc : nsrc - 1;
+ static const int cwidth = sizeof (T);
if (2 == finx) { // pop_heap special verification
// verify that the maximal element is in
@@ -204,7 +205,8 @@
"line %d std::%s <%s%{?}, %s%{;}> (\"%s\", ...) ==> "
"\"%{X=*.*}\", last is %#c, expected %#c",
__LINE__, fname, itname, ppred, funname, src,
- int (nsrc), -1, xsrc, xsrc [nsrc - 1].data_.val_, val);
+ cwidth, int (nsrc), -1, xsrc,
+ xsrc [nsrc - 1].data_.val_, val);
}
if (3 == finx) { // sort_heap special verification
@@ -213,7 +215,7 @@
"line %d std::%s <%s%{?}, %s%{;}> (\"%s\", ...) ==> "
"\"%{X=*.*}\" is not sorted",
__LINE__, fname, itname, ppred, funname, src,
- int (nsrc), -1, xsrc);
+ cwidth, int (nsrc), -1, xsrc);
}
else {
// verify that we got a heap:
@@ -222,7 +224,7 @@
"line %d std::%s <%s%{?}, %s%{;}> (\"%s\", ...) ==> "
"\"%{X=*.*}\" is not a heap",
__LINE__, fname, itname, ppred, funname, src,
- int (len), -1, xsrc);
+ cwidth, int (len), -1, xsrc);
}
// verify the complexity:
@@ -232,7 +234,7 @@
"\"%{X=*.*}\" complexity: got %zu invocations of %s, "
"expected no more %zu",
__LINE__, fname, itname, ppred, funname, src,
- int (nsrc), -1, xsrc, n_ops_lt,
+ cwidth, int (nsrc), -1, xsrc, n_ops_lt,
ppred ? "predicate" : "operator< ()", ops);
delete[] xsrc;
diff --git a/tests/algorithms/25.libc.cpp b/tests/algorithms/25.libc.cpp
index a16bbd6..83b507d 100644
--- a/tests/algorithms/25.libc.cpp
+++ b/tests/algorithms/25.libc.cpp
@@ -106,7 +106,7 @@
rw_assert (success, 0, line,
"line %d: extern \"C%{?}++%{;}\" qsort (\"%s\", ...) ==> "
"\"%{X=*.*}\" not sorted",
- __LINE__, cxx, src, int (nsrc), -1, xsrc);
+ __LINE__, cxx, src, int (sizeof (*xsrc)), int (nsrc), -1, xsrc);
delete[] xsrc;
}
diff --git a/tests/algorithms/25.merge.cpp b/tests/algorithms/25.merge.cpp
index 2c79ddb..174dffc 100644
--- a/tests/algorithms/25.merge.cpp
+++ b/tests/algorithms/25.merge.cpp
@@ -245,6 +245,8 @@
predname, src1, src2, ndst, xdst_res - xdst);
}
+ static const int cwidth = sizeof (*xdst);
+
// check that the sequence is sorted
success = is_sorted_lt (xdst, xdst_end);
rw_assert (success, 0, line,
@@ -253,7 +255,7 @@
"not sorted",
__LINE__, algname, it1name, !inplace, it2name, outname,
predicate, predname, src1, !inplace, src2, inplace, midinx,
- int (ndst), -1, xdst);
+ cwidth, int (ndst), -1, xdst);
// check that the algorithm is stable
std::size_t i = 1;
@@ -274,7 +276,7 @@
"not stable at %zu: got ids %d != %d for values %#c == %#c",
__LINE__, algname, it1name, !inplace, it2name, outname,
predicate, predname, src1, !inplace, src2, inplace, midinx,
- int (ndst), i, xdst, i, xdst [i - 1].origin_,
+ cwidth, int (ndst), i, xdst, i, xdst [i - 1].origin_,
xdst [i].origin_, xdst [i - 1].data_.val_, xdst [i].data_.val_);
// check the complexity
@@ -285,7 +287,7 @@
"complexity: got %zu, expected <= %zu",
__LINE__, algname, it1name, !inplace, it2name, outname,
predicate, predname, src1, !inplace, src2, inplace, midinx,
- int (ndst), -1, xdst, n_ops_lt, ndst - 1);
+ cwidth, int (ndst), -1, xdst, n_ops_lt, ndst - 1);
delete[] xsrc1;
delete[] xsrc2;
diff --git a/tests/algorithms/25.nth.element.cpp b/tests/algorithms/25.nth.element.cpp
index 3ea216d..c57da69 100644
--- a/tests/algorithms/25.nth.element.cpp
+++ b/tests/algorithms/25.nth.element.cpp
@@ -152,8 +152,8 @@
"line %d: %s<%s%{?}, %s%{;}>(\"%s\", %zu, ...) ==> "
"\"%{X=*.*}\", got %#c at %zu !< %#c at %zu",
__LINE__, fname, itname, ppred, funname, src, nth,
- int (nsrc), -1, xsrc, xsrc[i].data_.val_, i,
- xsrc[j].data_.val_, j);
+ int (sizeof (*xsrc)), int (nsrc), -1, xsrc,
+ xsrc[i].data_.val_, i, xsrc[j].data_.val_, j);
}
else {
rw_assert (success, 0, line,
diff --git a/tests/algorithms/25.partial.sort.cpp b/tests/algorithms/25.partial.sort.cpp
index 728572d..f7c443c 100644
--- a/tests/algorithms/25.partial.sort.cpp
+++ b/tests/algorithms/25.partial.sort.cpp
@@ -184,7 +184,7 @@
"line %d: %s<%s%{?}, %s%{;}%{?}, %s%{;}> "
"(\"%s\", %zu, ...): ==> \"%{X=*.*}\" not sorted",
__LINE__, fname, itname, copy, outname, ppred, funname,
- src, mid, int (mid), -1, res_x);
+ src, mid, int (sizeof (*res_x)), int (mid), -1, res_x);
}
else {
rw_assert (success, 0, line,
@@ -224,9 +224,9 @@
rw_assert (success, 0, line,
"line %d: %s<%s%{?}, %s%{;}%{?}, %s%{;}> "
"(\"%s\", %zu, ...): ==> \"%{X=*.*}\" got less element "
- "%{?}%#c%{;} in the unsorted part",
- __LINE__, fname, itname, copy, outname, ppred, funname,
- src, mid, int (copy ? mid : nsrc), -1, res_x,
+ "%{?}%#c%{;} in the unsorted part", __LINE__, fname,
+ itname, copy, outname, ppred, funname, src, mid,
+ int (sizeof (*res_x)), int (copy ? mid : nsrc), -1, res_x,
!copy, xsrc[j].data_.val_);
}
else {
diff --git a/tests/algorithms/25.partitions.cpp b/tests/algorithms/25.partitions.cpp
index dae78e5..158c859 100644
--- a/tests/algorithms/25.partitions.cpp
+++ b/tests/algorithms/25.partitions.cpp
@@ -126,16 +126,18 @@
: std::partition (first, last, pred);
// check that there is no leaked objects
- const std::size_t t_n_objs_diff =
+ const std::size_t t_n_objs_diff =
T::n_total_def_ctor_ + T::n_total_copy_ctor_
- t_n_ctors - T::n_total_dtor_ + t_n_dtors;
+ static const int cwidth = sizeof (T);
+
bool success = 0 == t_n_objs_diff;
rw_assert (success, 0, line,
"line %d: std::%s <%s, %s>(\"%s\", ...) ==> \"%{X=*.*}\", "
"number of objects changed on %d: %s detected",
__LINE__, fname, itname, funname, src,
- int (nsrc), -1, xsrc, t_n_objs_diff,
+ cwidth, int (nsrc), -1, xsrc, t_n_objs_diff,
t_n_objs_diff > 0 ? "memory leak" : "unexpected dtor call");
// check that the returned iterator points to the expected element
@@ -143,8 +145,8 @@
rw_assert (success, 0, line,
"line %d: std::%s <%s, %s>(\"%s\", ...) ==> \"%{X=*.*}\", "
"returned iterator it = first + %td, expected first + %zu",
- __LINE__, fname, itname, funname, src, int (nsrc),
- -1, xsrc, res.cur_ - first.cur_, offset);
+ __LINE__, fname, itname, funname, src,
+ cwidth, int (nsrc), -1, xsrc, res.cur_ - first.cur_, offset);
// check 25.2.12, p2 & p5
// "left" part of the array there the predicate should be true
@@ -158,8 +160,9 @@
rw_assert (success, 0, line,
"line %d: std::%s <%s, %s>(\"%s\", ...) "
"==> \"%{X=*.*}\", at %zu got: %#c !> %#c",
- __LINE__, fname, itname, funname, src, int (nsrc),
- -1, xsrc, i + 1, xsrc[i].data_.val_, value);
+ __LINE__, fname, itname, funname, src,
+ cwidth, int (nsrc), -1, xsrc, i + 1,
+ xsrc[i].data_.val_, value);
// "right" part of the array there the predicate should be false
@@ -172,8 +175,9 @@
rw_assert (success, 0, line,
"line %d: std::%s <%s, %s>(\"%s\", ...) "
"==> \"%{X=*.*}\", at %zu got: %#c !<= %#c",
- __LINE__, fname, itname, funname, src, int (nsrc),
- -1, xsrc, i + 1, xsrc[i].data_.val_, value);
+ __LINE__, fname, itname, funname, src,
+ cwidth, int (nsrc), -1, xsrc, i + 1,
+ xsrc[i].data_.val_, value);
// check the complexity, 25.2.12 p3 & p6
@@ -217,7 +221,8 @@
"expected \"%{X=*.*}\", realtive order broken at %zu, "
"%#c != %#c",
__LINE__, fname, itname, funname, src,
- int (nsrc), int (i), xsrc, int (ndst), int (i), xdst,
+ cwidth, int (nsrc), int (i), xsrc,
+ cwidth, int (ndst), int (i), xdst,
i, xsrc[i].data_.val_, xdst[i].data_.val_);
}
diff --git a/tests/algorithms/25.permutation.cpp b/tests/algorithms/25.permutation.cpp
index 30205e2..b87e277 100644
--- a/tests/algorithms/25.permutation.cpp
+++ b/tests/algorithms/25.permutation.cpp
@@ -160,7 +160,7 @@
"line %d. %s <%s%{?}, %s%{;}> (\"%s\", ...) "
"==> got \"%{X=*.*}\", expected \"%s\"",
__LINE__, algname, itname, 0 != ppred, predname, src,
- int (nsrc), int (i), xsrc, dst);
+ int (sizeof (*xsrc)), int (nsrc), int (i), xsrc, dst);
// verify the complexity: 25.3.9 p2 and p5.
// (last - first) / 2 swaps, 2 assign per swap
diff --git a/tests/algorithms/25.random.shuffle.cpp b/tests/algorithms/25.random.shuffle.cpp
index b331601..940892e 100644
--- a/tests/algorithms/25.random.shuffle.cpp
+++ b/tests/algorithms/25.random.shuffle.cpp
@@ -203,7 +203,7 @@
"with value %td: got \"%{X=*.*}\"",
i, fname, itname, rnd_gen, funname,
first_missing - missing,
- int (i), -1, buf);
+ int (sizeof (*buf)), int (i), -1, buf);
// verify 25.2.11, p2, complexity:
diff --git a/tests/algorithms/25.remove.cpp b/tests/algorithms/25.remove.cpp
index a8fa740..53f26bf 100644
--- a/tests/algorithms/25.remove.cpp
+++ b/tests/algorithms/25.remove.cpp
@@ -179,6 +179,8 @@
// variable "res" was set but never used
_RWSTD_UNUSED (end);
+ static const int cwidth = sizeof (T);
+
// verify that the returned iterator is set as expected
bool success = end.cur_ == first.cur_ + (nsrc - nrem);
rw_assert (success, 0, line,
@@ -195,7 +197,7 @@
"line %d: %s<%s>(\"%s\", ..., %#c) ==> "
"\"%{X=*.*}\"; expected element value %#c",
__LINE__, fname, itname, src, val,
- int (nsrc), int (i), xsrc, src [i]);
+ cwidth, int (nsrc), int (i), xsrc, src [i]);
}
@@ -208,7 +210,7 @@
"line %d: %s<%s>(\"%s\", ..., %#c) ==> \"%{X=#*.*}\"; "
"unstable at offset %zu element ids: %d and %d",
__LINE__, fname, itname, src, val,
- int (nsrc), int (i - 1), xsrc,
+ cwidth, int (nsrc), int (i - 1), xsrc,
i - 1, xsrc [i - 1].id_, xsrc [i].id_);
}
@@ -222,7 +224,7 @@
"line %d: %s<%s>(\"%s\", ..., %#c) ==> "
"\"%{X=*.*}\"; expected element value %#c",
__LINE__, fname, itname, src, val,
- int (nsrc), int (i), xsrc, val);
+ cwidth, int (nsrc), int (i), xsrc, val);
}
@@ -283,6 +285,8 @@
// variable "res" was set but never used
_RWSTD_UNUSED (end);
+ const int cwidth = sizeof (T);
+
// verify that the returned iterator is set as expected p 25.2.7.8
bool success = end.cur_ == result.cur_ + (nsrc - nrem);
rw_assert (success, 0, line,
@@ -298,7 +302,7 @@
"line %d: %s<%s>(\"%s\", ..., %#c) ==> "
"\"%{X=*.*}\"; expected element value %#c",
__LINE__, fname, itname, src, val,
- int (nsrc - nrem), int (i), xdst, src [i]);
+ cwidth, int (nsrc - nrem), int (i), xdst, src [i]);
}
// verify that the algorithm is stable: the relative order of the elements
@@ -310,7 +314,7 @@
"line %d: %s<%s>(\"%s\", ..., %#c) ==> \"%{X=#*.*}\"; "
"unstable at offset %zu: element ids: %d and %d",
__LINE__, fname, itname, src, val,
- int (nsrc - nrem), int (i - 1), xdst,
+ cwidth, int (nsrc - nrem), int (i - 1), xdst,
i - 1, xdst [i - 1].id_, xdst [i].id_);
}
diff --git a/tests/algorithms/25.replace.cpp b/tests/algorithms/25.replace.cpp
index e0c0687..fbd64e3 100644
--- a/tests/algorithms/25.replace.cpp
+++ b/tests/algorithms/25.replace.cpp
@@ -196,11 +196,13 @@
break;
}
+ static const int cwidth = sizeof (T);
+
rw_assert (success, 0, line,
"line %d: %s<%s>(\"%s\", ..., %#c, %#c) ==> "
"\"%{X=*.*}\"; unexpected element value %#c",
__LINE__, fname, itname, src, val, new_val,
- int (nsrc), int (i), xsrc, src [i]);
+ cwidth, int (nsrc), int (i), xsrc, src [i]);
// check the id (not just the value) of the matching element
// to make sure it has really been replaced
@@ -220,7 +222,7 @@
"\"%{X=#*.*}\"; failed to replace element %zu: "
"origin %d (%d, %d), expected %d (%d)",
__LINE__, fname, itname, src, val, new_val,
- int (nsrc), int (i), xsrc,
+ cwidth, int (nsrc), int (i), xsrc,
i, xsrc [i].origin_, xsrc [i].id_, xsrc [i].src_id_,
replace_with.origin_, replace_with.id_);
@@ -309,11 +311,13 @@
break;
}
+ static const int cwidth = sizeof (T);
+
rw_assert (success, 0, line,
"line %d: %s<%s>(\"%s\", ..., %#c) ==> "
"\"%{X=*.*}\"; unexpected element value %#c",
__LINE__, fname, itname, src, val,
- int (nsrc), int (i), xdst, src [i]);
+ cwidth, int (nsrc), int (i), xdst, src [i]);
// check the id (not just the value) of the matching element
// to make sure it has really been copied
@@ -332,7 +336,7 @@
"\"%{X=*.*}\"; failed to copy and replace element %zu: "
"origin %d (%d, %d), expected %d (%d)",
__LINE__, fname, itname, src, val, new_val,
- int (nsrc), int (i), xdst,
+ cwidth, int (nsrc), int (i), xdst,
i, xdst [i].origin_, xdst [i].id_, xdst [i].src_id_,
replace_with.origin_, replace_with.id_);
diff --git a/tests/algorithms/25.reverse.cpp b/tests/algorithms/25.reverse.cpp
index ec678c1..02ff0b9 100644
--- a/tests/algorithms/25.reverse.cpp
+++ b/tests/algorithms/25.reverse.cpp
@@ -153,7 +153,7 @@
"line %d: %s<%s>(\"%s\", ...) ==> "
"\"%{X=*.*}\"; unexpected element value %#c at offset %zu",
__LINE__, fname, itname, src,
- int (nsrc), int (i), xsrc,
+ int (sizeof (*xsrc)), int (nsrc), int (i), xsrc,
xsrc [nsrc - i - 1].data_.val_, i);
const std::size_t iter_swap_expect = nsrc / 2;
@@ -214,7 +214,7 @@
"line %d: %s<%s>(\"%s\", ...) ==> "
"\"%{X=*.*}\"; unexpected element value %#c at offset %zu",
__LINE__, fname, itname, src,
- int (nsrc), int (i), xsrc,
+ int (sizeof (*xsrc)), int (nsrc), int (i), xsrc,
xdst [nsrc - i - 1].data_.val_, i);
success = T::n_total_op_assign_ - last_n_op_assign == nsrc;
diff --git a/tests/algorithms/25.rotate.cpp b/tests/algorithms/25.rotate.cpp
index c4d0115..6f269d7 100644
--- a/tests/algorithms/25.rotate.cpp
+++ b/tests/algorithms/25.rotate.cpp
@@ -173,7 +173,8 @@
"line %d: %s<%s>(\"%s\", %zu, ...) ==> "
"\"%{X=*.*}\"; unexpected element value %#c at %zu",
__LINE__, fname, itname, src, midnsrc,
- int (nsrc), int (i), xsrc, xsrc [xpos].data_.val_, i);
+ int (sizeof (*xsrc)), int (nsrc), int (i), xsrc,
+ xsrc [xpos].data_.val_, i);
success = iter_swap_calls <= nsrc;
rw_assert (success, 0, line,
@@ -239,7 +240,8 @@
"line %d: %s<%s, %s>(\"%s\", %zu, ...) ==> "
"\"%{X=*.*}\"; unexpected element value %#c at %zu",
__LINE__, fname, it1name, it2name, src, midnsrc,
- int (nsrc), int (i), xsrc, xdst [xpos].data_.val_, i);
+ int (sizeof (*xsrc)), int (nsrc), int (i), xsrc,
+ xdst [xpos].data_.val_, i);
success = T::n_total_op_assign_ - last_n_op_assign == nsrc;
rw_assert (success, 0, line,
diff --git a/tests/algorithms/25.set.difference.cpp b/tests/algorithms/25.set.difference.cpp
index b4122cb..23d0335 100644
--- a/tests/algorithms/25.set.difference.cpp
+++ b/tests/algorithms/25.set.difference.cpp
@@ -216,11 +216,13 @@
// to avoid errors in --trace mode
i = i < ndst ? i : ndst - 1;
+ static const int cwidth = sizeof (*xdst);
+
rw_assert (success, 0, line,
"line %d: %s<%s, %s, %s%{?}, %s%{;}> (\"%s\", \"%s\", ...) "
" ==> \"%{X=*.*}\", expected \"%s\"",
__LINE__, fname, it1name, it2name, outname, predicate,
- funname, src1, src2, int (ndst), i, xdst, res);
+ funname, src1, src2, cwidth, int (ndst), i, xdst, res);
// verfiy that only elements from first sequence sequence were taken
success = n1 == ndst;
@@ -229,7 +231,7 @@
" ==> \"%{X=*.*}\" got %zu elements from first sequence and "
"%zu from second, expected %zu from first and 0 from second",
__LINE__, fname, it1name, it2name, outname, predicate, funname,
- src1, src2, int (ndst), -1, xdst, n1, n2, ndst);
+ src1, src2, cwidth, int (ndst), -1, xdst, n1, n2, ndst);
// verify that the operation is stable : two equal elements
// should go in the same order
@@ -248,7 +250,7 @@
" ==> \"%{X=*.*}\" not stable : elements %#c==%#c have "
"ids %d >= %d ",
__LINE__, fname, it1name, it2name, outname, predicate,
- funname, src1, src2, int (ndst), i, xdst,
+ funname, src1, src2, cwidth, int (ndst), i, xdst,
xdst[i - 1].data_.val_, xdst[i].data_.val_,
xdst[i - 1].origin_, xdst[i].origin_);
}
diff --git a/tests/algorithms/25.set.intersection.cpp b/tests/algorithms/25.set.intersection.cpp
index 58a6382..127eca5 100644
--- a/tests/algorithms/25.set.intersection.cpp
+++ b/tests/algorithms/25.set.intersection.cpp
@@ -216,11 +216,13 @@
// to avoid errors in --trace mode
i = i < ndst ? i : ndst - 1;
+ static const int cwidth = sizeof (*xdst);
+
rw_assert (success, 0, line,
"line %d: %s<%s, %s, %s%{?}, %s%{;}> (\"%s\", \"%s\", ...) "
" ==> \"%{X=*.*}\", expected \"%s\"",
__LINE__, fname, it1name, it2name, outname, predicate,
- funname, src1, src2, int (ndst), i, xdst, res);
+ funname, src1, src2, cwidth, int (ndst), i, xdst, res);
// check that the operation is stable : for two equal elements
// one from the first sequence should be taken
@@ -230,7 +232,7 @@
" ==> \"%{X=*.*}\" got %zu elements from first sequence and "
"%zu from second, expected %zu from first and 0 from second",
__LINE__, fname, it1name, it2name, outname, predicate, funname,
- src1, src2, int (ndst), -1, xdst, n1, n2, ndst);
+ src1, src2, cwidth, int (ndst), -1, xdst, n1, n2, ndst);
// check the complexity
const std::size_t n_exp_ops =
diff --git a/tests/algorithms/25.set.sym.difference.cpp b/tests/algorithms/25.set.sym.difference.cpp
index 7d6b024..4827b1b 100644
--- a/tests/algorithms/25.set.sym.difference.cpp
+++ b/tests/algorithms/25.set.sym.difference.cpp
@@ -219,11 +219,13 @@
// to avoid errors in --trace mode
i = i < ndst ? i : ndst - 1;
+ static const int cwidth = sizeof (*xdst);
+
rw_assert (success, 0, line,
"line %d: %s<%s, %s, %s%{?}, %s%{;}> (\"%s\", \"%s\", ...) "
" ==> \"%{X=*.*}\", expected \"%s\"",
__LINE__, algname, it1name, it2name, outname, predicate,
- funname, src1, src2, int (ndst), i, xdst, res);
+ funname, src1, src2, cwidth, int (ndst), i, xdst, res);
// verfiy that only elements from first sequence sequence were taken
success = n1 == nf;
@@ -233,7 +235,7 @@
"%zu from second, expected %zu from first and %zu from second",
__LINE__, algname, it1name, it2name, outname, predicate,
funname, src1, src2,
- int (ndst), -1, xdst, n1, n2, nf, ndst - nf);
+ cwidth, int (ndst), -1, xdst, n1, n2, nf, ndst - nf);
// verify that the operation is stable: two equal elements
// should go in the same order
@@ -254,7 +256,7 @@
" ==> \"%{X=*.*}\" not stable : elements %#c==%#c have "
"ids %d >= %d ",
__LINE__, algname, it1name, it2name, outname, predicate,
- funname, src1, src2, int (ndst), i, xdst,
+ funname, src1, src2, cwidth, int (ndst), i, xdst,
xdst[i - 1].data_.val_, xdst[i].data_.val_,
xdst[i - 1].origin_, xdst[i].origin_);
}
diff --git a/tests/algorithms/25.set.union.cpp b/tests/algorithms/25.set.union.cpp
index c2f6722..d8c057f 100644
--- a/tests/algorithms/25.set.union.cpp
+++ b/tests/algorithms/25.set.union.cpp
@@ -212,11 +212,13 @@
// to avoid errors in --trace mode
i = i < ndst ? i : ndst - 1;
+ static const int cwidth = sizeof (*xdst);
+
rw_assert (success, 0, line,
"line %d: %s<%s, %s, %s%{?}, %s%{;}> (\"%s\", \"%s\", ...) "
" ==> \"%{X=*.*}\", expected \"%s\"",
__LINE__, fname, it1name, it2name, outname, predicate,
- funname, src1, src2, int (ndst), i, xdst, res);
+ funname, src1, src2, cwidth, int (ndst), i, xdst, res);
// check that the operation is stable : for two equal elements
// one from the first sequence should be taken
@@ -226,7 +228,8 @@
" ==> \"%{X=*.*}\" got %zu elements from first sequence and "
"%zu from second, expected %zu from first and %zu from second",
__LINE__, fname, it1name, it2name, outname, predicate, funname,
- src1, src2, int (ndst), -1, xdst, n1, n2, nsrc1, ndst - nsrc1);
+ src1, src2, cwidth, int (ndst), -1, xdst,
+ n1, n2, nsrc1, ndst - nsrc1);
// check the complexity
const std::size_t n_exp_ops =
diff --git a/tests/algorithms/25.sort.cpp b/tests/algorithms/25.sort.cpp
index b8dcd9e..b0514f2 100644
--- a/tests/algorithms/25.sort.cpp
+++ b/tests/algorithms/25.sort.cpp
@@ -198,6 +198,8 @@
}
*/
+ static const int cwidth = sizeof (T);
+
// check that the array is sorted
bool success = is_sorted_lt (xsrc, xsrc_end);
if (src) {
@@ -205,7 +207,7 @@
"line %d: %s<%s%{?}, %s%{;}> (\"%s\", ...) ==> "
"\"%{X=*.*}\" not sorted",
__LINE__, fname, itname, ppred, funname, src,
- int (nsrc), -1, xsrc);
+ cwidth, int (nsrc), -1, xsrc);
}
else {
rw_assert (success, 0, line,
@@ -248,7 +250,7 @@
"\"%{X=*.*}\" relative order is broken at %zu: "
"got ids %zu and %zu for values %#c and %#c",
__LINE__, fname, itname, ppred, funname, src,
- int (nsrc), -1, xsrc, j, xsrc[j - 1].origin_,
+ cwidth, int (nsrc), -1, xsrc, j, xsrc[j - 1].origin_,
xsrc[j].origin_, xsrc[j - 1].data_.val_,
xsrc[j].data_.val_);
}
diff --git a/tests/algorithms/25.unique.cpp b/tests/algorithms/25.unique.cpp
index 00cc049..6a67339 100644
--- a/tests/algorithms/25.unique.cpp
+++ b/tests/algorithms/25.unique.cpp
@@ -141,9 +141,9 @@
rw_assert (0 == mismatch, 0, line,
"line %d: std::%s <%s%{?}, %s%{;}%{?}, %s%{;}>(\"%s\", ...) "
- "==> \"%s\", got \"%{X=*.@}\"",
- __LINE__, fname, itname, use_copy, outname, 0 != ppred,
- funname, src, dst, int (ndst), mismatch, xdst);
+ "==> \"%s\", got \"%{X=*.@}\"", __LINE__, fname, itname,
+ use_copy, outname, 0 != ppred, funname, src, dst,
+ int (sizeof (*xdst)), int (ndst), mismatch, xdst);
if (ppred)
n_total_ops = ppred->n_total_op_fcall_ - n_total_ops;
diff --git a/tests/containers/23.deque.modifiers.cpp b/tests/containers/23.deque.modifiers.cpp
index 992598f..ef2380b 100644
--- a/tests/containers/23.deque.modifiers.cpp
+++ b/tests/containers/23.deque.modifiers.cpp
@@ -357,12 +357,14 @@
char* funcall = 0;
std::size_t len = 0;
+ static const int cwidth = sizeof (*xseq);
+
rw_asnprintf (&funcall, &len, "deque(\"%{X=*.*}\").insert("
"%{?}begin(), %{:}%{?}end (), %{:}begin () + %zu%{;}%{;}"
"%{?}%d)%{:}%{?}\"%{X=*.*}\")%{:}%d, %d)%{;}%{;}",
- int (seqlen), -1, xseq, 0 == off, seqlen == off, off,
- nelems == -2, *ins, nelems == -1,
- int (inslen), -1, xins, nelems, *ins);
+ cwidth, int (seqlen), -1, xseq, 0 == off, seqlen == off,
+ off, nelems == -2, *ins, nelems == -1,
+ cwidth, int (inslen), -1, xins, nelems, *ins);
std::size_t n_copy = UserClass::n_total_copy_ctor_;
std::size_t n_asgn = UserClass::n_total_op_assign_;
@@ -870,12 +872,14 @@
char* funcall = 0;
std::size_t len = 0;
+ static const int cwidth = sizeof (*xseq);
+
rw_asnprintf (&funcall, &len,
"deque(\"%{X=*.*}\").assign("
"%{?}\"%{X=*.*}\")%{:}%d, %d)%{;}",
- seqlen, -1, xseq,
+ cwidth, seqlen, -1, xseq,
nelems < 0,
- asnlen, -1, xasn,
+ cwidth, asnlen, -1, xasn,
nelems, *asn);
std::size_t n_copy = UserClass::n_total_copy_ctor_;
@@ -1089,12 +1093,14 @@
char* funcall = 0;
std::size_t buflen = 0;
+ static const int cwidth = sizeof (*xseq);
+
if (std::size_t (-1) == len) { // erase(iterator)
rw_asnprintf (&funcall, &buflen,
"deque(\"%{X=*.*}\").erase(%{?}end()%{:}"
"%{?}begin () + %zu%{:}begin ()%{;}%{;}",
- seqlen, -1, xseq,
+ cwidth, seqlen, -1, xseq,
begoff == deq.size (), begoff, begoff);
exception_loop (line, Erase_1, funcall, 0,
@@ -1110,7 +1116,7 @@
"%{?}begin () + %zu%{:}begin ()%{;}%{;}"
"%{?})%{:}%{?}, end ())%{:}%{?}, begin ())"
"%{:}begin () + %zu%{;}%{;}%{;}",
- seqlen, -1, xseq,
+ cwidth, seqlen, -1, xseq,
begoff == deq.size (), begoff, begoff,
std::size_t (-1) == len,
end == deq.end (),
diff --git a/tests/containers/23.deque.special.cpp b/tests/containers/23.deque.special.cpp
index f50a0a8..74aca55 100644
--- a/tests/containers/23.deque.special.cpp
+++ b/tests/containers/23.deque.special.cpp
@@ -147,25 +147,27 @@
const Iterator rhs_end_1 = rhs.end ();
const SizeType rhs_size_1 = rhs.size ();
+ static const int cwidth = sizeof (T);
+
// verify that the iterators and sizes
// of the two objects were swapped
rw_assert (lhs_begin_0 == rhs_begin_1 && lhs_begin_1 == rhs_begin_0,
0, __LINE__,
"begin() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"",
- int (lhs_seq_len), -1, lhs_seq,
- int (rhs_seq_len), -1, rhs_seq);
+ cwidth, int (lhs_seq_len), -1, lhs_seq,
+ cwidth, int (rhs_seq_len), -1, rhs_seq);
rw_assert (lhs_end_0 == rhs_end_1 && lhs_end_1 == rhs_end_0,
0, __LINE__,
"end() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"",
- int (lhs_seq_len), -1, lhs_seq,
- int (rhs_seq_len), -1, rhs_seq);
+ cwidth, int (lhs_seq_len), -1, lhs_seq,
+ cwidth, int (rhs_seq_len), -1, rhs_seq);
rw_assert (lhs_size_0 == rhs_size_1 && lhs_size_1 == rhs_size_0,
0, __LINE__,
"size() not swapped for \"%{X=*.*}\" and \"%{X=*.*}\"",
- int (lhs_seq_len), -1, lhs_seq,
- int (rhs_seq_len), -1, rhs_seq);
+ cwidth, int (lhs_seq_len), -1, lhs_seq,
+ cwidth, int (rhs_seq_len), -1, rhs_seq);
// swap one of the containers with an empty unnamed temporary
// container and verify that the object is empty
@@ -177,11 +179,11 @@
rw_assert (lhs_begin_2 == lhs_end_2, 0, __LINE__,
"deque<%s>().begin() not swapped for \"%{X=*.*}\"",
- tname, int (rhs_seq_len), -1, rhs_seq);
+ tname, cwidth, int (rhs_seq_len), -1, rhs_seq);
rw_assert (0 == lhs_size_2, 0, __LINE__,
"deque<%s>().size() not swapped for \"%{X=*.*}\"",
- tname, int (rhs_seq_len), -1, rhs_seq);
+ tname, cwidth, int (rhs_seq_len), -1, rhs_seq);
}
diff --git a/tests/containers/23.vector.modifiers.cpp b/tests/containers/23.vector.modifiers.cpp
index c4d82a3..580585a 100644
--- a/tests/containers/23.vector.modifiers.cpp
+++ b/tests/containers/23.vector.modifiers.cpp
@@ -293,15 +293,17 @@
char* fcall = 0;
std::size_t len = 0;
+ static const int cwidth = sizeof (*xseq);
+
// format a string describing the function call being tested
// (used in diagnostic messages, if any, below)
rw_asnprintf (&fcall, &len, "vector(\"%{X=*.*}\").insert("
"%{?}begin()%{:}%{?}end()%{:}begin() + %zu%{;}%{;}, "
"%{?}%d%{:}%{?}\"%{X=*.*}\"%{:}%d, %d%{;}%{;})",
- int (seqlen), -1, xseq,
+ cwidth, int (seqlen), -1, xseq,
0 == off, int (seqlen) == off, off,
n == -2, *ins, n == -1,
- int (inslen), -1, xins, n, *ins);
+ cwidth, int (inslen), -1, xins, n, *ins);
// 23.2.4.3, p1
// Notes: Causes reallocation if the new size is greater than
diff --git a/tests/numerics/26.adjacent.diff.cpp b/tests/numerics/26.adjacent.diff.cpp
index a0d75d3..90967f3 100644
--- a/tests/numerics/26.adjacent.diff.cpp
+++ b/tests/numerics/26.adjacent.diff.cpp
@@ -197,6 +197,8 @@
UserClass* const src = new UserClass [N + 1];
UserClass* dst = same_seq ? src : new UserClass [N + 1];
+ static const int cwidth = sizeof (*src);
+
for (std::size_t i = 0; i != N; ++i) {
UserClass* const src_end = src + i;
@@ -229,7 +231,7 @@
"adjacent_difference <%s, %s%{?}, %s%{;}>"
"({%{X=+*}}, ...) == result + %td, got result + %td",
itname, outname, binop, opname,
- int (i), src, dst_end - dst, res - dst);
+ cwidth, int (i), src, dst_end - dst, res - dst);
for (k = 0; k < i; k++) {
success = dst [k].data_.val_ == tmp_val [k];
@@ -246,7 +248,7 @@
"adjacent_difference <%s, %s%{?}, %s%{;}>"
"({%{X=+*}}, ...) ==> {%{X=+*.*}}, expected %d",
itname, outname, binop, opname,
- int (i), src, int (i), int (k), dst, tmp_val [k]);
+ cwidth, int (i), src, int (i), int (k), dst, tmp_val [k]);
}
delete[] tmp_val;
@@ -262,7 +264,7 @@
"({%{X=+*}}, ...) complexity: got %zu invocations "
"of %s, expected %zu",
itname, outname, binop, opname,
- int (i), src, minus_ops,
+ cwidth, int (i), src, minus_ops,
binop ? "BinaryMinus" : "operator-", exp_minus_ops);
if (!success)
diff --git a/tests/numerics/26.inner.product.cpp b/tests/numerics/26.inner.product.cpp
index 8c13be3..8dbf2cc 100644
--- a/tests/numerics/26.inner.product.cpp
+++ b/tests/numerics/26.inner.product.cpp
@@ -260,7 +260,8 @@
"inner_product <%s, %s, %s%{?}, %s, %s%{;}>"
"({%{X=+*}}, {%{X=+*}}) == %d, got %d",
it1name, it2name, tname, binop, op1name, op2name,
- int (i), buf1, int (i), buf2, sum, res.data_.val_);
+ int (sizeof (*buf1)), int (i), buf1,
+ int (sizeof (*buf2)), int (i), buf2, sum, res.data_.val_);
sum += (buf1 [i].data_.val_ * buf2 [i].data_.val_);
diff --git a/tests/numerics/26.partial.sum.cpp b/tests/numerics/26.partial.sum.cpp
index 54484c1..0d717a1 100644
--- a/tests/numerics/26.partial.sum.cpp
+++ b/tests/numerics/26.partial.sum.cpp
@@ -218,13 +218,15 @@
const std::size_t plus_ops = binop ? Accumulator::funcalls_ :
UserClass::n_total_op_plus_assign_ - last_n_op_plus;
+ static const int cwidth = sizeof (*src);
+
// verify the returned iterator 26.4.3, p2
bool success = res == dst_end;
rw_assert (success, 0, __LINE__,
"partial_sum<%s, %s%{?}, %s%{;}>"
"({%{X=+*}}, ...) == result + %d, got result %td",
itname, outname, binop, opname,
- int (i), src, dst_end - dst, res - dst_end);
+ cwidth, int (i), src, dst_end - dst, res - dst_end);
int sum = 0;
for (k = 0; k < i; ++k) {
@@ -243,7 +245,8 @@
"partial_sum<%s, %s%{?}, %s%{;}>"
"({%{X=+*}}, ...) ==> {%{X=+*.*}}, expected %d",
itname, outname, binop, opname,
- int (i), src, int (i), int (k), dst, sum);
+ cwidth, int (i), src,
+ cwidth, int (i), int (k), dst, sum);
}
delete[] tmp_val;
@@ -259,7 +262,7 @@
"({%{X=+*}}, ...) complexity: got %zu invocations "
"of %s, expected %zu",
itname, outname, binop, opname,
- int (i), src, plus_ops,
+ cwidth, int (i), src, plus_ops,
binop ? "BinaryPlus" : "operator+", exp_plus_ops);
if (!success)
diff --git a/tests/self/0.printf.cpp b/tests/self/0.printf.cpp
index 3d922d6..be8a3e1 100644
--- a/tests/self/0.printf.cpp
+++ b/tests/self/0.printf.cpp
@@ -2925,27 +2925,32 @@
/***********************************************************************/
+// directive syntax:
+// "X=" [ '#' ] [ '+' ] [ '*' | <n> ] [ '.' [ '*' | '@' | <n> ] ]
+// where
+// '#' causes UserClass::id_ to be included in output
+// ignored for UserPOD
+// '+' forces UserClass::data_.val_ or UserPOD::data_.val to be
+// formatted as an integer (otherwise it is formatted as an
+// (optionally escaped) character '*' or <n> is the number
+// of elements in the sequence (the first occurrence)
+// '*', <n> is the offset of the cursor within the sequence
+// (where the cursor is a pair of pointy brackets
+// surrounding the element, e.g., >123<)
+// '@' is the pointer to the element to be surrended by the
+// pair of pointy brackets
+// first rw_snprintfa's variable argument of int type should be
+// sizeof(UserClass) or sizeof(UserPOD)
+
+#undef TEST
+#define TEST(fmt, a1, a2, a3, expect) \
+ do_test (__LINE__, fmt, expect, rw_sprintfa (fmt, cwidth, a1, a2, a3))
+
static void
test_userclass_format ()
{
- // %{X=} directive syntax:
- //
- // "X=" [ '#' ] [ '+' ] [ '*' | <n> ] [ '.' [ '*' | '@' | <n> ] ]
- //
- // where
- // '#' causes UserClass::id_ to be included in output
- // '+' forces UserClass::data_.val_ to be formatted as an int
- // otherwise it is formatted as an (optionally escaped)
- // char
- // '*' or <n> is the number of elements in the sequence
- // (the first occurrence)
- // '*', <n> is the offset of the cursor within the sequence
- // (where the cursor is a pair of pointy brackets
- // surrounding the element, e.g., >123<)
- // '@' is the pointer to the element to be surrended by the
- // pair of pointy brackets
-
UserClass* const x = UserClass::from_char ("abcdef");
+ static const int cwidth = sizeof (*x);
TEST ("[%{X=*}]", 0, x, 0, "[]");
TEST ("[%{X=*}]", 1, x, 0, "[a]");
@@ -2955,6 +2960,7 @@
TEST ("[%{X=*}]", 5, x, 0, "[abcde]");
TEST ("[%{X=*}]", 6, x, 0, "[abcdef]");
+
TEST ("[%{X=#*}]", 0, x, 0, "[]");
TEST ("[%{X=#*}]", 1, x, 0, "[1:a]");
TEST ("[%{X=#*}]", 2, x, 0, "[1:a2:b]");
@@ -2963,6 +2969,7 @@
TEST ("[%{X=#*}]", 5, x, 0, "[1:a2:b3:c4:d5:e]");
TEST ("[%{X=#*}]", 6, x, 0, "[1:a2:b3:c4:d5:e6:f]");
+
TEST ("[%{X=+*}]", 0, x, 0, "[]");
TEST ("[%{X=+*}]", 1, x, 0, "[97]");
TEST ("[%{X=+*}]", 2, x, 0, "[97,98]");
@@ -2971,6 +2978,35 @@
TEST ("[%{X=+*}]", 5, x, 0, "[97,98,99,100,101]");
TEST ("[%{X=+*}]", 6, x, 0, "[97,98,99,100,101,102]");
+
+ TEST ("[%{X=*.0}]", 0, x, 0, "[]");
+
+ TEST ("[%{X=*.0}]", 1, x, 0, "[>a<]");
+
+ TEST ("[%{X=*.*}]", 2, 0, x, "[>a<b]");
+ TEST ("[%{X=*.1}]", 2, x, 0, "[a>b<]");
+
+ TEST ("[%{X=*.0}]", 3, x, 0, "[>a<bc]");
+ TEST ("[%{X=*.*}]", 3, 1, x, "[a>b<c]");
+ TEST ("[%{X=*.*}]", 3, 2, x, "[ab>c<]");
+
+ TEST ("[%{X=*.*}]", 4, 0, x, "[>a<bcd]");
+ TEST ("[%{X=*.*}]", 4, 1, x, "[a>b<cd]");
+ TEST ("[%{X=*.*}]", 4, 2, x, "[ab>c<d]");
+ TEST ("[%{X=*.*}]", 4, 3, x, "[abc>d<]");
+
+ TEST ("[%{X=*.@}]", 4, x + 3, x, "[abc>d<]");
+ TEST ("[%{X=*.@}]", 4, x + 2, x, "[ab>c<d]");
+ TEST ("[%{X=*.@}]", 4, x + 1, x, "[a>b<cd]");
+ TEST ("[%{X=*.@}]", 4, x + 0, x, "[>a<bcd]");
+
+ TEST ("[%{X=#5.*}]", 0, x, 0, "[>1:a<2:b3:c4:d5:e]");
+ TEST ("[%{X=#5.*}]", 1, x, 0, "[1:a>2:b<3:c4:d5:e]");
+ TEST ("[%{X=#5.*}]", 2, x, 0, "[1:a2:b>3:c<4:d5:e]");
+ TEST ("[%{X=#5.*}]", 3, x, 0, "[1:a2:b3:c>4:d<5:e]");
+ TEST ("[%{X=#5.*}]", 4, x, 0, "[1:a2:b3:c4:d>5:e<]");
+
+
TEST ("[%{X=+*.0}]", 0, x, 0, "[]");
TEST ("[%{X=+*.0}]", 1, x, 0, "[>97<]");
@@ -3001,8 +3037,103 @@
delete[] x;
}
+static void
+test_userpod_format ()
+{
+ UserPOD* const x = UserPOD::from_char ("abcdef");
+ static const int cwidth = sizeof (*x);
+
+ TEST ("[%{X=*}]", 0, x, 0, "[]");
+ TEST ("[%{X=*}]", 1, x, 0, "[a]");
+ TEST ("[%{X=*}]", 2, x, 0, "[ab]");
+ TEST ("[%{X=*}]", 3, x, 0, "[abc]");
+ TEST ("[%{X=*}]", 4, x, 0, "[abcd]");
+ TEST ("[%{X=*}]", 5, x, 0, "[abcde]");
+ TEST ("[%{X=*}]", 6, x, 0, "[abcdef]");
+
+
+ TEST ("[%{X=#*}]", 0, x, 0, "[]");
+ TEST ("[%{X=#*}]", 1, x, 0, "[a]");
+ TEST ("[%{X=#*}]", 2, x, 0, "[ab]");
+ TEST ("[%{X=#*}]", 3, x, 0, "[abc]");
+ TEST ("[%{X=#*}]", 4, x, 0, "[abcd]");
+ TEST ("[%{X=#*}]", 5, x, 0, "[abcde]");
+ TEST ("[%{X=#*}]", 6, x, 0, "[abcdef]");
+
+
+ TEST ("[%{X=+*}]", 0, x, 0, "[]");
+ TEST ("[%{X=+*}]", 1, x, 0, "[97]");
+ TEST ("[%{X=+*}]", 2, x, 0, "[97,98]");
+ TEST ("[%{X=+*}]", 3, x, 0, "[97,98,99]");
+ TEST ("[%{X=+*}]", 4, x, 0, "[97,98,99,100]");
+ TEST ("[%{X=+*}]", 5, x, 0, "[97,98,99,100,101]");
+ TEST ("[%{X=+*}]", 6, x, 0, "[97,98,99,100,101,102]");
+
+
+ TEST ("[%{X=*.0}]", 0, x, 0, "[]");
+
+ TEST ("[%{X=*.0}]", 1, x, 0, "[>a<]");
+
+ TEST ("[%{X=*.*}]", 2, 0, x, "[>a<b]");
+ TEST ("[%{X=*.1}]", 2, x, 0, "[a>b<]");
+
+ TEST ("[%{X=*.0}]", 3, x, 0, "[>a<bc]");
+ TEST ("[%{X=*.*}]", 3, 1, x, "[a>b<c]");
+ TEST ("[%{X=*.*}]", 3, 2, x, "[ab>c<]");
+
+ TEST ("[%{X=*.*}]", 4, 0, x, "[>a<bcd]");
+ TEST ("[%{X=*.*}]", 4, 1, x, "[a>b<cd]");
+ TEST ("[%{X=*.*}]", 4, 2, x, "[ab>c<d]");
+ TEST ("[%{X=*.*}]", 4, 3, x, "[abc>d<]");
+
+ TEST ("[%{X=*.@}]", 4, x + 3, x, "[abc>d<]");
+ TEST ("[%{X=*.@}]", 4, x + 2, x, "[ab>c<d]");
+ TEST ("[%{X=*.@}]", 4, x + 1, x, "[a>b<cd]");
+ TEST ("[%{X=*.@}]", 4, x + 0, x, "[>a<bcd]");
+
+ TEST ("[%{X=#5.*}]", 0, x, 0, "[>a<bcde]");
+ TEST ("[%{X=#5.*}]", 1, x, 0, "[a>b<cde]");
+ TEST ("[%{X=#5.*}]", 2, x, 0, "[ab>c<de]");
+ TEST ("[%{X=#5.*}]", 3, x, 0, "[abc>d<e]");
+ TEST ("[%{X=#5.*}]", 4, x, 0, "[abcd>e<]");
+
+
+ TEST ("[%{X=+*.0}]", 0, x, 0, "[]");
+
+ TEST ("[%{X=+*.0}]", 1, x, 0, "[>97<]");
+
+ TEST ("[%{X=+*.*}]", 2, 0, x, "[>97<,98]");
+ TEST ("[%{X=+*.1}]", 2, x, 0, "[97,>98<]");
+
+ TEST ("[%{X=+*.0}]", 3, x, 0, "[>97<,98,99]");
+ TEST ("[%{X=+*.*}]", 3, 1, x, "[97,>98<,99]");
+ TEST ("[%{X=+*.*}]", 3, 2, x, "[97,98,>99<]");
+
+ TEST ("[%{X=+*.*}]", 4, 0, x, "[>97<,98,99,100]");
+ TEST ("[%{X=+*.*}]", 4, 1, x, "[97,>98<,99,100]");
+ TEST ("[%{X=+*.*}]", 4, 2, x, "[97,98,>99<,100]");
+ TEST ("[%{X=+*.*}]", 4, 3, x, "[97,98,99,>100<]");
+
+ TEST ("[%{X=+*.@}]", 4, x + 3, x, "[97,98,99,>100<]");
+ TEST ("[%{X=+*.@}]", 4, x + 2, x, "[97,98,>99<,100]");
+ TEST ("[%{X=+*.@}]", 4, x + 1, x, "[97,>98<,99,100]");
+ TEST ("[%{X=+*.@}]", 4, x + 0, x, "[>97<,98,99,100]");
+
+ TEST ("[%{X=+#5.*}]", 0, x, 0, "[>97<,98,99,100,101]");
+ TEST ("[%{X=+#5.*}]", 1, x, 0, "[97,>98<,99,100,101]");
+ TEST ("[%{X=+#5.*}]", 2, x, 0, "[97,98,>99<,100,101]");
+ TEST ("[%{X=+#5.*}]", 3, x, 0, "[97,98,99,>100<,101]");
+ TEST ("[%{X=+#5.*}]", 4, x, 0, "[97,98,99,100,>101<]");
+
+ delete[] x;
+}
+
/***********************************************************************/
+#undef TEST
+#define TEST(fmt, a1, a2, a3, expect) \
+ do_test (__LINE__, fmt, expect, rw_sprintfa (fmt, a1, a2, a3))
+
static int
user_fun_va (const char *fun_name, // name of calling function
char **pbuf, // pointer to a buffer
@@ -3400,6 +3531,7 @@
// must be exercised before user-defined formatting
test_userclass_format ();
+ test_userpod_format ();
test_user_defined_formatting ();
diff --git a/tests/src/value.cpp b/tests/src/value.cpp
index eb6bb4a..9cf570f 100644
--- a/tests/src/value.cpp
+++ b/tests/src/value.cpp
@@ -33,6 +33,7 @@
#include <stdarg.h> // for va_arg, va_list, ...
#include <stdlib.h> // for strtol()
#include <string.h> // for size_t, strlen()
+#include <wchar.h> // for wint_t
#include <rw_value.h>
@@ -680,6 +681,15 @@
}
+static inline void
+_rw_advance (const void*& parray, int idx, bool is_class)
+{
+ if (is_class)
+ parray = _RWSTD_STATIC_CAST (const UserClass*, parray) + idx;
+ else
+ parray = _RWSTD_STATIC_CAST (const UserPOD*, parray) + idx;
+}
+
static int
_rw_fmtxarrayv (char **pbuf, size_t *pbufsize, const char *fmt, va_list va)
{
@@ -687,51 +697,59 @@
RW_ASSERT (0 != pbufsize);
RW_ASSERT (0 != fmt);
- va_list* pva = 0; // pointer to rw_vsnprintf's va_list
bool fl_plus = false;
bool fl_pound = false;
int nelems = -1;
int cursor = -1;
- const UserClass* pelem = 0;
+ const void* pelem = 0;
// directive syntax:
// "X=" [ '#' ] [ '+' ] [ '*' | <n> ] [ '.' [ '*' | '@' | <n> ] ]
// where
// '#' causes UserClass::id_ to be included in output
- // '+' forces UserClass::data_.val_ to be formatted as an integer (
- // otherwise it is formatted as an (optionally escaped) character
- // '*' or <n> is the number of elements in the sequence (the
- // first occurrence)
+ // ignored for UserPOD
+ // '+' forces UserClass::data_.val_ or UserPOD::data_.val to be
+ // formatted as an integer (otherwise it is formatted as an
+ // (optionally escaped) character '*' or <n> is the number
+ // of elements in the sequence (the first occurrence)
// '*', <n> is the offset of the cursor within the sequence
// (where the cursor is a pair of pointy brackets
// surrounding the element, e.g., >123<)
// '@' is the pointer to the element to be surrended by the
// pair of pointy brackets
+ // first rw_snprintfa's variable argument of int type should be
+ // sizeof(UserClass) or sizeof(UserPOD)
if ('X' != fmt [0] || '=' != fmt [1])
return _RWSTD_INT_MIN;
+ // extract the address of the caller's variable argument list
+ va_list* const pva = va_arg (va, va_list*);
+ RW_ASSERT (0 != pva);
+
+ // process element width
+ const int cwidth = va_arg (*pva, int);
+ RW_ASSERT (sizeof (UserClass) == cwidth || sizeof (UserPOD) == cwidth);
+
+ const bool is_class = (sizeof (UserClass) == cwidth);
+
fmt += 2;
if ('+' == *fmt) {
- // use numerical formatting for UserClass::data_.val_
+ // use numerical formatting for data_.val_
fl_plus = true;
++fmt;
}
if ('#' == *fmt) {
// include UserClass::id_ in output
- fl_pound = true;
+ fl_pound = is_class;
++fmt;
}
if ('*' == *fmt) {
// process width
- pva = va_arg (va, va_list*);
-
- RW_ASSERT (0 != pva);
-
// extract the width from rw_snprintfa's variable argument
// list pass through to us by the caller
nelems = va_arg (*pva, int);
@@ -750,59 +768,41 @@
if ('.' == *fmt) {
// process precision (cursor)
if ('*' == *++fmt) {
- if (0 == pva)
- pva = va_arg (va, va_list*);
-
- RW_ASSERT (0 != pva);
-
- // extract the width from rw_snprintfa's variable argument
- // list passed through to us by the caller
+ // extract the cursor index from rw_snprintfa's variable
+ // argument list passed through to us by the caller
cursor = va_arg (*pva, int);
++fmt;
}
else if ('@' == *fmt) {
- if (0 == pva)
- pva = va_arg (va, va_list*);
-
- RW_ASSERT (0 != pva);
-
// extract the pointer from rw_snprintfa's variable argument
// list passed through to us by the caller
- pelem = va_arg (*pva, UserClass*);
-
+ pelem = va_arg (*pva, void*);
++fmt;
}
else if (isdigit (*fmt)) {
char* end = 0;
cursor = int (strtol (fmt, &end, 10));
-
fmt = end;
}
}
RW_ASSERT ('\0' == *fmt);
- // extract the address of the caller's variable argument list
- if (0 == pva)
- pva = va_arg (va, va_list*);
-
- RW_ASSERT (0 != pva);
-
- // extract a pointer to UserClass from rw_snprintfa's variable argument
- // list pass through to us by the caller
- const UserClass* const xbeg = va_arg (*pva, UserClass*);
+ // extract a pointer to UserClass or UserPOD from rw_snprintfa's
+ // variable argument list pass through to us by the caller
+ const void* const xbeg = va_arg (*pva, const void*);
if (-1 != cursor) {
RW_ASSERT (-1 < cursor);
RW_ASSERT (0 == pelem);
- pelem = xbeg + cursor;
+ pelem = xbeg;
+ _rw_advance (pelem, cursor, is_class);
}
// extract the address where to store the extracted argument
// for use by any subsequent positional paramaters
- const UserClass** const pparam = va_arg (va, const UserClass**);
-
+ const void** const pparam = va_arg (va, const void**);
RW_ASSERT (0 != pparam);
// store the extracted argument
@@ -820,8 +820,9 @@
// bytes appended) back to the caller
const char* pointer [2];
+ const void* px = xbeg;
- for (const UserClass *px = xbeg; px != xbeg + nelems; ++px) {
+ for (int i = 0; i != nelems; ++i) {
if (px == pelem) {
pointer [0] = ">";
@@ -832,22 +833,40 @@
pointer [1] = "";
}
+ int id;
+ int val;
+
+ if (is_class) {
+ const UserClass* const pclass =
+ _RWSTD_STATIC_CAST (const UserClass*, px);
+ val = pclass->data_.val_;
+ id = pclass->id_;
+ }
+ else {
+ const UserPOD* const ppod =
+ _RWSTD_STATIC_CAST (const UserPOD*, px);
+ val = ppod->data_.val_;
+ id = 0;
+ }
+
const int n =
rw_asnprintf (pbuf, pbufsize,
"%{+}%s" // '>'
"%{?}%d:%{;}"
- "%{?}%d%s%{?},%{;}%{:}%{lc}%{;}",
+ "%{?}%d%s%{?},%{;}%{:}%{lc}%s%{;}",
pointer [0], // ">" or ""
- fl_pound, px->id_, // "<id>:"
- fl_plus, px->data_.val_, // <val>
+ fl_pound, id, // "<id>:"
+ fl_plus, val, // <val>
pointer [1], // "<" or ""
- px + 1 < xbeg + nelems, // ','
- px->data_.val_, // <val>
+ i + 1 < nelems, // ','
+ wint_t (val), // <val>
pointer [1]); // "<" or ""
if (n < 0)
return n;
nbytes += n;
+
+ _rw_advance (px, 1, is_class);
}
//////////////////////////////////////////////////////////////////