| 2 | #include "core.h" |
| 3 | |
| 4 | class TestCore : public QObject { |
| 5 | Q_OBJECT |
| 6 | private slots: |
| 7 | void testSizeForKind() { |
| 8 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Hex8), 1); |
| 9 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Hex16), 2); |
| 10 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Hex32), 4); |
| 11 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Hex64), 8); |
| 12 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Float), 4); |
| 13 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Double), 8); |
| 14 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Vec3), 12); |
| 15 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Mat4x4), 64); |
| 16 | QCOMPARE(rcx::sizeForKind(rcx::NodeKind::Struct), 0); |
| 17 | } |
| 18 | |
| 19 | void testLinesForKind() { |
| 20 | QCOMPARE(rcx::linesForKind(rcx::NodeKind::Hex32), 1); |
| 21 | QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec2), 1); |
| 22 | QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec3), 1); |
| 23 | QCOMPARE(rcx::linesForKind(rcx::NodeKind::Vec4), 1); |
| 24 | QCOMPARE(rcx::linesForKind(rcx::NodeKind::Mat4x4), 4); |
| 25 | } |
| 26 | |
| 27 | void testKindStringRoundTrip() { |
| 28 | for (int i = 0; i <= static_cast<int>(rcx::NodeKind::Array); i++) { |
| 29 | auto kind = static_cast<rcx::NodeKind>(i); |
| 30 | QString s = rcx::kindToString(kind); |
| 31 | QCOMPARE(rcx::kindFromString(s), kind); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void testNodeTree_addAndChildren() { |
| 36 | rcx::NodeTree tree; |
| 37 | rcx::Node root; |
| 38 | root.kind = rcx::NodeKind::Struct; |
| 39 | root.name = "Root"; |
| 40 | root.parentId = 0; |
| 41 | int ri = tree.addNode(root); |
| 42 | QCOMPARE(ri, 0); |
| 43 | uint64_t rootId = tree.nodes[ri].id; |
| 44 | |
| 45 | rcx::Node child; |
| 46 | child.kind = rcx::NodeKind::Hex32; |
| 47 | child.name = "field"; |
| 48 | child.parentId = rootId; |
| 49 | child.offset = 0; |
| 50 | tree.addNode(child); |
| 51 | |
| 52 | auto children = tree.childrenOf(rootId); |
| 53 | QCOMPARE(children.size(), 1); |
| 54 | QCOMPARE(children[0], 1); |
| 55 | |
| 56 | auto roots = tree.childrenOf(0); |
| 57 | QCOMPARE(roots.size(), 1); |
| 58 | QCOMPARE(roots[0], 0); |
| 59 | } |
| 60 | |
| 61 | void testNodeTree_depth() { |
nothing calls this directly
no test coverage detected