40#ifndef _RWSTD_NO_EXPLICIT_INSTANTIATION
76template <
class FwdIterator,
class FwdCopyIterator,
81 const FwdIterator &it,
82 const FwdCopyIterator &itc,
83 const OutIterator &
out,
89 const char*
const itname =
91 const char*
const fname =
92 use_copy ?
"unique_copy" :
"unique";
93 const char*
const funname =
94 ppred ?
"BinaryPredicate" :
"operator==()";
96 const std::size_t
nsrc = std::strlen (src);
97 const std::size_t ndst = std::strlen (dst);
99 T*
const xsrc = T::from_char (src,
nsrc);
100 T* xdst = use_copy ? T::from_char (dst, ndst) : xsrc;
102 T*
const xsrc_end = xsrc +
nsrc;
103 T*
const xdst_end = xdst + ndst;
105 const FwdIterator first =
make_iter (xsrc, xsrc, xsrc_end, it);
106 const FwdIterator
last =
make_iter (xsrc_end, xsrc, xsrc_end, it);
108 const FwdCopyIterator first_c =
make_iter (xsrc, xsrc, xsrc_end, itc);
109 const FwdCopyIterator last_c =
make_iter (xsrc_end, xsrc, xsrc_end, itc);
114 std::size_t n_total_ops =
115 ppred ? Predicate::n_total_op_fcall_ : T::n_total_op_eq_;
117 OutIterator res_c (0, 0, 0);
118 FwdIterator
res (0, 0, 0);
122 std::unique_copy (first_c, last_c,
result, *ppred)
123 : std::unique_copy (first_c, last_c,
result);
126 std::unique (first,
last, *ppred)
127 : std::unique (first,
last);
129 const T*
const f_cur = use_copy ?
result.cur_ : first.cur_;
130 const T*
const r_cur = use_copy ? res_c.cur_ :
res.cur_;
132 bool success = r_cur == f_cur + ndst;
134 "line %d: std::%s <%s%{?}, %s%{;}%{?}, %s%{;}>(\"%s\", ...) "
135 "== (res + %zu), got (res + %td)",
136 __LINE__, fname, itname, use_copy, outname, 0 != ppred,
137 funname, src, ndst, r_cur - f_cur);
140 const T*
const mismatch = T::mismatch (xdst, dst, ndst);
143 "line %d: std::%s <%s%{?}, %s%{;}%{?}, %s%{;}>(\"%s\", ...) "
144 "==> \"%s\", got \"%{X=*.@}\"", __LINE__, fname, itname,
145 use_copy, outname, 0 != ppred, funname, src, dst,
146 int (
sizeof (*xdst)),
int (ndst), mismatch, xdst);
149 n_total_ops = ppred->n_total_op_fcall_ - n_total_ops;
151 n_total_ops = T::n_total_op_eq_ - n_total_ops;
154 const std::size_t n_expect_ops =
nsrc ?
nsrc - 1 : 0;
158 "line %d: std::%s <%s%{?}, %s%{;}%{?}, %s%{;}>(\"%s\", ...) "
159 "%s called %zu times, %zu expected",
160 __LINE__, fname, itname, use_copy, outname, 0 != ppred,
161 funname, src, funname, n_total_ops, n_expect_ops);
166template <
class FwdIterator,
class FwdCopyIterator,
169 const FwdCopyIterator &itc,
170 const OutIterator &
out,
176 const char*
const itname = use_copy ?
178 const char*
const fname = use_copy ?
"unique_copy" :
"unique";
179 const char*
const funname = ppred ?
"BinaryPredicate" :
"operator==()";
182 "std::%s (%s, %2$s%{?}, %s%{;}%{?}, %s%{;})",
183 fname, itname, use_copy, outname, ppred, funname);
185#define TEST(src, dst) \
186 test_unique (__LINE__, src, dst, it, itc, out, (T*)0, \
197 TEST (
"abcd",
"abcd");
198 TEST (
"abcde",
"abcde");
199 TEST (
"abcdef",
"abcdef");
200 TEST (
"abcdefg",
"abcdefg");
201 TEST (
"abcdefgh",
"abcdefgh");
202 TEST (
"abcdefghi",
"abcdefghi");
203 TEST (
"abcdefghij",
"abcdefghij");
204 TEST (
"abcdefghijk",
"abcdefghijk");
206 TEST (
"abcabc",
"abcabc");
207 TEST (
"abcabcabc",
"abcabcabc");
208 TEST (
"abcdabcd",
"abcdabcd");
209 TEST (
"abcdabcdabcd",
"abcdabcdabcd");
216 TEST (
"aaabb",
"ab");
217 TEST (
"aaabbb",
"ab");
218 TEST (
"abba",
"aba");
219 TEST (
"abbba",
"aba");
220 TEST (
"aaabbba",
"aba");
221 TEST (
"aaabbbaa",
"aba");
222 TEST (
"aaabbbaaa",
"aba");
223 TEST (
"aaabbbaaab",
"abab");
224 TEST (
"aaabbbaaabb",
"abab");
225 TEST (
"abbbbbaaabb",
"abab");
226 TEST (
"abaaaaaaabb",
"abab");
227 TEST (
"ababbbbbbbb",
"abab");
242template <
class T,
class Predicate,
class FwdIterator>
254 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
257 test_unique (fwd_iter, it, fwd_iter, (
T*)0, ppred,
true);
261 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
264 test_unique (bidir_iter, it, bidir_iter, (
T*)0, ppred,
true);
268 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
271 test_unique (rand_iter, it, rand_iter, (
T*)0, ppred,
true);
275 rw_note (0, __FILE__, __LINE__,
"OutputIterator test disabled");
278 test_unique (fwd_iter, it, output_iter, (
T*)0, ppred,
true);
284template <
class T,
class Predicate>
295 "template <class %s%{?}, class %s%{;}%{?}, class %s%{;}> "
296 "%s std::%s (%1$s, %1$s%{?}, %3$s%{;}%{?}, %5$s%{;})",
297 use_copy ?
"InputIterator" :
"ForwardIterator",
298 use_copy,
"OutputIterator", 0 != ppred,
"Predicate",
299 use_copy ?
"OutputIterator" :
"ForwardIterator",
300 use_copy ?
"unique_copy" :
"unique", use_copy, 0 != ppred);
305 rw_note (0, __FILE__, __LINE__,
"InputIterator test disabled");
313 rw_note (0, __FILE__, __LINE__,
"ForwardIterator test disabled");
319 test_unique (fwd_iter, fwd_iter, fwd_iter, (
T*)0, ppred,
false);
323 rw_note (0, __FILE__, __LINE__,
"BidirectionalIterator test disabled");
330 (
T*)0, ppred,
false);
334 rw_note (0, __FILE__, __LINE__,
"RandomAccessIterator test disabled");
341 (
T*)0, ppred,
false);
353 rw_note (0, __FILE__, __LINE__,
"std::unique test disabled");
359 rw_note (0, __FILE__, __LINE__,
360 "std::unique predicate test disabled");
368 rw_note (0, __FILE__, __LINE__,
"std::unique_copy test disabled");
374 rw_note (0, __FILE__, __LINE__,
375 "std::unique_copy predicate test disabled");
387int main (
int argc,
char *argv[])
389 return rw_test (argc, argv, __FILE__,
394 "|-no-InputIterator# "
395 "|-no-OutputIterator# "
396 "|-no-ForwardIterator# "
397 "|-no-BidirectionalIterator# "
398 "|-no-RandomAccessIterator# "
const MyBuffer< char > nsrc[]
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void test_unique(int line, const char *src, const char *dst, const FwdIterator &it, const FwdCopyIterator &itc, const OutIterator &out, const T *, const Predicate *ppred, bool use_copy)
int rw_opt_no_unique_copy
int rw_opt_no_output_iter
#define _RWSTD_NAMESPACE(name)
T * make_iter(T *cur, const T *, const T *, T *)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)