10 #include <gtest/gtest.h>
14 #include <ST_util/test_util.hpp>
15 #include "renderer_sdl.cpp"
16 #include <ST_util/string_util.hpp>
29 uint32_t wait_duration = 1500;
30 uint32_t fullscreen = 1;
32 SDL_Window *test_window{};
33 int16_t test_window_width = 0;
34 int16_t test_window_height = 0;
36 void SetUp()
override {
39 SDL_GetDisplayMode(0, 0, &DM);
40 test_window_width =
static_cast<int16_t
>(DM.w);
41 test_window_height =
static_cast<int16_t
>(DM.h);
43 test_window = SDL_CreateWindow(
"TEST", 0, 0, test_window_width, test_window_height, 0);
47 SDL_SetWindowFullscreen(test_window, fullscreen);
53 void TearDown()
override {
55 SDL_DestroyWindow(test_window);
62 for (uint32_t i = 0; i < wait_duration / 180; i++) {
65 }
else if (counter == 1) {
67 }
else if (counter == 2) {
69 }
else if (counter == 3) {
71 }
else if (counter == 4) {
73 }
else if (counter == 5) {
75 }
else if (counter == 6) {
90 SDL_Delay(wait_duration);
96 SDL_Delay(wait_duration);
102 SDL_Delay(wait_duration);
108 SDL_Delay(wait_duration);
114 SDL_Delay(wait_duration);
120 SDL_Delay(wait_duration);
124 SDL_Surface *test_surface = IMG_Load(
"test_image_2.png");
125 ASSERT_TRUE(
static_cast<bool>(test_surface));
126 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
127 test_assets[1] = test_surface;
131 SDL_Delay(wait_duration);
135 SDL_Surface *test_surface1 = IMG_Load(
"bg2_1.png");
136 SDL_Surface *test_surface2 = IMG_Load(
"bg2_3.png");
137 ASSERT_TRUE(
static_cast<bool>(test_surface1));
138 ASSERT_TRUE(
static_cast<bool>(test_surface2));
139 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
140 test_assets[0] = test_surface1;
141 test_assets[1] = test_surface2;
143 for (uint16_t i = 0; i < 1000; i++) {
144 for (uint8_t j = 0; j < 2; j++) {
152 SDL_Surface *test_surface = IMG_Load(
"test_image_1.png");
153 ASSERT_TRUE(
static_cast<bool>(test_surface));
154 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
155 test_assets[1] = test_surface;
159 SDL_Delay(wait_duration);
163 SDL_Surface *test_surface1 = IMG_Load(
"crate1.png");
164 SDL_Surface *test_surface2 = IMG_Load(
"fence.png");
165 ASSERT_TRUE(
static_cast<bool>(test_surface1));
166 ASSERT_TRUE(
static_cast<bool>(test_surface2));
167 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
168 test_assets[1] = test_surface1;
169 test_assets[2] = test_surface2;
174 SDL_Delay(wait_duration);
179 SDL_Surface *test_surface = IMG_Load(
"test_image_1.png");
180 ASSERT_TRUE(
static_cast<bool>(test_surface));
181 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
182 test_assets[1] = test_surface;
189 SDL_Delay(wait_duration);
193 uint8_t font_size = 20;
194 TTF_Font *test_font = TTF_OpenFont(
"test_font.ttf", font_size);
195 uint16_t font_hash = ST::hash_string(
"test_font.ttf " + std::to_string(font_size));
196 ASSERT_TRUE(
static_cast<bool>(test_font));
197 ska::bytell_hash_map<uint16_t, TTF_Font *> test_assets;
198 test_assets[font_hash] = test_font;
202 SDL_Delay(wait_duration);
206 uint8_t font_size = 50;
207 TTF_Font *test_font = TTF_OpenFont(
"test_font.ttf", font_size);
208 uint16_t font_hash = ST::hash_string(
"test_font.ttf " + std::to_string(font_size));
209 ASSERT_TRUE(
static_cast<bool>(test_font));
210 ska::bytell_hash_map<uint16_t, TTF_Font *> test_assets;
211 test_assets[font_hash] = test_font;
215 SDL_Delay(wait_duration);
219 uint8_t font_size = 90;
220 TTF_Font *test_font = TTF_OpenFont(
"test_font.ttf", font_size);
221 uint16_t font_hash = ST::hash_string(
"test_font.ttf " + std::to_string(font_size));
222 ASSERT_TRUE(
static_cast<bool>(test_font));
223 ska::bytell_hash_map<uint16_t, TTF_Font *> test_assets;
224 test_assets[font_hash] = test_font;
228 SDL_Delay(wait_duration);
232 uint8_t font_size = 20;
233 TTF_Font *test_font = TTF_OpenFont(
"test_font.ttf", font_size);
234 uint16_t font_hash = ST::hash_string(
"test_font.ttf " + std::to_string(font_size));
235 ASSERT_TRUE(
static_cast<bool>(test_font));
236 ska::bytell_hash_map<uint16_t, TTF_Font *> test_assets;
237 test_assets[font_hash] = test_font;
241 SDL_Delay(wait_duration);
245 uint8_t font_size = 50;
246 TTF_Font *test_font = TTF_OpenFont(
"test_font.ttf", font_size);
247 uint16_t font_hash = ST::hash_string(
"test_font.ttf " + std::to_string(font_size));
248 ASSERT_TRUE(
static_cast<bool>(test_font));
249 ska::bytell_hash_map<uint16_t, TTF_Font *> test_assets;
250 test_assets[font_hash] = test_font;
254 SDL_Delay(wait_duration);
258 uint8_t font_size = 90;
259 TTF_Font *test_font = TTF_OpenFont(
"test_font.ttf", font_size);
260 uint16_t font_hash = ST::hash_string(
"test_font.ttf " + std::to_string(font_size));
261 ASSERT_TRUE(
static_cast<bool>(test_font));
262 ska::bytell_hash_map<uint16_t, TTF_Font *> test_assets;
263 test_assets[font_hash] = test_font;
267 SDL_Delay(wait_duration);
271 SDL_Surface *test_surface = IMG_Load(
"test_sprite.png");
272 ASSERT_TRUE(
static_cast<bool>(test_surface));
273 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
274 test_assets[1] = test_surface;
276 for (uint32_t i = 0; i < wait_duration / 16; i++) {
277 uint32_t time = SDL_GetTicks() >> 7U;
286 SDL_Surface *test_surface = IMG_Load(
"test_sprite.png");
287 ASSERT_TRUE(
static_cast<bool>(test_surface));
288 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
289 test_assets[1] = test_surface;
291 for (uint32_t i = 0; i < wait_duration / 16; i++) {
292 uint32_t time = SDL_GetTicks() >> 7U;
301 SDL_Surface *test_surface = IMG_Load(
"test_sprite.png");
302 ASSERT_TRUE(
static_cast<bool>(test_surface));
303 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
304 test_assets[1] = test_surface;
306 for (uint32_t i = 0; i < wait_duration / 16; i++) {
307 uint32_t time = SDL_GetTicks() >> 7U;
318 SDL_Surface *test_surface = IMG_Load(
"test_overlay.png");
319 ASSERT_TRUE(
static_cast<bool>(test_surface));
320 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
321 test_assets[1] = test_surface;
323 for (uint32_t i = 0; i < wait_duration / 16; i++) {
324 uint32_t time = SDL_GetTicks() >> 7U;
337 SDL_Surface *test_surface1 = IMG_Load(
"atlas_test/1.png");
338 SDL_Surface *test_surface2 = IMG_Load(
"atlas_test/2.png");
339 SDL_Surface *test_surface3 = IMG_Load(
"atlas_test/3.png");
340 SDL_Surface *test_surface4 = IMG_Load(
"atlas_test/4.png");
341 SDL_Surface *test_surface5 = IMG_Load(
"atlas_test/5.png");
342 SDL_Surface *test_surface6 = IMG_Load(
"atlas_test/6.png");
343 SDL_Surface *test_surface7 = IMG_Load(
"atlas_test/7.png");
344 SDL_Surface *test_surface8 = IMG_Load(
"atlas_test/8.png");
345 SDL_Surface *test_surface9 = IMG_Load(
"atlas_test/9.png");
346 SDL_Surface *test_surface10 = IMG_Load(
"atlas_test/10.png");
347 SDL_Surface *test_surface11 = IMG_Load(
"atlas_test/11.png");
348 SDL_Surface *test_surface12 = IMG_Load(
"atlas_test/12.png");
349 SDL_Surface *test_surface13 = IMG_Load(
"atlas_test/13.png");
350 SDL_Surface *test_surface14 = IMG_Load(
"atlas_test/14.png");
351 SDL_Surface *test_surface15 = IMG_Load(
"atlas_test/15.png");
352 SDL_Surface *test_surface16 = IMG_Load(
"atlas_test/16.png");
353 SDL_Surface *test_surface17 = IMG_Load(
"atlas_test/17.png");
356 ASSERT_TRUE(
static_cast<bool>(test_surface1));
357 ASSERT_TRUE(
static_cast<bool>(test_surface2));
358 ASSERT_TRUE(
static_cast<bool>(test_surface3));
359 ASSERT_TRUE(
static_cast<bool>(test_surface4));
360 ASSERT_TRUE(
static_cast<bool>(test_surface5));
361 ASSERT_TRUE(
static_cast<bool>(test_surface6));
362 ASSERT_TRUE(
static_cast<bool>(test_surface7));
363 ASSERT_TRUE(
static_cast<bool>(test_surface8));
364 ASSERT_TRUE(
static_cast<bool>(test_surface9));
365 ASSERT_TRUE(
static_cast<bool>(test_surface10));
366 ASSERT_TRUE(
static_cast<bool>(test_surface11));
367 ASSERT_TRUE(
static_cast<bool>(test_surface12));
368 ASSERT_TRUE(
static_cast<bool>(test_surface13));
369 ASSERT_TRUE(
static_cast<bool>(test_surface14));
370 ASSERT_TRUE(
static_cast<bool>(test_surface15));
371 ASSERT_TRUE(
static_cast<bool>(test_surface16));
372 ASSERT_TRUE(
static_cast<bool>(test_surface17));
375 ska::bytell_hash_map<uint16_t, SDL_Surface *> test_assets;
376 test_assets[1] = test_surface1;
377 test_assets[2] = test_surface2;
378 test_assets[3] = test_surface3;
379 test_assets[4] = test_surface4;
380 test_assets[5] = test_surface5;
381 for (
int i = 0; i < 90 * 12; i += 17) {
382 test_assets[6 + i] = test_surface6;
383 test_assets[7 + i] = test_surface7;
384 test_assets[8 + i] = test_surface8;
385 test_assets[9 + i] = test_surface9;
386 test_assets[10 + i] = test_surface10;
387 test_assets[11 + i] = test_surface11;
388 test_assets[12 + i] = test_surface12;
389 test_assets[13 + i] = test_surface13;
390 test_assets[14 + i] = test_surface14;
391 test_assets[15 + i] = test_surface15;
392 test_assets[16 + i] = test_surface16;
393 test_assets[17 + i] = test_surface17;
397 SDL_Rect dst_rect = {0, 0, 1024, 1024};
398 SDL_RenderCopy(sdl_renderer, textures[1].atlas,
nullptr, &dst_rect);
403 int main(
int argc,
char **argv) {
404 ::testing::InitGoogleTest(&argc, argv);
405 return RUN_ALL_TESTS();
Tests fixture for the renderer_sdl.
uint16_t draw_text_lru_cached(uint16_t font, const std::string &arg2, int x, int y, SDL_Color color_font)
void upload_fonts(ska::bytell_hash_map< uint16_t, TTF_Font * > *fonts)
void upload_surfaces(ska::bytell_hash_map< uint16_t, SDL_Surface * > *surfaces)
void draw_overlay(uint16_t arg, uint8_t sprite, uint8_t sprite_num)
void draw_sprite_scaled(uint16_t arg, int32_t x, int32_t y, uint8_t sprite, uint8_t animation, uint8_t animation_num, uint8_t sprite_num, float scale_x, float scale_y)
void draw_sprite(uint16_t arg, int32_t x, int32_t y, uint8_t sprite, uint8_t animation, uint8_t animation_num, uint8_t sprite_num)
void clear_screen(SDL_Color color)
void draw_texture(uint16_t arg, int32_t x, int32_t y)
uint16_t draw_text_cached_glyphs(uint16_t font, const std::string &text, int x, int y, SDL_Color color_font)
void draw_background_parallax(uint16_t arg, uint16_t offset)
int8_t initialize(SDL_Window *win, int16_t width, int16_t height)
void draw_texture_scaled(uint16_t arg, int32_t x, int32_t y, float scale_x, float scale_y)
void draw_background(uint16_t arg)
void draw_rectangle(int32_t x, int32_t y, int32_t w, int32_t h, SDL_Color color)
void set_draw_color(uint8_t, uint8_t, uint8_t, uint8_t)
void draw_rectangle_filled(int32_t x, int32_t y, int32_t w, int32_t h, SDL_Color color)