Fix size of fake screen

Unit tests (WML and C++ alike) require that the fake screen has nonzero
size. Thus, we again report a nonzero screen size with a fake screen.

Unfortunately, this didn't fix the unit test I was testing
(test_end_turn). The problem is that the null theme is returning that
the game area has zero size; however, I haven't found any differences
between 1.13 and master that would explain why the problem occurs in
master but not 1.13. I'll need to debug 1.13 separately later on...
This commit is contained in:
Jyrki Vesterinen 2018-03-20 20:54:29 +02:00
parent 239fde451a
commit e70a9c769d
3 changed files with 16 additions and 4 deletions

View file

@ -80,7 +80,7 @@ namespace test_utils {
fake_display_manager::get_manager()->get_display();
if(width >= 0 && height >= 0) {
display.video().make_test_fake();
display.video().make_test_fake(width, height);
}
return display;

View file

@ -51,6 +51,7 @@ CVideo::CVideo(FAKE_TYPES type)
, gl_context()
#endif
, fake_screen_(false)
, fake_size_(0u, 0u)
, help_string_(0)
, updated_locked_(0)
, flip_locked_(0)
@ -122,11 +123,14 @@ void CVideo::blit_surface(int x, int y, surface surf, SDL_Rect* srcrect, SDL_Rec
void CVideo::make_fake()
{
fake_screen_ = true;
fake_size_ = { 1024, 768 };
}
void CVideo::make_test_fake()
void CVideo::make_test_fake(const unsigned width, const unsigned height)
{
fake_interactive = true;
fake_size_.first = width;
fake_size_.second = height;
}
void CVideo::init_window()
@ -205,7 +209,9 @@ void CVideo::set_window_mode(const MODE_EVENT mode, const point& size)
SDL_Rect CVideo::screen_area(bool as_pixels) const
{
if(!window) {
return sdl::empty_rect;
return {0, 0,
static_cast<int>(fake_size_.first),
static_cast<int>(fake_size_.second)};
}
// First, get the renderer size in pixels.

View file

@ -22,6 +22,7 @@
#include <SDL_render.h>
#include <memory>
#include <utility>
class surface;
class texture;
@ -55,8 +56,11 @@ public:
/**
* Creates a fake frame buffer for the unit tests.
*
* @param width The width of the buffer.
* @param height The height of the buffer
*/
void make_test_fake();
void make_test_fake(const unsigned width = 1024, const unsigned height = 768);
bool faked() const
{
@ -258,6 +262,8 @@ private:
// if there is no display at all, but we 'fake' it for clients
bool fake_screen_;
std::pair<unsigned, unsigned> fake_size_;
/** Helper class to manage SDL events. */
class video_event_handler : public events::sdl_handler
{