diff --git a/Client/udpscope/tests/PaneTreeTest.cpp b/Client/udpscope/tests/PaneTreeTest.cpp index 087a0e2..c076803 100644 --- a/Client/udpscope/tests/PaneTreeTest.cpp +++ b/Client/udpscope/tests/PaneTreeTest.cpp @@ -167,3 +167,64 @@ TEST(PaneTree, HitTestFindsInsetSplitHandlesAndTheCloseButton) { EXPECT_EQ(PaneTree::hitTestHandle(pane, 392.0, 8.0), Handle::Close); EXPECT_EQ(PaneTree::hitTestHandle(pane, 200.0, 150.0), Handle::None); } + +// Gap 1: closeLeaf only tested with first child closed; test closing the second child. +TEST(PaneTree, ClosingTheSecondLeafPreservesTheFirstLeafContent) { + PaneTree tree; + tree.splitLeaf(tree.root(), Orient::Columns); + auto leaves = leavesOf(tree, kScreen); + ASSERT_EQ(leaves.size(), 2u); + + // Assign distinct signals to each leaf + leaves[0].leaf->signals.push_back(Assignment{"Signal_A", Color{}, 1.5f, VScale{}}); + leaves[1].leaf->signals.push_back(Assignment{"Signal_B", Color{}, 1.5f, VScale{}}); + + // Close the second leaf; the first should survive with its content + tree.closeLeaf(leaves[1].leaf); + + EXPECT_EQ(tree.leafCount(), 1u); + leaves = leavesOf(tree, kScreen); + ASSERT_EQ(leaves.size(), 1u); + ASSERT_EQ(leaves[0].leaf->signals.size(), 1u); + EXPECT_EQ(leaves[0].leaf->signals[0].signalName, "Signal_A"); +} + +// Gap 2: closeLeaf only tested at depth 1; test at depth 2 (deeper recursion in findParent). +TEST(PaneTree, ClosingALeafAtDepth2PreservesOthersAndUpdatesCount) { + PaneTree tree; + // Build tree: split root (a, b), split b to get depth-2 leaf in the RIGHT subtree + tree.splitLeaf(tree.root(), Orient::Columns); // depth 1: root splits into a, b + auto leaves = leavesOf(tree, kScreen); + ASSERT_EQ(leaves.size(), 2u); + + tree.splitLeaf(leaves[1].leaf, Orient::Rows); // depth 2: b splits into b.a, b.b + leaves = leavesOf(tree, kScreen); + ASSERT_EQ(leaves.size(), 3u); + + // Assign distinct signals to each of the three leaves + leaves[0].leaf->signals.push_back(Assignment{"Depth1_Left", Color{}, 1.5f, VScale{}}); + leaves[1].leaf->signals.push_back(Assignment{"Depth2_TopRight", Color{}, 1.5f, VScale{}}); + leaves[2].leaf->signals.push_back(Assignment{"Depth2_BottomRight", Color{}, 1.5f, VScale{}}); + + // Close the first depth-2 leaf (leaves[1], which is in the right subtree) + tree.closeLeaf(leaves[1].leaf); + + EXPECT_EQ(tree.leafCount(), 2u); + leaves = leavesOf(tree, kScreen); + ASSERT_EQ(leaves.size(), 2u); + + // Verify the surviving depth-2 leaf has its signal intact + bool found_left = false; + bool found_bottom_right = false; + for (const auto& leaf : leaves) { + ASSERT_EQ(leaf.leaf->signals.size(), 1u); + if (leaf.leaf->signals[0].signalName == "Depth1_Left") { + found_left = true; + } + if (leaf.leaf->signals[0].signalName == "Depth2_BottomRight") { + found_bottom_right = true; + } + } + EXPECT_TRUE(found_left); + EXPECT_TRUE(found_bottom_right); +}