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