OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 Trio trio; | 161 Trio trio; |
162 trio.appendChildren(); | 162 trio.appendChildren(); |
163 | 163 |
164 trio.root->removeChild(trio.firstChild.get()); | 164 trio.root->removeChild(trio.firstChild.get()); |
165 EXPECT_TRUE(trio.firstChild->orphan()); | 165 EXPECT_TRUE(trio.firstChild->orphan()); |
166 EXPECT_EQ(trio.middleChild->previous(), nullNode.get()); | 166 EXPECT_EQ(trio.middleChild->previous(), nullNode.get()); |
167 EXPECT_EQ(trio.root->firstChild(), trio.middleChild.get()); | 167 EXPECT_EQ(trio.root->firstChild(), trio.middleChild.get()); |
168 EXPECT_EQ(trio.root->lastChild(), trio.lastChild.get()); | 168 EXPECT_EQ(trio.root->lastChild(), trio.lastChild.get()); |
169 } | 169 } |
170 | 170 |
| 171 TEST(WTF, TreeNodeTakeChildrenFrom) |
| 172 { |
| 173 RefPtr<TestTree> newParent = TestTree::create(); |
| 174 Trio trio; |
| 175 trio.appendChildren(); |
| 176 |
| 177 newParent->takeChildrenFrom(trio.root.get()); |
| 178 |
| 179 EXPECT_FALSE(trio.root->hasChildren()); |
| 180 EXPECT_TRUE(newParent->hasChildren()); |
| 181 EXPECT_EQ(trio.firstChild.get(), newParent->firstChild()); |
| 182 EXPECT_EQ(trio.middleChild.get(), newParent->firstChild()->next()); |
| 183 EXPECT_EQ(trio.lastChild.get(), newParent->lastChild()); |
| 184 } |
| 185 |
171 class TrioWithGrandChild : public Trio { | 186 class TrioWithGrandChild : public Trio { |
172 public: | 187 public: |
173 TrioWithGrandChild() | 188 TrioWithGrandChild() |
174 : grandChild(TestTree::create()) | 189 : grandChild(TestTree::create()) |
175 { | 190 { |
176 } | 191 } |
177 | 192 |
178 void appendChildren() | 193 void appendChildren() |
179 { | 194 { |
180 Trio::appendChildren(); | 195 Trio::appendChildren(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 228 |
214 unsigned orderIndex = 0; | 229 unsigned orderIndex = 0; |
215 for (TestTree* node = traverseFirstPostOrder(trio.root.get()); node; node =
traverseNextPostOrder(node), orderIndex++) | 230 for (TestTree* node = traverseFirstPostOrder(trio.root.get()); node; node =
traverseNextPostOrder(node), orderIndex++) |
216 EXPECT_EQ(node, order[orderIndex]); | 231 EXPECT_EQ(node, order[orderIndex]); |
217 EXPECT_EQ(orderIndex, sizeof(order) / sizeof(TestTree*)); | 232 EXPECT_EQ(orderIndex, sizeof(order) / sizeof(TestTree*)); |
218 | 233 |
219 } | 234 } |
220 | 235 |
221 | 236 |
222 } // namespace | 237 } // namespace |
OLD | NEW |