OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 LifeCycleWatcher watcher; | 119 LifeCycleWatcher watcher; |
120 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); | 120 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); |
121 { | 121 { |
122 ScopedVector<LifeCycleObject> scoped_vector; | 122 ScopedVector<LifeCycleObject> scoped_vector; |
123 scoped_vector.push_back(watcher.NewLifeCycleObject()); | 123 scoped_vector.push_back(watcher.NewLifeCycleObject()); |
124 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); | 124 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
125 } | 125 } |
126 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); | 126 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); |
127 } | 127 } |
128 | 128 |
| 129 TEST(ScopedVectorTest, MoveConstruct) { |
| 130 LifeCycleWatcher watcher; |
| 131 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); |
| 132 { |
| 133 ScopedVector<LifeCycleObject> scoped_vector; |
| 134 scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| 135 EXPECT_FALSE(scoped_vector.empty()); |
| 136 |
| 137 ScopedVector<LifeCycleObject> scoped_vector_copy(scoped_vector.Pass()); |
| 138 EXPECT_TRUE(scoped_vector.empty()); |
| 139 EXPECT_FALSE(scoped_vector_copy.empty()); |
| 140 |
| 141 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| 142 } |
| 143 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); |
| 144 } |
| 145 |
| 146 TEST(ScopedVectorTest, MoveAssign) { |
| 147 LifeCycleWatcher watcher; |
| 148 EXPECT_EQ(LC_INITIAL, watcher.life_cycle_state()); |
| 149 { |
| 150 ScopedVector<LifeCycleObject> scoped_vector; |
| 151 scoped_vector.push_back(watcher.NewLifeCycleObject()); |
| 152 ScopedVector<LifeCycleObject> scoped_vector_assign; |
| 153 EXPECT_FALSE(scoped_vector.empty()); |
| 154 |
| 155 scoped_vector_assign = scoped_vector.Pass(); |
| 156 EXPECT_TRUE(scoped_vector.empty()); |
| 157 EXPECT_FALSE(scoped_vector_assign.empty()); |
| 158 |
| 159 EXPECT_EQ(LC_CONSTRUCTED, watcher.life_cycle_state()); |
| 160 } |
| 161 EXPECT_EQ(LC_DESTROYED, watcher.life_cycle_state()); |
| 162 } |
| 163 |
129 TEST(ScopedVectorTest, InsertRange) { | 164 TEST(ScopedVectorTest, InsertRange) { |
130 LifeCycleWatcher watchers[5]; | 165 LifeCycleWatcher watchers[5]; |
131 | 166 |
132 std::vector<LifeCycleObject*> vec; | 167 std::vector<LifeCycleObject*> vec; |
133 for(LifeCycleWatcher* it = watchers; it != watchers + arraysize(watchers); | 168 for(LifeCycleWatcher* it = watchers; it != watchers + arraysize(watchers); |
134 ++it) { | 169 ++it) { |
135 EXPECT_EQ(LC_INITIAL, it->life_cycle_state()); | 170 EXPECT_EQ(LC_INITIAL, it->life_cycle_state()); |
136 vec.push_back(it->NewLifeCycleObject()); | 171 vec.push_back(it->NewLifeCycleObject()); |
137 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); | 172 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); |
138 } | 173 } |
139 // Start scope for ScopedVector. | 174 // Start scope for ScopedVector. |
140 { | 175 { |
141 ScopedVector<LifeCycleObject> scoped_vector; | 176 ScopedVector<LifeCycleObject> scoped_vector; |
142 scoped_vector.insert(scoped_vector.end(), vec.begin() + 1, vec.begin() + 3); | 177 scoped_vector.insert(scoped_vector.end(), vec.begin() + 1, vec.begin() + 3); |
143 for(LifeCycleWatcher* it = watchers; it != watchers + arraysize(watchers); | 178 for(LifeCycleWatcher* it = watchers; it != watchers + arraysize(watchers); |
144 ++it) | 179 ++it) |
145 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); | 180 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); |
146 } | 181 } |
147 for(LifeCycleWatcher* it = watchers; it != watchers + 1; ++it) | 182 for(LifeCycleWatcher* it = watchers; it != watchers + 1; ++it) |
148 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); | 183 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); |
149 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it) | 184 for(LifeCycleWatcher* it = watchers + 1; it != watchers + 3; ++it) |
150 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state()); | 185 EXPECT_EQ(LC_DESTROYED, it->life_cycle_state()); |
151 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers); | 186 for(LifeCycleWatcher* it = watchers + 3; it != watchers + arraysize(watchers); |
152 ++it) | 187 ++it) |
153 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); | 188 EXPECT_EQ(LC_CONSTRUCTED, it->life_cycle_state()); |
154 } | 189 } |
155 | 190 |
156 } // namespace | 191 } // namespace |
OLD | NEW |