PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/tests/llframetimer_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 112 lines | 74 code | 6 blank | 32 comment | 2 complexity | 8505a82e1d40dacc24953b72b76e9768 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltiming_test.cpp
  3. * @date 2006-07-23
  4. * @brief Tests the timers.
  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. #include "linden_common.h"
  28. #include "../llframetimer.h"
  29. #include "../llsd.h"
  30. #include "../test/lltut.h"
  31. namespace tut
  32. {
  33. struct frametimer_test
  34. {
  35. frametimer_test()
  36. {
  37. LLFrameTimer::updateFrameTime();
  38. }
  39. };
  40. typedef test_group<frametimer_test> frametimer_group_t;
  41. typedef frametimer_group_t::object frametimer_object_t;
  42. tut::frametimer_group_t frametimer_instance("LLFrameTimer");
  43. template<> template<>
  44. void frametimer_object_t::test<1>()
  45. {
  46. F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
  47. LLFrameTimer timer;
  48. timer.setExpiryAt(seconds_since_epoch);
  49. F64 expires_at = timer.expiresAt();
  50. ensure_distance(
  51. "set expiry matches get expiry",
  52. expires_at,
  53. seconds_since_epoch,
  54. 0.001);
  55. }
  56. template<> template<>
  57. void frametimer_object_t::test<2>()
  58. {
  59. F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
  60. seconds_since_epoch += 10.0;
  61. LLFrameTimer timer;
  62. timer.setExpiryAt(seconds_since_epoch);
  63. F64 expires_at = timer.expiresAt();
  64. ensure_distance(
  65. "set expiry matches get expiry 1",
  66. expires_at,
  67. seconds_since_epoch,
  68. 0.001);
  69. seconds_since_epoch += 10.0;
  70. timer.setExpiryAt(seconds_since_epoch);
  71. expires_at = timer.expiresAt();
  72. ensure_distance(
  73. "set expiry matches get expiry 2",
  74. expires_at,
  75. seconds_since_epoch,
  76. 0.001);
  77. }
  78. template<> template<>
  79. void frametimer_object_t::test<3>()
  80. {
  81. F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
  82. seconds_since_epoch += 2.0;
  83. LLFrameTimer timer;
  84. timer.setExpiryAt(seconds_since_epoch);
  85. ensure("timer not expired on create", !timer.hasExpired());
  86. int ii;
  87. for(ii = 0; ii < 10; ++ii)
  88. {
  89. ms_sleep(150);
  90. LLFrameTimer::updateFrameTime();
  91. }
  92. ensure("timer not expired after a bit", !timer.hasExpired());
  93. for(ii = 0; ii < 10; ++ii)
  94. {
  95. ms_sleep(100);
  96. LLFrameTimer::updateFrameTime();
  97. }
  98. ensure("timer expired", timer.hasExpired());
  99. }
  100. /*
  101. template<> template<>
  102. void frametimer_object_t::test<4>()
  103. {
  104. }
  105. */
  106. }