Use expanded heuristics for GPU rasterization on future OS versions
[chromium-blink-merge.git] / cc / base / scoped_ptr_vector_unittest.cc
blob8190b37b83b3b49931f6f45275d6db1d4d474935
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 <set>
7 #include "cc/base/scoped_ptr_vector.h"
8 #include "testing/gmock/include/gmock/gmock.h"
10 namespace cc {
11 namespace {
13 class Data {
14 public:
15 static scoped_ptr<Data> Create(int i) { return make_scoped_ptr(new Data(i)); }
16 int data() const { return data_; }
17 private:
18 explicit Data(int i) : data_(i) {}
19 int data_;
22 class IsOddPredicate {
23 public:
24 bool operator()(const Data* data) { return (data->data() % 2) == 1; }
27 TEST(ScopedPtrVectorTest, PushBack) {
28 ScopedPtrVector<Data> v;
30 // Insert 5 things into the vector.
31 v.push_back(Data::Create(1));
32 v.push_back(Data::Create(2));
33 v.push_back(Data::Create(3));
34 v.push_back(Data::Create(4));
35 v.push_back(Data::Create(5));
37 EXPECT_EQ(5u, v.size());
38 EXPECT_EQ(1, v[0]->data());
39 EXPECT_EQ(2, v[1]->data());
40 EXPECT_EQ(3, v[2]->data());
41 EXPECT_EQ(4, v[3]->data());
42 EXPECT_EQ(5, v[4]->data());
45 TEST(ScopedPtrVectorTest, InsertAndTake) {
46 // Insert 3 things into each vector.
47 ScopedPtrVector<Data> v;
48 v.push_back(Data::Create(1));
49 v.push_back(Data::Create(2));
50 v.push_back(Data::Create(6));
52 ScopedPtrVector<Data> v2;
53 v2.push_back(Data::Create(3));
54 v2.push_back(Data::Create(4));
55 v2.push_back(Data::Create(5));
57 ScopedPtrVector<Data>::iterator it = v.begin();
58 ++it;
59 ++it;
60 EXPECT_EQ(6, (*it)->data());
62 v.insert_and_take(it, v2);
64 EXPECT_EQ(6u, v.size());
65 EXPECT_EQ(1, v[0]->data());
66 EXPECT_EQ(2, v[1]->data());
67 EXPECT_EQ(3, v[2]->data());
68 EXPECT_EQ(4, v[3]->data());
69 EXPECT_EQ(5, v[4]->data());
70 EXPECT_EQ(6, v[5]->data());
72 EXPECT_EQ(3u, v2.size());
73 EXPECT_EQ(NULL, v2[0]);
74 EXPECT_EQ(NULL, v2[1]);
75 EXPECT_EQ(NULL, v2[2]);
78 TEST(ScopedPtrVectorTest, Partition) {
79 ScopedPtrVector<Data> v;
80 v.push_back(Data::Create(1));
81 v.push_back(Data::Create(2));
82 v.push_back(Data::Create(3));
83 v.push_back(Data::Create(4));
84 v.push_back(Data::Create(5));
86 ScopedPtrVector<Data>::iterator it = v.partition(IsOddPredicate());
87 std::set<int> odd_numbers;
88 for (ScopedPtrVector<Data>::iterator second_it = v.begin();
89 second_it != it;
90 ++second_it) {
91 EXPECT_EQ(1, (*second_it)->data() % 2);
92 odd_numbers.insert((*second_it)->data());
94 EXPECT_EQ(3u, odd_numbers.size());
96 std::set<int> even_numbers;
97 for (; it != v.end(); ++it) {
98 EXPECT_EQ(0, (*it)->data() % 2);
99 even_numbers.insert((*it)->data());
101 EXPECT_EQ(2u, even_numbers.size());
104 } // namespace
105 } // namespace cc