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

Side by Side Diff: base/memory/scoped_ptr_unittest.cc

Issue 1479473002: base: Use std::move() instead of Pass() for real movable types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: basepass: missing-include Created 5 years 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
« no previous file with comments | « base/memory/scoped_ptr.h ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 private: 78 private:
79 static int g_new_count; 79 static int g_new_count;
80 static int g_delete_count; 80 static int g_delete_count;
81 }; 81 };
82 82
83 int OverloadedNewAndDelete::g_new_count = 0; 83 int OverloadedNewAndDelete::g_new_count = 0;
84 int OverloadedNewAndDelete::g_delete_count = 0; 84 int OverloadedNewAndDelete::g_delete_count = 0;
85 85
86 scoped_ptr<ConDecLogger> PassThru(scoped_ptr<ConDecLogger> logger) { 86 scoped_ptr<ConDecLogger> PassThru(scoped_ptr<ConDecLogger> logger) {
87 return logger.Pass(); 87 return logger;
88 } 88 }
89 89
90 void GrabAndDrop(scoped_ptr<ConDecLogger> logger) { 90 void GrabAndDrop(scoped_ptr<ConDecLogger> logger) {
91 } 91 }
92 92
93 // Do not delete this function! It's existence is to test that you can 93 // Do not delete this function! It's existence is to test that you can
94 // return a temporarily constructed version of the scoper. 94 // return a temporarily constructed version of the scoper.
95 scoped_ptr<ConDecLogger> TestReturnOfType(int* constructed) { 95 scoped_ptr<ConDecLogger> TestReturnOfType(int* constructed) {
96 return scoped_ptr<ConDecLogger>(new ConDecLogger(constructed)); 96 return scoped_ptr<ConDecLogger>(new ConDecLogger(constructed));
97 } 97 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 TEST(ScopedPtrTest, ScopedPtrDepthSubtyping) { 172 TEST(ScopedPtrTest, ScopedPtrDepthSubtyping) {
173 int constructed = 0; 173 int constructed = 0;
174 174
175 // Test construction from a scoped_ptr to a derived class. 175 // Test construction from a scoped_ptr to a derived class.
176 { 176 {
177 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); 177 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
178 EXPECT_EQ(1, constructed); 178 EXPECT_EQ(1, constructed);
179 EXPECT_TRUE(scoper.get()); 179 EXPECT_TRUE(scoper.get());
180 180
181 scoped_ptr<ConDecLoggerParent> scoper_parent(scoper.Pass()); 181 scoped_ptr<ConDecLoggerParent> scoper_parent(std::move(scoper));
182 EXPECT_EQ(1, constructed); 182 EXPECT_EQ(1, constructed);
183 EXPECT_TRUE(scoper_parent.get()); 183 EXPECT_TRUE(scoper_parent.get());
184 EXPECT_FALSE(scoper.get()); 184 EXPECT_FALSE(scoper.get());
185 185
186 EXPECT_EQ(10, scoper_parent->SomeMeth(10)); 186 EXPECT_EQ(10, scoper_parent->SomeMeth(10));
187 EXPECT_EQ(10, scoper_parent.get()->SomeMeth(10)); 187 EXPECT_EQ(10, scoper_parent.get()->SomeMeth(10));
188 EXPECT_EQ(10, (*scoper_parent).SomeMeth(10)); 188 EXPECT_EQ(10, (*scoper_parent).SomeMeth(10));
189 } 189 }
190 EXPECT_EQ(0, constructed); 190 EXPECT_EQ(0, constructed);
191 191
192 // Test assignment from a scoped_ptr to a derived class. 192 // Test assignment from a scoped_ptr to a derived class.
193 { 193 {
194 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); 194 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
195 EXPECT_EQ(1, constructed); 195 EXPECT_EQ(1, constructed);
196 EXPECT_TRUE(scoper.get()); 196 EXPECT_TRUE(scoper.get());
197 197
198 scoped_ptr<ConDecLoggerParent> scoper_parent; 198 scoped_ptr<ConDecLoggerParent> scoper_parent;
199 scoper_parent = scoper.Pass(); 199 scoper_parent = std::move(scoper);
200 EXPECT_EQ(1, constructed); 200 EXPECT_EQ(1, constructed);
201 EXPECT_TRUE(scoper_parent.get()); 201 EXPECT_TRUE(scoper_parent.get());
202 EXPECT_FALSE(scoper.get()); 202 EXPECT_FALSE(scoper.get());
203 } 203 }
204 EXPECT_EQ(0, constructed); 204 EXPECT_EQ(0, constructed);
205 205
206 // Test construction of a scoped_ptr with an additional const annotation. 206 // Test construction of a scoped_ptr with an additional const annotation.
207 { 207 {
208 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); 208 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
209 EXPECT_EQ(1, constructed); 209 EXPECT_EQ(1, constructed);
210 EXPECT_TRUE(scoper.get()); 210 EXPECT_TRUE(scoper.get());
211 211
212 scoped_ptr<const ConDecLogger> scoper_const(scoper.Pass()); 212 scoped_ptr<const ConDecLogger> scoper_const(std::move(scoper));
213 EXPECT_EQ(1, constructed); 213 EXPECT_EQ(1, constructed);
214 EXPECT_TRUE(scoper_const.get()); 214 EXPECT_TRUE(scoper_const.get());
215 EXPECT_FALSE(scoper.get()); 215 EXPECT_FALSE(scoper.get());
216 216
217 EXPECT_EQ(10, scoper_const->SomeMeth(10)); 217 EXPECT_EQ(10, scoper_const->SomeMeth(10));
218 EXPECT_EQ(10, scoper_const.get()->SomeMeth(10)); 218 EXPECT_EQ(10, scoper_const.get()->SomeMeth(10));
219 EXPECT_EQ(10, (*scoper_const).SomeMeth(10)); 219 EXPECT_EQ(10, (*scoper_const).SomeMeth(10));
220 } 220 }
221 EXPECT_EQ(0, constructed); 221 EXPECT_EQ(0, constructed);
222 222
223 // Test assignment to a scoped_ptr with an additional const annotation. 223 // Test assignment to a scoped_ptr with an additional const annotation.
224 { 224 {
225 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed)); 225 scoped_ptr<ConDecLogger> scoper(new ConDecLogger(&constructed));
226 EXPECT_EQ(1, constructed); 226 EXPECT_EQ(1, constructed);
227 EXPECT_TRUE(scoper.get()); 227 EXPECT_TRUE(scoper.get());
228 228
229 scoped_ptr<const ConDecLogger> scoper_const; 229 scoped_ptr<const ConDecLogger> scoper_const;
230 scoper_const = scoper.Pass(); 230 scoper_const = std::move(scoper);
231 EXPECT_EQ(1, constructed); 231 EXPECT_EQ(1, constructed);
232 EXPECT_TRUE(scoper_const.get()); 232 EXPECT_TRUE(scoper_const.get());
233 EXPECT_FALSE(scoper.get()); 233 EXPECT_FALSE(scoper.get());
234 } 234 }
235 EXPECT_EQ(0, constructed); 235 EXPECT_EQ(0, constructed);
236 236
237 // Test assignment to a scoped_ptr deleter of parent type. 237 // Test assignment to a scoped_ptr deleter of parent type.
238 { 238 {
239 // Custom deleters never touch these value. 239 // Custom deleters never touch these value.
240 double dummy_value, dummy_value2; 240 double dummy_value, dummy_value2;
241 int deletes = 0; 241 int deletes = 0;
242 int alternate_deletes = 0; 242 int alternate_deletes = 0;
243 scoped_ptr<double, CountingDeleter> scoper(&dummy_value, 243 scoped_ptr<double, CountingDeleter> scoper(&dummy_value,
244 CountingDeleter(&deletes)); 244 CountingDeleter(&deletes));
245 scoped_ptr<double, CountingDeleterChild> scoper_child( 245 scoped_ptr<double, CountingDeleterChild> scoper_child(
246 &dummy_value2, CountingDeleterChild(&alternate_deletes)); 246 &dummy_value2, CountingDeleterChild(&alternate_deletes));
247 247
248 EXPECT_TRUE(scoper); 248 EXPECT_TRUE(scoper);
249 EXPECT_TRUE(scoper_child); 249 EXPECT_TRUE(scoper_child);
250 EXPECT_EQ(0, deletes); 250 EXPECT_EQ(0, deletes);
251 EXPECT_EQ(0, alternate_deletes); 251 EXPECT_EQ(0, alternate_deletes);
252 252
253 // Test this compiles and correctly overwrites the deleter state. 253 // Test this compiles and correctly overwrites the deleter state.
254 scoper = scoper_child.Pass(); 254 scoper = std::move(scoper_child);
255 EXPECT_TRUE(scoper); 255 EXPECT_TRUE(scoper);
256 EXPECT_FALSE(scoper_child); 256 EXPECT_FALSE(scoper_child);
257 EXPECT_EQ(1, deletes); 257 EXPECT_EQ(1, deletes);
258 EXPECT_EQ(0, alternate_deletes); 258 EXPECT_EQ(0, alternate_deletes);
259 259
260 scoper.reset(); 260 scoper.reset();
261 EXPECT_FALSE(scoper); 261 EXPECT_FALSE(scoper);
262 EXPECT_FALSE(scoper_child); 262 EXPECT_FALSE(scoper_child);
263 EXPECT_EQ(1, deletes); 263 EXPECT_EQ(1, deletes);
264 EXPECT_EQ(1, alternate_deletes); 264 EXPECT_EQ(1, alternate_deletes);
265 265
266 scoper_child.reset(&dummy_value); 266 scoper_child.reset(&dummy_value);
267 EXPECT_TRUE(scoper_child); 267 EXPECT_TRUE(scoper_child);
268 EXPECT_EQ(1, deletes); 268 EXPECT_EQ(1, deletes);
269 EXPECT_EQ(1, alternate_deletes); 269 EXPECT_EQ(1, alternate_deletes);
270 scoped_ptr<double, CountingDeleter> scoper_construct(scoper_child.Pass()); 270 scoped_ptr<double, CountingDeleter> scoper_construct(
271 std::move(scoper_child));
271 EXPECT_TRUE(scoper_construct); 272 EXPECT_TRUE(scoper_construct);
272 EXPECT_FALSE(scoper_child); 273 EXPECT_FALSE(scoper_child);
273 EXPECT_EQ(1, deletes); 274 EXPECT_EQ(1, deletes);
274 EXPECT_EQ(1, alternate_deletes); 275 EXPECT_EQ(1, alternate_deletes);
275 276
276 scoper_construct.reset(); 277 scoper_construct.reset();
277 EXPECT_EQ(1, deletes); 278 EXPECT_EQ(1, deletes);
278 EXPECT_EQ(2, alternate_deletes); 279 EXPECT_EQ(2, alternate_deletes);
279 } 280 }
280 } 281 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 357
357 { 358 {
358 ConDecLogger* loggers = new ConDecLogger[kNumLoggers]; 359 ConDecLogger* loggers = new ConDecLogger[kNumLoggers];
359 scoped_ptr<ConDecLogger[]> scoper(loggers); 360 scoped_ptr<ConDecLogger[]> scoper(loggers);
360 EXPECT_TRUE(scoper); 361 EXPECT_TRUE(scoper);
361 for (int i = 0; i < kNumLoggers; ++i) { 362 for (int i = 0; i < kNumLoggers; ++i) {
362 scoper[i].SetPtr(&constructed); 363 scoper[i].SetPtr(&constructed);
363 } 364 }
364 EXPECT_EQ(kNumLoggers, constructed); 365 EXPECT_EQ(kNumLoggers, constructed);
365 366
366 // Test Pass() with constructor; 367 // Test moving with constructor;
367 scoped_ptr<ConDecLogger[]> scoper2(scoper.Pass()); 368 scoped_ptr<ConDecLogger[]> scoper2(std::move(scoper));
368 EXPECT_EQ(kNumLoggers, constructed); 369 EXPECT_EQ(kNumLoggers, constructed);
369 370
370 // Test Pass() with assignment; 371 // Test moving with assignment;
371 scoped_ptr<ConDecLogger[]> scoper3; 372 scoped_ptr<ConDecLogger[]> scoper3;
372 scoper3 = scoper2.Pass(); 373 scoper3 = std::move(scoper2);
373 EXPECT_EQ(kNumLoggers, constructed); 374 EXPECT_EQ(kNumLoggers, constructed);
374 EXPECT_FALSE(scoper); 375 EXPECT_FALSE(scoper);
375 EXPECT_FALSE(scoper2); 376 EXPECT_FALSE(scoper2);
376 EXPECT_TRUE(scoper3); 377 EXPECT_TRUE(scoper3);
377 } 378 }
378 EXPECT_EQ(0, constructed); 379 EXPECT_EQ(0, constructed);
379 } 380 }
380 381
381 TEST(ScopedPtrTest, PassBehavior) { 382 TEST(ScopedPtrTest, MoveBehavior) {
382 int constructed = 0; 383 int constructed = 0;
383 { 384 {
384 ConDecLogger* logger = new ConDecLogger(&constructed); 385 ConDecLogger* logger = new ConDecLogger(&constructed);
385 scoped_ptr<ConDecLogger> scoper(logger); 386 scoped_ptr<ConDecLogger> scoper(logger);
386 EXPECT_EQ(1, constructed); 387 EXPECT_EQ(1, constructed);
387 388
388 // Test Pass() with constructor; 389 // Test moving with constructor;
389 scoped_ptr<ConDecLogger> scoper2(scoper.Pass()); 390 scoped_ptr<ConDecLogger> scoper2(std::move(scoper));
390 EXPECT_EQ(1, constructed); 391 EXPECT_EQ(1, constructed);
391 392
392 // Test Pass() with assignment; 393 // Test moving with assignment;
393 scoped_ptr<ConDecLogger> scoper3; 394 scoped_ptr<ConDecLogger> scoper3;
394 scoper3 = scoper2.Pass(); 395 scoper3 = std::move(scoper2);
395 EXPECT_EQ(1, constructed); 396 EXPECT_EQ(1, constructed);
396 EXPECT_FALSE(scoper.get()); 397 EXPECT_FALSE(scoper.get());
397 EXPECT_FALSE(scoper2.get()); 398 EXPECT_FALSE(scoper2.get());
398 EXPECT_TRUE(scoper3.get()); 399 EXPECT_TRUE(scoper3.get());
399 } 400 }
400 401
401 // Test uncaught Pass() does not have side effects. 402 // Test uncaught Pass() does not have side effects, because Pass()
403 // is implemented by std::move().
404 // TODO(danakj): Remove this test case when we remove Pass().
402 { 405 {
403 ConDecLogger* logger = new ConDecLogger(&constructed); 406 ConDecLogger* logger = new ConDecLogger(&constructed);
404 scoped_ptr<ConDecLogger> scoper(logger); 407 scoped_ptr<ConDecLogger> scoper(logger);
405 EXPECT_EQ(1, constructed); 408 EXPECT_EQ(1, constructed);
406 409
407 // Should auto-destruct logger by end of scope. 410 // Should auto-destruct logger by end of scope.
408 scoped_ptr<ConDecLogger>&& rvalue = scoper.Pass(); 411 scoped_ptr<ConDecLogger>&& rvalue = scoper.Pass();
409 // The Pass() function mimics std::move(), which does not have side-effects. 412 // The Pass() function mimics std::move(), which does not have side-effects.
410 EXPECT_TRUE(scoper.get()); 413 EXPECT_TRUE(scoper.get());
411 EXPECT_TRUE(rvalue); 414 EXPECT_TRUE(rvalue);
412 } 415 }
413 EXPECT_EQ(0, constructed); 416 EXPECT_EQ(0, constructed);
414 417
415 // Test that passing to function which does nothing does not leak. 418 // Test that passing to function which does nothing does not leak.
416 { 419 {
417 ConDecLogger* logger = new ConDecLogger(&constructed); 420 ConDecLogger* logger = new ConDecLogger(&constructed);
418 scoped_ptr<ConDecLogger> scoper(logger); 421 scoped_ptr<ConDecLogger> scoper(logger);
419 EXPECT_EQ(1, constructed); 422 EXPECT_EQ(1, constructed);
420 423
421 // Should auto-destruct logger by end of scope. 424 // Should auto-destruct logger by end of scope.
422 GrabAndDrop(scoper.Pass()); 425 GrabAndDrop(std::move(scoper));
423 EXPECT_FALSE(scoper.get()); 426 EXPECT_FALSE(scoper.get());
424 } 427 }
425 EXPECT_EQ(0, constructed); 428 EXPECT_EQ(0, constructed);
426 } 429 }
427 430
428 TEST(ScopedPtrTest, ReturnTypeBehavior) { 431 TEST(ScopedPtrTest, ReturnTypeBehavior) {
429 int constructed = 0; 432 int constructed = 0;
430 433
431 // Test that we can return a scoped_ptr. 434 // Test that we can return a scoped_ptr.
432 { 435 {
433 ConDecLogger* logger = new ConDecLogger(&constructed); 436 ConDecLogger* logger = new ConDecLogger(&constructed);
434 scoped_ptr<ConDecLogger> scoper(logger); 437 scoped_ptr<ConDecLogger> scoper(logger);
435 EXPECT_EQ(1, constructed); 438 EXPECT_EQ(1, constructed);
436 439
437 PassThru(scoper.Pass()); 440 PassThru(std::move(scoper));
438 EXPECT_FALSE(scoper.get()); 441 EXPECT_FALSE(scoper.get());
439 } 442 }
440 EXPECT_EQ(0, constructed); 443 EXPECT_EQ(0, constructed);
441 444
442 // Test uncaught return type not leak. 445 // Test uncaught return type not leak.
443 { 446 {
444 ConDecLogger* logger = new ConDecLogger(&constructed); 447 ConDecLogger* logger = new ConDecLogger(&constructed);
445 scoped_ptr<ConDecLogger> scoper(logger); 448 scoped_ptr<ConDecLogger> scoper(logger);
446 EXPECT_EQ(1, constructed); 449 EXPECT_EQ(1, constructed);
447 450
448 // Should auto-destruct logger by end of scope. 451 // Should auto-destruct logger by end of scope.
449 PassThru(scoper.Pass()); 452 PassThru(std::move(scoper));
450 EXPECT_FALSE(scoper.get()); 453 EXPECT_FALSE(scoper.get());
451 } 454 }
452 EXPECT_EQ(0, constructed); 455 EXPECT_EQ(0, constructed);
453 456
454 // Call TestReturnOfType() so the compiler doesn't warn for an unused 457 // Call TestReturnOfType() so the compiler doesn't warn for an unused
455 // function. 458 // function.
456 { 459 {
457 TestReturnOfType(&constructed); 460 TestReturnOfType(&constructed);
458 } 461 }
459 EXPECT_EQ(0, constructed); 462 EXPECT_EQ(0, constructed);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 CountingDeleter(&deletes)); 533 CountingDeleter(&deletes));
531 scoped_ptr<double, CountingDeleter> scoper2( 534 scoped_ptr<double, CountingDeleter> scoper2(
532 &dummy_value2, 535 &dummy_value2,
533 CountingDeleter(&alternate_deletes)); 536 CountingDeleter(&alternate_deletes));
534 EXPECT_EQ(0, deletes); 537 EXPECT_EQ(0, deletes);
535 EXPECT_EQ(0, alternate_deletes); 538 EXPECT_EQ(0, alternate_deletes);
536 539
537 // Pass the second deleter through a constructor and an operator=. Then 540 // Pass the second deleter through a constructor and an operator=. Then
538 // reinitialize the empty scopers to ensure that each one is deleting 541 // reinitialize the empty scopers to ensure that each one is deleting
539 // properly. 542 // properly.
540 scoped_ptr<double, CountingDeleter> scoper3(scoper2.Pass()); 543 scoped_ptr<double, CountingDeleter> scoper3(std::move(scoper2));
541 scoper = scoper3.Pass(); 544 scoper = std::move(scoper3);
542 EXPECT_EQ(1, deletes); 545 EXPECT_EQ(1, deletes);
543 546
544 scoper2.reset(&dummy_value2); 547 scoper2.reset(&dummy_value2);
545 scoper3.reset(&dummy_value2); 548 scoper3.reset(&dummy_value2);
546 EXPECT_EQ(0, alternate_deletes); 549 EXPECT_EQ(0, alternate_deletes);
547 550
548 } 551 }
549 EXPECT_EQ(1, deletes); 552 EXPECT_EQ(1, deletes);
550 EXPECT_EQ(3, alternate_deletes); 553 EXPECT_EQ(3, alternate_deletes);
551 554
(...skipping 16 matching lines...) Expand all
568 571
569 scoper2.swap(scoper1); 572 scoper2.swap(scoper1);
570 EXPECT_EQ(&dummy_value, scoper2.get()); 573 EXPECT_EQ(&dummy_value, scoper2.get());
571 EXPECT_FALSE(scoper1.get()); 574 EXPECT_FALSE(scoper1.get());
572 EXPECT_FALSE(scoper1.get() == scoper2.get()); 575 EXPECT_FALSE(scoper1.get() == scoper2.get());
573 EXPECT_TRUE(scoper1.get() != scoper2.get()); 576 EXPECT_TRUE(scoper1.get() != scoper2.get());
574 } 577 }
575 } 578 }
576 579
577 // Sanity check test for overloaded new and delete operators. Does not do full 580 // Sanity check test for overloaded new and delete operators. Does not do full
578 // coverage of reset/release/Pass() operations as that is redundant with the 581 // coverage of reset/release/move operations as that is redundant with the
579 // above. 582 // above.
580 TEST(ScopedPtrTest, OverloadedNewAndDelete) { 583 TEST(ScopedPtrTest, OverloadedNewAndDelete) {
581 { 584 {
582 OverloadedNewAndDelete::ResetCounters(); 585 OverloadedNewAndDelete::ResetCounters();
583 scoped_ptr<OverloadedNewAndDelete> scoper(new OverloadedNewAndDelete()); 586 scoped_ptr<OverloadedNewAndDelete> scoper(new OverloadedNewAndDelete());
584 EXPECT_TRUE(scoper.get()); 587 EXPECT_TRUE(scoper.get());
585 588
586 scoped_ptr<OverloadedNewAndDelete> scoper2(scoper.Pass()); 589 scoped_ptr<OverloadedNewAndDelete> scoper2(std::move(scoper));
587 } 590 }
588 EXPECT_EQ(1, OverloadedNewAndDelete::delete_count()); 591 EXPECT_EQ(1, OverloadedNewAndDelete::delete_count());
589 EXPECT_EQ(1, OverloadedNewAndDelete::new_count()); 592 EXPECT_EQ(1, OverloadedNewAndDelete::new_count());
590 } 593 }
591 594
592 scoped_ptr<int> NullIntReturn() { 595 scoped_ptr<int> NullIntReturn() {
593 return nullptr; 596 return nullptr;
594 } 597 }
595 598
596 TEST(ScopedPtrTest, Nullptr) { 599 TEST(ScopedPtrTest, Nullptr) {
(...skipping 28 matching lines...) Expand all
625 class Sub : public Super {}; 628 class Sub : public Super {};
626 629
627 scoped_ptr<Sub> SubClassReturn() { 630 scoped_ptr<Sub> SubClassReturn() {
628 return make_scoped_ptr(new Sub); 631 return make_scoped_ptr(new Sub);
629 } 632 }
630 633
631 TEST(ScopedPtrTest, Conversion) { 634 TEST(ScopedPtrTest, Conversion) {
632 scoped_ptr<Sub> sub1(new Sub); 635 scoped_ptr<Sub> sub1(new Sub);
633 scoped_ptr<Sub> sub2(new Sub); 636 scoped_ptr<Sub> sub2(new Sub);
634 637
635 // Upcast with Pass() works. 638 // Upcast with move works.
636 scoped_ptr<Super> super1 = sub1.Pass(); 639 scoped_ptr<Super> super1 = std::move(sub1);
637 super1 = sub2.Pass(); 640 super1 = std::move(sub2);
638 641
639 // Upcast with an rvalue works. 642 // Upcast with an rvalue works.
640 scoped_ptr<Super> super2 = SubClassReturn(); 643 scoped_ptr<Super> super2 = SubClassReturn();
641 super2 = SubClassReturn(); 644 super2 = SubClassReturn();
642 } 645 }
643 646
644 // Logging a scoped_ptr<T> to an ostream shouldn't convert it to a boolean 647 // Logging a scoped_ptr<T> to an ostream shouldn't convert it to a boolean
645 // value first. 648 // value first.
646 TEST(ScopedPtrTest, LoggingDoesntConvertToBoolean) { 649 TEST(ScopedPtrTest, LoggingDoesntConvertToBoolean) {
647 scoped_ptr<int> x(new int); 650 scoped_ptr<int> x(new int);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 EXPECT_FALSE(p < nullptr); 828 EXPECT_FALSE(p < nullptr);
826 EXPECT_TRUE(nullptr < p); 829 EXPECT_TRUE(nullptr < p);
827 EXPECT_FALSE(pnull < nullptr); 830 EXPECT_FALSE(pnull < nullptr);
828 EXPECT_FALSE(nullptr < pnull); 831 EXPECT_FALSE(nullptr < pnull);
829 832
830 EXPECT_FALSE(p <= nullptr); 833 EXPECT_FALSE(p <= nullptr);
831 EXPECT_TRUE(nullptr <= p); 834 EXPECT_TRUE(nullptr <= p);
832 EXPECT_TRUE(pnull <= nullptr); 835 EXPECT_TRUE(pnull <= nullptr);
833 EXPECT_TRUE(nullptr <= pnull); 836 EXPECT_TRUE(nullptr <= pnull);
834 } 837 }
OLDNEW
« no previous file with comments | « base/memory/scoped_ptr.h ('k') | base/memory/shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698