| 178 | // ── Nested struct ── |
| 179 | |
| 180 | void testNestedStruct() { |
| 181 | rcx::NodeTree tree; |
| 182 | |
| 183 | // Outer struct |
| 184 | rcx::Node outer; |
| 185 | outer.kind = rcx::NodeKind::Struct; |
| 186 | outer.name = "Outer"; |
| 187 | outer.structTypeName = "Outer"; |
| 188 | outer.parentId = 0; |
| 189 | int oi = tree.addNode(outer); |
| 190 | uint64_t outerId = tree.nodes[oi].id; |
| 191 | |
| 192 | // Inner struct as child |
| 193 | rcx::Node inner; |
| 194 | inner.kind = rcx::NodeKind::Struct; |
| 195 | inner.name = "pos"; |
| 196 | inner.structTypeName = "Vec2f"; |
| 197 | inner.parentId = outerId; |
| 198 | inner.offset = 0; |
| 199 | int ii = tree.addNode(inner); |
| 200 | uint64_t innerId = tree.nodes[ii].id; |
| 201 | |
| 202 | // Inner fields |
| 203 | rcx::Node ix; |
| 204 | ix.kind = rcx::NodeKind::Float; |
| 205 | ix.name = "x"; |
| 206 | ix.parentId = innerId; |
| 207 | ix.offset = 0; |
| 208 | tree.addNode(ix); |
| 209 | |
| 210 | rcx::Node iy; |
| 211 | iy.kind = rcx::NodeKind::Float; |
| 212 | iy.name = "y"; |
| 213 | iy.parentId = innerId; |
| 214 | iy.offset = 4; |
| 215 | tree.addNode(iy); |
| 216 | |
| 217 | // Another field in outer after inner |
| 218 | rcx::Node f2; |
| 219 | f2.kind = rcx::NodeKind::Int32; |
| 220 | f2.name = "score"; |
| 221 | f2.parentId = outerId; |
| 222 | f2.offset = 8; |
| 223 | tree.addNode(f2); |
| 224 | |
| 225 | QString result = rcx::renderCpp(tree, outerId); |
| 226 | |
| 227 | // Inner struct should be defined before outer |
| 228 | int innerPos = result.indexOf("struct Vec2f {"); |
| 229 | int outerPos = result.indexOf("struct Outer {"); |
| 230 | QVERIFY(innerPos >= 0); |
| 231 | QVERIFY(outerPos >= 0); |
| 232 | QVERIFY(innerPos < outerPos); |
| 233 | |
| 234 | // Inner struct fields |
| 235 | QVERIFY(result.contains("float x;")); |
| 236 | QVERIFY(result.contains("float y;")); |
| 237 | QVERIFY(result.contains("static_assert(sizeof(Vec2f) == 0x8")); |