The Battle for Wesnoth
1.17.23+dev
tests
main.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2007 - 2023
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 <SDL2/SDL.h>
34
35
#include "
filesystem.hpp
"
36
#include "
game_config.hpp
"
37
#include "
game_errors.hpp
"
38
#include "
gui/core/event/handler.hpp
"
39
#include "
gui/gui.hpp
"
40
#include "
config.hpp
"
41
#include "
log.hpp
"
42
43
#include "
tests/utils/fake_display.hpp
"
44
#include "
game_display.hpp
"
45
/**
46
* @todo add all others exception handlers too
47
**/
48
49
static
void
exception_translator_config
(
const
config::error
&
e
)
50
{
51
throw
"config:error: "
+
e
.message;
52
}
53
54
static
void
exception_translator_game
(
const
game::error
&
e
)
55
{
56
throw
"game::error: "
+
e
.message;
57
}
58
59
std::ofstream
reporter
;
60
61
struct
wesnoth_global_fixture
{
62
wesnoth_global_fixture
()
63
{
64
using namespace
boost::unit_test;
65
using namespace
std::literals;
66
boost::filesystem::path
file(
"boost_test_result.xml"
);
67
for
(
int
i
= 1;
i
< framework::master_test_suite().argc;
i
++) {
68
if
(framework::master_test_suite().argv[
i
- 1] ==
"--output_file"
s
) {
69
file = framework::master_test_suite().argv[
i
];
70
break
;
71
}
72
}
73
74
reporter
.open(file.string());
75
assert(
reporter
.is_open() );
76
77
results_reporter::set_stream(
reporter
);
78
// lg::set_log_domain_severity("all",lg::debug());
79
game_config::path
=
filesystem::get_cwd
();
80
81
// declare this here so that it will always be at the front of the event queue.
82
events::event_context
global_context;
83
84
// Initialize unit tests
85
SDL_Init(SDL_INIT_TIMER);
86
test_utils::get_fake_display
(1024, 768);
87
88
gui2::init
();
89
static
const
gui2::event::manager
gui_event_manager;
90
91
// TODO: For some reason this fails on MacOS and prevents any tests from running
92
// It's not crucial to change the log levels though, so just skip over it.
93
#ifndef __APPLE__
94
// Set more report as default
95
if
(runtime_config::get<log_level>(runtime_config::btrt_log_level) == invalid_log_level)
96
unit_test_log.set_threshold_level(log_messages);
97
if
(runtime_config::get<report_level>(runtime_config::btrt_report_level) == INV_REPORT_LEVEL)
98
results_reporter::set_level
(SHORT_REPORT);
99
#endif
100
unit_test_monitor.register_exception_translator<
game::error
>(&
exception_translator_game
);
101
unit_test_monitor.register_exception_translator<
config::error
>(&
exception_translator_config
);
102
}
103
~wesnoth_global_fixture
()
104
{
105
SDL_Quit();
106
}
107
};
108
109
BOOST_GLOBAL_FIXTURE
(
wesnoth_global_fixture
);
110
111
/*
112
* This is a main compilation unit for the test program.
113
* main() function is defined by the framework.
114
*
115
* Please don't put your tests in this file.
116
*/
117
118
/* vim: set ts=4 sw=4: */
gui2::event::manager
Definition:
handler.hpp:31
fake_display.hpp
filesystem.hpp
Declarations for File-IO.
i
std::size_t i
Definition:
function.cpp:968
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:59
exception_translator_game
static void exception_translator_game(const game::error &e)
Definition:
main.cpp:54
exception_translator_config
static void exception_translator_config(const config::error &e)
Definition:
main.cpp:49
BOOST_GLOBAL_FIXTURE
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
filesystem::get_cwd
std::string get_cwd()
Definition:
filesystem.cpp:963
game_config::path
std::string path
Definition:
filesystem.cpp:86
gui2::init
void init()
Initializes the GUI subsystems.
Definition:
gui.cpp:36
preferences::set_level
void set_level(const std::string &value)
Definition:
game.cpp:696
test_utils::get_fake_display
game_display & get_fake_display(const int width, const int height)
Gets a fake test display.
Definition:
fake_display.cpp:79
config::error
Definition:
config.hpp:670
events::event_context
Definition:
events.hpp:138
game::error
Base class for all the errors encountered by the engine.
Definition:
exceptions.hpp:29
wesnoth_global_fixture
Definition:
main.cpp:61
wesnoth_global_fixture::~wesnoth_global_fixture
~wesnoth_global_fixture()
Definition:
main.cpp:103
wesnoth_global_fixture::wesnoth_global_fixture
wesnoth_global_fixture()
Definition:
main.cpp:62
s
static map_location::DIRECTION s
Definition:
test_map_location.cpp:28
config.hpp
e
#define e
Generated by
1.9.1