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

Side by Side Diff: base/linked_list_unittest.cc

Issue 266020: Use static_cast in LinkNode<T>::value() so that it works with... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 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 | « base/linked_list.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
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/linked_list.h" 5 #include "base/linked_list.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 namespace { 10 namespace {
11 11
12 class Node : public LinkNode<Node> { 12 class Node : public LinkNode<Node> {
13 public: 13 public:
14 explicit Node(int id) : id_(id) {} 14 explicit Node(int id) : id_(id) {}
15 15
16 int id() const { return id_; } 16 int id() const { return id_; }
17 17
18 private: 18 private:
19 int id_; 19 int id_;
20 }; 20 };
21 21
22 class MultipleInheritanceNodeBase {
23 public:
24 MultipleInheritanceNodeBase() : field_taking_up_space_(0) {}
25 int field_taking_up_space_;
26 };
27
28 class MultipleInheritanceNode : public MultipleInheritanceNodeBase,
29 public LinkNode<MultipleInheritanceNode> {
30 public:
31 MultipleInheritanceNode() {}
32 };
33
22 // Checks that when iterating |list| (either from head to tail, or from 34 // Checks that when iterating |list| (either from head to tail, or from
23 // tail to head, as determined by |forward|), we get back |node_ids|, 35 // tail to head, as determined by |forward|), we get back |node_ids|,
24 // which is an array of size |num_nodes|. 36 // which is an array of size |num_nodes|.
25 void ExpectListContentsForDirection(const LinkedList<Node>& list, 37 void ExpectListContentsForDirection(const LinkedList<Node>& list,
26 int num_nodes, const int* node_ids, bool forward) { 38 int num_nodes, const int* node_ids, bool forward) {
27 int i = 0; 39 int i = 0;
28 for (const LinkNode<Node>* node = (forward ? list.head() : list.tail()); 40 for (const LinkNode<Node>* node = (forward ? list.head() : list.tail());
29 node != list.end(); 41 node != list.end();
30 node = (forward ? node->next() : node->previous())) { 42 node = (forward ? node->next() : node->previous())) {
31 ASSERT_LT(i, num_nodes); 43 ASSERT_LT(i, num_nodes);
(...skipping 17 matching lines...) Expand all
49 } 61 }
50 } 62 }
51 63
52 TEST(LinkedList, Empty) { 64 TEST(LinkedList, Empty) {
53 LinkedList<Node> list; 65 LinkedList<Node> list;
54 EXPECT_EQ(list.end(), list.head()); 66 EXPECT_EQ(list.end(), list.head());
55 EXPECT_EQ(list.end(), list.tail()); 67 EXPECT_EQ(list.end(), list.tail());
56 ExpectListContents(list, 0, NULL); 68 ExpectListContents(list, 0, NULL);
57 } 69 }
58 70
59
60 TEST(LinkedList, Append) { 71 TEST(LinkedList, Append) {
61 LinkedList<Node> list; 72 LinkedList<Node> list;
62 ExpectListContents(list, 0, NULL); 73 ExpectListContents(list, 0, NULL);
63 74
64 Node n1(1); 75 Node n1(1);
65 list.Append(&n1); 76 list.Append(&n1);
66 77
67 EXPECT_EQ(&n1, list.head()); 78 EXPECT_EQ(&n1, list.head());
68 EXPECT_EQ(&n1, list.tail()); 79 EXPECT_EQ(&n1, list.tail());
69 { 80 {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 n4.InsertAfter(&n1); 245 n4.InsertAfter(&n1);
235 246
236 EXPECT_EQ(&n1, list.head()); 247 EXPECT_EQ(&n1, list.head());
237 EXPECT_EQ(&n3, list.tail()); 248 EXPECT_EQ(&n3, list.tail());
238 { 249 {
239 const int expected[] = {1, 4, 2, 3}; 250 const int expected[] = {1, 4, 2, 3};
240 ExpectListContents(list, arraysize(expected), expected); 251 ExpectListContents(list, arraysize(expected), expected);
241 } 252 }
242 } 253 }
243 254
255 TEST(LinkedList, MultipleInheritanceNode) {
256 MultipleInheritanceNode node;
257 EXPECT_EQ(&node, node.value());
258 }
259
244 } // namespace 260 } // namespace
245 } // namespace base 261 } // namespace base
OLDNEW
« no previous file with comments | « base/linked_list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698