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

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

Issue 7134061: ui/base/models: Rewrite the TreeNodeModelTest.RemoveAllNodes unittest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better comment Created 9 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 | « no previous file | 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) 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 "base/basictypes.h"
5 #include "base/string16.h" 6 #include "base/string16.h"
6 #include "base/string_number_conversions.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/base/models/tree_node_model.h" 9 #include "ui/base/models/tree_node_model.h"
10 10
11 namespace ui { 11 namespace ui {
12 12
13 class TreeNodeModelTest : public testing::Test, public TreeModelObserver { 13 class TreeNodeModelTest : public testing::Test, public TreeModelObserver {
14 public: 14 public:
15 TreeNodeModelTest() 15 TreeNodeModelTest()
16 : added_count_(0), 16 : added_count_(0),
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 ASSERT_EQ(0, model.GetChildCount(root)); 121 ASSERT_EQ(0, model.GetChildCount(root));
122 } 122 }
123 123
124 // Verify if the nodes added under the root are all deleted when calling 124 // Verify if the nodes added under the root are all deleted when calling
125 // RemoveAll. Note that is responsability of the caller to free the memory 125 // RemoveAll. Note that is responsability of the caller to free the memory
126 // of the nodes removed after RemoveAll is called. 126 // of the nodes removed after RemoveAll is called.
127 // The tree looks like this: 127 // The tree looks like this:
128 // root 128 // root
129 // |-- child1 129 // |-- child1
130 // | |-- foo1 130 // | |-- foo
131 // | |-- child0 131 // | |-- bar0
132 // | |-- child1 132 // | |-- bar1
133 // +-------|-- child2 133 // | |-- bar2
134 // |-- child2
135 // +-- child3
134 TEST_F(TreeNodeModelTest, RemoveAllNodes) { 136 TEST_F(TreeNodeModelTest, RemoveAllNodes) {
135 TreeNodeWithValue<int>* root = 137 TreeNodeWithValue<int> root;
136 new TreeNodeWithValue<int>(ASCIIToUTF16("root"), 0);
137 TreeNodeModel<TreeNodeWithValue<int> > model(root);
138 model.AddObserver(this);
139 ClearCounts();
140 138
141 // Create the first child node. 139 TreeNodeWithValue<int> child1;
142 TreeNodeWithValue<int>* child1 = 140 TreeNodeWithValue<int> child2;
143 new TreeNodeWithValue<int>(ASCIIToUTF16("child 1"), 1); 141 TreeNodeWithValue<int> child3;
144 model.Add(root, child1, 0);
145 142
146 TreeNodeWithValue<int>* foo1 = 143 root.Add(&child1, 0);
147 new TreeNodeWithValue<int>(ASCIIToUTF16("foo1"), 2); 144 root.Add(&child2, 1);
148 model.Add(child1, foo1, 0); 145 root.Add(&child3, 2);
149 146
150 // Add some nodes to |foo1|. 147 TreeNodeWithValue<int>* foo = new TreeNodeWithValue<int>(2);
151 for (int i = 0; i < 3; ++i) { 148 child1.Add(foo, 0);
152 model.Add(foo1,
153 new TreeNodeWithValue<int>(ASCIIToUTF16("child") +
154 base::IntToString16(i), i), i);
155 }
156 149
157 ASSERT_EQ(3, model.GetChildCount(foo1)); 150 // Add some nodes to |foo|.
151 for (int i = 0; i < 3; ++i)
152 foo->Add(new TreeNodeWithValue<int>(i), i);
158 153
159 // Now remove all nodes from root. 154 ASSERT_EQ(3, root.child_count());
160 root->RemoveAll(); 155 ASSERT_EQ(1, child1.child_count());
156 ASSERT_EQ(3, foo->child_count());
161 157
162 // Release memory, so we don't leak. 158 // Now remove the child nodes from root.
163 delete child1; 159 root.RemoveAll();
164 160
165 ASSERT_EQ(0, model.GetChildCount(root)); 161 ASSERT_EQ(0, root.child_count());
162 ASSERT_TRUE(root.empty());
163
164 ASSERT_EQ(1, child1.child_count());
165 ASSERT_EQ(3, foo->child_count());
166 } 166 }
167 167
168 // Verify if the model returns correct indexes for the specified nodes. 168 // Verify if the model returns correct indexes for the specified nodes.
169 // The tree looks like this: 169 // The tree looks like this:
170 // root 170 // root
171 // |-- child1 171 // |-- child1
172 // | |-- foo1 172 // | |-- foo1
173 // +-- child2 173 // +-- child2
174 TEST_F(TreeNodeModelTest, GetIndexOf) { 174 TEST_F(TreeNodeModelTest, GetIndexOf) {
175 TreeNodeWithValue<int> root; 175 TreeNodeWithValue<int> root;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 TEST_F(TreeNodeModelTest, IsRoot) { 323 TEST_F(TreeNodeModelTest, IsRoot) {
324 TreeNodeWithValue<int> root; 324 TreeNodeWithValue<int> root;
325 EXPECT_TRUE(root.is_root()); 325 EXPECT_TRUE(root.is_root());
326 326
327 TreeNodeWithValue<int>* child1 = new TreeNodeWithValue<int>(1); 327 TreeNodeWithValue<int>* child1 = new TreeNodeWithValue<int>(1);
328 root.Add(child1, root.child_count()); 328 root.Add(child1, root.child_count());
329 EXPECT_FALSE(child1->is_root()); 329 EXPECT_FALSE(child1->is_root());
330 } 330 }
331 331
332 } // namespace ui 332 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698