MathLib
Loading...
Searching...
No Matches
TestSceneNode.cpp
Go to the documentation of this file.
4#include <cassert>
5#include <iostream>
6#include <cstdlib>
7
8
27{
28
29using namespace Math;
30
35{
36 std::cout << __func__ << std::endl;
37
38 auto node = SceneNodef::make();
39
40 assert( node->parent().expired() ); // No parent
41 assert( node->children().empty() ); // No children
42}
43
48{
49 std::cout << __func__ << std::endl;
50
51 // Via weak_ptr
52 {
53 std::shared_ptr<SceneNodef> node = SceneNodef::make();
54 std::weak_ptr<SceneNodef> child_node = node->createChildNode({ 1.0f, 2.0f, 3.0f }, Quaternionf::make_rotation( Degreef{45.0f}, 1.0f, 0.0f, 0.0f ));
55
56 assert( !child_node.expired() );
57 assert( !child_node.lock()->parent().expired() );
58 assert( child_node.lock()->parent().lock() == node); // Child's parent() is the node it was created from
59 assert( child_node.lock()->parent().lock()->children().size() == 1 ); // It is the only child in the parent
60 assert( child_node.lock()->parent().lock()->children().front() == child_node.lock() ); // That only child is the newly created node
61 assert( node->children().size() == 1 );
62 assert( !node->children().empty() );
63 assert( std::ranges::find( node->children(), child_node.lock() ) != node->children().end() );
64 }
65
66 // Via shared_ptr
67 {
68 std::shared_ptr<SceneNodef> node = SceneNodef::make();
69 std::shared_ptr<SceneNodef> child_node{ node->createChildNode({ 1.0f, 2.0f, 3.0f }, Quaternionf::make_rotation( Degreef{45.0f}, 1.0f, 0.0f, 0.0f )) };
70
71 assert( child_node );
72 assert( !child_node->parent().expired() );
73 assert( child_node->parent().lock() == node);
74 assert( child_node->parent().lock()->children().size() == 1 );
75 assert( child_node->parent().lock()->children().front() == child_node );
76 assert( node->children().size() == 1 );
77 assert( !node->children().empty() );
78 assert( std::ranges::find( node->children(), child_node ) != node->children().end() );
79 }
80}
81
86{
87 std::cout << __func__ << std::endl;
88
89 std::shared_ptr<SceneNodef> node = SceneNodef::make();
90 std::shared_ptr<SceneNodef> child_node{ node->createChildNode({ 1.0f, 2.0f, 3.0f }, Quaternionf::make_rotation( Degreef{45.0f}, 1.0f, 0.0f, 0.0f )) };
91
92 assert( std::ranges::find( node->children(), child_node ) != node->children().end() ); // child_node IS in node->children()
93 assert( !child_node->parent().expired() );
94 assert( child_node->parent().use_count() == 1 );
95 assert( child_node->parent().lock() == node );
96
97 node->detachChild( child_node );
98
99 assert( std::ranges::find( node->children(), child_node ) == node->children().end() ); // No longer in node's children()
100 assert( child_node->parent().expired() );
101 assert( child_node->parent().use_count() == 0 );
102}
103
108{
109 std::cout << __func__ << std::endl;
110
111 std::shared_ptr<SceneNodef> node = SceneNodef::make();
112 std::shared_ptr<SceneNodef> child_node = SceneNodef::make();
113
114 assert( std::ranges::find(node->children(), child_node) == node->children().end() ); // child_node is not in node's children()
115 assert( child_node->parent().expired() );
116 assert( child_node->parent().use_count() == 0 );
117
118 node->attachChild(child_node);
119
120 assert( std::ranges::find(node->children(), child_node) != node->children().end() ); // child_node IS in node's children()
121 assert( !child_node->parent().expired() );
122 assert( child_node->parent().use_count() == 1 );
123 assert( child_node->parent().lock() == node );
124}
125
129void Run()
130{
131 std::cout << "Running SceneNode Tests..." << std::endl;
132
135 DetachChild();
136 AttachChild();
137
138 std::cout << "PASSED!" << std::endl;
139}
140}
142
143int main(void)
144{
146 return EXIT_SUCCESS;
147}
int main(void)
Definition Angle.hpp:16
void DefaultConstructedState()
void CanCreateChildNode()