33#ifndef _RWSTD_NO_EXT_CXX_0X
165 rw_info (0,
"util.smartptr.shared.cons", 0,
166 "shared_ptr constructors");
169 std::shared_ptr<char>
ptr;
175 std::shared_ptr<const short>
ptr;
181 std::shared_ptr<volatile int>
ptr;
187 std::shared_ptr<const volatile long>
ptr;
193 const char*
const p =
new char (
'A');
194 std::shared_ptr<const char>
ptr (
p);
200 const char*
const p =
new char (
'A');
201 std::shared_ptr<const void>
ptr (
p);
207 short*
const p =
new short (__LINE__);
208 std::shared_ptr<volatile void>
ptr (
p);
214 double*
const p =
new double ();
215 std::shared_ptr<const volatile void>
ptr (
p);
220#if ILL_FORMED == -1 || ILL_FORMED == __LINE__
223 char*
const p =
new char (
'A');
224 std::shared_ptr<int>
ptr (
p);
235 std::shared_ptr<const Derived<int> > ptr_d (pd0);
236 std::shared_ptr<const Base_0<int> > ptr_0 (pd1);
237 std::shared_ptr<const Base_1<int> > ptr_1 (pd2);
238 std::shared_ptr<const Base<int> > ptr_b (pd3);
240 rw_assert (pd0 == ptr_d.get (), 0, __LINE__,
241 "shared_ptr<Derived>(Derived* = %#p).get() == %#p, got %#p",
242 pd0, pd0, ptr_d.get ());
244 rw_assert (pd1 == ptr_0.get (), 0, __LINE__,
245 "shared_ptr<Base_0>(Derived* = %#p).get() == %#p, got %#p",
248 rw_assert (pd2 == ptr_1.get (), 0, __LINE__,
249 "shared_ptr<Base_1>(Derived* = %#p).get() == %#p, got %#p",
252 rw_assert (pd3 == ptr_b.get (), 0, __LINE__,
253 "shared_ptr<Baee>(Derived* = %#p).get() == %#p, got %#p",
256 rw_assert (1 == ptr_d.use_count (), 0, __LINE__,
"");
257 rw_assert (1 == ptr_0.use_count (), 0, __LINE__,
"");
258 rw_assert (1 == ptr_1.use_count (), 0, __LINE__,
"");
259 rw_assert (1 == ptr_b.use_count (), 0, __LINE__,
"");
263 int*
const p =
new int (__LINE__);
265 std::shared_ptr<int>
ptr (
p,
d);
276 rw_info (0,
"util.smartptr.shared.copy", 0,
277 "shared_ptr copy constructors");
281 std::shared_ptr<void>
ptr;
282 std::shared_ptr<void> cpy (
ptr);
284 rw_assert (0 == cpy.get (), 0, __LINE__,
"");
286 rw_assert (0 == cpy.use_count (), 0, __LINE__,
"");
291 std::shared_ptr<double>
ptr;
292 std::shared_ptr<double> cpy (
ptr);
294 rw_assert (
ptr.use_count () == cpy.use_count (), 0, __LINE__,
"");
299 int*
const p =
new int (__LINE__);
300 std::shared_ptr<int>
ptr (
p);
301 std::shared_ptr<int> cpy (
ptr);
303 rw_assert (
ptr.use_count () == cpy.use_count (), 0, __LINE__,
"");
308 int*
const p =
new int (__LINE__);
309 std::shared_ptr<int>
ptr (
p);
310 std::shared_ptr<void> cpy (
ptr);
312 rw_assert (
ptr.use_count () == cpy.use_count (), 0, __LINE__,
"");
315#if ILL_FORMED == -1 || ILL_FORMED == __LINE__
319 int*
const p =
new int (__LINE__);
320 std::shared_ptr<void>
ptr (
p);
321 std::shared_ptr<int> cpy (
ptr);
323 rw_assert (
ptr.use_count () == cpy.use_count (), 0, __LINE__,
"");
332#if !defined (_RWSTD_HP_aCC_MAJOR) || 6 <= _RWSTD_HP_aCC_MAJOR \
333 || 3 == _RWSTD_HP_aCC_MAJOR && __hpxstd98
353 std::shared_ptr<v_Derived_i> ptr_d (
pd);
354 std::shared_ptr<v_Base_0_i> ptr_0 (ptr_d);
355 std::shared_ptr<v_Base_1_i> ptr_1 (ptr_d);
356 std::shared_ptr<v_Base_i> ptr_b (ptr_d);
359 "shared_ptr<Derived>(Derived* = %#p).get() == %#p, got %#p",
360 pd,
pd, ptr_d.get ());
362 rw_assert (ptr_d.get () == ptr_0.get (), 0, __LINE__,
363 "shared_ptr<Base_0>(const shared_ptr<Derived>(%#p))"
364 ".get() == %#p, got %#p",
366 (v_Base_0_i*)ptr_d.get (), ptr_0.get ());
368 rw_assert (ptr_d.get () == ptr_1.get (), 0, __LINE__,
369 "shared_ptr<Base_1>(const shared_ptr<Derived>(%#p))"
370 ".get() == %#p, got %#p",
372 (v_Base_1_i*)ptr_d.get (), ptr_1.get ());
374 rw_assert (ptr_d.get () == ptr_b.get (), 0, __LINE__,
375 "shared_ptr<Base>(const shared_ptr<Derived>(%#p))"
376 ".get() == %#p, got %#p",
378 (v_Base_i*)ptr_d.get (), ptr_b.get ());
380 rw_assert (4 == ptr_d.use_count (), 0, __LINE__,
"");
381 rw_assert (ptr_d.use_count () == ptr_0.use_count (), 0, __LINE__,
"");
382 rw_assert (ptr_d.use_count () == ptr_1.use_count (), 0, __LINE__,
"");
383 rw_assert (ptr_d.use_count () == ptr_b.use_count (), 0, __LINE__,
"");
392 rw_info (0,
"util.smartptr.shared.dest", 0,
393 "shared_ptr destructor");
399 std::shared_ptr<Base<int> >
ptr;
451 std::shared_ptr<int>
ptr ((
int*)0,
d);
453 std::shared_ptr<int> cpy (
ptr);
466 std::shared_ptr<int>
ptr ((
int*)0,
d);
474 int*
const p =
new int (__LINE__);
478 std::shared_ptr<int>
ptr (
p,
d);
497 "shared_ptr<Derived>(Derived*) called ~Derived()");
499 "shared_ptr<Derived>(Derived*) called ~Base_1()");
501 "shared_ptr<Derived>(Derived*) called ~Base_0()");
503 "shared_ptr<Derived>(Derived*) called ~Base()");
515 "shared_ptr<Base_1>(Derived*) called ~Derived()");
517 "shared_ptr<Base_1>(Derived*) called ~Base_1()");
519 "shared_ptr<Base_1>(Derived*) called ~Base_0()");
521 "shared_ptr<Base_1>(Derived*) called ~Base()");
533 "shared_ptr<Base_0>(Derived*) called ~Derived()");
535 "shared_ptr<Base_0>(Derived*) called ~Base_1()");
537 "shared_ptr<Base_0>(Derived*) called ~Base_0()");
539 "shared_ptr<Base_0>(Derived*) called ~Base()");
551 "shared_ptr<Base>(Derived*) called ~Derived()");
553 "shared_ptr<Base>(Derived*) called ~Base_1()");
555 "shared_ptr<Base>(Derived*) called ~Base_0()");
557 "shared_ptr<Base>(Derived*) called ~Base()");
569 "shared_ptr<void>(Derived*) called ~Derived()");
571 "shared_ptr<void>(Derived*) called ~Base_1()");
573 "shared_ptr<void>(Derived*) called ~Base_0()");
575 "shared_ptr<void>(Derived*) called ~Base()");
584 rw_info (0,
"util.smartptr.shared.assign", 0,
585 "shared_ptr assignment operators");
588 std::shared_ptr<void> ptr0;
589 std::shared_ptr<void> ptr1;
593 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
594 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
598 int*
const p =
new int (__LINE__);
599 std::shared_ptr<int> ptr0 (
p);
600 std::shared_ptr<int> ptr1;
604 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
605 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
609 int*
const p =
new int (__LINE__);
610 std::shared_ptr<int> ptr0 (
p);
611 std::shared_ptr<void> ptr1;
615 rw_assert (ptr1.get () == ptr0.get (), 0, __LINE__,
"");
616 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
622 std::shared_ptr<Derived<int> > ptr0 (
p);
623 std::shared_ptr<Base<int> > ptr1;
627 rw_assert (ptr1.get ()->id == ptr0.get ()->id, 0, __LINE__,
628 "%d == %d, got %d", ptr1.get ()->id, ptr1.get ()->id,
630 rw_assert (ptr1.use_count () == ptr0.use_count (), 0, __LINE__,
"");
636 const std::shared_ptr<Derived<int> > ptr_d (
pd);
638 std::shared_ptr<Base_0<int> > ptr_0;
639 std::shared_ptr<Base_1<int> > ptr_1;
640 std::shared_ptr<Base<int> > ptr_b;
641 std::shared_ptr<void> ptr_v;
648 rw_assert (ptr_d.get () == ptr_0.get (), 0, __LINE__,
649 "(shared_ptr<Base_0>() = shared_ptr<Derived>(Derived* "
650 "= %#p)).get() == %#p, got %#p",
651 ptr_d.get (), (
Base_0<int>*)ptr_d.get (), ptr_0.get ());
653 rw_assert (ptr_d.get () == ptr_1.get (), 0, __LINE__,
654 "(shared_ptr<Base_1>() = shared_ptr<Derived>(Derived* "
655 "= %#p)).get() == %#p, got %#p",
656 ptr_d.get (), (
Base_1<int>*)ptr_d.get (), ptr_1.get ());
658 rw_assert (ptr_d.get () == ptr_b.get (), 0, __LINE__,
659 "(shared_ptr<Base>() = shared_ptr<Derived>(Derived* = %#p))"
660 ".get() == %#p, got %#p",
661 ptr_d.get (), (
Base<int>*)ptr_d.get (), ptr_b.get ());
663 rw_assert (ptr_d.get () == ptr_v.get (), 0, __LINE__,
664 "(shared_ptr<void>() = shared_ptr<Derived>(Derived* = %#p))"
665 ".get() == %#p, got %#p",
666 ptr_d.get (), (
void*)ptr_d.get (), ptr_v.get ());
668 rw_assert (5 == ptr_d.use_count (), 0, __LINE__,
"");
669 rw_assert (ptr_0.use_count () == ptr_d.use_count (), 0, __LINE__,
"");
670 rw_assert (ptr_1.use_count () == ptr_d.use_count (), 0, __LINE__,
"");
671 rw_assert (ptr_b.use_count () == ptr_d.use_count (), 0, __LINE__,
"");
672 rw_assert (ptr_v.use_count () == ptr_d.use_count (), 0, __LINE__,
"");
681 rw_info (0,
"util.smartptr.shared.mod", 0,
682 "shared_ptr modifiers");
685 "shared_ptr modifiers not exercised");
693 rw_info (0,
"util.smartptr.shared.obs", 0,
694 "shared_ptr observers");
697 std::shared_ptr<void>
ptr;
703 "shared_ptr observers not exercised");
711 rw_info (0,
"util.smartptr.shared.cmp", 0,
712 "shared_ptr comparison");
715 std::shared_ptr<void>
ptr;
722 std::shared_ptr<void> ptr0;
723 std::shared_ptr<int> ptr1;
724 rw_assert (ptr0 == ptr1, 0, __LINE__,
"");
725 rw_assert (ptr1 == ptr0, 0, __LINE__,
"");
727 rw_assert (!(ptr0 != ptr1), 0, __LINE__,
"");
728 rw_assert (!(ptr1 != ptr0), 0, __LINE__,
"");
731#if ILL_FORMED == -1 || ILL_FORMED == __LINE__
734 std::shared_ptr<char> ptr0;
735 std::shared_ptr<int> ptr1;
737 rw_assert (ptr0 == ptr1, 0, __LINE__,
"");
738 rw_assert (ptr1 == ptr0, 0, __LINE__,
"");
740 rw_assert (!(ptr0 != ptr1), 0, __LINE__,
"");
741 rw_assert (!(ptr1 != ptr0), 0, __LINE__,
"");
747 int*
const p =
new int (__LINE__);
748 std::shared_ptr<int> ptr0 (
p);
749 std::shared_ptr<int> ptr1 (ptr0);
751 rw_assert (ptr0 == ptr1, 0, __LINE__,
"");
752 rw_assert (ptr1 == ptr0, 0, __LINE__,
"");
754 rw_assert (!(ptr0 != ptr1), 0, __LINE__,
"");
755 rw_assert (!(ptr1 != ptr0), 0, __LINE__,
"");
759 int*
const p0 =
new int (__LINE__);
760 int*
const p1 =
new int (__LINE__);
761 std::shared_ptr<int> ptr0 (p0);
762 std::shared_ptr<int> ptr1 (
p1);
764 rw_assert (!(ptr0 == ptr1), 0, __LINE__,
"");
765 rw_assert (!(ptr1 == ptr0), 0, __LINE__,
"");
767 rw_assert (ptr0 != ptr1, 0, __LINE__,
"");
768 rw_assert (ptr1 != ptr0, 0, __LINE__,
"");
774 std::shared_ptr<Derived<int> > ptr2 (
p);
775 std::shared_ptr<Base_1<int> > ptr1 (ptr2);
776 std::shared_ptr<Base_0<int> > ptr0 (ptr2);
777 std::shared_ptr<Base<int> > ptr_b1 (ptr1);
778 std::shared_ptr<Base<int> > ptr_b0 (ptr0);
780 const bool eq_1_2 = (ptr1.get () == ptr2.get ()) == (ptr1 == ptr2);
781 const bool eq_0_2 = (ptr0.get () == ptr2.get ()) == (ptr0 == ptr2);
789 std::shared_ptr<void>
ptr;
795 std::shared_ptr<void>
ptr;
796 std::shared_ptr<void> cpy (
ptr);
802 int*
const p =
new int (__LINE__);
803 std::shared_ptr<void>
ptr (
p);
804 std::shared_ptr<void> cpy (
ptr);
812 std::shared_ptr<Derived<int> > ptr2 (
p);
813 std::shared_ptr<Base_1<int> > ptr1 (ptr2);
814 std::shared_ptr<Base_0<int> > ptr0 (ptr2);
815 std::shared_ptr<void>
ptr (ptr0);
820 rw_assert (!(ptr0 < ptr1) && !(ptr0 < ptr1), 0, __LINE__,
"");
821 rw_assert (!(ptr0 < ptr2) && !(ptr0 < ptr2), 0, __LINE__,
"");
822 rw_assert (!(ptr1 < ptr2) && !(ptr1 < ptr2), 0, __LINE__,
"");
826 short*
const p0 =
new short (__LINE__);
827 float*
const p1 =
new float (__LINE__);
829 std::shared_ptr<short> ptr0 (p0);
830 std::shared_ptr<float> ptr1 (
p1);
832 rw_assert (ptr0 < ptr1 || ptr1 < ptr0, 0, __LINE__,
"");
841 rw_info (0,
"util.smartptr.shared.io", 0,
845 "shared_ptr I/O not exercised");
853 rw_info (0,
"util.smartptr.shared.spec", 0,
854 "shared_ptr specialized algorithms");
857 "shared_ptr specialized algorithms not exercised");
865 rw_info (0,
"util.smartptr.shared.cast", 0,
874 "shared_ptr casts not exercised");
882 rw_info (0,
"util.smartptr.shared.getdeleter", 0,
883 "shared_ptr get_deleter");
886 "shared_ptr get_deleter not exercised");
892static int no_copy_ctor;
895static int no_modifiers;
896static int no_observers;
897static int no_comparison;
899static int no_specialized;
901static int no_deleter;
909 rw_note (0, 0, __LINE__, "%s test disabled", #what); \
913 } typedef void unused_typedef
932int main (
int argc,
char *argv[])
934 return rw_test (argc, argv, __FILE__,
935 "util.smartptr.shared",
967 "test disabled because _RWSTD_NO_EXT_CXX_0X is defined");
971int main (
int argc,
char *argv[])
973 return rw_test (argc, argv, __FILE__,
974 "util.smartptr.shared",
void test_io(charT *, Traits *, Allocator *, const StringTestCaseData< charT > &tdata)
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)
#define _RWSTD_UNUSED(arg)
_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 *,...)