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

Side by Side Diff: ui/base/models/tree_node_iterator_unittest.cc

Issue 8273041: Permanent folders changes (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: "Post-review changes." Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "ui/base/models/tree_node_iterator.h" 7 #include "ui/base/models/tree_node_iterator.h"
8 #include "ui/base/models/tree_node_model.h" 8 #include "ui/base/models/tree_node_model.h"
9 9
10 namespace ui { 10 namespace ui {
(...skipping 20 matching lines...) Expand all
31 31
32 ASSERT_TRUE(iterator.has_next()); 32 ASSERT_TRUE(iterator.has_next());
33 ASSERT_EQ(f4, iterator.Next()); 33 ASSERT_EQ(f4, iterator.Next());
34 34
35 ASSERT_TRUE(iterator.has_next()); 35 ASSERT_TRUE(iterator.has_next());
36 ASSERT_EQ(f4->GetChild(0), iterator.Next()); 36 ASSERT_EQ(f4->GetChild(0), iterator.Next());
37 37
38 ASSERT_FALSE(iterator.has_next()); 38 ASSERT_FALSE(iterator.has_next());
39 } 39 }
40 40
41 static bool PruneOdd(TreeNodeWithValue<int>* node) {
42 return node->value % 2;
43 }
44
45 static bool PruneEven(TreeNodeWithValue<int>* node) {
46 return !(node->value % 2);
47 }
48
49 // The tree used for testing:
50 // * + 1
51 // + 2
52 // + 3 + 4 + 5
53 // + 7
54
55 TEST(TreeNodeIteratorPruneTest, Test) {
56 TreeNodeWithValue<int> root;
57 root.Add(new TreeNodeWithValue<int>(1), 0);
58 root.Add(new TreeNodeWithValue<int>(2), 1);
59 TreeNodeWithValue<int>* f3 = new TreeNodeWithValue<int>(3);
60 root.Add(f3, 2);
61 TreeNodeWithValue<int>* f4 = new TreeNodeWithValue<int>(4);
62 f3->Add(f4, 0);
63 f4->Add(new TreeNodeWithValue<int>(5), 0);
64 f3->Add(new TreeNodeWithValue<int>(7), 1);
65
66 TreeNodeIterator<TreeNodeWithValue<int> > oddIterator(&root, PruneOdd);
67 ASSERT_TRUE(oddIterator.has_next());
68 ASSERT_EQ(2, oddIterator.Next()->value);
69 ASSERT_FALSE(oddIterator.has_next());
70
71 TreeNodeIterator<TreeNodeWithValue<int> > evenIterator(&root, PruneEven);
72 ASSERT_TRUE(evenIterator.has_next());
73 ASSERT_EQ(1, evenIterator.Next()->value);
74 ASSERT_TRUE(evenIterator.has_next());
75 ASSERT_EQ(3, evenIterator.Next()->value);
76 ASSERT_TRUE(evenIterator.has_next());
77 ASSERT_EQ(7, evenIterator.Next()->value);
78 ASSERT_FALSE(evenIterator.has_next());
79 }
80
41 } // namespace ui 81 } // namespace ui
OLDNEW
« chrome/browser/bookmarks/bookmark_model.cc ('K') | « ui/base/models/tree_node_iterator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698