Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | // // Tests for // template <typename T, typename U, typename R> // bool operator==(intrusive_shared_ptr<T, R> const& x, U* y); // // template <typename T, typename U, typename R> // bool operator!=(intrusive_shared_ptr<T, R> const& x, U* y); // // template <typename T, typename U, typename R> // bool operator==(T* x, intrusive_shared_ptr<U, R> const& y); // // template <typename T, typename U, typename R> // bool operator!=(T* x, intrusive_shared_ptr<U, R> const& y); // #include <libkern/c++/intrusive_shared_ptr.h> #include <darwintest.h> #include "test_policy.h" struct Base { int i; }; struct Derived : Base { }; struct T { int i; }; template <typename T, typename U> static void check_eq(T t, U u) { CHECK(t == u); CHECK(u == t); CHECK(!(t != u)); CHECK(!(u != t)); } template <typename T, typename U> static void check_ne(T t, U u) { CHECK(!(t == u)); CHECK(!(u == t)); CHECK(t != u); CHECK(u != t); } template <typename T, typename TQual> static void tests() { T obj1{1}; T obj2{2}; { test_shared_ptr<TQual> const a(&obj1, libkern::no_retain); TQual* b = &obj2; check_ne(a, b); } { test_shared_ptr<TQual> const a(&obj1, libkern::no_retain); TQual* b = &obj1; check_eq(a, b); } { test_shared_ptr<TQual> const a = nullptr; TQual* b = &obj2; check_ne(a, b); } { test_shared_ptr<TQual> const a(&obj1, libkern::no_retain); TQual* b = nullptr; check_ne(a, b); } { test_shared_ptr<TQual> const a = nullptr; TQual* b = nullptr; check_eq(a, b); } } template <typename T, typename RelatedT> static void tests_convert() { T obj{1}; { test_shared_ptr<T> const a(&obj, libkern::no_retain); RelatedT* b = &obj; check_eq(a, b); } { test_shared_ptr<RelatedT> const a(&obj, libkern::no_retain); T* b = &obj; check_eq(a, b); } } T_DECL(compare_equal_raw, "intrusive_shared_ptr.compare.equal.raw", T_META_TAG_VM_PREFERRED) { tests<T, T>(); tests<T, T const>(); tests_convert<Derived, Base>(); tests_convert<Derived, Base const>(); } |