Selaa lähdekoodia

Adding test for timer

legacy
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> 8 vuotta sitten
vanhempi
commit
15d3a82b5c
3 muutettua tiedostoa jossa 55 lisäystä ja 3 poistoa
  1. +5
    -2
      src/lol/sys/timer.h
  2. +1
    -1
      src/t/Makefile.am
  3. +49
    -0
      src/t/sys/timer.cpp

+ 5
- 2
src/lol/sys/timer.h Näytä tiedosto

@@ -37,10 +37,13 @@ private:

float GetSeconds(bool reset)
{
std::chrono::steady_clock::time_point tp, tp0 = m_tp;
tp = std::chrono::steady_clock::now();
std::chrono::steady_clock::time_point
tp = std::chrono::steady_clock::now(),
tp0 = m_tp;

if (reset)
m_tp = tp;

return std::chrono::duration_cast<std::chrono::duration<float>>(tp - tp0).count();
}



+ 1
- 1
src/t/Makefile.am Näytä tiedosto

@@ -28,7 +28,7 @@ test_math_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit
test_math_DEPENDENCIES = @LOL_DEPS@

test_sys_SOURCES = test-common.cpp \
sys/thread.cpp
sys/thread.cpp sys/timer.cpp
test_sys_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit
test_sys_DEPENDENCIES = @LOL_DEPS@



+ 49
- 0
src/t/sys/timer.cpp Näytä tiedosto

@@ -0,0 +1,49 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2014—2015 Guillaume Bittoun <guillaume.bittoun@gmail.com>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#include <lol/engine-internal.h>

#include <lolunit.h>

#include <iostream>
namespace lol
{

lolunit_declare_fixture(timer_test)
{
void setup()
{
}

void teardown()
{
}

lolunit_declare_test(timers)
{
Timer timer0, timer1;

timer0.Wait(1.5);

float t0 = timer1.Poll();
float t1 = timer1.Get();
lolunit_assert_doubles_equal(t0, t1, 1e-5);
lolunit_assert_doubles_equal(1.5, t1, 1e-3);

timer1.Wait(1.5);
lolunit_assert_doubles_equal(3.0, timer0.Get(), 1e-3);
}
};

}

Ladataan…
Peruuta
Tallenna