Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: third_party/WebKit/Source/wtf/DequeTest.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "wtf/Deque.h" 26 #include "wtf/Deque.h"
27 27
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "wtf/HashSet.h" 29 #include "wtf/HashSet.h"
30 #include "wtf/OwnPtr.h" 30 #include "wtf/PtrUtil.h"
31 #include "wtf/PassOwnPtr.h"
32 #include <memory> 31 #include <memory>
33 32
34 namespace WTF { 33 namespace WTF {
35 34
36 namespace { 35 namespace {
37 36
38 TEST(DequeTest, Basic) 37 TEST(DequeTest, Basic)
39 { 38 {
40 Deque<int> intDeque; 39 Deque<int> intDeque;
41 EXPECT_TRUE(intDeque.isEmpty()); 40 EXPECT_TRUE(intDeque.isEmpty());
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 private: 170 private:
172 int m_i; 171 int m_i;
173 int* m_destructNumber; 172 int* m_destructNumber;
174 }; 173 };
175 174
176 template <typename OwnPtrDeque> 175 template <typename OwnPtrDeque>
177 void ownPtrTest() 176 void ownPtrTest()
178 { 177 {
179 int destructNumber = 0; 178 int destructNumber = 0;
180 OwnPtrDeque deque; 179 OwnPtrDeque deque;
181 deque.append(adoptPtr(new DestructCounter(0, &destructNumber))); 180 deque.append(wrapUnique(new DestructCounter(0, &destructNumber)));
182 deque.append(adoptPtr(new DestructCounter(1, &destructNumber))); 181 deque.append(wrapUnique(new DestructCounter(1, &destructNumber)));
183 EXPECT_EQ(2u, deque.size()); 182 EXPECT_EQ(2u, deque.size());
184 183
185 OwnPtr<DestructCounter>& counter0 = deque.first(); 184 std::unique_ptr<DestructCounter>& counter0 = deque.first();
186 EXPECT_EQ(0, counter0->get()); 185 EXPECT_EQ(0, counter0->get());
187 int counter1 = deque.last()->get(); 186 int counter1 = deque.last()->get();
188 EXPECT_EQ(1, counter1); 187 EXPECT_EQ(1, counter1);
189 EXPECT_EQ(0, destructNumber); 188 EXPECT_EQ(0, destructNumber);
190 189
191 size_t index = 0; 190 size_t index = 0;
192 for (auto iter = deque.begin(); iter != deque.end(); ++iter) { 191 for (auto iter = deque.begin(); iter != deque.end(); ++iter) {
193 OwnPtr<DestructCounter>& refCounter = *iter; 192 std::unique_ptr<DestructCounter>& refCounter = *iter;
194 EXPECT_EQ(index, static_cast<size_t>(refCounter->get())); 193 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()));
195 EXPECT_EQ(index, static_cast<size_t>((*refCounter).get())); 194 EXPECT_EQ(index, static_cast<size_t>((*refCounter).get()));
196 index++; 195 index++;
197 } 196 }
198 EXPECT_EQ(0, destructNumber); 197 EXPECT_EQ(0, destructNumber);
199 198
200 auto it = deque.begin(); 199 auto it = deque.begin();
201 for (index = 0; index < deque.size(); ++index) { 200 for (index = 0; index < deque.size(); ++index) {
202 OwnPtr<DestructCounter>& refCounter = *it; 201 std::unique_ptr<DestructCounter>& refCounter = *it;
203 EXPECT_EQ(index, static_cast<size_t>(refCounter->get())); 202 EXPECT_EQ(index, static_cast<size_t>(refCounter->get()));
204 index++; 203 index++;
205 ++it; 204 ++it;
206 } 205 }
207 EXPECT_EQ(0, destructNumber); 206 EXPECT_EQ(0, destructNumber);
208 207
209 EXPECT_EQ(0, deque.first()->get()); 208 EXPECT_EQ(0, deque.first()->get());
210 deque.removeFirst(); 209 deque.removeFirst();
211 EXPECT_EQ(1, deque.first()->get()); 210 EXPECT_EQ(1, deque.first()->get());
212 EXPECT_EQ(1u, deque.size()); 211 EXPECT_EQ(1u, deque.size());
213 EXPECT_EQ(1, destructNumber); 212 EXPECT_EQ(1, destructNumber);
214 213
215 OwnPtr<DestructCounter> ownCounter1 = std::move(deque.first()); 214 std::unique_ptr<DestructCounter> ownCounter1 = std::move(deque.first());
216 deque.removeFirst(); 215 deque.removeFirst();
217 EXPECT_EQ(counter1, ownCounter1->get()); 216 EXPECT_EQ(counter1, ownCounter1->get());
218 EXPECT_EQ(0u, deque.size()); 217 EXPECT_EQ(0u, deque.size());
219 EXPECT_EQ(1, destructNumber); 218 EXPECT_EQ(1, destructNumber);
220 219
221 ownCounter1.reset(); 220 ownCounter1.reset();
222 EXPECT_EQ(2, destructNumber); 221 EXPECT_EQ(2, destructNumber);
223 222
224 size_t count = 1025; 223 size_t count = 1025;
225 destructNumber = 0; 224 destructNumber = 0;
226 for (size_t i = 0; i < count; ++i) 225 for (size_t i = 0; i < count; ++i)
227 deque.prepend(adoptPtr(new DestructCounter(i, &destructNumber))); 226 deque.prepend(wrapUnique(new DestructCounter(i, &destructNumber)));
228 227
229 // Deque relocation must not destruct OwnPtr element. 228 // Deque relocation must not destruct std::unique_ptr element.
230 EXPECT_EQ(0, destructNumber); 229 EXPECT_EQ(0, destructNumber);
231 EXPECT_EQ(count, deque.size()); 230 EXPECT_EQ(count, deque.size());
232 231
233 OwnPtrDeque copyDeque; 232 OwnPtrDeque copyDeque;
234 deque.swap(copyDeque); 233 deque.swap(copyDeque);
235 EXPECT_EQ(0, destructNumber); 234 EXPECT_EQ(0, destructNumber);
236 EXPECT_EQ(count, copyDeque.size()); 235 EXPECT_EQ(count, copyDeque.size());
237 EXPECT_EQ(0u, deque.size()); 236 EXPECT_EQ(0u, deque.size());
238 237
239 copyDeque.clear(); 238 copyDeque.clear();
240 EXPECT_EQ(count, static_cast<size_t>(destructNumber)); 239 EXPECT_EQ(count, static_cast<size_t>(destructNumber));
241 } 240 }
242 241
243 TEST(DequeTest, OwnPtr) 242 TEST(DequeTest, OwnPtr)
244 { 243 {
245 ownPtrTest<Deque<OwnPtr<DestructCounter>>>(); 244 ownPtrTest<Deque<std::unique_ptr<DestructCounter>>>();
246 ownPtrTest<Deque<OwnPtr<DestructCounter>, 2>>(); 245 ownPtrTest<Deque<std::unique_ptr<DestructCounter>, 2>>();
247 } 246 }
248 247
249 class MoveOnly { 248 class MoveOnly {
250 public: 249 public:
251 explicit MoveOnly(int i = 0) 250 explicit MoveOnly(int i = 0)
252 : m_i(i) 251 : m_i(i)
253 { } 252 { }
254 253
255 MoveOnly(MoveOnly&& other) 254 MoveOnly(MoveOnly&& other)
256 : m_i(other.m_i) 255 : m_i(other.m_i)
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 EXPECT_EQ(0, counter); 601 EXPECT_EQ(0, counter);
603 602
604 counter = 0; 603 counter = 0;
605 Deque<CountCopy, 1> yetAnother(std::move(deque)); // Move construction. 604 Deque<CountCopy, 1> yetAnother(std::move(deque)); // Move construction.
606 EXPECT_EQ(0, counter); 605 EXPECT_EQ(0, counter);
607 } 606 }
608 607
609 } // anonymous namespace 608 } // anonymous namespace
610 609
611 } // namespace WTF 610 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/DataLog.cpp ('k') | third_party/WebKit/Source/wtf/FilePrintStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698