The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
tests
main.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2007 - 2025
3
by Karol Nowak <grywacz@gmail.com>
4
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY.
12
13
See the COPYING file for more details.
14
*/
15
16
#define GETTEXT_DOMAIN "wesnoth-test"
17
18
19
#define BOOST_TEST_MODULE wesnoth unit tests master suite
20
21
#ifndef BOOST_TEST_DYN_LINK
22
#error Compiler misconfiguration - must define BOOST_TEST_DYN_LINK
23
#endif
24
25
#include <boost/test/unit_test.hpp>
26
#include <boost/test/unit_test_monitor.hpp>
27
#include <boost/test/unit_test_parameters.hpp>
28
#include <boost/test/results_reporter.hpp>
29
#include <boost/filesystem/path.hpp>
30
31
#include <fstream>
32
33
#include <SDL3/SDL.h>
34
35
#include "
events.hpp
"
36
#include "
filesystem.hpp
"
37
#include "
game_config.hpp
"
38
#include "
game_errors.hpp
"
39
#include "
gui/core/event/handler.hpp
"
40
#include "
gui/gui.hpp
"
41
#include "
config.hpp
"
42
#include "
log.hpp
"
43
44
#include "
tests/utils/fake_display.hpp
"
45
#include "
game_display.hpp
"
46
/**
47
* @todo add all others exception handlers too
48
**/
49
50
static
void
exception_translator_config
(
const
config::error
&
e
)
51
{
52
throw
"config:error: "
+
e
.message;
53
}
54
55
static
void
exception_translator_game
(
const
game::error
&
e
)
56
{
57
throw
"game::error: "
+
e
.message;
58
}
59
60
std::ofstream
reporter
;
61
62
struct
wesnoth_global_fixture
{
63
wesnoth_global_fixture
()
64
{
65
using namespace
boost::unit_test;
66
using namespace
std::literals;
67
events::set_main_thread
();
68
boost::filesystem::path file(
"boost_test_result.xml"
);
69
for
(
int
i
= 1;
i
< framework::master_test_suite().argc;
i
++) {
70
if
(framework::master_test_suite().argv[
i
- 1] ==
"--output_file"
s
) {
71
file = framework::master_test_suite().argv[
i
];
72
break
;
73
}
74
}
75
76
reporter
.open(file.string());
77
assert(
reporter
.is_open() );
78
79
results_reporter::set_stream(
reporter
);
80
// lg::set_log_domain_severity("all",lg::debug());
81
game_config::path
=
filesystem::get_cwd
();
82
filesystem::set_user_data_dir
(std::string());
83
84
// declare this here so that it will always be at the front of the event queue.
85
events::event_context
global_context;
86
87
// Initialize unit tests
88
test_utils::set_test_resolution
(1024, 768);
89
90
gui2::init
();
91
gui2::switch_theme
(
"default"
);
92
static
const
gui2::event::manager
gui_event_manager;
93
94
// TODO: For some reason this fails on MacOS and prevents any tests from running
95
// It's not crucial to change the log levels though, so just skip over it.
96
#ifndef __APPLE__
97
// Set more report as default
98
if
(runtime_config::get<log_level>(runtime_config::btrt_log_level) == invalid_log_level)
99
unit_test_log.set_threshold_level(log_messages);
100
if
(runtime_config::get<report_level>(runtime_config::btrt_report_level) == INV_REPORT_LEVEL)
101
results_reporter::set_level(SHORT_REPORT);
102
#endif
103
unit_test_monitor.register_exception_translator<
game::error
>(&
exception_translator_game
);
104
unit_test_monitor.register_exception_translator<
config::error
>(&
exception_translator_config
);
105
}
106
~wesnoth_global_fixture
()
107
{
108
SDL_Quit();
109
}
110
};
111
112
BOOST_GLOBAL_FIXTURE
(
wesnoth_global_fixture
);
113
114
/*
115
* This is a main compilation unit for the test program.
116
* main() function is defined by the framework.
117
*
118
* Please don't put your tests in this file.
119
*/
120
121
/* vim: set ts=4 sw=4: */
gui2::event::manager
Definition
handler.hpp:31
config.hpp
Definitions for the interface to Wesnoth Markup Language (WML).
events.hpp
fake_display.hpp
filesystem.hpp
Declarations for File-IO.
game_config.hpp
game_display.hpp
game_errors.hpp
gui.hpp
handler.hpp
log.hpp
Standard logging facilities (interface).
reporter
std::ofstream reporter
Definition
main.cpp:60
exception_translator_game
static void exception_translator_game(const game::error &e)
Definition
main.cpp:55
exception_translator_config
static void exception_translator_config(const config::error &e)
Definition
main.cpp:50
BOOST_GLOBAL_FIXTURE
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
events::set_main_thread
void set_main_thread()
Definition
events.cpp:468
filesystem::set_user_data_dir
void set_user_data_dir(std::string path)
filesystem::get_cwd
std::string get_cwd()
game_config::path
std::string path
Definition
filesystem.cpp:106
gui2::init
void init()
Initializes the GUI subsystems.
Definition
gui.cpp:108
gui2::switch_theme
void switch_theme(const std::string &theme_id)
Set and activate the given gui2 theme.
Definition
gui.cpp:149
test_utils::set_test_resolution
void set_test_resolution(const int width, const int height)
Sets the dummy display resolution for use by the tests.
Definition
fake_display.cpp:41
config::error
Definition
config.hpp:626
events::event_context
Definition
events.hpp:144
game::error
Base class for all the errors encountered by the engine.
Definition
exceptions.hpp:29
wesnoth_global_fixture
Definition
main.cpp:62
wesnoth_global_fixture::~wesnoth_global_fixture
~wesnoth_global_fixture()
Definition
main.cpp:106
wesnoth_global_fixture::wesnoth_global_fixture
wesnoth_global_fixture()
Definition
main.cpp:63
s
static map_location::direction s
Definition
test_map_location.cpp:28
i
#define i
e
#define e
Generated by
1.9.8