PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 1ms 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
  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
 28#include "linden_common.h"
 29
 30#include "../llframetimer.h"
 31#include "../llsd.h"
 32
 33#include "../test/lltut.h"
 34
 35namespace tut
 36{
 37	struct frametimer_test
 38	{
 39		frametimer_test()
 40		{
 41			LLFrameTimer::updateFrameTime();			
 42		}
 43	};
 44	typedef test_group<frametimer_test> frametimer_group_t;
 45	typedef frametimer_group_t::object frametimer_object_t;
 46	tut::frametimer_group_t frametimer_instance("LLFrameTimer");
 47
 48	template<> template<>
 49	void frametimer_object_t::test<1>()
 50	{
 51		F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
 52		LLFrameTimer timer;
 53		timer.setExpiryAt(seconds_since_epoch);
 54		F64 expires_at = timer.expiresAt();
 55		ensure_distance(
 56			"set expiry matches get expiry",
 57			expires_at,
 58			seconds_since_epoch,
 59			0.001);
 60	}
 61
 62	template<> template<>
 63	void frametimer_object_t::test<2>()
 64	{
 65		F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
 66		seconds_since_epoch += 10.0;
 67		LLFrameTimer timer;
 68		timer.setExpiryAt(seconds_since_epoch);
 69		F64 expires_at = timer.expiresAt();
 70		ensure_distance(
 71			"set expiry matches get expiry 1",
 72			expires_at,
 73			seconds_since_epoch,
 74			0.001);
 75		seconds_since_epoch += 10.0;
 76		timer.setExpiryAt(seconds_since_epoch);
 77		expires_at = timer.expiresAt();
 78		ensure_distance(
 79			"set expiry matches get expiry 2",
 80			expires_at,
 81			seconds_since_epoch,
 82			0.001);
 83	}
 84	template<> template<>
 85	void frametimer_object_t::test<3>()
 86	{
 87		F64 seconds_since_epoch = LLFrameTimer::getTotalSeconds();
 88		seconds_since_epoch += 2.0;
 89		LLFrameTimer timer;
 90		timer.setExpiryAt(seconds_since_epoch);
 91		ensure("timer not expired on create", !timer.hasExpired());
 92		int ii;
 93		for(ii = 0; ii < 10; ++ii)
 94		{
 95			ms_sleep(150);
 96			LLFrameTimer::updateFrameTime();			
 97		}
 98		ensure("timer not expired after a bit", !timer.hasExpired());
 99		for(ii = 0; ii < 10; ++ii)
100		{
101			ms_sleep(100);
102			LLFrameTimer::updateFrameTime();			
103		}
104		ensure("timer expired", timer.hasExpired());
105	}
106/*
107	template<> template<>
108	void frametimer_object_t::test<4>()
109	{
110	}
111*/
112}