The Battle for Wesnoth  1.15.12+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/test/unit_test.hpp>
25 #include <boost/test/unit_test_monitor.hpp>
26 #include <boost/test/unit_test_parameters.hpp>
27 #include <boost/test/results_reporter.hpp>
28 
29 #include <fstream>
30 
31 #include <SDL2/SDL.h>
32 
33 #include "filesystem.hpp"
34 #include "game_config.hpp"
35 #include "game_errors.hpp"
37 #include "gui/gui.hpp"
38 #include "config.hpp"
39 #include "log.hpp"
40 
42 #include "game_display.hpp"
43 /**
44  * @todo add all others exception handlers too
45  **/
46 
48 {
49  throw "config:error: " + e.message;
50 }
51 
53 {
54  throw "game::error: " + e.message;
55 }
56 
57 std::ofstream reporter;
58 
61  {
62  using namespace boost::unit_test;
63  reporter.open("boost_test_result.xml");
64  assert( reporter.is_open() );
65 
66  results_reporter::set_stream(reporter);
67 // lg::set_log_domain_severity("all",lg::debug());
69 
70 
71  // Initialize unit tests
72  SDL_Init(SDL_INIT_TIMER);
74 
75  gui2::init();
76  static const gui2::event::manager gui_event_manager;
77 
78  // Set more report as default
79  if(runtime_config::get<log_level>(runtime_config::btrt_log_level) == invalid_log_level)
80  unit_test_log.set_threshold_level(log_messages);
81  if(runtime_config::get<report_level>(runtime_config::btrt_report_level) == INV_REPORT_LEVEL)
82  results_reporter::set_level(SHORT_REPORT);
83  unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
84  unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
85  }
87  {
88  SDL_Quit();
89  }
90 };
91 
93 
94 /*
95  * This is a main compilation unit for the test program.
96  * main() function is defined by the framework.
97  *
98  * Please don't put your tests in this file.
99  */
100 
101 /* 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:876
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
void init()
Initializes the GUI subsystems.
Definition: gui.cpp:35
std::string path
Definition: game_config.cpp:38
void set_level(const std::string &value)
Definition: game.cpp:704
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:52
static void exception_translator_config(const config::error &e)
Definition: main.cpp:47
std::ofstream reporter
Definition: main.cpp:57