The Battle for Wesnoth  1.17.0-dev
main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2021
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"
38 #include "gui/gui.hpp"
39 #include "config.hpp"
40 #include "log.hpp"
41 
43 #include "game_display.hpp"
44 /**
45  * @todo add all others exception handlers too
46  **/
47 
49 {
50  throw "config:error: " + e.message;
51 }
52 
54 {
55  throw "game::error: " + e.message;
56 }
57 
58 std::ofstream reporter;
59 
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());
70 
71 
72  // Initialize unit tests
73  SDL_Init(SDL_INIT_TIMER);
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  }
88  {
89  SDL_Quit();
90  }
91 };
92 
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_display & get_fake_display(const int width, const int height)
Gets a fake test display.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string get_cwd()
Definition: filesystem.cpp:879
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
void init()
Initializes the GUI subsystems.
Definition: gui.cpp:36
std::string path
Definition: game_config.cpp:39
void set_level(const std::string &value)
Definition: game.cpp:710
Declarations for File-IO.
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:28
Standard logging facilities (interface).
std::string message
Definition: exceptions.hpp:30
#define e
static void exception_translator_game(const game::error &e)
Definition: main.cpp:53
static void exception_translator_config(const config::error &e)
Definition: main.cpp:48
std::ofstream reporter
Definition: main.cpp:58