node test start

This commit is contained in:
devZoGok
2021-10-19 19:06:41 +03:00
parent 2a16c82be4
commit 532b1f6363
6 changed files with 194 additions and 7 deletions
+3 -1
View File
@@ -19,13 +19,15 @@ set(model modelReader.cpp assimpModelReader.cpp vbModelReader.cpp)
set(anim animationController.cpp animationChannel.cpp animation.cpp)
set(armature skeleton.cpp bone.cpp)
set(library ${render} ${math} ${model} ${utils} ${gui} ${armature} ${anim})
set(test cameraTest.cpp)
set(test cameraTest.cpp nodeTest.cpp)
add_library(vb01 SHARED ${library})
target_link_libraries(vb01 glfw)
target_link_libraries(vb01 glad)
target_link_libraries(vb01 assimp)
target_link_libraries(vb01 freetype)
add_executable(vb01Tests main.cpp ${test} ${library})
target_link_libraries(vb01Tests cppunit)
target_link_libraries(vb01Tests glfw)
+2 -3
View File
@@ -1,5 +1,5 @@
#include"cameraTest.h"
#include<cppunit/TestCase.h>
#include "cameraTest.h"
#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestCaller.h>
@@ -7,7 +7,6 @@
using namespace CppUnit;
namespace vb01{
CameraTest::CameraTest(){
}
+6 -3
View File
@@ -1,8 +1,9 @@
#ifndef CAMERA_TEST_H
#define CAMERA_TEST_H
#include<cppunit/TestFixture.h>
#include"camera.h"
#include "camera.h"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
namespace CppUnit{
@@ -14,12 +15,14 @@ namespace vb01{
CPPUNIT_TEST_SUITE( CameraTest );
CPPUNIT_TEST( testLookAt );
CPPUNIT_TEST_SUITE_END();
public:
CameraTest();
void setUp();
void tearDown();
void testLookAt();
private:
void testLookAt();
Camera *cam = nullptr;
};
}
+3
View File
@@ -2,7 +2,9 @@
#include <cppunit/TestResult.h>
#include <cppunit/TestCaller.h>
#include <cppunit/ui/text/TestRunner.h>
#include "cameraTest.h"
#include "nodeTest.h"
using namespace CppUnit;
using namespace vb01;
@@ -10,6 +12,7 @@ using namespace vb01;
int main(){
TextUi::TestRunner runner;
runner.addTest(CameraTest::suite());
runner.addTest(NodeTest::suite());
runner.run();
return 0;
}
+128
View File
@@ -0,0 +1,128 @@
#include "nodeTest.h"
#include "node.h"
#include "root.h"
#include <vector>
using namespace std;
namespace vb01{
NodeTest::NodeTest(){
}
void NodeTest::setUp(){
rootNode = Root::getSingleton()->getRootNode();
nodeA = new Node();
nodeB = new Node();
nodeC = new Node();
nodeD = new Node();
parentA = new Node();
childA0 = new Node();
childA1 = new Node();
childA2 = new Node();
parentA->attachChild(childA0);
parentA->attachChild(childA1);
parentA->attachChild(childA2);
parentB = new Node();
childB0 = new Node();
childB1 = new Node();
childB2 = new Node();
parentB->attachChild(childB0);
parentB->attachChild(childB1);
parentB->attachChild(childB2);
parentC = new Node();
childC0 = new Node();
childC1 = new Node();
childC2 = new Node();
parentC->attachChild(childC0);
parentC->attachChild(childC1);
parentC->attachChild(childC2);
parentD = new Node();
childD0 = new Node();
childD1 = new Node();
childD2 = new Node();
parentD->attachChild(childD0);
parentD->attachChild(childD1);
parentD->attachChild(childD2);
parentA->attachChild(parentB);
parentB->attachChild(parentC);
parentC->attachChild(parentD);
rootNode->attachChild(nodeA);
nodeA->attachChild(nodeB);
/*
nodeA->attachChild(nodeC);
nodeA->attachChild(nodeD);
*/
}
void NodeTest::tearDown(){
delete nodeD;
delete nodeC;
delete nodeB;
nodeA->dettachChild(nodeB);
delete nodeA;
}
void NodeTest::testDetachChild(){
nodeA->dettachChild(nodeB);
CPPUNIT_ASSERT(nodeA->getChild(0) != nodeB);
}
void NodeTest::testAdjustDir(){
float maxAngle = .001;
Vector3 dir[]{
Vector3(0, 1, 0),
Vector3(.8, .2, 0).norm(),
Vector3(-.6, 0, .9).norm(),
Vector3(0, -1, -.4).norm(),
Vector3(1, 1, 1).norm()
};
int numDirs = sizeof(dir) / sizeof(Vector3);
for(int i = 0; i < numDirs; i++){
nodeA->lookAt(dir[i], rootNode);
CPPUNIT_ASSERT(nodeA->getGlobalAxis(2).getAngleBetween(dir[i]) < maxAngle);
}
}
void NodeTest::testAdjustUp(){
float maxAngle = .001;
Vector3 dir[]{
Vector3(0, 1, 0),
Vector3(.8, .2, 0).norm(),
Vector3(-.6, 0, .9).norm(),
Vector3(0, -1, -.4).norm(),
Vector3(1, 1, 1).norm()
};
int numDirs = sizeof(dir) / sizeof(Vector3);
for(int i = 0; i < numDirs; i++){
/*
nodeA->lookAt(dir[i], rootNode);
CPPUNIT_ASSERT(nodeA->getGlobalAxis(2).getAngleBetween(dir[i]) < maxAngle);
*/
}
}
void NodeTest::testGetDescendants(){
vector<Node*> parentADescendants;
vector<Node*> parentBDescendants;
vector<Node*> parentCDescendants;
vector<Node*> parentDDescendants;
parentA->getDescendants(parentA, parentADescendants);
parentB->getDescendants(parentB, parentBDescendants);
parentC->getDescendants(parentC, parentCDescendants);
parentD->getDescendants(parentD, parentDDescendants);
parentD->getDescendants(parentD, parentDDescendants);
CPPUNIT_ASSERT(parentDDescendants[0] == childD0);
CPPUNIT_ASSERT(parentDDescendants[1] == childD1);
CPPUNIT_ASSERT(parentDDescendants[2] == childD2);
}
}
+52
View File
@@ -0,0 +1,52 @@
#ifndef NODE_TEST_H
#define NODE_TEST_H
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
namespace vb01{
class Node;
class NodeTest : public CppUnit::TestFixture{
CPPUNIT_TEST_SUITE(NodeTest);
//CPPUNIT_TEST(testDetachChild);
CPPUNIT_TEST(testAdjustDir);
CPPUNIT_TEST(testAdjustUp);
CPPUNIT_TEST(testGetDescendants);
CPPUNIT_TEST_SUITE_END();
public:
NodeTest();
void setUp();
void tearDown();
private:
void testAdjustDir();
void testAdjustUp();
void testDetachChild();
void testGetDescendants();
Node *rootNode = nullptr,
*parentA = nullptr,
*childA0 = nullptr,
*childA1 = nullptr,
*childA2 = nullptr,
*parentB = nullptr,
*childB0 = nullptr,
*childB1 = nullptr,
*childB2 = nullptr,
*parentC = nullptr,
*childC0 = nullptr,
*childC1 = nullptr,
*childC2 = nullptr,
*parentD = nullptr,
*childD0 = nullptr,
*childD1 = nullptr,
*childD2 = nullptr,
*nodeA = nullptr,
*nodeB = nullptr,
*nodeC = nullptr,
*nodeD = nullptr;
};
}
#endif