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. 4 5 #include "cc/base/scoped_ptr_vector.h" 6 #include "testing/gmock/include/gmock/gmock.h" 7 8 namespace cc { 9 namespace { 10 11 class Data { 12 public: 13 static scoped_ptr<Data> Create(int i) { return make_scoped_ptr(new Data(i)); } 14 int data() const { return data_; } 15 private: 16 explicit Data(int i) : data_(i) {} 17 int data_; 18 }; 19 20 TEST(ScopedPtrVectorTest, PushBack) { 21 ScopedPtrVector<Data> v; 22 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)); 29 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()); 36 } 37 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)); 44 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)); 49 50 ScopedPtrVector<Data>::iterator it = v.begin(); 51 ++it; 52 ++it; 53 EXPECT_EQ(6, (*it)->data()); 54 55 v.insert_and_take(it, v2); 56 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()); 64 65 EXPECT_EQ(3u, v2.size()); 66 EXPECT_EQ(NULL, v2[0]); 67 EXPECT_EQ(NULL, v2[1]); 68 EXPECT_EQ(NULL, v2[2]); 69 } 70 71 } // namespace 72 } // namespace cc 73