]> git.saurik.com Git - apple/xnu.git/blame - tests/intrusive_shared_ptr_src/compare.equal.nullptr.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / compare.equal.nullptr.cpp
CommitLineData
f427ee49
A
1//
2// Tests for
3// template <typename T, typename R>
4// bool operator==(intrusive_shared_ptr<T, R> const& x, std::nullptr_t);
5//
6// template <typename T, typename R>
7// bool operator!=(intrusive_shared_ptr<T, R> const& x, std::nullptr_t);
8//
9// template <typename T, typename R>
10// bool operator==(std::nullptr_t, intrusive_shared_ptr<T, R> const& x);
11//
12// template <typename T, typename R>
13// bool operator!=(std::nullptr_t, intrusive_shared_ptr<T, R> const& x);
14//
15
16#include <libkern/c++/intrusive_shared_ptr.h>
17#include <darwintest.h>
18#include "test_policy.h"
19
20struct T { int i; };
21
22template <typename T, typename U>
23static void
24check_eq(T t, U u)
25{
26 CHECK(t == u);
27 CHECK(u == t);
28 CHECK(!(t != u));
29 CHECK(!(u != t));
30}
31
32template <typename T, typename U>
33static void
34check_ne(T t, U u)
35{
36 CHECK(!(t == u));
37 CHECK(!(u == t));
38 CHECK(t != u);
39 CHECK(u != t);
40}
41
42template <typename T, typename TQual>
43static void
44tests()
45{
46 T obj{3};
47
48 {
49 test_shared_ptr<TQual> const a(&obj, libkern::no_retain);
50 check_ne(a, nullptr);
51 }
52
53 {
54 test_shared_ptr<TQual> const a = nullptr;
55 check_eq(a, nullptr);
56 }
57}
58
59T_DECL(compare_equal_nullptr, "intrusive_shared_ptr.compare.equal.nullptr") {
60 tests<T, T>();
61 tests<T, T const>();
62}