76TEST(fxcrt, AutoRestorerRetainPtr) {
77 PseudoRetainable obj1;
78 PseudoRetainable obj2;
79 RetainPtr<PseudoRetainable> ptr(&obj1);
80 EXPECT_EQ(1, obj1.retain_count());
81 EXPECT_EQ(0, obj1.release_count());
83 AutoRestorer<RetainPtr<PseudoRetainable>> restorer(&ptr);
85 EXPECT_EQ(2, obj1.retain_count());
86 EXPECT_EQ(0, obj1.release_count());
88 EXPECT_EQ(&obj2, ptr.Get());
91 EXPECT_TRUE(obj1.alive());
92 EXPECT_EQ(2, obj1.retain_count());
93 EXPECT_EQ(1, obj1.release_count());
96 EXPECT_TRUE(obj1.alive());
97 EXPECT_EQ(1, obj2.retain_count());
98 EXPECT_EQ(0, obj2.release_count());
100 EXPECT_EQ(&obj1, ptr.Get());
103 EXPECT_TRUE(obj1.alive());
104 EXPECT_EQ(3, obj1.retain_count());
105 EXPECT_EQ(2, obj1.release_count());
108 EXPECT_FALSE(obj2.alive());
109 EXPECT_EQ(1, obj2.retain_count());
110 EXPECT_EQ(1, obj2.release_count());
113TEST(fxcrt, AutoRestorerRetainPtrNoOp) {
114 PseudoRetainable obj1;
115 RetainPtr<PseudoRetainable> ptr(&obj1);
116 EXPECT_EQ(1, obj1.retain_count());
117 EXPECT_EQ(0, obj1.release_count());
119 AutoRestorer<RetainPtr<PseudoRetainable>> restorer(&ptr);
120 EXPECT_EQ(2, obj1.retain_count());
121 EXPECT_EQ(0, obj1.release_count());
123 EXPECT_EQ(&obj1, ptr.Get());
126 EXPECT_TRUE(obj1.alive());
127 EXPECT_EQ(2, obj1.retain_count());
128 EXPECT_EQ(1, obj1.release_count());
131TEST(fxcrt, AutoRestorerRetainPtrAbandon) {
132 PseudoRetainable obj1;
133 PseudoRetainable obj2;
134 RetainPtr<PseudoRetainable> ptr(&obj1);
135 EXPECT_EQ(1, obj1.retain_count());
136 EXPECT_EQ(0, obj1.release_count());
138 AutoRestorer<RetainPtr<PseudoRetainable>> restorer(&ptr);
140 EXPECT_EQ(2, obj1.retain_count());
141 EXPECT_EQ(0, obj1.release_count());
143 EXPECT_EQ(&obj2, ptr.Get());
146 EXPECT_EQ(2, obj1.retain_count());
147 EXPECT_EQ(1, obj1.release_count());
150 EXPECT_EQ(1, obj2.retain_count());
151 EXPECT_EQ(0, obj2.release_count());
153 restorer.AbandonRestoration();
155 EXPECT_EQ(&obj2, ptr.Get());
158 EXPECT_FALSE(obj1.alive());
159 EXPECT_EQ(2, obj1.retain_count());
160 EXPECT_EQ(2, obj1.release_count());
163 EXPECT_TRUE(obj2.alive());
164 EXPECT_EQ(1, obj2.retain_count());
165 EXPECT_EQ(0, obj2.release_count());