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

Side by Side Diff: webrtc/base/scopedptrcollection_unittest.cc

Issue 2812553002: Revert of Delete class ScopedPtrCollection. Replaced with vector of unique_ptr. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « webrtc/base/scopedptrcollection.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12
13 #include "webrtc/base/constructormagic.h"
14 #include "webrtc/base/scopedptrcollection.h"
15 #include "webrtc/base/gunit.h"
16
17 namespace rtc {
18
19 namespace {
20
21 class InstanceCounter {
22 public:
23 explicit InstanceCounter(int* num_instances)
24 : num_instances_(num_instances) {
25 ++(*num_instances_);
26 }
27 ~InstanceCounter() {
28 --(*num_instances_);
29 }
30
31 private:
32 int* num_instances_;
33
34 RTC_DISALLOW_COPY_AND_ASSIGN(InstanceCounter);
35 };
36
37 } // namespace
38
39 class ScopedPtrCollectionTest : public testing::Test {
40 protected:
41 ScopedPtrCollectionTest()
42 : num_instances_(0),
43 collection_(new ScopedPtrCollection<InstanceCounter>()) {
44 }
45
46 int num_instances_;
47 std::unique_ptr<ScopedPtrCollection<InstanceCounter> > collection_;
48 };
49
50 TEST_F(ScopedPtrCollectionTest, PushBack) {
51 EXPECT_EQ(0u, collection_->collection().size());
52 EXPECT_EQ(0, num_instances_);
53 const int kNum = 100;
54 for (int i = 0; i < kNum; ++i) {
55 collection_->PushBack(new InstanceCounter(&num_instances_));
56 }
57 EXPECT_EQ(static_cast<size_t>(kNum), collection_->collection().size());
58 EXPECT_EQ(kNum, num_instances_);
59 collection_.reset();
60 EXPECT_EQ(0, num_instances_);
61 }
62
63 TEST_F(ScopedPtrCollectionTest, Remove) {
64 InstanceCounter* ic = new InstanceCounter(&num_instances_);
65 collection_->PushBack(ic);
66 EXPECT_EQ(1u, collection_->collection().size());
67 collection_->Remove(ic);
68 EXPECT_EQ(1, num_instances_);
69 collection_.reset();
70 EXPECT_EQ(1, num_instances_);
71 delete ic;
72 EXPECT_EQ(0, num_instances_);
73 }
74
75
76 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/scopedptrcollection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698