PageRenderTime 1206ms CodeModel.GetById 33ms RepoModel.GetById 8ms 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
Possible License(s): LGPL-2.1
  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. #include "linden_common.h"
  29. #include "m4math.h"
  30. #include "v3math.h"
  31. #include "../lljoint.h"
  32. #include "../test/lltut.h"
  33. namespace tut
  34. {
  35. struct lljoint_data
  36. {
  37. };
  38. typedef test_group<lljoint_data> lljoint_test;
  39. typedef lljoint_test::object lljoint_object;
  40. tut::lljoint_test lljoint_testcase("LLJoint");
  41. template<> template<>
  42. void lljoint_object::test<1>()
  43. {
  44. LLJoint lljoint;
  45. LLJoint* jnt = lljoint.getParent();
  46. ensure("getParent() failed ", (NULL == jnt));
  47. ensure("getRoot() failed ", (&lljoint == lljoint.getRoot()));
  48. }
  49. template<> template<>
  50. void lljoint_object::test<2>()
  51. {
  52. std::string str = "LLJoint";
  53. LLJoint parent(str), child;
  54. child.setup(str, &parent);
  55. LLJoint* jnt = child.getParent();
  56. ensure("setup() failed ", (&parent == jnt));
  57. }
  58. template<> template<>
  59. void lljoint_object::test<3>()
  60. {
  61. LLJoint parent, child;
  62. std::string str = "LLJoint";
  63. child.setup(str, &parent);
  64. LLJoint* jnt = parent.findJoint(str);
  65. ensure("findJoint() failed ", (&child == jnt));
  66. }
  67. template<> template<>
  68. void lljoint_object::test<4>()
  69. {
  70. LLJoint parent;
  71. std::string str1 = "LLJoint", str2;
  72. parent.setName(str1);
  73. str2 = parent.getName();
  74. ensure("setName() failed ", (str1 == str2));
  75. }
  76. template<> template<>
  77. void lljoint_object::test<5>()
  78. {
  79. LLJoint lljoint;
  80. LLVector3 vec3(2.3f,30.f,10.f);
  81. lljoint.setPosition(vec3);
  82. LLVector3 pos = lljoint.getPosition();
  83. ensure("setPosition()/getPosition() failed ", (vec3 == pos));
  84. }
  85. template<> template<>
  86. void lljoint_object::test<6>()
  87. {
  88. LLJoint lljoint;
  89. LLVector3 vec3(2.3f,30.f,10.f);
  90. lljoint.setWorldPosition(vec3);
  91. LLVector3 pos = lljoint.getWorldPosition();
  92. ensure("1:setWorldPosition()/getWorldPosition() failed ", (vec3 == pos));
  93. LLVector3 lastPos = lljoint.getLastWorldPosition();
  94. ensure("2:getLastWorldPosition failed ", (vec3 == lastPos));
  95. }
  96. template<> template<>
  97. void lljoint_object::test<7>()
  98. {
  99. LLJoint lljoint("LLJoint");
  100. LLQuaternion q(2.3f,30.f,10.f,1.f);
  101. lljoint.setRotation(q);
  102. LLQuaternion rot = lljoint.getRotation();
  103. ensure("setRotation()/getRotation() failed ", (q == rot));
  104. }
  105. template<> template<>
  106. void lljoint_object::test<8>()
  107. {
  108. LLJoint lljoint("LLJoint");
  109. LLQuaternion q(2.3f,30.f,10.f,1.f);
  110. lljoint.setWorldRotation(q);
  111. LLQuaternion rot = lljoint.getWorldRotation();
  112. ensure("1:setWorldRotation()/getWorldRotation() failed ", (q == rot));
  113. LLQuaternion lastRot = lljoint.getLastWorldRotation();
  114. ensure("2:getLastWorldRotation failed ", (q == lastRot));
  115. }
  116. template<> template<>
  117. void lljoint_object::test<9>()
  118. {
  119. LLJoint lljoint;
  120. LLVector3 vec3(2.3f,30.f,10.f);
  121. lljoint.setScale(vec3);
  122. LLVector3 scale = lljoint.getScale();
  123. ensure("setScale()/getScale failed ", (vec3 == scale));
  124. }
  125. template<> template<>
  126. void lljoint_object::test<10>()
  127. {
  128. LLJoint lljoint("LLJoint");
  129. LLMatrix4 mat;
  130. mat.setIdentity();
  131. lljoint.setWorldMatrix(mat);//giving warning setWorldMatrix not correctly implemented;
  132. LLMatrix4 mat4 = lljoint.getWorldMatrix();
  133. ensure("setWorldMatrix()/getWorldMatrix failed ", (mat4 == mat));
  134. }
  135. template<> template<>
  136. void lljoint_object::test<11>()
  137. {
  138. LLJoint lljoint("parent");
  139. S32 joint_num = 12;
  140. lljoint.setJointNum(joint_num);
  141. S32 jointNum = lljoint.getJointNum();
  142. ensure("setJointNum()/getJointNum failed ", (jointNum == joint_num));
  143. }
  144. template<> template<>
  145. void lljoint_object::test<12>()
  146. {
  147. LLJoint lljoint;
  148. LLVector3 vec3(2.3f,30.f,10.f);
  149. lljoint.setSkinOffset(vec3);
  150. LLVector3 offset = lljoint.getSkinOffset();
  151. ensure("1:setSkinOffset()/getSkinOffset() failed ", (vec3 == offset));
  152. }
  153. template<> template<>
  154. void lljoint_object::test<13>()
  155. {
  156. LLJoint lljointgp("gparent");
  157. LLJoint lljoint("parent");
  158. LLJoint lljoint1("child1");
  159. lljoint.addChild(&lljoint1);
  160. LLJoint lljoint2("child2");
  161. lljoint.addChild(&lljoint2);
  162. LLJoint lljoint3("child3");
  163. lljoint.addChild(&lljoint3);
  164. LLJoint* jnt = NULL;
  165. jnt = lljoint2.getParent();
  166. ensure("addChild() failed ", (&lljoint == jnt));
  167. LLJoint* jnt1 = lljoint.findJoint("child3");
  168. ensure("findJoint() failed ", (&lljoint3 == jnt1));
  169. lljoint.removeChild(&lljoint3);
  170. LLJoint* jnt2 = lljoint.findJoint("child3");
  171. ensure("removeChild() failed ", (NULL == jnt2));
  172. lljointgp.addChild(&lljoint);
  173. ensure("GetParent() failed ", (&lljoint== lljoint2.getParent()));
  174. ensure("getRoot() failed ", (&lljointgp == lljoint2.getRoot()));
  175. ensure("getRoot() failed ", &lljoint1 == lljoint.findJoint("child1"));
  176. lljointgp.removeAllChildren();
  177. // parent removed from grandparent - so should not be able to locate child
  178. ensure("removeAllChildren() failed ", (NULL == lljointgp.findJoint("child1")));
  179. // it should still exist in parent though
  180. ensure("removeAllChildren() failed ", (&lljoint1 == lljoint.findJoint("child1")));
  181. }
  182. template<> template<>
  183. void lljoint_object::test<14>()
  184. {
  185. LLJoint lljointgp("gparent");
  186. LLJoint llparent1("parent1");
  187. LLJoint llparent2("parent2");
  188. LLJoint llchild("child1");
  189. LLJoint lladoptedchild("child2");
  190. llparent1.addChild(&llchild);
  191. llparent1.addChild(&lladoptedchild);
  192. llparent2.addChild(&lladoptedchild);
  193. ensure("1. addChild failed to remove prior parent", lladoptedchild.getParent() == &llparent2);
  194. ensure("2. addChild failed to remove prior parent", llparent1.findJoint("child2") == NULL);
  195. }
  196. /*
  197. Test cases for the following not added. They perform operations
  198. on underlying LLXformMatrix and LLVector3 elements which have
  199. been unit tested separately.
  200. Unit Testing these functions will basically require re-implementing
  201. logic of these function in the test case itself
  202. 1) void WorldMatrixChildren();
  203. 2) void updateWorldMatrixParent();
  204. 3) void updateWorldPRSParent();
  205. 4) void updateWorldMatrix();
  206. 5) LLXformMatrix *getXform() { return &mXform; }
  207. 6) void setConstraintSilhouette(LLDynamicArray<LLVector3>& silhouette);
  208. 7) void clampRotation(LLQuaternion old_rot, LLQuaternion new_rot);
  209. */
  210. }