lltiming_tut.cpp

Go to the documentation of this file.
00001 
00033 #include "linden_common.h"
00034 #include "lltut.h"
00035 
00036 #include "llframetimer.h"
00037 #include "llsd.h"
00038 
00039 namespace tut
00040 {
00041         struct frametimer_test
00042         {
00043                 frametimer_test()
00044                 {
00045                         LLFrameTimer::updateFrameTime();                        
00046                 }
00047         };
00048         typedef test_group<frametimer_test> frametimer_group_t;
00049         typedef frametimer_group_t::object frametimer_object_t;
00050         tut::frametimer_group_t frametimer_instance("frametimer");
00051 
00052         template<> template<>
00053         void frametimer_object_t::test<1>()
00054         {
00055                 F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
00056                 LLFrameTimer timer;
00057                 timer.setExpiryAt(seconds_since_epoch);
00058                 F64 expires_at = timer.expiresAt();
00059                 ensure_distance(
00060                         "set expiry matches get expiry",
00061                         expires_at,
00062                         seconds_since_epoch,
00063                         0.001);
00064         }
00065 
00066         template<> template<>
00067         void frametimer_object_t::test<2>()
00068         {
00069                 F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
00070                 seconds_since_epoch += 10.0;
00071                 LLFrameTimer timer;
00072                 timer.setExpiryAt(seconds_since_epoch);
00073                 F64 expires_at = timer.expiresAt();
00074                 ensure_distance(
00075                         "set expiry matches get expiry 1",
00076                         expires_at,
00077                         seconds_since_epoch,
00078                         0.001);
00079                 seconds_since_epoch += 10.0;
00080                 timer.setExpiryAt(seconds_since_epoch);
00081                 expires_at = timer.expiresAt();
00082                 ensure_distance(
00083                         "set expiry matches get expiry 2",
00084                         expires_at,
00085                         seconds_since_epoch,
00086                         0.001);
00087         }
00088         template<> template<>
00089         void frametimer_object_t::test<3>()
00090         {
00091                 F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
00092                 seconds_since_epoch += 2.0;
00093                 LLFrameTimer timer;
00094                 timer.setExpiryAt(seconds_since_epoch);
00095                 ensure("timer not expired on create", !timer.hasExpired());
00096                 int ii;
00097                 for(ii = 0; ii < 10; ++ii)
00098                 {
00099                         ms_sleep(150);
00100                         LLFrameTimer::updateFrameTime();                        
00101                 }
00102                 ensure("timer not expired after a bit", !timer.hasExpired());
00103                 for(ii = 0; ii < 10; ++ii)
00104                 {
00105                         ms_sleep(100);
00106                         LLFrameTimer::updateFrameTime();                        
00107                 }
00108                 ensure("timer expired", timer.hasExpired());
00109         }
00110 /*
00111         template<> template<>
00112         void frametimer_object_t::test<4>()
00113         {
00114         }
00115 */
00116 }

Generated on Thu Jul 1 06:09:19 2010 for Second Life Viewer by  doxygen 1.4.7