]>
Commit | Line | Data |
---|---|---|
cb323159 A |
1 | #include <darwintest.h> |
2 | #include <darwintest_utils.h> | |
3 | #include <stdio.h> | |
4 | #include <assert.h> | |
5 | #include <typeinfo> | |
6 | ||
7 | #if 0 | |
8 | # define OSPTR_LOG T_LOG | |
9 | #elif 0 | |
10 | # define OSPTR_LOG printf | |
11 | #else | |
12 | # define OSPTR_LOG(x...) do { } while(0) | |
13 | #endif | |
14 | ||
15 | T_GLOBAL_META( | |
16 | T_META_NAMESPACE("osptr"), | |
17 | T_META_CHECK_LEAKS(false), | |
18 | T_META_RUN_CONCURRENTLY(true) | |
19 | ); | |
20 | ||
21 | class OSMetaClassBase | |
22 | { | |
23 | public: | |
24 | virtual void | |
25 | retain() const | |
26 | { | |
27 | } | |
28 | virtual void | |
29 | release() const | |
30 | { | |
31 | } | |
32 | virtual void | |
33 | taggedRetain(void *tag) const | |
34 | { | |
35 | } | |
36 | virtual void | |
37 | taggedRelease(void *tag) const | |
38 | { | |
39 | } | |
40 | ||
41 | static void *type_id; | |
42 | }; | |
43 | ||
44 | void *OSMetaClassBase::type_id; | |
45 | ||
46 | #define OSTypeAlloc(T) new T | |
47 | #define OSTypeID(T) T::type_id | |
48 | ||
49 | #include <libkern/c++/OSPtr.h> | |
50 | ||
51 | class Base : public OSMetaClassBase { | |
52 | public: | |
53 | Base() : OSMetaClassBase() | |
54 | { | |
55 | } | |
56 | }; | |
57 | ||
58 | class Derived : public Base { | |
59 | public: | |
60 | Derived() : Base() | |
61 | { | |
62 | } | |
63 | }; | |
64 | ||
65 | typedef OSPtr<Base> BasePtr; | |
66 | typedef OSPtr<Derived> DerivedPtr; | |
67 | ||
68 | T_DECL(dumb_osptr, "Dumb OSPtrs work") | |
69 | { | |
70 | BasePtr x = nullptr; | |
71 | T_ASSERT_EQ_PTR(x, nullptr, NULL); | |
72 | T_ASSERT_TRUE(typeid(BasePtr) == typeid(Base *), NULL); | |
73 | T_ASSERT_TRUE(typeid(DerivedPtr) == typeid(Derived *), NULL); | |
74 | ||
75 | OSTaggedPtr<Base, Base> y = nullptr; | |
76 | OSTaggedPtr<Derived, Base> z = nullptr; | |
77 | T_ASSERT_EQ_PTR(y, nullptr, NULL); | |
78 | T_ASSERT_TRUE(typeid(y) == typeid(Base *), NULL); | |
79 | T_ASSERT_TRUE(typeid(z) == typeid(Derived *), NULL); | |
80 | } |