From 56e1b2990a17a06d3853b093a6c03741cefa83a0 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Tue, 22 Mar 2022 19:26:20 +0200 Subject: [PATCH] Node::clone tests --- nodeTest.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++- nodeTest.h | 31 ++++++++++++------ 2 files changed, 111 insertions(+), 11 deletions(-) diff --git a/nodeTest.cpp b/nodeTest.cpp index 11250d8..503926d 100644 --- a/nodeTest.cpp +++ b/nodeTest.cpp @@ -1,6 +1,10 @@ #include "nodeTest.h" -#include "node.h" +#include "bone.h" #include "root.h" +#include "skeleton.h" +#include "mesh.h" +#include "meshData.h" +#include "keyframeChannel.h" #include @@ -34,11 +38,96 @@ namespace vb01{ ancestorA->attachChild(ancestorB); ancestorB->attachChild(ancestorC); ancestorC->attachChild(ancestorD); + + originalA = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "A"); + originalB = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "B"); + originalC = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "C"); + originalD = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "D"); + + rootNode->attachChild(originalA); + originalA->attachChild(originalB); + originalA->attachChild(originalC); + originalC->attachChild(originalD); } void NodeTest::tearDown(){ } + void NodeTest::setupOriginalNodes(){ + + } + + void NodeTest::testClonedMeshes(){ + int numTris = 3; + u32 *indices = new u32[3 * 3]; + originalD->attachMesh(new Mesh(MeshData(nullptr, indices, numTris))); + + Node *clonedA = originalA->clone(); + vector clonedDescendands; + clonedA->getDescendants(clonedDescendands); + Node *clonedD = nullptr; + + for(Node *desc : clonedDescendands) + if(desc->getName() == "D"){ + clonedD = desc; + break; + } + + CPPUNIT_ASSERT(clonedD->getMesh(0)->getMeshBase().vertices == nullptr); + CPPUNIT_ASSERT(clonedD->getMesh(0)->getMeshBase().indices == indices); + CPPUNIT_ASSERT(clonedD->getMesh(0)->getMeshBase().numTris == numTris); + } + + void NodeTest::testClonedDrivers(){ + vector keyframes = vector{ + KeyframeChannel::createKeyframe(KeyframeInterpolation::LINEAR, 1, 1), + KeyframeChannel::createKeyframe(KeyframeInterpolation::LINEAR, 2, 2), + KeyframeChannel::createKeyframe(KeyframeInterpolation::LINEAR, 3, 3) + }; + KeyframeChannelType channelType = KeyframeChannelType::POS_X; + KeyframeChannel channel = KeyframeChannel::createKeyframeChannel(channelType, "D", keyframes); + Driver::VariableType driverType = Driver::POS_X; + Driver *driver = new Driver(nullptr, channel, driverType); + originalB->addDriver(driver); + + Node *clonedA = originalA->clone(); + vector clonedDescendands; + clonedA->getDescendants(clonedDescendands); + Node *clonedB = nullptr; + Node *clonedD = nullptr; + + for(Node *desc : clonedDescendands){ + if(desc->getName() == "B"){ + clonedB = desc; + break; + } + else if(desc->getName() == "D"){ + clonedD = desc; + break; + } + } + + Driver *driverClone = clonedB->getDriver(0); + CPPUNIT_ASSERT(driverClone->getAnimatable() == clonedD); + CPPUNIT_ASSERT(driverClone->getKeyframeChannel().type == channelType); + CPPUNIT_ASSERT(driverClone->getType() == driverType); + } + + void NodeTest::testClonedSkeletons(){ + Skeleton *skeleton = new Skeleton(); + skeleton->addBone((Bone*)originalC, nullptr); + skeleton->addBone((Bone*)originalD, nullptr); + originalA->addSkeleton(skeleton); + + Node *clonedA = originalA->clone(); + CPPUNIT_ASSERT(!empty(clonedA->getSkeletons())); + CPPUNIT_ASSERT(clonedA->getSkeleton(0)); + + Skeleton *clonedSkeleton = originalA->getSkeleton(0); + CPPUNIT_ASSERT(clonedSkeleton->getBone(0)->getName() == originalC->getName()); + CPPUNIT_ASSERT(clonedSkeleton->getBone(1)->getName() == originalD->getName()); + } + void NodeTest::testGetAncestors(){ vector ancestors = ancestorD->getAncestors(); CPPUNIT_ASSERT(ancestors[ancestors.size() - 1] == rootNode); diff --git a/nodeTest.h b/nodeTest.h index e4a6b18..989181e 100644 --- a/nodeTest.h +++ b/nodeTest.h @@ -9,6 +9,9 @@ namespace vb01{ class NodeTest : public CppUnit::TestFixture{ CPPUNIT_TEST_SUITE(NodeTest); + CPPUNIT_TEST(testClonedMeshes); + CPPUNIT_TEST(testClonedDrivers); + CPPUNIT_TEST(testClonedSkeletons); CPPUNIT_TEST(testGetAncestors); CPPUNIT_TEST(testAdjustDir); CPPUNIT_TEST(testAdjustUp); @@ -23,6 +26,10 @@ namespace vb01{ void setUp(); void tearDown(); private: + void setupOriginalNodes(); + void testClonedMeshes(); + void testClonedDrivers(); + void testClonedSkeletons(); void testAdjustDir(); void testAdjustUp(); void testDetachChild(); @@ -32,16 +39,20 @@ namespace vb01{ void testLocalToGlobalOrientation(); void testGlobalToLocalOrientation(); - Node *rootNode = nullptr, - *ancestorA = nullptr, - *ancestorB = nullptr, - *ancestorC = nullptr, - *ancestorD = nullptr, - *lookNodeParent = nullptr, - *lookNode = nullptr, - *firstChainNode = nullptr, - *secondChainNode = nullptr, - *thirdChainNode = nullptr; + Node *rootNode = nullptr; + Node *ancestorA = nullptr; + Node *ancestorB = nullptr; + Node *ancestorC = nullptr; + Node *ancestorD = nullptr; + Node *lookNodeParent = nullptr; + Node *lookNode = nullptr; + Node *firstChainNode = nullptr; + Node *secondChainNode = nullptr; + Node *thirdChainNode = nullptr; + Node *originalA = nullptr; + Node *originalB = nullptr; + Node *originalC = nullptr; + Node *originalD = nullptr; }; }