1 // Copyright 2012 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.
5 #include "cc/base/scoped_ptr_vector.h"
6 #include "testing/gmock/include/gmock/gmock.h"
13 static scoped_ptr
<Data
> Create(int i
) { return make_scoped_ptr(new Data(i
)); }
14 int data() const { return data_
; }
16 explicit Data(int i
) : data_(i
) {}
20 TEST(ScopedPtrVectorTest
, PushBack
) {
21 ScopedPtrVector
<Data
> v
;
23 // Insert 5 things into the vector.
24 v
.push_back(Data::Create(1));
25 v
.push_back(Data::Create(2));
26 v
.push_back(Data::Create(3));
27 v
.push_back(Data::Create(4));
28 v
.push_back(Data::Create(5));
30 EXPECT_EQ(5u, v
.size());
31 EXPECT_EQ(1, v
[0]->data());
32 EXPECT_EQ(2, v
[1]->data());
33 EXPECT_EQ(3, v
[2]->data());
34 EXPECT_EQ(4, v
[3]->data());
35 EXPECT_EQ(5, v
[4]->data());
38 TEST(ScopedPtrVectorTest
, InsertAndTake
) {
39 // Insert 3 things into each vector.
40 ScopedPtrVector
<Data
> v
;
41 v
.push_back(Data::Create(1));
42 v
.push_back(Data::Create(2));
43 v
.push_back(Data::Create(6));
45 ScopedPtrVector
<Data
> v2
;
46 v2
.push_back(Data::Create(3));
47 v2
.push_back(Data::Create(4));
48 v2
.push_back(Data::Create(5));
50 ScopedPtrVector
<Data
>::iterator it
= v
.begin();
53 EXPECT_EQ(6, (*it
)->data());
55 v
.insert_and_take(it
, v2
);
57 EXPECT_EQ(6u, v
.size());
58 EXPECT_EQ(1, v
[0]->data());
59 EXPECT_EQ(2, v
[1]->data());
60 EXPECT_EQ(3, v
[2]->data());
61 EXPECT_EQ(4, v
[3]->data());
62 EXPECT_EQ(5, v
[4]->data());
63 EXPECT_EQ(6, v
[5]->data());
65 EXPECT_EQ(3u, v2
.size());
66 EXPECT_EQ(NULL
, v2
[0]);
67 EXPECT_EQ(NULL
, v2
[1]);
68 EXPECT_EQ(NULL
, v2
[2]);