MCPcopy Create free account
hub / github.com/IChooseYou/Reclass / testStructSpan

Method testStructSpan

tests/test_core.cpp:411–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409 }
410
411 void testStructSpan() {
412 using namespace rcx;
413 NodeTree tree;
414 tree.baseAddress = 0;
415
416 // Struct with UInt32 (offset 0, 4 bytes) + UInt64 (offset 4, 8 bytes)
417 Node root;
418 root.kind = NodeKind::Struct;
419 root.name = "Root";
420 root.parentId = 0;
421 int ri = tree.addNode(root);
422 uint64_t rootId = tree.nodes[ri].id;
423
424 Node f1;
425 f1.kind = NodeKind::UInt32;
426 f1.name = "a";
427 f1.parentId = rootId;
428 f1.offset = 0;
429 tree.addNode(f1);
430
431 Node f2;
432 f2.kind = NodeKind::UInt64;
433 f2.name = "b";
434 f2.parentId = rootId;
435 f2.offset = 4;
436 tree.addNode(f2);
437
438 // Span = max(0+4, 4+8) = 12
439 QCOMPARE(tree.structSpan(rootId), 12);
440
441 // Nested struct: inner at offset 0 with a UInt64 at offset 0 (size 8)
442 NodeTree tree2;
443 Node outer;
444 outer.kind = NodeKind::Struct;
445 outer.name = "Outer";
446 outer.parentId = 0;
447 int oi = tree2.addNode(outer);
448 uint64_t outerId = tree2.nodes[oi].id;
449
450 Node inner;
451 inner.kind = NodeKind::Struct;
452 inner.name = "Inner";
453 inner.parentId = outerId;
454 inner.offset = 0;
455 int ii = tree2.addNode(inner);
456 uint64_t innerId = tree2.nodes[ii].id;
457
458 Node leaf;
459 leaf.kind = NodeKind::UInt64;
460 leaf.name = "x";
461 leaf.parentId = innerId;
462 leaf.offset = 0;
463 tree2.addNode(leaf);
464
465 // Inner span = 8, outer span = max(0+8) = 8
466 QCOMPARE(tree2.structSpan(innerId), 8);
467 QCOMPARE(tree2.structSpan(outerId), 8);
468

Callers

nothing calls this directly

Calls 2

structSpanMethod · 0.80
addNodeMethod · 0.45

Tested by

no test coverage detected