PageRenderTime 76ms CodeModel.GetById 26ms app.highlight 45ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcharacter/tests/lljoint_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 240 lines | 167 code | 28 blank | 45 comment | 24 complexity | a1a1a8b67afd8dbd62ae91949608a388 MD5 | raw file
  1/**
  2 * @file lljoint_test.cpp
  3 * @author Adroit
  4 * @date 2007-03
  5 * @brief lljoint test cases.
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "linden_common.h"
 30#include "m4math.h"
 31#include "v3math.h"
 32
 33#include "../lljoint.h"
 34
 35#include "../test/lltut.h"
 36
 37
 38namespace tut
 39{
 40	struct lljoint_data
 41	{
 42	};
 43	typedef test_group<lljoint_data> lljoint_test;
 44	typedef lljoint_test::object lljoint_object;
 45	tut::lljoint_test lljoint_testcase("LLJoint");
 46
 47	template<> template<>
 48	void lljoint_object::test<1>()
 49	{
 50		LLJoint lljoint;
 51		LLJoint* jnt = lljoint.getParent();
 52		ensure("getParent() failed ", (NULL == jnt));
 53		ensure("getRoot() failed ", (&lljoint == lljoint.getRoot()));
 54	}
 55
 56	template<> template<>
 57	void lljoint_object::test<2>()
 58	{
 59		std::string str = "LLJoint";
 60		LLJoint parent(str), child;
 61		child.setup(str, &parent);
 62		LLJoint* jnt = child.getParent();
 63		ensure("setup() failed ", (&parent == jnt));
 64	}
 65
 66	template<> template<>
 67	void lljoint_object::test<3>()
 68	{
 69		LLJoint parent, child;
 70		std::string str = "LLJoint";
 71		child.setup(str, &parent);
 72		LLJoint* jnt = parent.findJoint(str);
 73		ensure("findJoint() failed ", (&child == jnt));
 74	}
 75
 76	template<> template<>
 77	void lljoint_object::test<4>()
 78	{
 79		LLJoint parent;
 80		std::string str1 = "LLJoint", str2;
 81		parent.setName(str1);
 82		str2 = parent.getName();
 83		ensure("setName() failed ", (str1 == str2));
 84	}
 85
 86	template<> template<>
 87	void lljoint_object::test<5>()
 88	{
 89		LLJoint lljoint;
 90		LLVector3 vec3(2.3f,30.f,10.f);
 91		lljoint.setPosition(vec3);
 92		LLVector3 pos = lljoint.getPosition();
 93		ensure("setPosition()/getPosition() failed ", (vec3 == pos));
 94	}
 95
 96	template<> template<>
 97	void lljoint_object::test<6>()
 98	{
 99		LLJoint lljoint;
100		LLVector3 vec3(2.3f,30.f,10.f);
101		lljoint.setWorldPosition(vec3);
102		LLVector3 pos = lljoint.getWorldPosition();
103		ensure("1:setWorldPosition()/getWorldPosition() failed ", (vec3 == pos));
104		LLVector3 lastPos = lljoint.getLastWorldPosition();
105		ensure("2:getLastWorldPosition failed ", (vec3 == lastPos));
106	}
107	
108	template<> template<>
109	void lljoint_object::test<7>()
110	{
111		LLJoint lljoint("LLJoint");
112		LLQuaternion q(2.3f,30.f,10.f,1.f);
113		lljoint.setRotation(q);
114		LLQuaternion rot = lljoint.getRotation();
115		ensure("setRotation()/getRotation() failed ", (q == rot));
116	}
117	template<> template<>
118	void lljoint_object::test<8>()
119	{
120		LLJoint lljoint("LLJoint");
121		LLQuaternion q(2.3f,30.f,10.f,1.f);
122		lljoint.setWorldRotation(q);
123		LLQuaternion rot = lljoint.getWorldRotation();
124		ensure("1:setWorldRotation()/getWorldRotation() failed ", (q == rot));
125		LLQuaternion lastRot = lljoint.getLastWorldRotation();
126		ensure("2:getLastWorldRotation failed ", (q == lastRot));
127	}
128
129	template<> template<>
130	void lljoint_object::test<9>()
131	{
132		LLJoint lljoint;
133		LLVector3 vec3(2.3f,30.f,10.f);
134		lljoint.setScale(vec3);
135		LLVector3 scale = lljoint.getScale();
136		ensure("setScale()/getScale failed ", (vec3 == scale));
137	}
138
139	template<> template<>
140	void lljoint_object::test<10>()
141	{
142		LLJoint lljoint("LLJoint");
143		LLMatrix4 mat;
144		mat.setIdentity();
145		lljoint.setWorldMatrix(mat);//giving warning setWorldMatrix not correctly implemented;
146		LLMatrix4 mat4 = lljoint.getWorldMatrix();
147		ensure("setWorldMatrix()/getWorldMatrix failed ", (mat4 == mat));
148	}
149
150	template<> template<>
151	void lljoint_object::test<11>()
152	{
153		LLJoint lljoint("parent");
154		S32 joint_num = 12;
155		lljoint.setJointNum(joint_num);
156		S32 jointNum = 	lljoint.getJointNum();
157		ensure("setJointNum()/getJointNum failed ", (jointNum == joint_num));
158	}
159
160	template<> template<>
161	void lljoint_object::test<12>()
162	{
163		LLJoint lljoint;
164		LLVector3 vec3(2.3f,30.f,10.f);
165		lljoint.setSkinOffset(vec3);
166		LLVector3 offset = lljoint.getSkinOffset();
167		ensure("1:setSkinOffset()/getSkinOffset() failed ", (vec3 == offset));
168	}
169
170	template<> template<>
171	void lljoint_object::test<13>()
172	{
173		LLJoint lljointgp("gparent");
174		LLJoint lljoint("parent");
175		LLJoint lljoint1("child1");
176		lljoint.addChild(&lljoint1);
177		LLJoint lljoint2("child2");
178		lljoint.addChild(&lljoint2);
179		LLJoint lljoint3("child3");
180		lljoint.addChild(&lljoint3);
181
182		LLJoint* jnt = NULL;
183		jnt = lljoint2.getParent();
184		ensure("addChild() failed ", (&lljoint == jnt));
185		LLJoint* jnt1 = lljoint.findJoint("child3");
186		ensure("findJoint() failed ", (&lljoint3 == jnt1));
187		lljoint.removeChild(&lljoint3);
188		LLJoint* jnt2 = lljoint.findJoint("child3");
189		ensure("removeChild() failed ", (NULL == jnt2));
190
191		lljointgp.addChild(&lljoint);
192		ensure("GetParent() failed ", (&lljoint== lljoint2.getParent()));
193		ensure("getRoot() failed ", (&lljointgp == lljoint2.getRoot()));
194
195		ensure("getRoot() failed ", &lljoint1 == lljoint.findJoint("child1"));
196
197		lljointgp.removeAllChildren();
198		// parent removed from grandparent - so should not be able to locate child
199		ensure("removeAllChildren() failed ", (NULL == lljointgp.findJoint("child1")));
200		// it should still exist in parent though
201		ensure("removeAllChildren() failed ", (&lljoint1 == lljoint.findJoint("child1")));
202	}
203
204	template<> template<>
205	void lljoint_object::test<14>()
206	{
207		LLJoint lljointgp("gparent");
208		
209		LLJoint llparent1("parent1");
210		LLJoint llparent2("parent2");
211
212		LLJoint llchild("child1");
213		LLJoint lladoptedchild("child2");
214		llparent1.addChild(&llchild);
215		llparent1.addChild(&lladoptedchild);
216
217		llparent2.addChild(&lladoptedchild);
218		ensure("1. addChild failed to remove prior parent", lladoptedchild.getParent() == &llparent2);
219		ensure("2. addChild failed to remove prior parent", llparent1.findJoint("child2") == NULL);
220	}
221
222
223	/*
224		Test cases for the following not added. They perform operations 
225		on underlying LLXformMatrix	and LLVector3 elements which have
226		been unit tested separately. 
227		Unit Testing these functions will basically require re-implementing
228		logic of these function in the test case itself
229
230		1) void WorldMatrixChildren();
231        2) void updateWorldMatrixParent();
232        3) void updateWorldPRSParent();
233        4) void updateWorldMatrix();
234        5) LLXformMatrix *getXform() { return &mXform; }
235        6) void setConstraintSilhouette(LLDynamicArray<LLVector3>& silhouette);
236        7) void clampRotation(LLQuaternion old_rot, LLQuaternion new_rot);
237
238	*/
239}
240