view tests/elapsedtimer/main.cpp @ 108:af84dd3d585b

Irccd: try to fix errors in timer tests, #486
author David Demelier <markand@malikania.fr>
date Wed, 27 Apr 2016 13:07:21 +0200
parents 1125d90b3b44
children 6635b9187d71
line wrap: on
line source

/*
 * main.cpp -- test ElapsedTimer
 *
 * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <thread>

#include <gtest/gtest.h>

#include <irccd/elapsed-timer.hpp>

using namespace irccd;
using namespace std::chrono_literals;

TEST(TestElapsedTimer, standard)
{
	ElapsedTimer timer;

	std::this_thread::sleep_for(300ms);

	ASSERT_GE(timer.elapsed(), 250U);
	ASSERT_LE(timer.elapsed(), 350U);
}

TEST(TestElapsedTimer, reset)
{
	ElapsedTimer timer;

	std::this_thread::sleep_for(300ms);

	timer.reset();

	ASSERT_LE(timer.elapsed(), 100U);
}

int main(int argc, char **argv)
{
	testing::InitGoogleTest(&argc, argv);

	return RUN_ALL_TESTS();
}