-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_time_test.cpp
44 lines (41 loc) · 1.1 KB
/
load_time_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "load_time.hpp"
#include <gtest/gtest.h>
#define ASSERT_TIME(a, b) { \
static const double base = LoadTime::TIME_BASE_SEC; \
static const double base_ms = LoadTime::TIME_BASE_MILLISEC; \
EXPECT_NEAR(a, b / base, 1.0 / (base / base_ms) * (1000.0 / 60)); \
}
TEST(LoadTimeTest, elapsed_time)
{
LoadTime lt;
lt.activate(0);
lt.start(0);
usleep(10000);
lt.stop(0);
lt.flip();
ASSERT_TIME(0.01f, lt.elapsed_time(0));
}
TEST(LoadTimeTest, activate)
{
LoadTime lt;
lt.start(0); usleep(10000); lt.stop(0);
lt.start(1); usleep(10000); lt.stop(1);
lt.flip();
ASSERT_TIME(0.0, lt.elapsed_time(0));
ASSERT_TIME(0.0, lt.elapsed_time(1));
lt.activate(0);
lt.start(0); usleep(10000); lt.stop(0);
lt.start(1); usleep(10000); lt.stop(1);
lt.flip();
ASSERT_TIME(0.01, lt.elapsed_time(0));
ASSERT_TIME(0.0, lt.elapsed_time(1));
lt.activate(1);
lt.start(0); usleep(10000); lt.stop(0);
lt.start(1); usleep(10000); lt.stop(1);
lt.flip();
ASSERT_TIME(0.01, lt.elapsed_time(0));
ASSERT_TIME(0.01, lt.elapsed_time(1));
}