DBC Framework
DBC parsing and CAN signal decoding framework
Loading...
Searching...
No Matches
tree_node_test.cpp
1// Standalone C++17 test: no Qt required.
2#include "dbc_tree_builder.h"
3#include <stdexcept>
4#include <type_traits>
5
6static void Check(bool condition) {
7 if (!condition) throw std::runtime_error("Tree navigation test failed");
8}
9
10int main() {
11 static_assert(!std::is_move_constructible<TreeNode>::value, "Node addresses must be stable");
12 DbcDatabase database;
13 FrameInfo frame;
14 SignalInfo signal;
15 frame.signals.push_back(signal);
16 frame.signals.push_back(signal);
17 database.frames.push_back(frame);
18 database.frames.push_back(frame);
19 std::unique_ptr<TreeNode> root = DbcTreeBuilder().Build(database);
20 Check(root->GetParent() == nullptr && root->GetRow() == 0);
21 root->AddChild(nullptr);
22 Check(root->GetChildCount() == 2 && !root->GetChild(2));
23 for (std::size_t row = 0; row < root->GetChildCount(); ++row) {
24 const TreeNode *child = root->GetChild(row);
25 Check(child->GetParent() == root.get() && child->GetRow() == row);
26 for (std::size_t position = 0; position < child->GetChildCount(); ++position) {
27 const TreeNode *leaf = child->GetChild(position);
28 Check(leaf->GetParent() == child && leaf->GetRow() == position);
29 }
30 }
31 std::unique_ptr<TreeNode> transferred = std::move(root);
32 Check(transferred->GetChild(0)->GetParent() == transferred.get());
33}
Builds a simple tree from parsed DBC database.
std::unique_ptr< TreeNode > Build(const DbcDatabase &database) const
Build tree representation of parsed DBC data.
Tree node for later use in model/view or other hierarchy consumers.
Definition tree_node.h:35
const TreeNode * GetChild(std::size_t index) const
Get child by index.
Definition tree_node.cpp:38
const TreeNode * GetParent() const
Definition tree_node.cpp:68
std::size_t GetChildCount() const
Get child count.
Definition tree_node.cpp:34
std::size_t GetRow() const
Definition tree_node.cpp:72
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Parsed DBC content stored in a simple internal form.
std::vector< FrameInfo > frames
Describes one CAN frame from a DBC file.
Definition frame_info.h:24
Describes one signal inside a DBC frame.
Definition signal_info.h:24