── Test: setNodeValue undo/redo restores data ──
| 123 | |
| 124 | // ── Test: setNodeValue undo/redo restores data ── |
| 125 | void testSetNodeValueUndoRedo() { |
| 126 | int idx = -1; |
| 127 | for (int i = 0; i < m_doc->tree.nodes.size(); i++) { |
| 128 | if (m_doc->tree.nodes[i].name == "field_u32") { idx = i; break; } |
| 129 | } |
| 130 | QVERIFY(idx >= 0); |
| 131 | uint64_t addr = m_doc->tree.computeOffset(idx); |
| 132 | |
| 133 | // Original: 0xDEADBEEF |
| 134 | QByteArray orig = m_doc->provider->readBytes(addr, 4); |
| 135 | uint32_t origVal; |
| 136 | memcpy(&origVal, orig.data(), 4); |
| 137 | QCOMPARE(origVal, (uint32_t)0xDEADBEEF); |
| 138 | |
| 139 | // Write new value |
| 140 | m_ctrl->setNodeValue(idx, 0, "99"); |
| 141 | QApplication::processEvents(); |
| 142 | |
| 143 | uint32_t newVal; |
| 144 | QByteArray after = m_doc->provider->readBytes(addr, 4); |
| 145 | memcpy(&newVal, after.data(), 4); |
| 146 | QCOMPARE(newVal, (uint32_t)99); |
| 147 | |
| 148 | // Undo → should restore original |
| 149 | m_doc->undoStack.undo(); |
| 150 | QApplication::processEvents(); |
| 151 | |
| 152 | QByteArray undone = m_doc->provider->readBytes(addr, 4); |
| 153 | uint32_t undoneVal; |
| 154 | memcpy(&undoneVal, undone.data(), 4); |
| 155 | QCOMPARE(undoneVal, (uint32_t)0xDEADBEEF); |
| 156 | |
| 157 | // Redo → should restore new value |
| 158 | m_doc->undoStack.redo(); |
| 159 | QApplication::processEvents(); |
| 160 | |
| 161 | QByteArray redone = m_doc->provider->readBytes(addr, 4); |
| 162 | uint32_t redoneVal; |
| 163 | memcpy(&redoneVal, redone.data(), 4); |
| 164 | QCOMPARE(redoneVal, (uint32_t)99); |
| 165 | } |
| 166 | |
| 167 | // ── Test: setNodeValue on Float field ── |
| 168 | void testSetNodeValueFloat() { |
nothing calls this directly
no test coverage detected