mirror of https://github.com/OpenTTD/OpenTTD.git
Add: WindowDesc unit test to validate NWidgetPart lists.
This commit is contained in:
parent
1c94fb0389
commit
b1eb5533eb
|
@ -1,6 +1,7 @@
|
||||||
add_test_files(
|
add_test_files(
|
||||||
landscape_partial_pixel_z.cpp
|
landscape_partial_pixel_z.cpp
|
||||||
math_func.cpp
|
math_func.cpp
|
||||||
|
mock_environment.h
|
||||||
mock_fontcache.h
|
mock_fontcache.h
|
||||||
mock_spritecache.cpp
|
mock_spritecache.cpp
|
||||||
mock_spritecache.h
|
mock_spritecache.h
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* This file is part of OpenTTD.
|
||||||
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||||
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file mock_environment.h Singleton instance to create a mock FontCache/SpriteCache environment. */
|
||||||
|
|
||||||
|
#ifndef MOCK_ENVIRONMENT_H
|
||||||
|
#define MOCK_ENVIRONMENT_H
|
||||||
|
|
||||||
|
#include "mock_fontcache.h"
|
||||||
|
#include "mock_spritecache.h"
|
||||||
|
|
||||||
|
/** Singleton class to set up the mock environemnt once. */
|
||||||
|
class MockEnvironment {
|
||||||
|
public:
|
||||||
|
static MockEnvironment &Instance()
|
||||||
|
{
|
||||||
|
static MockEnvironment instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
MockEnvironment(MockEnvironment const &) = delete;
|
||||||
|
void operator=(MockEnvironment const &) = delete;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MockEnvironment()
|
||||||
|
{
|
||||||
|
/* Mock SpriteCache initialization is needed for some widget generators. */
|
||||||
|
MockGfxLoadSprites();
|
||||||
|
|
||||||
|
/* Mock FontCache initialization is needed for some NWidgetParts. */
|
||||||
|
MockFontCache::InitializeFontCaches();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* MOCK_ENVIRONMENT_H */
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include "../3rdparty/catch2/catch.hpp"
|
#include "../3rdparty/catch2/catch.hpp"
|
||||||
|
|
||||||
|
#include "mock_environment.h"
|
||||||
|
|
||||||
#include "../window_gui.h"
|
#include "../window_gui.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +21,13 @@
|
||||||
*/
|
*/
|
||||||
extern std::vector<WindowDesc*> *_window_descs;
|
extern std::vector<WindowDesc*> *_window_descs;
|
||||||
|
|
||||||
|
|
||||||
|
class WindowDescTestsFixture {
|
||||||
|
private:
|
||||||
|
MockEnvironment &mock = MockEnvironment::Instance();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("WindowDesc - ini_key uniqueness")
|
TEST_CASE("WindowDesc - ini_key uniqueness")
|
||||||
{
|
{
|
||||||
std::set<std::string> seen;
|
std::set<std::string> seen;
|
||||||
|
@ -73,3 +82,17 @@ TEST_CASE("WindowDesc - NWidgetParts properly closed")
|
||||||
|
|
||||||
CHECK(IsNWidgetTreeClosed(window_desc->nwid_begin, window_desc->nwid_end));
|
CHECK(IsNWidgetTreeClosed(window_desc->nwid_begin, window_desc->nwid_end));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_METHOD(WindowDescTestsFixture, "WindowDesc - NWidgetPart validity")
|
||||||
|
{
|
||||||
|
const WindowDesc *window_desc = GENERATE(from_range(std::begin(*_window_descs), std::end(*_window_descs)));
|
||||||
|
|
||||||
|
INFO(fmt::format("{}:{}", window_desc->file, window_desc->line));
|
||||||
|
|
||||||
|
int biggest_index = -1;
|
||||||
|
NWidgetStacked *shade_select = nullptr;
|
||||||
|
NWidgetBase *root = nullptr;
|
||||||
|
|
||||||
|
REQUIRE_NOTHROW(root = MakeWindowNWidgetTree(window_desc->nwid_begin, window_desc->nwid_end, &biggest_index, &shade_select));
|
||||||
|
CHECK((root != nullptr));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue