-
Notifications
You must be signed in to change notification settings - Fork 0
/
fps_test.cpp
50 lines (46 loc) · 1.06 KB
/
fps_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
45
46
47
48
49
50
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "fps.hpp"
#include <gtest/gtest.h>
#include <SDL.h>
class FpsTest : public ::testing::Test
{
protected:
SDL_Window *window_;
SDL_Renderer *renderer_;
void SetUp()
{
window_ = NULL;
renderer_ = NULL;
int ret = SDL_Init(SDL_INIT_TIMER);
ASSERT_EQ(0, ret);
window_ = SDL_CreateWindow("TextureTest", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 10, 10, 0);
ASSERT_TRUE(window_ != NULL);
renderer_ = SDL_CreateRenderer(window_, -1, 0);
ASSERT_TRUE(renderer_ != NULL);
}
void TearDown()
{
SDL_DestroyRenderer(renderer_);
renderer_ = NULL;
SDL_DestroyWindow(window_);
window_ = NULL;
SDL_Quit();
}
};
TEST_F(FpsTest, update)
{
FPS fps;
fps.next_ticks = SDL_GetTicks() + 1000;
for (int i = 0; i < 9; ++i) {
SDL_Delay(100);
fps.update();
EXPECT_EQ(static_cast<uint32_t>(i + 1), fps.frames);
EXPECT_EQ(0U, fps.latest_frames);
}
SDL_Delay(100 + 50);
fps.update();
EXPECT_EQ(0U, fps.frames);
EXPECT_EQ(10U, fps.latest_frames);
}