Files
dbc/tests/tree_node_test.cpp
T
2026-10-06 17:14:50 -04:00

34 lines
1.3 KiB
C++

// Standalone C++17 test: no Qt required.
#include "dbc_tree_builder.h"
#include <stdexcept>
#include <type_traits>
static void Check(bool condition) {
if (!condition) throw std::runtime_error("Tree navigation test failed");
}
int main() {
static_assert(!std::is_move_constructible<TreeNode>::value, "Node addresses must be stable");
DbcDatabase database;
FrameInfo frame;
SignalInfo signal;
frame.signals.push_back(signal);
frame.signals.push_back(signal);
database.frames.push_back(frame);
database.frames.push_back(frame);
auto root = DbcTreeBuilder().Build(database);
Check(root->GetParent() == nullptr && root->GetRow() == 0);
root->AddChild(nullptr);
Check(root->GetChildCount() == 2 && !root->GetChild(2));
for (std::size_t row = 0; row < root->GetChildCount(); ++row) {
const TreeNode *child = root->GetChild(row);
Check(child->GetParent() == root.get() && child->GetRow() == row);
for (std::size_t position = 0; position < child->GetChildCount(); ++position) {
const TreeNode *leaf = child->GetChild(position);
Check(leaf->GetParent() == child && leaf->GetRow() == position);
}
}
auto transferred = std::move(root);
Check(transferred->GetChild(0)->GetParent() == transferred.get());
}