The Battle for Wesnoth  1.15.2+dev
main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2018 by Karol Nowak <grywacz@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-test"
16 
17 
18 #define BOOST_TEST_MODULE wesnoth unit tests master suite
19 
20 #ifndef BOOST_TEST_DYN_LINK
21 #error Compiler misconfiguration - must define BOOST_TEST_DYN_LINK
22 #endif
23 
24 #include <boost/version.hpp>
25 
26 #include <boost/test/unit_test.hpp>
27 #include <boost/test/unit_test_monitor.hpp>
28 #if BOOST_VERSION >= 105900
29 #include <boost/test/unit_test_parameters.hpp>
30 #else
31 #include <boost/test/detail/unit_test_parameters.hpp>
32 #endif
33 #include <boost/test/results_reporter.hpp>
34 
35 
36 #include <fstream>
37 
38 #include <SDL2/SDL.h>
39 
40 #include "filesystem.hpp"
41 #include "game_config.hpp"
42 #include "game_errors.hpp"
44 #include "gui/gui.hpp"
45 #include "config.hpp"
46 #include "log.hpp"
47 
49 #include "game_display.hpp"
50 /**
51  * @todo add all others exception handlers too
52  **/
53 
55 {
56  throw "config:error: " + e.message;
57 }
58 
60 {
61  throw "game::error: " + e.message;
62 }
63 
64 std::ofstream reporter;
65 
68  {
69  using namespace boost::unit_test;
70  reporter.open("boost_test_result.xml");
71  assert( reporter.is_open() );
72 
73  results_reporter::set_stream(reporter);
74 // lg::set_log_domain_severity("all",lg::debug());
76 
77 
78  // Initialize unit tests
79  SDL_Init(SDL_INIT_TIMER);
81 
82  gui2::init();
83  static const gui2::event::manager gui_event_manager;
84 
85 
86 
87  // Set more report as default
88 #if BOOST_VERSION >= 106400
89  if(runtime_config::get<log_level>(runtime_config::btrt_log_level) == invalid_log_level)
90  unit_test_log.set_threshold_level(log_messages);
91  if(runtime_config::get<report_level>(runtime_config::btrt_report_level) == INV_REPORT_LEVEL)
92  results_reporter::set_level(SHORT_REPORT);
93  unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
94  unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
95 #elif BOOST_VERSION >= 106000
96  if(runtime_config::get<log_level>(runtime_config::LOG_LEVEL) == invalid_log_level)
97  unit_test_log.set_threshold_level(log_messages);
98  if(runtime_config::get<report_level>(runtime_config::REPORT_LEVEL) == INV_REPORT_LEVEL)
99  results_reporter::set_level(SHORT_REPORT);
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 #else
103  if(runtime_config::log_level() == invalid_log_level)
104  unit_test_log.set_threshold_level(log_messages);
105  if(runtime_config::report_level() == INV_REPORT_LEVEL)
106  results_reporter::set_level(SHORT_REPORT);
107  unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
108  unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
109 #endif
110  }
112  {
113  SDL_Quit();
114  }
115 };
116 
118 
119 /*
120  * This is a main compilation unit for the test program.
121  * main() function is defined by the framework.
122  *
123  * Please don't put your tests in this file.
124  */
125 
126 /* 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:881
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
void init()
Initializes the GUI subsystems.
Definition: gui.cpp:35
std::string path
Definition: game_config.cpp:39
void set_level(const std::string &value)
Definition: game.cpp:738
Declarations for File-IO.
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
Standard logging facilities (interface).
std::string message
Definition: exceptions.hpp:31
#define e
static void exception_translator_game(const game::error &e)
Definition: main.cpp:59
static void exception_translator_config(const config::error &e)
Definition: main.cpp:54
std::ofstream reporter
Definition: main.cpp:64