The Battle for Wesnoth  1.19.6+dev
main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2024
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 #include <boost/filesystem/path.hpp>
30 
31 #include <fstream>
32 
33 #include <SDL2/SDL.h>
34 
35 #include "filesystem.hpp"
36 #include "game_config.hpp"
37 #include "game_errors.hpp"
39 #include "gui/gui.hpp"
40 #include "config.hpp"
41 #include "log.hpp"
42 
44 #include "game_display.hpp"
45 /**
46  * @todo add all others exception handlers too
47  **/
48 
50 {
51  throw "config:error: " + e.message;
52 }
53 
55 {
56  throw "game::error: " + e.message;
57 }
58 
59 std::ofstream reporter;
60 
63  {
64  using namespace boost::unit_test;
65  using namespace std::literals;
66  boost::filesystem::path file("boost_test_result.xml");
67  for(int i = 1; i < framework::master_test_suite().argc; i++) {
68  if(framework::master_test_suite().argv[i - 1] == "--output_file"s) {
69  file = framework::master_test_suite().argv[i];
70  break;
71  }
72  }
73 
74  reporter.open(file.string());
75  assert( reporter.is_open() );
76 
77  results_reporter::set_stream(reporter);
78 // lg::set_log_domain_severity("all",lg::debug());
80  filesystem::set_user_data_dir(std::string());
81 
82  // declare this here so that it will always be at the front of the event queue.
83  events::event_context global_context;
84 
85  // Initialize unit tests
86  SDL_Init(SDL_INIT_TIMER);
88 
89  gui2::init();
90  gui2::switch_theme("default");
91  static const gui2::event::manager gui_event_manager;
92 
93  // TODO: For some reason this fails on MacOS and prevents any tests from running
94  // It's not crucial to change the log levels though, so just skip over it.
95 #ifndef __APPLE__
96  // Set more report as default
97  if(runtime_config::get<log_level>(runtime_config::btrt_log_level) == invalid_log_level)
98  unit_test_log.set_threshold_level(log_messages);
99  if(runtime_config::get<report_level>(runtime_config::btrt_report_level) == INV_REPORT_LEVEL)
100  results_reporter::set_level(SHORT_REPORT);
101 #endif
102  unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
103  unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
104  }
106  {
107  SDL_Quit();
108  }
109 };
110 
112 
113 /*
114  * This is a main compilation unit for the test program.
115  * main() function is defined by the framework.
116  *
117  * Please don't put your tests in this file.
118  */
119 
120 /* vim: set ts=4 sw=4: */
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
std::size_t i
Definition: function.cpp:1029
Standard logging facilities (interface).
std::ofstream reporter
Definition: main.cpp:59
static void exception_translator_game(const game::error &e)
Definition: main.cpp:54
static void exception_translator_config(const config::error &e)
Definition: main.cpp:49
BOOST_GLOBAL_FIXTURE(wesnoth_global_fixture)
std::string get_cwd()
Definition: filesystem.cpp:920
void set_user_data_dir(std::string newprefdir)
Definition: filesystem.cpp:721
std::string path
Definition: filesystem.cpp:91
void init()
Initializes the GUI subsystems.
Definition: gui.cpp:34
void switch_theme(const std::string &current_theme)
Set and activate the given gui2 theme.
Definition: gui.cpp:135
game_display & get_fake_display(const int width, const int height)
Gets a fake test display.
Base class for all the errors encountered by the engine.
Definition: exceptions.hpp:29
static map_location::direction s
#define e