The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2016 by Karol Nowak <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 >= 106000
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 <SDL.h>
39 
40 #include "filesystem.hpp"
41 #include "game_config.hpp"
42 #include "game_errors.hpp"
44 #include "gui/widgets/helper.hpp"
45 #include "network.hpp"
46 #include "config.hpp"
47 #include "log.hpp"
48 
50 #include "game_display.hpp"
51 /**
52  * @todo add all others exception handlers too
53  **/
54 
56 {
57  throw "config:error: " + e.message;
58 }
59 
61 {
62  throw "network::error: " + e.message;
63 }
64 
65 
66 
68 {
69  throw "game::error: " + e.message;
70 }
71 
72 std::ofstream reporter;
73 
76  {
77  reporter.open("boost_test_result.xml");
78  assert( reporter.is_open() );
79 
80  boost::unit_test::results_reporter::set_stream(reporter);
81 // lg::set_log_domain_severity("all",lg::debug());
83 
84 
85  // Initialize unit tests
86  SDL_Init(SDL_INIT_TIMER);
88 
89  gui2::init();
90  static const gui2::event::tmanager gui_event_manager;
91 
92 
93 
94  // Set more report as default
95 #if BOOST_VERSION >= 106000
96  if (boost::unit_test::runtime_config::get<boost::unit_test::log_level>(boost::unit_test::runtime_config::LOG_LEVEL) == boost::unit_test::invalid_log_level)
97  boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
98  if (boost::unit_test::runtime_config::get<boost::unit_test::report_level>(boost::unit_test::runtime_config::REPORT_LEVEL) == boost::unit_test::INV_REPORT_LEVEL)
99  boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
100  boost::unit_test::unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
101  boost::unit_test::unit_test_monitor.register_exception_translator<network::error>(&exception_translator_network);
102  boost::unit_test::unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
103 #else
104  if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level)
105  boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
106  if (boost::unit_test::runtime_config::report_level() == boost::unit_test::INV_REPORT_LEVEL)
107  boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
108  boost::unit_test::unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
109  boost::unit_test::unit_test_monitor.register_exception_translator<network::error>(&exception_translator_network);
110  boost::unit_test::unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
111 #endif
112  }
114  {
115  SDL_Quit();
116  }
117 };
118 
120 
121 /*
122  * This is a main compilation unit for the test program.
123  * main() function is defined by the framework.
124  *
125  * Please don't put your tests in this file.
126  */
127 
128 /* vim: set ts=4 sw=4: */
129 
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()
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
std::string path
static void exception_translator_network(const network::error &e)
Definition: main.cpp:60
bool init()
Initializes the gui subsystems.
Definition: helper.cpp:37
void set_level(const std::string &value)
Declarations for File-IO.
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:27
Standard logging facilities (interface).
std::string message
Definition: exceptions.hpp:29
#define e
static void exception_translator_game(const game::error &e)
Definition: main.cpp:67
static void exception_translator_config(const config::error &e)
Definition: main.cpp:55
std::ofstream reporter
Definition: main.cpp:72