ptr_util_unittest.cc 893 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/memory/ptr_util.h"
  5. #include <stddef.h>
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace base {
  8. namespace {
  9. class DeleteCounter {
  10. public:
  11. DeleteCounter() { ++count_; }
  12. ~DeleteCounter() { --count_; }
  13. static size_t count() { return count_; }
  14. private:
  15. static size_t count_;
  16. };
  17. size_t DeleteCounter::count_ = 0;
  18. } // namespace
  19. TEST(PtrUtilTest, WrapUnique) {
  20. EXPECT_EQ(0u, DeleteCounter::count());
  21. DeleteCounter* counter = new DeleteCounter;
  22. EXPECT_EQ(1u, DeleteCounter::count());
  23. std::unique_ptr<DeleteCounter> owned_counter = WrapUnique(counter);
  24. EXPECT_EQ(1u, DeleteCounter::count());
  25. owned_counter.reset();
  26. EXPECT_EQ(0u, DeleteCounter::count());
  27. }
  28. } // namespace base