33#ifndef _RWSTD_NO_EXT_CXX_0X
127 rw_info (0,
"util.smartptr.weak.cons", 0,
128 "weak_ptr constructors");
131 std::weak_ptr<char> weak;
132 rw_assert (0 == weak.use_count (), 0, __LINE__,
"");
136 std::shared_ptr<char>
shared;
137 std::weak_ptr<char> weak (
shared);
138 rw_assert (0 == weak.use_count (), 0, __LINE__,
"");
142 std::shared_ptr<char>
shared;
143 std::weak_ptr<void> weak (
shared);
144 rw_assert (0 == weak.use_count (), 0, __LINE__,
"");
148 int*
const p =
new int (__LINE__);
149 std::shared_ptr<int>
shared (
p);
150 std::weak_ptr<int> weak (
shared);
155 int*
const p =
new int (__LINE__);
158 std::weak_ptr<int> weak (
shared1);
164 int*
const p =
new int (__LINE__);
165 std::shared_ptr<int>
shared (
p);
166 std::weak_ptr<void> weak (
shared);
169 rw_assert (0 == weak.use_count (), 0, __LINE__,
"");
174 std::shared_ptr<Derived<int> >
shared (
p);
175 std::weak_ptr<Base<int> > weak (
shared);
178 rw_assert (0 == weak.use_count (), 0, __LINE__,
"");
187 rw_info (0,
"util.smartptr.weak.copy", 0,
188 "weak_ptr copy constructors");
192 std::weak_ptr<void> weak;
193 std::weak_ptr<void> copy (weak);
194 rw_assert (0 == weak.use_count (), 0, __LINE__,
"");
195 rw_assert (0 == copy.use_count (), 0, __LINE__,
"");
200 int*
const p =
new int (__LINE__);
201 std::shared_ptr<int>
shared (
p);
202 std::weak_ptr<int> weak (
shared);
203 std::weak_ptr<int> copy (weak);
211 int*
const p =
new int (__LINE__);
214 std::weak_ptr<int> weak (
shared1);
215 std::weak_ptr<int> copy (weak);
223 int*
const p =
new int (__LINE__);
226 std::weak_ptr<int> weak (
shared1);
227 std::weak_ptr<void> copy (weak);
236 std::shared_ptr<Derived<int> >
shared0 (
p);
238 std::weak_ptr<Derived<int> > weak (
shared1);
239 std::weak_ptr<Base<int> > copy (weak);
245 rw_assert (copy.use_count () == weak.use_count (), 0, __LINE__,
"");
249 rw_assert (copy.use_count () == weak.use_count (), 0, __LINE__,
"");
259 rw_info (0,
"util.smartptr.weak.dest", 0,
260 "weak_ptr destructor");
266 std::weak_ptr<Base<int> > weak;
275 std::shared_ptr<Base<int> >
shared (
p);
277 std::weak_ptr<Base<int> > weak (
shared);
288 std::shared_ptr<Derived<int> >
shared (
p);
291 std::weak_ptr<Base<int> > weak (
shared);
303 std::shared_ptr<Derived<int> >
shared (
p);
306 std::weak_ptr<Base<int> > weak (
shared);
307 std::weak_ptr<Base<int> > copy (
shared);
319 std::shared_ptr<Derived<int> >
shared (
p);
322 std::weak_ptr<Base<int> > weak (
shared);
334 std::weak_ptr<Derived<int> > weak;
338 std::shared_ptr<Derived<int> >
shared (
p);
352 rw_info (0,
"util.smartptr.weak.assign", 0,
353 "weak_ptr assignment operators");
358 std::weak_ptr<void> ptr0;
359 std::weak_ptr<void> ptr1;
363 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
364 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
368 int*
const p =
new int (__LINE__);
369 std::weak_ptr<int> ptr0 (
p);
370 std::weak_ptr<int> ptr1;
374 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
375 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
379 int*
const p =
new int (__LINE__);
380 std::weak_ptr<int> ptr0 (
p);
381 std::weak_ptr<void> ptr1;
385 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
386 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
391 std::weak_ptr<Derived<int> > ptr0 (
p);
392 std::weak_ptr<Base<int> > ptr1;
396 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
397 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
402 std::weak_ptr<Base<int> > ptr0 (
p);
403 std::weak_ptr<void> ptr1;
407 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
408 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
420 rw_info (0,
"util.smartptr.weak.mod", 0,
421 "weak_ptr modifiers");
424 "weak_ptr modifiers not exercised");
432 rw_info (0,
"util.smartptr.weak.obs", 0,
433 "weak_ptr observers");
436 std::weak_ptr<void> weak;
437 rw_assert (0 == weak.use_count (), 0, __LINE__,
"");
441 std::weak_ptr<void> weak;
442 rw_assert (weak.expired (), 0, __LINE__,
"");
446 std::shared_ptr<void>
shared;
447 std::weak_ptr<void> weak (
shared);
448 rw_assert (weak.expired (), 0, __LINE__,
"");
452 int*
const p =
new int (__LINE__);
453 std::shared_ptr<void>
shared (
p);
454 std::weak_ptr<void> weak (
shared);
455 rw_assert (!weak.expired (), 0, __LINE__,
"");
459 int*
const p =
new int (__LINE__);
460 std::shared_ptr<void>
shared (
p);
461 std::weak_ptr<void> weak (
shared);
463 rw_assert (weak.expired (), 0, __LINE__,
"");
467 std::weak_ptr<void> weak;
468 std::shared_ptr<void>
shared (weak.lock ());
470 rw_assert (0 == weak.use_count (), 0, __LINE__,
471 "weak_ptr<void>::use_count() == 1, got %ld",
474 "shared_ptr<void>::use_count() == 1, got %ld",
479 int*
const p =
new int (__LINE__);
481 std::weak_ptr<void> weak (
shared0);
482 std::shared_ptr<void>
shared1 (weak.lock ());
484 rw_assert (2 == weak.use_count (), 0, __LINE__,
485 "weak_ptr<void>::use_count() == 2, got %ld",
488 "shared_ptr<void>::use_count() == 2, got %ld",
493 int*
const p =
new int (__LINE__);
495 std::weak_ptr<void> weak (
shared0);
496 std::shared_ptr<void>
shared1 (weak.lock ());
497 std::shared_ptr<void> shared2 (
shared1);
499 rw_assert (3 == weak.use_count (), 0, __LINE__,
500 "weak_ptr<void>::use_count() == 3, got %ld",
503 "shared_ptr<void>::use_count() == 3, got %ld",
508 rw_assert (2 == weak.use_count (), 0, __LINE__,
509 "weak_ptr<void>::use_count() == 2, got %ld",
514 rw_assert (1 == weak.use_count (), 0, __LINE__,
515 "weak_ptr<void>::use_count() == 1, got %ld",
520 rw_assert (0 == weak.use_count (), 0, __LINE__,
521 "weak_ptr<void>::use_count() == 0, got %ld",
531 rw_info (0,
"util.smartptr.weak.cmp", 0,
532 "weak_ptr comparison");
535 "weak_ptr comparison not exercised");
543 rw_info (0,
"util.smartptr.weak.spec", 0,
544 "weak_ptr specialized algorithms");
547 "weak_ptr specialized algorithms not exercised");
553static int no_copy_ctor;
556static int no_modifiers;
557static int no_observers;
558static int no_comparison;
559static int no_specialized;
567 rw_note (0, 0, __LINE__, "%s test disabled", #what); \
571 } typedef void unused_typedef
587int main (
int argc,
char *argv[])
589 return rw_test (argc, argv, __FILE__,
590 "util.smartptr.weak",
599 "|-no-specialized# ",
616 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
620int main (
int argc,
char *argv[])
622 return rw_test (argc, argv, __FILE__,
623 "util.smartptr.weak",
const std::string shared[nstrings]
const std::string shared1(64, '_')
const std::string shared0
void test_assign(int line, int exceptions, const Iterator &dummy, int nelems, const char *seq, std::size_t seqlen, const char *asn, std::size_t asnlen, const char *res, std::size_t reslen)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
void test_copy_ctor(const T *, const char *tname)
void test_ctor(const charT *, const Traits *, const char *cname, const char *tname)
_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_assert(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_warn(int, const char *, int, const char *,...)