1bb611c8fSApple OSS Distributions //
2bb611c8fSApple OSS Distributions // Tests for
3bb611c8fSApple OSS Distributions // bounded_ptr& operator=(std::nullptr_t);
4bb611c8fSApple OSS Distributions //
5bb611c8fSApple OSS Distributions
6bb611c8fSApple OSS Distributions #include <cstddef>
7bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_ptr.h>
8bb611c8fSApple OSS Distributions #include <darwintest.h>
9bb611c8fSApple OSS Distributions #include <darwintest_utils.h>
10bb611c8fSApple OSS Distributions #include "test_utils.h"
11bb611c8fSApple OSS Distributions
12bb611c8fSApple OSS Distributions #define _assert(...) T_ASSERT_TRUE((__VA_ARGS__), # __VA_ARGS__)
13bb611c8fSApple OSS Distributions
14bb611c8fSApple OSS Distributions struct T { };
15bb611c8fSApple OSS Distributions
16bb611c8fSApple OSS Distributions template <typename T, typename TQual>
17bb611c8fSApple OSS Distributions static void
tests()18bb611c8fSApple OSS Distributions tests()
19bb611c8fSApple OSS Distributions {
20bb611c8fSApple OSS Distributions T obj{};
21bb611c8fSApple OSS Distributions
22bb611c8fSApple OSS Distributions // Assign from nullptr
23bb611c8fSApple OSS Distributions {
24bb611c8fSApple OSS Distributions test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
25bb611c8fSApple OSS Distributions _assert(p != nullptr);
26bb611c8fSApple OSS Distributions test_bounded_ptr<TQual>& ref = (p = nullptr);
27bb611c8fSApple OSS Distributions _assert(&ref == &p);
28bb611c8fSApple OSS Distributions _assert(p == nullptr);
29bb611c8fSApple OSS Distributions }
30bb611c8fSApple OSS Distributions
31bb611c8fSApple OSS Distributions // Assign from NULL
32bb611c8fSApple OSS Distributions {
33bb611c8fSApple OSS Distributions test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
34bb611c8fSApple OSS Distributions _assert(p != nullptr);
35bb611c8fSApple OSS Distributions test_bounded_ptr<TQual>& ref = (p = NULL);
36bb611c8fSApple OSS Distributions _assert(&ref == &p);
37bb611c8fSApple OSS Distributions _assert(p == nullptr);
38bb611c8fSApple OSS Distributions }
39bb611c8fSApple OSS Distributions
40bb611c8fSApple OSS Distributions // Assign from 0
41bb611c8fSApple OSS Distributions {
42bb611c8fSApple OSS Distributions test_bounded_ptr<TQual> p(&obj, &obj, &obj + 1);
43bb611c8fSApple OSS Distributions _assert(p != nullptr);
44bb611c8fSApple OSS Distributions test_bounded_ptr<TQual>& ref = (p = 0);
45bb611c8fSApple OSS Distributions _assert(&ref == &p);
46bb611c8fSApple OSS Distributions _assert(p == nullptr);
47bb611c8fSApple OSS Distributions }
48bb611c8fSApple OSS Distributions }
49bb611c8fSApple OSS Distributions
50*8d741a5dSApple OSS Distributions T_DECL(assign_nullptr, "bounded_ptr.assign.nullptr", T_META_TAG_VM_PREFERRED) {
51bb611c8fSApple OSS Distributions tests<T, T>();
52bb611c8fSApple OSS Distributions tests<T, T const>();
53bb611c8fSApple OSS Distributions tests<T, T volatile>();
54bb611c8fSApple OSS Distributions tests<T, T const volatile>();
55bb611c8fSApple OSS Distributions }
56