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

Side by Side Diff: content/browser/indexed_db/list_set_unittest.cc

Issue 15659013: Revert "Migrate the IndexedDB backend from Blink to Chromium" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/indexed_db/list_set.h ('k') | content/browser/indexed_db/webidbcursor_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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 "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "content/browser/indexed_db/list_set.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace content {
11
12 TEST(ListSetTest, ListSetIterator) {
13 list_set<int> set;
14 for (int i = 3; i > 0; --i)
15 set.insert(i);
16
17 list_set<int>::iterator it = set.begin();
18 EXPECT_EQ(3, *it);
19 ++it;
20 EXPECT_EQ(2, *it);
21 it++;
22 EXPECT_EQ(1, *it);
23 --it;
24 EXPECT_EQ(2, *it);
25 it--;
26 EXPECT_EQ(3, *it);
27 ++it;
28 EXPECT_EQ(2, *it);
29 it++;
30 EXPECT_EQ(1, *it);
31 ++it;
32 EXPECT_EQ(set.end(), it);
33 }
34
35 TEST(ListSetTest, ListSetConstIterator) {
36 list_set<int> set;
37 for (int i = 5; i > 0; --i)
38 set.insert(i);
39
40 const list_set<int>& ref = set;
41
42 list_set<int>::const_iterator it = ref.begin();
43 for (int i = 5; i > 0; --i) {
44 EXPECT_EQ(i, *it);
45 ++it;
46 }
47 EXPECT_EQ(ref.end(), it);
48 }
49
50 TEST(ListSetTest, ListSetPrimitive) {
51 list_set<int> set;
52 EXPECT_TRUE(set.empty());
53 EXPECT_EQ(static_cast<size_t>(0), set.size());
54 {
55 list_set<int>::iterator it = set.begin();
56 EXPECT_EQ(set.end(), it);
57 }
58
59 for (int i = 5; i > 0; --i)
60 set.insert(i);
61 EXPECT_EQ(static_cast<size_t>(5), set.size());
62 EXPECT_FALSE(set.empty());
63
64 set.erase(3);
65 EXPECT_EQ(static_cast<size_t>(4), set.size());
66
67 EXPECT_TRUE(set.has(2));
68 set.erase(2);
69 EXPECT_FALSE(set.has(2));
70 EXPECT_EQ(static_cast<size_t>(3), set.size());
71
72 {
73 list_set<int>::iterator it = set.begin();
74 EXPECT_EQ(5, *it);
75 ++it;
76 EXPECT_EQ(4, *it);
77 ++it;
78 EXPECT_EQ(1, *it);
79 ++it;
80 EXPECT_EQ(set.end(), it);
81 }
82
83 set.erase(1);
84 set.erase(4);
85 set.erase(5);
86
87 EXPECT_EQ(static_cast<size_t>(0), set.size());
88 EXPECT_TRUE(set.empty());
89 {
90 list_set<int>::iterator it = set.begin();
91 EXPECT_EQ(set.end(), it);
92 }
93 }
94
95 template <typename T> class Wrapped {
96 public:
97 Wrapped(const T& value) : value_(value) {}
98 Wrapped(const Wrapped<T>& other) : value_(other.value_) {}
99 Wrapped& operator=(const Wrapped<T>& rhs) {
100 value_ = rhs.value_;
101 return *this;
102 }
103 int value() const { return value_; }
104 bool operator<(const Wrapped<T>& rhs) const { return value_ < rhs.value_; }
105 bool operator==(const Wrapped<T>& rhs) const { return value_ == rhs.value_; }
106
107 private:
108 T value_;
109 };
110
111 TEST(ListSetTest, ListSetObject) {
112 list_set<Wrapped<int> > set;
113 EXPECT_EQ(static_cast<size_t>(0), set.size());
114 {
115 list_set<Wrapped<int> >::iterator it = set.begin();
116 EXPECT_EQ(set.end(), it);
117 }
118
119 set.insert(Wrapped<int>(0));
120 set.insert(Wrapped<int>(1));
121 set.insert(Wrapped<int>(2));
122
123 EXPECT_EQ(static_cast<size_t>(3), set.size());
124
125 {
126 list_set<Wrapped<int> >::iterator it = set.begin();
127 EXPECT_EQ(0, it->value());
128 ++it;
129 EXPECT_EQ(1, it->value());
130 ++it;
131 EXPECT_EQ(2, it->value());
132 ++it;
133 EXPECT_EQ(set.end(), it);
134 }
135
136 set.erase(Wrapped<int>(0));
137 set.erase(Wrapped<int>(1));
138 set.erase(Wrapped<int>(2));
139
140 EXPECT_EQ(static_cast<size_t>(0), set.size());
141 {
142 list_set<Wrapped<int> >::iterator it = set.begin();
143 EXPECT_EQ(set.end(), it);
144 }
145 }
146
147 TEST(ListSetTest, ListSetPointer) {
148 scoped_ptr<Wrapped<int> > w0(new Wrapped<int>(0));
149 scoped_ptr<Wrapped<int> > w1(new Wrapped<int>(1));
150 scoped_ptr<Wrapped<int> > w2(new Wrapped<int>(2));
151
152 list_set<Wrapped<int>*> set;
153 EXPECT_EQ(static_cast<size_t>(0), set.size());
154 {
155 list_set<Wrapped<int>*>::iterator it = set.begin();
156 EXPECT_EQ(set.end(), it);
157 }
158
159 set.insert(w0.get());
160 set.insert(w1.get());
161 set.insert(w2.get());
162
163 EXPECT_EQ(static_cast<size_t>(3), set.size());
164
165 {
166 list_set<Wrapped<int>*>::iterator it = set.begin();
167 EXPECT_EQ(0, (*it)->value());
168 ++it;
169 EXPECT_EQ(1, (*it)->value());
170 ++it;
171 EXPECT_EQ(2, (*it)->value());
172 ++it;
173 EXPECT_EQ(set.end(), it);
174 }
175
176 set.erase(w0.get());
177 set.erase(w1.get());
178 set.erase(w2.get());
179
180 EXPECT_EQ(static_cast<size_t>(0), set.size());
181 {
182 list_set<Wrapped<int>*>::iterator it = set.begin();
183 EXPECT_EQ(set.end(), it);
184 }
185 }
186
187 template <typename T>
188 class RefCounted : public base::RefCounted<RefCounted<T> > {
189 public:
190 RefCounted(const T& value) : value_(value) {}
191 T value() { return value_; }
192
193 private:
194 virtual ~RefCounted() {}
195 friend class base::RefCounted<RefCounted<T> >;
196 T value_;
197 };
198
199 TEST(ListSetTest, ListSetRefCounted) {
200 list_set<scoped_refptr<RefCounted<int> > > set;
201 EXPECT_EQ(static_cast<size_t>(0), set.size());
202 {
203 list_set<scoped_refptr<RefCounted<int> > >::iterator it = set.begin();
204 EXPECT_EQ(set.end(), it);
205 }
206
207 scoped_refptr<RefCounted<int> > r0(new RefCounted<int>(0));
208 scoped_refptr<RefCounted<int> > r1(new RefCounted<int>(1));
209 scoped_refptr<RefCounted<int> > r2(new RefCounted<int>(2));
210
211 set.insert(r0);
212 set.insert(r1);
213 set.insert(r2);
214
215 EXPECT_EQ(static_cast<size_t>(3), set.size());
216
217 {
218 list_set<scoped_refptr<RefCounted<int> > >::iterator it = set.begin();
219 EXPECT_EQ(0, (*it)->value());
220 ++it;
221 EXPECT_EQ(1, (*it)->value());
222 ++it;
223 EXPECT_EQ(2, (*it)->value());
224 ++it;
225 EXPECT_EQ(set.end(), it);
226 }
227
228 set.erase(r0);
229 set.erase(r1);
230 set.erase(r2);
231
232 EXPECT_EQ(static_cast<size_t>(0), set.size());
233 {
234 list_set<scoped_refptr<RefCounted<int> > >::iterator it = set.begin();
235 EXPECT_EQ(set.end(), it);
236 }
237 }
238
239 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/list_set.h ('k') | content/browser/indexed_db/webidbcursor_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698