| 59 | } |
| 60 | |
| 61 | class TestController : public QObject { |
| 62 | Q_OBJECT |
| 63 | private: |
| 64 | RcxDocument* m_doc = nullptr; |
| 65 | RcxController* m_ctrl = nullptr; |
| 66 | QSplitter* m_splitter = nullptr; |
| 67 | RcxEditor* m_editor = nullptr; |
| 68 | |
| 69 | private slots: |
| 70 | void init() { |
| 71 | m_doc = new RcxDocument(); |
| 72 | buildSmallTree(m_doc->tree); |
| 73 | m_doc->provider = std::make_unique<BufferProvider>(makeSmallBuffer()); |
| 74 | |
| 75 | m_splitter = new QSplitter(); |
| 76 | // Pass nullptr as parent so controller is not auto-deleted with splitter |
| 77 | m_ctrl = new RcxController(m_doc, nullptr); |
| 78 | m_editor = m_ctrl->addSplitEditor(m_splitter); |
| 79 | |
| 80 | m_splitter->resize(800, 600); |
| 81 | m_splitter->show(); |
| 82 | QVERIFY(QTest::qWaitForWindowExposed(m_splitter)); |
| 83 | QApplication::processEvents(); |
| 84 | } |
| 85 | |
| 86 | void cleanup() { |
| 87 | // Delete controller first (disconnects from editor signals) |
| 88 | delete m_ctrl; |
| 89 | m_ctrl = nullptr; |
| 90 | m_editor = nullptr; // owned by splitter |
| 91 | delete m_splitter; |
| 92 | m_splitter = nullptr; |
| 93 | delete m_doc; |
| 94 | m_doc = nullptr; |
| 95 | } |
| 96 | |
| 97 | // ── Test: setNodeValue writes bytes to provider ── |
| 98 | void testSetNodeValueWritesData() { |
| 99 | // Find field_u32 (index 1, child of root at index 0) |
| 100 | int idx = -1; |
| 101 | for (int i = 0; i < m_doc->tree.nodes.size(); i++) { |
| 102 | if (m_doc->tree.nodes[i].name == "field_u32") { idx = i; break; } |
| 103 | } |
| 104 | QVERIFY(idx >= 0); |
| 105 | |
| 106 | // Verify original value in provider |
| 107 | uint64_t addr = m_doc->tree.computeOffset(idx); |
| 108 | QByteArray origBytes = m_doc->provider->readBytes(addr, 4); |
| 109 | uint32_t origVal; |
| 110 | memcpy(&origVal, origBytes.data(), 4); |
| 111 | QCOMPARE(origVal, (uint32_t)0xDEADBEEF); |
| 112 | |
| 113 | // Write new value "42" (decimal) |
| 114 | m_ctrl->setNodeValue(idx, 0, "42"); |
| 115 | QApplication::processEvents(); |
| 116 | |
| 117 | // Read back: should be 42 in little-endian |
| 118 | QByteArray newBytes = m_doc->provider->readBytes(addr, 4); |
nothing calls this directly
no outgoing calls
no test coverage detected