The Battle for Wesnoth
1.17.4+dev
tests
main.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2007 - 2022
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
30
#include <fstream>
31
32
#include <SDL2/SDL.h>
33
34
#include "
filesystem.hpp
"
35
#include "
game_config.hpp
"
36
#include "
game_errors.hpp
"
37
#include "
gui/core/event/handler.hpp
"
38
#include "
gui/gui.hpp
"
39
#include "
config.hpp
"
40
#include "
log.hpp
"
41
42
#include "
tests/utils/fake_display.hpp
"
43
#include "
game_display.hpp
"
44
/**
45
* @todo add all others exception handlers too
46
**/
47
48
static
void
exception_translator_config
(
const
config::error
&
e
)
49
{
50
throw
"config:error: "
+ e.
message
;
51
}
52
53
static
void
exception_translator_game
(
const
game::error
&
e
)
54
{
55
throw
"game::error: "
+ e.
message
;
56
}
57
58
std::ofstream
reporter
;
59
60
struct
wesnoth_global_fixture
{
61
wesnoth_global_fixture
()
62
{
63
using namespace
boost::unit_test;
64
reporter
.open(
"boost_test_result.xml"
);
65
assert(
reporter
.is_open() );
66
67
results_reporter::set_stream(
reporter
);
68
// lg::set_log_domain_severity("all",lg::debug());
69
game_config::path
=
filesystem::get_cwd
();
70
71
72
// Initialize unit tests
73
SDL_Init(SDL_INIT_TIMER);
74
test_utils::get_fake_display
(1024, 768);
75
76
gui2::init
();
77
static
const
gui2::event::manager
gui_event_manager;
78
79
// Set more report as default
80
if
(runtime_config::get<log_level>(runtime_config::btrt_log_level) == invalid_log_level)
81
unit_test_log.set_threshold_level(log_messages);
82
if
(runtime_config::get<report_level>(runtime_config::btrt_report_level) == INV_REPORT_LEVEL)
83
results_reporter::set_level
(SHORT_REPORT);
84
unit_test_monitor.register_exception_translator<
game::error
>(&
exception_translator_game
);
85
unit_test_monitor.register_exception_translator<
config::error
>(&
exception_translator_config
);
86
}
87
~wesnoth_global_fixture
()
88
{
89
SDL_Quit();
90
}
91
};
92
93
BOOST_GLOBAL_FIXTURE
(
wesnoth_global_fixture
);
94
95
/*
96
* This is a main compilation unit for the test program.
97
* main() function is defined by the framework.
98
*
99
* Please don't put your tests in this file.
100
*/
101
102
/* vim: set ts=4 sw=4: */
game_config.hpp
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
wesnoth_global_fixture::~wesnoth_global_fixture
~wesnoth_global_fixture()
Definition:
main.cpp:87
game_display.hpp
config.hpp
Definitions for the interface to Wesnoth Markup Language (WML).
game_errors.hpp
filesystem::get_cwd
std::string get_cwd()
Definition:
filesystem.cpp:879
wesnoth_global_fixture
Definition:
main.cpp:60
BOOST_GLOBAL_FIXTURE
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
fake_display.hpp
gui2::init
void init()
Initializes the GUI subsystems.
Definition:
gui.cpp:36
gui2::event::manager
Definition:
handler.hpp:30
game_config::path
std::string path
Definition:
game_config.cpp:39
preferences::set_level
void set_level(const std::string &value)
Definition:
game.cpp:703
wesnoth_global_fixture::wesnoth_global_fixture
wesnoth_global_fixture()
Definition:
main.cpp:61
handler.hpp
gui.hpp
filesystem.hpp
Declarations for File-IO.
game::error
Base class for all the errors encountered by the engine.
Definition:
exceptions.hpp:28
log.hpp
Standard logging facilities (interface).
game::error::message
std::string message
Definition:
exceptions.hpp:30
e
#define e
config::error
Definition:
config.hpp:582
exception_translator_game
static void exception_translator_game(const game::error &e)
Definition:
main.cpp:53
exception_translator_config
static void exception_translator_config(const config::error &e)
Definition:
main.cpp:48
reporter
std::ofstream reporter
Definition:
main.cpp:58
Generated by
1.8.13