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