/indra/llprimitive/tests/llprimitive_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 231 lines · 141 code · 43 blank · 47 comment · 23 complexity · 94a44f3cf9f23c8ff4020cf72e523c34 MD5 · raw file

  1. /**
  2. * @file llprimitive_test.cpp
  3. * @brief llprimitive tests
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "../test/lltut.h"
  28. #include "../llprimitive.h"
  29. #include "../../llmath/llvolumemgr.h"
  30. class DummyVolumeMgr : public LLVolumeMgr
  31. {
  32. public:
  33. DummyVolumeMgr() : LLVolumeMgr(), mVolumeTest(NULL), mCurrDetailTest(0) {}
  34. ~DummyVolumeMgr()
  35. {
  36. }
  37. virtual LLVolume *refVolume(const LLVolumeParams &volume_params, const S32 detail)
  38. {
  39. if (mVolumeTest.isNull() || volume_params != mCurrParamsTest || detail != mCurrDetailTest)
  40. {
  41. F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
  42. mVolumeTest = new LLVolume(volume_params, volume_detail, FALSE, FALSE);
  43. mCurrParamsTest = volume_params;
  44. mCurrDetailTest = detail;
  45. return mVolumeTest;
  46. }
  47. else
  48. {
  49. return mVolumeTest;
  50. }
  51. }
  52. virtual void unrefVolume(LLVolume *volumep)
  53. {
  54. if (mVolumeTest == volumep)
  55. {
  56. mVolumeTest = NULL;
  57. }
  58. }
  59. private:
  60. LLPointer<LLVolume> mVolumeTest;
  61. LLVolumeParams mCurrParamsTest;
  62. S32 mCurrDetailTest;
  63. };
  64. class PRIMITIVE_TEST_SETUP
  65. {
  66. public:
  67. PRIMITIVE_TEST_SETUP()
  68. {
  69. volume_manager_test = new DummyVolumeMgr();
  70. LLPrimitive::setVolumeManager(volume_manager_test);
  71. }
  72. ~PRIMITIVE_TEST_SETUP()
  73. {
  74. LLPrimitive::cleanupVolumeManager();
  75. }
  76. DummyVolumeMgr * volume_manager_test;
  77. };
  78. namespace tut
  79. {
  80. struct llprimitive
  81. {
  82. PRIMITIVE_TEST_SETUP setup_class;
  83. };
  84. typedef test_group<llprimitive> llprimitive_t;
  85. typedef llprimitive_t::object llprimitive_object_t;
  86. tut::llprimitive_t tut_llprimitive("LLPrimitive");
  87. template<> template<>
  88. void llprimitive_object_t::test<1>()
  89. {
  90. set_test_name("Test LLPrimitive Instantiation");
  91. LLPrimitive test;
  92. }
  93. template<> template<>
  94. void llprimitive_object_t::test<2>()
  95. {
  96. set_test_name("Test LLPrimitive PCode setter and getter.");
  97. LLPrimitive test;
  98. ensure_equals(test.getPCode(), 0);
  99. LLPCode code = 1;
  100. test.setPCode(code);
  101. ensure_equals(test.getPCode(), code);
  102. }
  103. template<> template<>
  104. void llprimitive_object_t::test<3>()
  105. {
  106. set_test_name("Test llprimitive constructor and initer.");
  107. LLPCode code = 1;
  108. LLPrimitive primitive;
  109. primitive.init_primitive(code);
  110. ensure_equals(primitive.getPCode(), code);
  111. }
  112. template<> template<>
  113. void llprimitive_object_t::test<4>()
  114. {
  115. set_test_name("Test Static llprimitive constructor and initer.");
  116. LLPCode code = 1;
  117. LLPrimitive * primitive = LLPrimitive::createPrimitive(code);
  118. ensure(primitive != NULL);
  119. ensure_equals(primitive->getPCode(), code);
  120. }
  121. template<> template<>
  122. void llprimitive_object_t::test<5>()
  123. {
  124. set_test_name("Test setVolume creation of new unique volume.");
  125. LLPrimitive primitive;
  126. LLVolumeParams params;
  127. // Make sure volume starts off null
  128. ensure(primitive.getVolume() == NULL);
  129. // Make sure we have no texture entries before setting the volume
  130. ensure_equals(primitive.getNumTEs(), 0);
  131. // Test that GEOMETRY has not been flagged as changed.
  132. ensure(!primitive.isChanged(LLXform::GEOMETRY));
  133. // Make sure setVolume returns true
  134. ensure(primitive.setVolume(params, 0, true) == TRUE);
  135. LLVolume* new_volume = primitive.getVolume();
  136. // make sure new volume was actually created
  137. ensure(new_volume != NULL);
  138. // Make sure that now that we've set the volume we have texture entries
  139. ensure_not_equals(primitive.getNumTEs(), 0);
  140. // Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
  141. ensure_equals(new_volume->getNumFaces(), 6);
  142. ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
  143. // Test that GEOMETRY has been flagged as changed.
  144. ensure(primitive.isChanged(LLXform::GEOMETRY));
  145. // Run it twice to make sure it doesn't create a different one if params are the same
  146. ensure(primitive.setVolume(params, 0, true) == FALSE);
  147. ensure(new_volume == primitive.getVolume());
  148. // Change the param definition and try setting it again.
  149. params.setRevolutions(4);
  150. ensure(primitive.setVolume(params, 0, true) == TRUE);
  151. // Ensure that we now have a different volume
  152. ensure(new_volume != primitive.getVolume());
  153. }
  154. template<> template<>
  155. void llprimitive_object_t::test<6>()
  156. {
  157. set_test_name("Test setVolume creation of new NOT-unique volume.");
  158. LLPrimitive primitive;
  159. LLVolumeParams params;
  160. // Make sure volume starts off null
  161. ensure(primitive.getVolume() == NULL);
  162. // Make sure we have no texture entries before setting the volume
  163. ensure_equals(primitive.getNumTEs(), 0);
  164. // Test that GEOMETRY has not been flagged as changed.
  165. ensure(!primitive.isChanged(LLXform::GEOMETRY));
  166. // Make sure setVolume returns true
  167. ensure(primitive.setVolume(params, 0, false) == TRUE);
  168. LLVolume* new_volume = primitive.getVolume();
  169. // make sure new volume was actually created
  170. ensure(new_volume != NULL);
  171. // Make sure that now that we've set the volume we have texture entries
  172. ensure_not_equals(primitive.getNumTEs(), 0);
  173. // Make sure that the number of texture entries equals the number of faces in the volume (should be 6)
  174. ensure_equals(new_volume->getNumFaces(), 6);
  175. ensure_equals(primitive.getNumTEs(), new_volume->getNumFaces());
  176. // Test that GEOMETRY has been flagged as changed.
  177. ensure(primitive.isChanged(LLXform::GEOMETRY));
  178. // Run it twice to make sure it doesn't create a different one if params are the same
  179. ensure(primitive.setVolume(params, 0, false) == FALSE);
  180. ensure(new_volume == primitive.getVolume());
  181. // Change the param definition and try setting it again.
  182. params.setRevolutions(4);
  183. ensure(primitive.setVolume(params, 0, false) == TRUE);
  184. // Ensure that we now have a different volume
  185. ensure(new_volume != primitive.getVolume());
  186. }
  187. }
  188. #include "llmessagesystem_stub.cpp"