| 48 | } |
| 49 | |
| 50 | class TestContextMenu : public QObject { |
| 51 | Q_OBJECT |
| 52 | private: |
| 53 | RcxDocument* m_doc = nullptr; |
| 54 | RcxController* m_ctrl = nullptr; |
| 55 | QSplitter* m_splitter = nullptr; |
| 56 | RcxEditor* m_editor = nullptr; |
| 57 | |
| 58 | int findNode(const QString& name) const { |
| 59 | for (int i = 0; i < m_doc->tree.nodes.size(); i++) |
| 60 | if (m_doc->tree.nodes[i].name == name) return i; |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | int countNodes() const { return m_doc->tree.nodes.size(); } |
| 65 | |
| 66 | private slots: |
| 67 | void init() { |
| 68 | m_doc = new RcxDocument(); |
| 69 | buildTree(m_doc->tree); |
| 70 | m_doc->provider = std::make_unique<BufferProvider>(makeBuffer()); |
| 71 | |
| 72 | m_splitter = new QSplitter(); |
| 73 | m_ctrl = new RcxController(m_doc, nullptr); |
| 74 | m_editor = m_ctrl->addSplitEditor(m_splitter); |
| 75 | |
| 76 | m_splitter->resize(800, 600); |
| 77 | m_splitter->show(); |
| 78 | QVERIFY(QTest::qWaitForWindowExposed(m_splitter)); |
| 79 | QApplication::processEvents(); |
| 80 | } |
| 81 | |
| 82 | void cleanup() { |
| 83 | delete m_ctrl; m_ctrl = nullptr; |
| 84 | m_editor = nullptr; |
| 85 | delete m_splitter; m_splitter = nullptr; |
| 86 | delete m_doc; m_doc = nullptr; |
| 87 | } |
| 88 | |
| 89 | // ── Insert adds exactly one node ── |
| 90 | |
| 91 | void testInsertAddsOneNode() { |
| 92 | int before = countNodes(); |
| 93 | uint64_t rootId = m_doc->tree.nodes[0].id; |
| 94 | m_ctrl->insertNode(rootId, 16, NodeKind::Hex64, "inserted"); |
| 95 | QApplication::processEvents(); |
| 96 | |
| 97 | QCOMPARE(countNodes(), before + 1); |
| 98 | |
| 99 | int idx = findNode("inserted"); |
| 100 | QVERIFY(idx >= 0); |
| 101 | QCOMPARE(m_doc->tree.nodes[idx].kind, NodeKind::Hex64); |
| 102 | QCOMPARE(m_doc->tree.nodes[idx].offset, 16); |
| 103 | QCOMPARE(m_doc->tree.nodes[idx].parentId, rootId); |
| 104 | } |
| 105 | |
| 106 | // ── Insert at auto-offset places after last sibling ── |
| 107 |
nothing calls this directly
no outgoing calls
no test coverage detected