PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/tests/llworldmipmap_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 165 lines | 92 code | 9 blank | 64 comment | 9 complexity | 000dc87bd49151e07fd58224063a721f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llworldmipmap_test.cpp
  3. * @author Merov Linden
  4. * @date 2009-02-03
  5. *
  6. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. // Dependencies
  28. #include "linden_common.h"
  29. #include "../llviewertexture.h"
  30. #include "../llviewercontrol.h"
  31. // Class to test
  32. #include "../llworldmipmap.h"
  33. // Tut header
  34. #include "../test/lltut.h"
  35. // -------------------------------------------------------------------------------------------
  36. // Stubbing: Declarations required to link and run the class being tested
  37. // Notes:
  38. // * Add here stubbed implementation of the few classes and methods used in the class to be tested
  39. // * Add as little as possible (let the link errors guide you)
  40. // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code)
  41. // * A simulator for a class can be implemented here. Please comment and document thoroughly.
  42. void LLViewerTexture::setBoostLevel(S32 ) { }
  43. LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromUrl(const std::string&, BOOL, LLViewerTexture::EBoostLevel, S8,
  44. LLGLint, LLGLenum, const LLUUID& ) { return NULL; }
  45. LLControlGroup::LLControlGroup(const std::string& name) : LLInstanceTracker<LLControlGroup, std::string>(name) { }
  46. LLControlGroup::~LLControlGroup() { }
  47. std::string LLControlGroup::getString(const std::string& ) { return std::string("test_url"); }
  48. LLControlGroup gSavedSettings("test_settings");
  49. // End Stubbing
  50. // -------------------------------------------------------------------------------------------
  51. // -------------------------------------------------------------------------------------------
  52. // TUT
  53. // -------------------------------------------------------------------------------------------
  54. namespace tut
  55. {
  56. // Test wrapper declaration
  57. struct worldmipmap_test
  58. {
  59. // Derived test class
  60. class LLTestWorldMipmap : public LLWorldMipmap
  61. {
  62. // Put here stubbs of virtual methods we shouldn't call all the way down
  63. };
  64. // Instance to be tested
  65. LLTestWorldMipmap* mMap;
  66. // Constructor and destructor of the test wrapper
  67. worldmipmap_test()
  68. {
  69. mMap = new LLTestWorldMipmap;
  70. }
  71. ~worldmipmap_test()
  72. {
  73. delete mMap;
  74. }
  75. };
  76. // Tut templating thingamagic: test group, object and test instance
  77. typedef test_group<worldmipmap_test> worldmipmap_t;
  78. typedef worldmipmap_t::object worldmipmap_object_t;
  79. tut::worldmipmap_t tut_worldmipmap("LLWorldMipmap");
  80. // ---------------------------------------------------------------------------------------
  81. // Test functions
  82. // Notes:
  83. // * Test as many as you possibly can without requiring a full blown simulation of everything
  84. // * The tests are executed in sequence so the test instance state may change between calls
  85. // * Remember that you cannot test private methods with tut
  86. // ---------------------------------------------------------------------------------------
  87. // Test static methods
  88. // Test 1 : scaleToLevel()
  89. template<> template<>
  90. void worldmipmap_object_t::test<1>()
  91. {
  92. S32 level = mMap->scaleToLevel(0.0);
  93. ensure("scaleToLevel() test 1 failed", level == LLWorldMipmap::MAP_LEVELS);
  94. level = mMap->scaleToLevel(LLWorldMipmap::MAP_TILE_SIZE);
  95. ensure("scaleToLevel() test 2 failed", level == 1);
  96. level = mMap->scaleToLevel(10 * LLWorldMipmap::MAP_TILE_SIZE);
  97. ensure("scaleToLevel() test 3 failed", level == 1);
  98. }
  99. // Test 2 : globalToMipmap()
  100. template<> template<>
  101. void worldmipmap_object_t::test<2>()
  102. {
  103. U32 grid_x, grid_y;
  104. mMap->globalToMipmap(1000.f*REGION_WIDTH_METERS, 1000.f*REGION_WIDTH_METERS, 1, &grid_x, &grid_y);
  105. ensure("globalToMipmap() test 1 failed", (grid_x == 1000) && (grid_y == 1000));
  106. mMap->globalToMipmap(0.0, 0.0, LLWorldMipmap::MAP_LEVELS, &grid_x, &grid_y);
  107. ensure("globalToMipmap() test 2 failed", (grid_x == 0) && (grid_y == 0));
  108. }
  109. // Test 3 : getObjectsTile()
  110. template<> template<>
  111. void worldmipmap_object_t::test<3>()
  112. {
  113. // Depends on some inline methods in LLViewerImage... Thinking about how to make this work
  114. // LLPointer<LLViewerImage> img = mMap->getObjectsTile(0, 0, 1);
  115. // ensure("getObjectsTile() test failed", img.isNull());
  116. }
  117. // Test 4 : equalizeBoostLevels()
  118. template<> template<>
  119. void worldmipmap_object_t::test<4>()
  120. {
  121. try
  122. {
  123. mMap->equalizeBoostLevels();
  124. }
  125. catch (...)
  126. {
  127. fail("equalizeBoostLevels() test failed");
  128. }
  129. }
  130. // Test 5 : dropBoostLevels()
  131. template<> template<>
  132. void worldmipmap_object_t::test<5>()
  133. {
  134. try
  135. {
  136. mMap->dropBoostLevels();
  137. }
  138. catch (...)
  139. {
  140. fail("dropBoostLevels() test failed");
  141. }
  142. }
  143. // Test 6 : reset()
  144. template<> template<>
  145. void worldmipmap_object_t::test<6>()
  146. {
  147. try
  148. {
  149. mMap->reset();
  150. }
  151. catch (...)
  152. {
  153. fail("reset() test failed");
  154. }
  155. }
  156. }