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